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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
# -*- coding: utf-8 -*-
"""
Copyright 2010 Olivier Belanger
This file is part of pyo, a python module to help digital signal
processing script creation.
pyo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pyo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public Licensehack for OSX display
along with pyo. If not, see <http://www.gnu.org/licenses/>.
"""
from types import ListType, FloatType, IntType
import math, sys, os, random
try:
from PIL import Image, ImageDraw, ImageTk
WITH_PIL = True
except:
WITH_PIL = False
try:
import wxversion
if (wxversion.checkInstalled("2.8")):
wxversion.ensureMinimal("2.8")
import wx
from _wxwidgets import *
PYO_USE_WX = True
except:
PYO_USE_WX = False
if not PYO_USE_WX:
try:
from Tkinter import *
from _tkwidgets import *
except:
if sys.platform == "linux2":
response = raw_input("""python-tk package is missing! It is needed to use pyo graphical interfaces.
Do you want to install it? (yes/no): """)
if response == 'yes':
os.system('sudo apt-get install python-tk')
else:
print "Tkinter is missing! It is needed to use pyo graphical interfaces. Please install it!"
sys.exit()
WINDOWS = []
CTRLWINDOWS = []
GRAPHWINDOWS = []
TABLEWINDOWS = []
SNDTABLEWINDOWS = []
MATRIXWINDOWS = []
def createRootWindow():
if not PYO_USE_WX:
if len(WINDOWS) == 0:
root = Tk()
root.withdraw()
return None
else:
return None
else:
if wx.GetApp() == None:
win = wx.PySimpleApp()
return win
else:
return None
def tkCloseWindow(win):
win.destroy()
if win in WINDOWS: WINDOWS.remove(win)
def tkCloseWindowFromKeyboard(event):
win = event.widget
if not isinstance(win, ServerGUI):
win.destroy()
if win in WINDOWS: WINDOWS.remove(win)
def tkCreateToplevelWindow():
win = Toplevel()
WINDOWS.append(win)
win.protocol('WM_DELETE_WINDOW', lambda win=win: tkCloseWindow(win))
win.bind("<Escape>", tkCloseWindowFromKeyboard)
return win
def wxCreateDelayedCtrlWindows():
for win in CTRLWINDOWS:
f = PyoObjectControl(None, win[0], win[1])
if win[2] == None: title = win[0].__class__.__name__
else: title = win[2]
f.SetTitle(title)
f.SetPosition((random.randint(250,500), random.randint(200,400)))
f.Show()
def wxCreateDelayedGraphWindows():
for win in GRAPHWINDOWS:
f = TableGrapher(None, win[0], win[1], win[2], win[3])
if win[4] == None: title = win[0].__class__.__name__
else: title = win[4]
f.SetTitle(title)
f.SetPosition((random.randint(250,500), random.randint(200,400)))
f.Show()
def wxCreateDelayedTableWindows():
for win in TABLEWINDOWS:
if WITH_PIL: f = ViewTable_withPIL(None, win[0], win[1])
else: f = ViewTable_withoutPIL(None, win[0], win[1])
f.SetPosition((random.randint(250,500), random.randint(200,400)))
f.SetTitle(win[2])
f.Show()
def wxCreateDelayedSndTableWindows():
for win in SNDTABLEWINDOWS:
if WITH_PIL: f = SndViewTable_withPIL(None, win[0], win[1], win[3])
else: f = SndViewTable_withoutPIL(None, win[0], win[1], win[3])
f.SetPosition((random.randint(250,500), random.randint(200,400)))
f.SetTitle(win[2])
f.Show()
def wxCreateDelayedMatrixWindows():
for win in MATRIXWINDOWS:
if WITH_PIL: f = ViewMatrix_withPIL(None, win[0], win[1])
else: f = ViewMatrix_withoutPIL(None, win[0], win[1])
f.SetPosition((random.randint(250,500), random.randint(200,400)))
f.SetTitle(win[2])
f.Show()
def createCtrlWindow(obj, map_list, title, wxnoserver=False):
if not PYO_USE_WX:
createRootWindow()
win = tkCreateToplevelWindow()
f = PyoObjectControl(win, obj, map_list)
win.resizable(True, False)
if title == None: title = obj.__class__.__name__
win.title(title)
else:
if wxnoserver or wx.GetApp() != None:
if wx.GetApp() == None:
root = createRootWindow()
else:
root = None
f = PyoObjectControl(None, obj, map_list)
if title == None: title = obj.__class__.__name__
f.SetTitle(title)
f.Show()
if root != None:
root.MainLoop()
else:
CTRLWINDOWS.append([obj, map_list, title])
def createGraphWindow(obj, mode, xlen, yrange, title, wxnoserver=False):
if not PYO_USE_WX:
print "WxPython must be installed to use the 'graph' method."
if 0:
createRootWindow()
win = tkCreateToplevelWindow()
f = PyoObjectControl(win, obj, map_list)
win.resizable(True, False)
if title == None: title = obj.__class__.__name__
win.title(title)
else:
if wxnoserver or wx.GetApp() != None:
if wx.GetApp() == None:
root = createRootWindow()
else:
root = None
f = TableGrapher(None, obj, mode, xlen, yrange)
if title == None: title = obj.__class__.__name__
f.SetTitle(title)
f.Show()
if root != None:
root.MainLoop()
else:
GRAPHWINDOWS.append([obj, mode, xlen, yrange, title])
def createViewTableWindow(samples, title="Table waveform", wxnoserver=False, tableclass=None):
if not PYO_USE_WX:
createRootWindow()
win = tkCreateToplevelWindow()
if WITH_PIL: f = ViewTable_withPIL(win, samples)
else: f = ViewTable_withoutPIL(win, samples)
win.resizable(False, False)
win.title(title)
else:
if wxnoserver or wx.GetApp() != None:
if wx.GetApp() == None:
root = createRootWindow()
else:
root = None
if WITH_PIL: f = ViewTable_withPIL(None, samples, tableclass)
else: f = ViewTable_withoutPIL(None, samples, tableclass)
f.Show()
f.SetTitle(title)
else:
TABLEWINDOWS.append([samples, tableclass, title])
def createSndViewTableWindow(obj, title="Table waveform", wxnoserver=False, tableclass=None, mouse_callback=None):
if not PYO_USE_WX:
createRootWindow()
win = tkCreateToplevelWindow()
if WITH_PIL: f = ViewTable_withPIL(win, obj._base_objs[0].getViewTable())
else: f = ViewTable_withoutPIL(win, obj._base_objs[0].getViewTable())
win.resizable(False, False)
win.title(title)
else:
if wxnoserver or wx.GetApp() != None:
if wx.GetApp() == None:
root = createRootWindow()
else:
root = None
if WITH_PIL: f = SndViewTable_withPIL(None, obj, tableclass, mouse_callback)
else: f = SndViewTable_withoutPIL(None, obj, tableclass, mouse_callback)
f.Show()
f.SetTitle(title)
else:
SNDTABLEWINDOWS.append([obj, tableclass, title, mouse_callback])
def createViewMatrixWindow(samples, size, title="Matrix viewer", wxnoserver=False):
if not WITH_PIL: print """The Python Imaging Library is not installed.
It helps a lot to speed up matrix drawing!"""
if not PYO_USE_WX:
createRootWindow()
win = tkCreateToplevelWindow()
if WITH_PIL: f = ViewMatrix_withPIL(win, samples, size)
else: f = ViewMatrix_withoutPIL(win, samples, size)
win.resizable(False, False)
win.title(title)
else:
if wxnoserver or wx.GetApp() != None:
if wx.GetApp() == None:
root = createRootWindow()
else:
root = None
if WITH_PIL: f = ViewMatrix_withPIL(None, samples, size)
else: f = ViewMatrix_withoutPIL(None, samples, size)
f.Show()
f.SetTitle(title)
else:
MATRIXWINDOWS.append([samples,size,title])
def createServerGUI(nchnls, start, stop, recstart, recstop, setAmp, started, locals, shutdown, meter, timer, amp):
if not PYO_USE_WX:
createRootWindow()
win = tkCreateToplevelWindow()
f = ServerGUI(win, nchnls, start, stop, recstart, recstop, setAmp, started, locals, shutdown, meter, timer, amp)
f.master.title("pyo server")
f.focus_set()
else:
win = createRootWindow()
f = ServerGUI(None, nchnls, start, stop, recstart, recstop, setAmp, started, locals, shutdown, meter, timer, amp)
f.SetTitle("pyo server")
f.Show()
wx.CallAfter(wxCreateDelayedCtrlWindows)
wx.CallAfter(wxCreateDelayedGraphWindows)
wx.CallAfter(wxCreateDelayedTableWindows)
wx.CallAfter(wxCreateDelayedSndTableWindows)
wx.CallAfter(wxCreateDelayedMatrixWindows)
wx.CallAfter(f.Raise)
return f, win
|