-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCodeChampion.py
73 lines (64 loc) · 2.07 KB
/
CodeChampion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import glob
import random
import sublime, sublime_plugin,wave
from subprocess import call
from .libs.decorators import thread
try:
import winsound
except Exception:
pass
SETTING_NAME = "CodeChampion.sublime-settings"
class PlaySound():
platform = sublime.platform()
soundType = 'win'
is_playing = False
def play(self):
if(self.platform == 'osx'):
self.osx_play()
elif(self.platform == 'windows'):
self.windows_play()
elif(self.platform == 'linux'):
self.linux_play()
@thread
def osx_play(self):
if(self.is_playing == False):
volume = sublime.load_settings(SETTING_NAME).get('mac_osx_volume')
self.is_playing = True
soundFilePath = self.get_sound_file_path(self.soundType)
call(["afplay", "-v", str(volume), soundFilePath])
self.is_playing = False
@thread
def windows_play(self):
if(self.is_playing == False):
self.is_playing = True
soundFilePath = self.get_sound_file_path(self.soundType)
winsound.PlaySound(soundFilePath, winsound.SND_FILENAME | winsound.SND_ASYNC | winsound.SND_NODEFAULT)
self.is_playing = False
@thread
def linux_play(self):
if(self.is_playing == False):
self.is_playing = True
soundFilePath = self.get_sound_file_path(self.soundType)
call(["aplay", soundFilePath])
self.is_playing = False
def get_sound_file_path(self, soundType):
soundFilePath = ''
soundFile = sublime.load_settings(SETTING_NAME).get(soundType)
baseDirectory = os.path.join(sublime.packages_path(), 'Code Champion', 'sounds', soundType)
if soundFile == 'Random':
allSoundFiles = glob.glob(os.path.join(baseDirectory, '*'))
soundFilePath = random.choice(allSoundFiles)
else:
soundFilePath = os.path.join(baseDirectory, soundFile)
return soundFilePath
class PlaychampionCommand(sublime_plugin.TextCommand):
is_playing = False
player = PlaySound()
def run(self, edit, type):
self.player.soundType = type
self.player.play()
class ChangesoundCommand(sublime_plugin.TextCommand):
def run(self, edit, sound, type):
sublime.load_settings(SETTING_NAME).set(type, sound)
sublime.save_settings(SETTING_NAME)