1
# -*- coding: utf-8 -*-
3
Copyright 2010 Olivier Belanger
5
This file is part of pyo, a python module to help digital signal
6
processing script creation.
8
pyo is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
13
pyo is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public Licensehack for OSX display
19
along with pyo. If not, see <http://www.gnu.org/licenses/>.
21
from types import ListType, FloatType, IntType
22
import math, sys, os, random
26
from PIL import Image, ImageDraw, ImageTk
33
if (wxversion.checkInstalled("2.8")):
34
wxversion.ensureMinimal("2.8")
36
from _wxwidgets import *
41
if hasattr(__builtin__, 'EPYO_APP_OPENED'):
48
from _tkwidgets import *
51
WxPython is not found for the current python version.
52
Pyo will use a minimal GUI toolkit written with Tkinter.
53
This toolkit has limited functionnalities and is no more
54
maintained or updated. If you want to use all of pyo's
55
GUI features, you should install WxPython, available here:
56
http://www.wxpython.org/
61
Neither WxPython nor Tkinter are found for the current python version.
62
Pyo's GUI features are disabled. For a complete GUI toolkit, you should
63
consider installing WxPython, available here: http://www.wxpython.org/
66
X, Y, CURRENT_X, MAX_X, NEXT_Y = 800, 700, 30, 30, 30
77
def createRootWindow():
94
def tkCloseWindow(win):
96
if win in WINDOWS: WINDOWS.remove(win)
98
def tkCloseWindowFromKeyboard(event):
100
if not isinstance(win, ServerGUI):
102
if win in WINDOWS: WINDOWS.remove(win)
104
def tkCreateToplevelWindow():
107
win.protocol('WM_DELETE_WINDOW', lambda win=win: tkCloseWindow(win))
108
win.bind("<Escape>", tkCloseWindowFromKeyboard)
111
def wxDisplayWindow(f, title):
112
global CURRENT_X, MAX_X, NEXT_Y
115
if sys.platform == "linux2":
118
px, py, NEXT_Y = CURRENT_X, NEXT_Y, NEXT_Y + y
119
if x + CURRENT_X > MAX_X: MAX_X = x + CURRENT_X
120
f.SetPosition((px, py))
122
px, py, NEXT_Y, CURRENT_X = MAX_X, 50, 50 + y, MAX_X
123
if x + CURRENT_X > MAX_X: MAX_X = x + CURRENT_X
124
f.SetPosition((px, py))
126
f.SetPosition((random.randint(250,500), random.randint(200,400)))
129
def wxShowWindow(f, title, root):
135
def wxCreateDelayedCtrlWindows():
136
for win in CTRLWINDOWS:
137
f = PyoObjectControl(None, win[0], win[1])
138
if win[2] == None: title = win[0].__class__.__name__
140
wxDisplayWindow(f, title)
142
def wxCreateDelayedGraphWindows():
143
for win in GRAPHWINDOWS:
144
f = TableGrapher(None, win[0], win[1], win[2], win[3])
145
if win[4] == None: title = win[0].__class__.__name__
147
wxDisplayWindow(f, title)
149
def wxCreateDelayedDataGraphWindows():
150
for win in DATAGRAPHWINDOWS:
151
f = DataTableGrapher(None, win[0], win[1])
152
if win[2] == None: title = win[0].__class__.__name__
154
wxDisplayWindow(f, title)
156
def wxCreateDelayedTableWindows():
157
global CURRENT_X, MAX_X, NEXT_Y
158
for win in TABLEWINDOWS:
160
f = ViewTable(None, win[0], win[1], object)
162
object._setViewFrame(f)
163
wxDisplayWindow(f, win[2])
165
def wxCreateDelayedSndTableWindows():
166
global CURRENT_X, MAX_X, NEXT_Y
167
for win in SNDTABLEWINDOWS:
168
f = SndViewTable(None, win[0], win[1], win[3])
169
win[0]._setViewFrame(f)
170
wxDisplayWindow(f, win[2])
172
def wxCreateDelayedMatrixWindows():
173
global CURRENT_X, MAX_X, NEXT_Y
174
for win in MATRIXWINDOWS:
176
if WITH_PIL: f = ViewMatrix_withPIL(None, win[0], win[1], object)
177
else: f = ViewMatrix_withoutPIL(None, win[0], win[1], object)
179
object._setViewFrame(f)
180
wxDisplayWindow(f, win[2])
182
def wxCreateDelayedSpectrumWindows():
183
for win in SPECTRUMWINDOWS:
184
f = SpectrumDisplay(None, win[0])
185
if win[1] == None: title = win[0].__class__.__name__
188
win[0]._setViewFrame(f)
189
wxDisplayWindow(f, title)
191
def createCtrlWindow(obj, map_list, title, wxnoserver=False):
194
win = tkCreateToplevelWindow()
195
f = PyoObjectControl(win, obj, map_list)
196
win.resizable(True, False)
197
if title == None: title = obj.__class__.__name__
200
if wxnoserver or WX_APP:
201
root = createRootWindow()
202
f = PyoObjectControl(None, obj, map_list)
203
if title == None: title = obj.__class__.__name__
204
wxShowWindow(f, title, root)
206
CTRLWINDOWS.append([obj, map_list, title])
208
def createGraphWindow(obj, mode, xlen, yrange, title, wxnoserver=False):
210
print "WxPython must be installed to use the 'graph()' method."
212
if wxnoserver or WX_APP:
213
root = createRootWindow()
214
f = TableGrapher(None, obj, mode, xlen, yrange)
215
if title == None: title = obj.__class__.__name__
216
wxShowWindow(f, title, root)
218
GRAPHWINDOWS.append([obj, mode, xlen, yrange, title])
220
def createDataGraphWindow(obj, yrange, title, wxnoserver=False):
222
print "WxPython must be installed to use the 'graph()' method."
224
if wxnoserver or WX_APP:
225
root = createRootWindow()
226
f = DataTableGrapher(None, obj, yrange)
227
if title == None: title = obj.__class__.__name__
228
wxShowWindow(f, title, root)
230
DATAGRAPHWINDOWS.append([obj, yrange, title])
232
def createViewTableWindow(samples, title="Table waveform", wxnoserver=False, tableclass=None, object=None):
235
win = tkCreateToplevelWindow()
236
if WITH_PIL: f = ViewTable_withPIL(win, samples)
237
else: f = ViewTable_withoutPIL(win, samples)
238
win.resizable(False, False)
241
if wxnoserver or WX_APP:
242
root = createRootWindow()
243
f = ViewTable(None, samples, tableclass, object)
244
wxShowWindow(f, title, root)
246
object._setViewFrame(f)
248
TABLEWINDOWS.append([samples, tableclass, title, object])
250
def createSndViewTableWindow(obj, title="Table waveform", wxnoserver=False, tableclass=None, mouse_callback=None):
253
win = tkCreateToplevelWindow()
254
if WITH_PIL: f = ViewTable_withPIL(win, obj._base_objs[0].getViewTable())
255
else: f = ViewTable_withoutPIL(win, obj._base_objs[0].getViewTable())
256
win.resizable(False, False)
259
if wxnoserver or WX_APP:
260
root = createRootWindow()
261
f = SndViewTable(None, obj, tableclass, mouse_callback)
262
if title == None: title = obj.__class__.__name__
263
wxShowWindow(f, title, root)
266
SNDTABLEWINDOWS.append([obj, tableclass, title, mouse_callback])
268
def createViewMatrixWindow(samples, size, title="Matrix viewer", wxnoserver=False, object=None):
269
if not WITH_PIL: print """The Python Imaging Library is not installed.
270
It helps a lot to speed up matrix drawing!"""
273
win = tkCreateToplevelWindow()
274
if WITH_PIL: f = ViewMatrix_withPIL(win, samples, size)
275
else: f = ViewMatrix_withoutPIL(win, samples, size)
276
win.resizable(False, False)
279
if wxnoserver or WX_APP:
280
root = createRootWindow()
281
if WITH_PIL: f = ViewMatrix_withPIL(None, samples, size, object)
282
else: f = ViewMatrix_withoutPIL(None, samples, size, object)
283
wxShowWindow(f, title, root)
285
object._setViewFrame(f)
287
MATRIXWINDOWS.append([samples,size,title, object])
289
def createSpectrumWindow(object, title, wxnoserver=False):
291
print "WxPython must be installed to use the Spectrum display."
293
if wxnoserver or WX_APP:
294
root = createRootWindow()
295
f = SpectrumDisplay(None, object)
296
if title == None: title = object.__class__.__name__
297
wxShowWindow(f, title, root)
299
object._setViewFrame(f)
301
SPECTRUMWINDOWS.append([object, title])
303
def createServerGUI(nchnls, start, stop, recstart, recstop, setAmp, started, locals, shutdown, meter, timer, amp, exit):
304
global X, Y, MAX_X, NEXT_Y
307
win = tkCreateToplevelWindow()
308
f = ServerGUI(win, nchnls, start, stop, recstart, recstop, setAmp, started, locals, shutdown, meter, timer, amp)
309
f.master.title("pyo server")
312
win = createRootWindow()
313
f = ServerGUI(None, nchnls, start, stop, recstart, recstop, setAmp, started, locals, shutdown, meter, timer, amp, exit)
314
f.SetTitle("pyo server")
315
f.SetPosition((30, 30))
317
X,Y = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X)-50, wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)-50
318
if sys.platform == "linux2":
319
MAX_X, NEXT_Y = f.GetSize()[0]+30, f.GetSize()[1]+55
321
MAX_X, NEXT_Y = f.GetSize()[0]+30, f.GetSize()[1]+30
322
wx.CallAfter(wxCreateDelayedTableWindows)
323
wx.CallAfter(wxCreateDelayedGraphWindows)
324
wx.CallAfter(wxCreateDelayedDataGraphWindows)
325
wx.CallAfter(wxCreateDelayedSndTableWindows)
326
wx.CallAfter(wxCreateDelayedMatrixWindows)
327
wx.CallAfter(wxCreateDelayedCtrlWindows)
328
wx.CallAfter(wxCreateDelayedSpectrumWindows)
329
wx.CallAfter(f.Raise)
b'\\ No newline at end of file'