~ubuntu-branches/ubuntu/wily/python-pyo/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/wxpython3.0.patch/pyolib/_widgets.py

  • Committer: Package Import Robot
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2015-05-25 09:55:36 UTC
  • mfrom: (13.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20150525095536-haz5xfrxl6u3m085
Tags: 0.7.5-2
Minor packaging fixes and push to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
"""
3
 
Copyright 2010 Olivier Belanger
4
 
 
5
 
This file is part of pyo, a python module to help digital signal
6
 
processing script creation.
7
 
 
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.
12
 
 
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.
17
 
 
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/>.
20
 
"""
21
 
from types import ListType, FloatType, IntType
22
 
import math, sys, os, random
23
 
import __builtin__
24
 
 
25
 
try:
26
 
    from PIL import Image, ImageDraw, ImageTk
27
 
    WITH_PIL = True
28
 
except:
29
 
    WITH_PIL = False
30
 
 
31
 
try:
32
 
    import wxversion
33
 
    if (wxversion.checkInstalled("2.8")):
34
 
        wxversion.ensureMinimal("2.8")
35
 
    import wx
36
 
    from _wxwidgets import *
37
 
    PYO_USE_WX = True
38
 
except:
39
 
    PYO_USE_WX = False
40
 
 
41
 
if hasattr(__builtin__, 'EPYO_APP_OPENED'):
42
 
    PYO_USE_WX = True
43
 
 
44
 
PYO_USE_TK = False
45
 
if not PYO_USE_WX:
46
 
    try:
47
 
        from Tkinter import *
48
 
        from _tkwidgets import *
49
 
        PYO_USE_TK = True
50
 
        print """
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/
57
 
"""
58
 
    except:
59
 
        PYO_USE_TK = False
60
 
        print """
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/
64
 
"""
65
 
 
66
 
X, Y, CURRENT_X, MAX_X, NEXT_Y = 800, 700, 30, 30, 30
67
 
WINDOWS = []
68
 
CTRLWINDOWS = []
69
 
GRAPHWINDOWS = []
70
 
DATAGRAPHWINDOWS = []
71
 
TABLEWINDOWS = []
72
 
SNDTABLEWINDOWS = []
73
 
MATRIXWINDOWS = []
74
 
SPECTRUMWINDOWS = []
75
 
WX_APP = False
76
 
 
77
 
def createRootWindow():
78
 
    global WX_APP
79
 
    if not PYO_USE_WX:
80
 
        if len(WINDOWS) == 0:
81
 
            root = Tk()
82
 
            root.withdraw()
83
 
            return None
84
 
        else:
85
 
            return None
86
 
    else:        
87
 
        if not WX_APP: 
88
 
            win = wx.App(False)
89
 
            WX_APP = True 
90
 
            return win
91
 
        else:
92
 
            return None
93
 
 
94
 
def tkCloseWindow(win):
95
 
    win.destroy()
96
 
    if win in WINDOWS: WINDOWS.remove(win)
97
 
 
98
 
def tkCloseWindowFromKeyboard(event):
99
 
    win = event.widget
100
 
    if not isinstance(win, ServerGUI): 
101
 
        win.destroy()
102
 
        if win in WINDOWS: WINDOWS.remove(win)
103
 
                
104
 
def tkCreateToplevelWindow():
105
 
    win = Toplevel()
106
 
    WINDOWS.append(win)
107
 
    win.protocol('WM_DELETE_WINDOW', lambda win=win: tkCloseWindow(win))
108
 
    win.bind("<Escape>", tkCloseWindowFromKeyboard)
109
 
    return win
110
 
 
111
 
def wxDisplayWindow(f, title):
112
 
    global CURRENT_X, MAX_X, NEXT_Y
113
 
    f.SetTitle(title)
114
 
    x, y = f.GetSize()
115
 
    if sys.platform == "linux2":
116
 
        y += 25
117
 
    if y + NEXT_Y < Y:
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))
121
 
    elif x + MAX_X < X:
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))
125
 
    else:
126
 
        f.SetPosition((random.randint(250,500), random.randint(200,400)))
127
 
    f.Show()
128
 
 
129
 
def wxShowWindow(f, title, root):
130
 
    f.SetTitle(title)
131
 
    f.Show()
132
 
    if root != None:
133
 
        root.MainLoop()
134
 
    
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__
139
 
        else: title = win[2]
140
 
        wxDisplayWindow(f, title)
141
 
 
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__
146
 
        else: title = win[4]
147
 
        wxDisplayWindow(f, title)
148
 
 
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__
153
 
        else: title = win[2]
154
 
        wxDisplayWindow(f, title)
155
 
 
156
 
def wxCreateDelayedTableWindows():
157
 
    global CURRENT_X, MAX_X, NEXT_Y
158
 
    for win in TABLEWINDOWS:
159
 
        object = win[3]
160
 
        f = ViewTable(None, win[0], win[1], object)
161
 
        if object != None:
162
 
            object._setViewFrame(f)
163
 
        wxDisplayWindow(f, win[2])
164
 
 
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])
171
 
 
172
 
def wxCreateDelayedMatrixWindows():
173
 
    global CURRENT_X, MAX_X, NEXT_Y
174
 
    for win in MATRIXWINDOWS:
175
 
        object = win[3]
176
 
        if WITH_PIL: f = ViewMatrix_withPIL(None, win[0], win[1], object)
177
 
        else: f = ViewMatrix_withoutPIL(None, win[0], win[1], object)
178
 
        if object != None:
179
 
            object._setViewFrame(f)
180
 
        wxDisplayWindow(f, win[2])
181
 
 
182
 
def wxCreateDelayedSpectrumWindows():
183
 
    for win in SPECTRUMWINDOWS:
184
 
        f = SpectrumDisplay(None, win[0])
185
 
        if win[1] == None: title = win[0].__class__.__name__
186
 
        else: title = win[1]
187
 
        if win[0] != None:
188
 
            win[0]._setViewFrame(f)
189
 
        wxDisplayWindow(f, title)
190
 
    
191
 
def createCtrlWindow(obj, map_list, title, wxnoserver=False):
192
 
    if not PYO_USE_WX:
193
 
        createRootWindow()
194
 
        win = tkCreateToplevelWindow()
195
 
        f = PyoObjectControl(win, obj, map_list)
196
 
        win.resizable(True, False)
197
 
        if title == None: title = obj.__class__.__name__
198
 
        win.title(title)
199
 
    else:
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)
205
 
        else:
206
 
            CTRLWINDOWS.append([obj, map_list, title])
207
 
 
208
 
def createGraphWindow(obj, mode, xlen, yrange, title, wxnoserver=False):
209
 
    if not PYO_USE_WX:
210
 
        print "WxPython must be installed to use the 'graph()' method."
211
 
    else:
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)
217
 
        else:
218
 
            GRAPHWINDOWS.append([obj, mode, xlen, yrange, title])   
219
 
 
220
 
def createDataGraphWindow(obj, yrange, title, wxnoserver=False):
221
 
    if not PYO_USE_WX:
222
 
        print "WxPython must be installed to use the 'graph()' method."
223
 
    else:
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)
229
 
        else:
230
 
            DATAGRAPHWINDOWS.append([obj, yrange, title])   
231
 
        
232
 
def createViewTableWindow(samples, title="Table waveform", wxnoserver=False, tableclass=None, object=None):
233
 
    if not PYO_USE_WX:
234
 
        createRootWindow()
235
 
        win = tkCreateToplevelWindow()
236
 
        if WITH_PIL: f = ViewTable_withPIL(win, samples)
237
 
        else: f = ViewTable_withoutPIL(win, samples)
238
 
        win.resizable(False, False)
239
 
        win.title(title)
240
 
    else:
241
 
        if wxnoserver or WX_APP:
242
 
            root = createRootWindow()
243
 
            f = ViewTable(None, samples, tableclass, object)
244
 
            wxShowWindow(f, title, root)
245
 
            if object != None:
246
 
                object._setViewFrame(f)
247
 
        else:
248
 
            TABLEWINDOWS.append([samples, tableclass, title, object])    
249
 
 
250
 
def createSndViewTableWindow(obj, title="Table waveform", wxnoserver=False, tableclass=None, mouse_callback=None):
251
 
    if not PYO_USE_WX:
252
 
        createRootWindow()
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)
257
 
        win.title(title)
258
 
    else:
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)
264
 
            obj._setViewFrame(f)
265
 
        else:
266
 
            SNDTABLEWINDOWS.append([obj, tableclass, title, mouse_callback])
267
 
        
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!"""
271
 
    if not PYO_USE_WX:
272
 
        createRootWindow()    
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)
277
 
        win.title(title)
278
 
    else:
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)
284
 
            if object != None:
285
 
                object._setViewFrame(f)
286
 
        else:
287
 
            MATRIXWINDOWS.append([samples,size,title, object])    
288
 
 
289
 
def createSpectrumWindow(object, title, wxnoserver=False):
290
 
    if not PYO_USE_WX:
291
 
        print "WxPython must be installed to use the Spectrum display."
292
 
    else:
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)
298
 
            if object != None:
299
 
                object._setViewFrame(f)
300
 
        else:
301
 
            SPECTRUMWINDOWS.append([object, title])   
302
 
        
303
 
def createServerGUI(nchnls, start, stop, recstart, recstop, setAmp, started, locals, shutdown, meter, timer, amp, exit):
304
 
    global X, Y, MAX_X, NEXT_Y
305
 
    if not PYO_USE_WX:
306
 
        createRootWindow()
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")
310
 
        f.focus_set()
311
 
    else:
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))
316
 
        f.Show()
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
320
 
        else:
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)
330
 
    return f, win
331
 
        
 
 
b'\\ No newline at end of file'