Revision 4d2b7a46
Added by Vincent Le Goff over 4 years ago
src/client.py | ||
---|---|---|
32 | 32 |
|
33 | 33 |
""" |
34 | 34 |
|
35 |
import os |
|
35 | 36 |
import re |
36 | 37 |
from telnetlib import Telnet, WONT, WILL, ECHO |
37 | 38 |
import threading |
... | ... | |
104 | 105 |
if self.client: |
105 | 106 |
self.client.set_option_negotiation_callback(self.handle_option) |
106 | 107 |
|
108 |
def load_script(self, world): |
|
109 |
"""Load the config.set script.""" |
|
110 |
path = world.path |
|
111 |
path = os.path.join(path, "config.set") |
|
112 |
if os.path.exists(path): |
|
113 |
file = open(path, "r") |
|
114 |
content = file.read() |
|
115 |
file.close() |
|
116 |
|
|
117 |
# Execute the script |
|
118 |
self.sharp_engine.execute(content) |
|
119 |
|
|
107 | 120 |
def link_window(self, window): |
108 | 121 |
"""Link to a window (a GUI object). |
109 | 122 |
|
... | ... | |
116 | 129 |
""" |
117 | 130 |
self.window = window |
118 | 131 |
window.client = self |
132 |
self.load_script(window.world) |
|
119 | 133 |
|
120 | 134 |
def handle_message(self, msg): |
121 | 135 |
"""When the client receives a message.""" |
src/scripting/trigger.py | ||
---|---|---|
66 | 66 |
# The '*' sign will be replaced by a group |
67 | 67 |
reaction = reaction.replace("\\*", "(.*?)") |
68 | 68 |
reaction = "^" + reaction + "$" |
69 |
print "test", reaction |
|
69 | 70 |
|
70 | 71 |
return re.compile(reaction, re.IGNORECASE) |
71 | 72 |
|
... | ... | |
76 | 77 |
|
77 | 78 |
def execute(self): |
78 | 79 |
"""Execute the trigger.""" |
80 |
print "execute the trigger", self |
|
79 | 81 |
self.sharp_engine.execute(self.action) |
src/sharp/engine.py | ||
---|---|---|
63 | 63 |
globals = self.globals |
64 | 64 |
locals = self.locals |
65 | 65 |
for instruction in instructions: |
66 |
print "Execute", instruction |
|
66 | 67 |
exec(instruction, globals, locals) |
67 | 68 |
|
68 | 69 |
def feed(self, content): |
src/sharp/functions/play.py | ||
---|---|---|
28 | 28 |
|
29 | 29 |
"""Module containing the Play function class.""" |
30 | 30 |
|
31 |
from pygame import mixer |
|
32 |
mixer.init() |
|
31 |
import winsound |
|
33 | 32 |
|
34 | 33 |
from sharp import Function |
35 | 34 |
|
... | ... | |
41 | 40 |
|
42 | 41 |
""" |
43 | 42 |
|
44 |
def init(self): |
|
45 |
"""Initialize the cache of sounds.""" |
|
46 |
self.cache = {} |
|
47 |
|
|
48 | 43 |
def run(self, filename): |
49 | 44 |
"""Say the text.""" |
50 |
if filename in self.cache: |
|
51 |
sound = self.cache[filename] |
|
52 |
else: |
|
53 |
sound = mixer.Sound(filename) |
|
54 |
self.cache[filename] = sound |
|
55 |
|
|
56 |
sound.play() |
|
45 |
winsound.PlaySound(filename, winsound.SND_ASYNC | winsound.SND_FILENAME) |
src/ui/window.py | ||
---|---|---|
46 | 46 |
self.CreateMenuBar() |
47 | 47 |
self.InitUI(world) |
48 | 48 |
|
49 |
@property |
|
50 |
def world(self): |
|
51 |
return self.panel and self.panel.world or None |
|
52 |
|
|
49 | 53 |
def _get_client(self): |
50 | 54 |
return self.panel.client |
51 | 55 |
def _set_client(self, client): |
Also available in: Unified diff
Replace pygame by winsound to play sounds (faster although not portable)