Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit c4b9eaace5f958d286da15a02873ada1fec1a138

reverting changes from common/util
  
11# -*- coding: utf-8 -*-
2from gi.repository import Gtk
2import pygtk
3pygtk.require( '2.0' )
4import gtk
35
4class Credits( Gtk.Window ):
6class Credits( gtk.Window ):
57 def __init__(self , handleCreditsCloseCallback , pos):
6 Gtk.Window.__init__( self, Gtk.WINDOW_TOPLEVEL )
7 self.set_type_hint(Gdk.WINDOW_TYPE_HINT_DIALOG)
8 gtk.Window.__init__( self, gtk.WINDOW_TOPLEVEL )
9 self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
810 self.connect('destroy' , self.destroy)
911 #self.set_decorated(False)
1012 self.handleCreditsCloseCallback = handleCreditsCloseCallback
1113 self.move(pos[0] , pos[1])
1214
13 self.vbox = Gtk.VBox()
14 self.tb = Gtk.TextBuffer()
15 self.vbox = gtk.VBox()
16 self.tb = gtk.TextBuffer()
1517 self.tb.set_text('miniTamTam\n\nby\n\nOlivier Bélanger\nJames Bergstra\nEric Lamothe\nNathanaël Lécaudé\nAdrian Martin\nJean Piché\nSean Wood\n\nThanks to\n\nBarry Vercoe\nVictor Lazzarini\nMarco Pesenti Gritti\nSimon Schampijer\nPeter Kirn\n\nUniversité de Montréal 2006')
16 self.tw = Gtk.TextView(buffer = self.tb)
18 self.tw = gtk.TextView(buffer = self.tb)
1719 self.tw.set_editable(False)
1820 self.tw.set_cursor_visible(False)
1921 #self.tw.set_right_margin(10)
2022 #self.tw.set_left_margin(10)
21 self.tw.set_justification(Gtk.JUSTIFY_CENTER)
23 self.tw.set_justification(gtk.JUSTIFY_CENTER)
2224 self.vbox.add(self.tw)
2325
24 self.closeButton = Gtk.Button(label='X')
26 self.closeButton = gtk.Button(label='X')
2527 self.closeButton.connect('clicked' , self.destroy)
2628 self.vbox.add(self.closeButton)
2729 self.add(self.vbox)
3636
3737if __name__ == '__main__':
3838 credits = Credits()
39 Gtk.main()
39 gtk.main()
  
1from gi.repository import Gtk
1import pygtk
2pygtk.require( '2.0' )
3import gtk
24
35import time
46
99from common.Util.ThemeWidgets import *
1010Tooltips = Config.Tooltips
1111
12class InstrumentPanel( Gtk.EventBox ):
12class InstrumentPanel( gtk.EventBox ):
1313 def __init__(self,setInstrument = None, playInstrument = None, enterMode = False, micRec = None, synthRec = None, rowLen = 8, _instDic = None, force_load = True ):
14 Gtk.EventBox.__init__(self)
14 gtk.EventBox.__init__(self)
1515
1616 self.instrumentDB = InstrumentDB.getRef()
1717 self.setInstrument = setInstrument
4646 if Config.DEBUG > 4: print "InstrumentPanel load", self.loadStage
4747
4848 if self.loadStage[0] == 0:
49 color = Gdk.color_parse(Config.PANEL_BCK_COLOR)
50 self.modify_bg(Gtk.STATE_NORMAL, color)
49 color = gtk.gdk.color_parse(Config.PANEL_BCK_COLOR)
50 self.modify_bg(gtk.STATE_NORMAL, color)
5151 self.loadStage[0] = 1
5252 if timeout >= 0 and time.time() > timeout: return False
5353
5454 if self.loadStage[0] == 1:
55 self.tooltips = Gtk.Tooltips()
55 self.tooltips = gtk.Tooltips()
5656 self.loadStage[0] = 2
5757 if timeout >= 0 and time.time() > timeout: return False
5858
6161 self.recstate = False
6262 self.lastInstrumentWidget = None
6363
64 self.mainVBox = Gtk.VBox()
64 self.mainVBox = gtk.VBox()
6565 self.loadStage[0] = 3
6666 if timeout >= 0 and time.time() > timeout: return False
6767
150150
151151 def loadToolbar( self, timeout = -1, loadStage = [0,0,0] ):
152152 if loadStage[1] == 0:
153 self.loadData["toolbarBox"] = Gtk.HBox()
153 self.loadData["toolbarBox"] = gtk.HBox()
154154 self.firstTbBtn = None
155155 self.loadStage[1] = 1
156156 if timeout >= 0 and time.time() > timeout: return False
241241 def loadInstrumentViewport( self ):
242242 self.instrumentBox = RoundHBox(fillcolor = Config.INSTRUMENT_GRID_COLOR, bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS)
243243
244 self.scrollWin = Gtk.ScrolledWindow()
245 self.scrollWin.set_policy(Gtk.POLICY_NEVER,Gtk.POLICY_AUTOMATIC)
244 self.scrollWin = gtk.ScrolledWindow()
245 self.scrollWin.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC)
246246
247 self.tableEventBox = Gtk.EventBox()
248 color = Gdk.color_parse(Config.INSTRUMENT_GRID_COLOR)
249 self.tableEventBox.modify_bg(Gtk.STATE_NORMAL, color)
247 self.tableEventBox = gtk.EventBox()
248 color = gtk.gdk.color_parse(Config.INSTRUMENT_GRID_COLOR)
249 self.tableEventBox.modify_bg(gtk.STATE_NORMAL, color)
250250
251251 self.scrollWin.add_with_viewport(self.tableEventBox)
252 self.tableEventBox.get_parent().set_shadow_type( Gtk.SHADOW_NONE )
252 self.tableEventBox.get_parent().set_shadow_type( gtk.SHADOW_NONE )
253253 self.instrumentBox.pack_start(self.scrollWin,True,True,0)
254 self.mainVBox.pack_start(self.instrumentBox, True, True, 0)
254 self.mainVBox.pack_start(self.instrumentBox)
255255 self.show_all()
256256
257257 def prepareInstrumentTable(self,category = 'all'):
278278 if instrumentNum % cols is not 0: #S'il y a un reste
279279 rows = rows + 1
280280
281 self.instTable = Gtk.Table(rows,cols,True)
281 self.instTable = gtk.Table(rows,cols,True)
282282 self.instTable.set_row_spacings(0)
283283 self.instTable.set_col_spacings(0)
284284
287287 if row*cols+col >= instrumentNum:
288288 break
289289 instBox = self.instDic[instruments[row*cols+col]]
290 self.instTable.attach(instBox, col, col+1, row, row+1, Gtk.SHRINK, Gtk.SHRINK, 0, 0)
290 self.instTable.attach(instBox, col, col+1, row, row+1, gtk.SHRINK, gtk.SHRINK, 0, 0)
291291
292292 self.tableEventBox.add(self.instTable)
293293 self.instTable.show_all()
302302 def handleInstrumentButtonClick(self,widget,instrument):
303303 if widget.get_active() is True and self.recstate == False:
304304 if self.setInstrument:
305 widget.event( Gdk.Event( Gdk.LEAVE_NOTIFY ) ) # fake the leave event
305 widget.event( gtk.gdk.Event( gtk.gdk.LEAVE_NOTIFY ) ) # fake the leave event
306306 self.setInstrument(instrument)
307307 if self.playInstrument: self.playInstrument(instrument)
308308 if self.enterMode:
331331 btn.handler_unblock(btn.clickedHandler)
332332
333333
334class DrumPanel( Gtk.EventBox ):
334class DrumPanel( gtk.EventBox ):
335335 def __init__(self, setDrum = None):
336 Gtk.EventBox.__init__(self)
337 color = Gdk.color_parse(Config.PANEL_BCK_COLOR)
338 self.modify_bg(Gtk.STATE_NORMAL, color)
336 gtk.EventBox.__init__(self)
337 color = gtk.gdk.color_parse(Config.PANEL_BCK_COLOR)
338 self.modify_bg(gtk.STATE_NORMAL, color)
339339
340340 self.setDrum = setDrum
341341 self.instrumentList = []
367367 def setDrums(self,widget,data):
368368 if widget.get_active():
369369 if self.setDrum:
370 widget.event( Gdk.Event( Gdk.LEAVE_NOTIFY ) ) # fake the leave event
370 widget.event( gtk.gdk.Event( gtk.gdk.LEAVE_NOTIFY ) ) # fake the leave event
371371 self.setDrum(data)
372372
373373 def set_activeInstrument( self, instrument, state ):
378378 btn.handler_unblock(btn.clickedHandler)
379379
380380if __name__ == "__main__":
381 win = Gtk.Window()
381 win = gtk.Window()
382382 wc = DrumPanel(None)
383383 win.add(wc)
384384 win.show()
385 #start the Gtk event loop
386 Gtk.main()
385 #start the gtk event loop
386 gtk.main()
  
1from gi.repository import Gtk
1import pygtk
2pygtk.require( '2.0' )
3import gtk
24import random
35from common.Util.ThemeWidgets import keyButton
46import common.Config as Config
57KEY_MAP_PIANO = Config.KEY_MAP_PIANO
68
7class KeyboardWindow(Gtk.Window):
9class KeyboardWindow(gtk.Window):
810 def __init__(self, size = None, pos = 0, popup = False):
911 if popup is False:
10 Gtk.Window.__init__(self , Gtk.WINDOW_TOPLEVEL)
12 gtk.Window.__init__(self , gtk.WINDOW_TOPLEVEL)
1113 else:
12 Gtk.Window.__init__(self , Gtk.WINDOW_POPUP)
13 color = Gdk.color_parse("#000000")
14 self.modify_bg(Gtk.STATE_NORMAL, color)
14 gtk.Window.__init__(self , gtk.WINDOW_POPUP)
15 color = gtk.gdk.color_parse("#000000")
16 self.modify_bg(gtk.STATE_NORMAL, color)
1517 self.set_decorated(False)
1618
17 self.add_events(Gdk.BUTTON_PRESS_MASK | Gdk.BUTTON_RELEASE_MASK | Gdk.ENTER_NOTIFY_MASK | Gdk.KEY_PRESS_MASK)
19 self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.ENTER_NOTIFY_MASK | gtk.gdk.KEY_PRESS_MASK)
1820 self.connect("key-press-event",self.handle_keypress)
1921 self.connect("key-release-event",self.handle_keyrelease)
2022 self.connect("button-press-event",self.handle_mousePress)
4949
5050 self.btn_dic = {}
5151
52 mainvbox = Gtk.VBox()
53 mainhbox = Gtk.HBox()
52 mainvbox = gtk.VBox()
53 mainhbox = gtk.HBox()
5454
5555 #Main keyboard section
56 vbox = Gtk.VBox()
56 vbox = gtk.VBox()
5757 for row in [1,2,3,4,5]:
58 hbox = Gtk.HBox()
58 hbox = gtk.HBox()
5959 for key in self.rows[row]:
6060 self.btn_dic[key[0]] = keyButton(self.pixel_space * key[1], self.height, [0,0,0], [0.5,0.5,0.5])
6161 hbox.pack_start(self.btn_dic[key[0]], padding = self.pixel_space//2)
6262 vbox.pack_start(hbox, padding = self.pixel_space//2)
63 mainhbox.pack_start(vbox, True, True, 0)
63 mainhbox.pack_start(vbox)
6464
6565 #Right part of the keyboard
66 right_vbox = Gtk.VBox()
67 right_tophbox = Gtk.HBox()
68 right_lowhbox = Gtk.HBox()
66 right_vbox = gtk.VBox()
67 right_tophbox = gtk.HBox()
68 right_lowhbox = gtk.HBox()
6969
7070 self.btn_dic[self.right_section[0][0]] = keyButton(self.pixel_space * self.right_section[0][1], self.height, [0,0,0], [0.5,0.5,0.5])
7171 self.btn_dic[self.right_section[1][0]] = keyButton(self.pixel_space * self.right_section[1][1][0], self.pixel_space * self.right_section[1][1][1], [0,0,0], [0.5,0.5,0.5])
8484 right_vbox.pack_start(right_lowhbox, padding = self.pixel_space//2)
8585
8686 #Mouse buttons
87 mouse_hbox = Gtk.HBox()
87 mouse_hbox = gtk.HBox()
8888 self.btn_dic["left_mouse"] = keyButton(self.pixel_space * 6, self.pixel_space * 2, [0,0,0], [0.5,0.5,0.5])
8989 self.btn_dic["right_mouse"] = keyButton(self.pixel_space * 6, self.pixel_space * 2, [0,0,0], [0.5,0.5,0.5])
9090 mouse_hbox.pack_start(self.btn_dic["left_mouse"], True, True, self.pixel_space//2)
9696 self.btn_dic[key].connect("enter",self.handle_mouseEnter)
9797 self.btn_dic[key].connect("leave",self.handle_mouseLeave)
9898
99 mainhbox.pack_start(right_vbox, True, True, 0)
100 mainvbox.pack_start(mainhbox, True, True, 0)
99 mainhbox.pack_start(right_vbox)
100 mainvbox.pack_start(mainhbox)
101101 mainvbox.pack_start(mouse_hbox, padding = self.pixel_space//2)
102102
103103 self.add(mainvbox)
175175
176176if __name__ == "__main__":
177177 win = KeyboardWindow()
178 win.connect("destroy",Gtk.main_quit)
178 win.connect("destroy",gtk.main_quit)
179179 win.show_all()
180 Gtk.main()
180 gtk.main()
  
1import gi
2gi.require_version('Gtk', '3.0')
3from gi.repository import Gtk
4from gi.repository import GObject
1import pygtk
2pygtk.require('2.0')
3import gtk
4import gobject
55import os
66from common.Util.ThemeWidgets import *
77import common.Config as Config
88import commands
99Tooltips = Config.Tooltips()
1010
11class LoopSettings( Gtk.VBox ):
11class LoopSettings( gtk.VBox ):
1212 def __init__( self, popup, playFunction, setChannelFunction, doneLoopSettingsPopup ):
13 Gtk.VBox.__init__( self )
14 self.tooltips = Gtk.Tooltips()
13 gtk.VBox.__init__( self )
14 self.tooltips = gtk.Tooltips()
1515 self.popup = popup
1616 self.playFunction = playFunction
1717 self.setChannel = setChannelFunction
2424 self.register = 0
2525 self.ok = True
2626
27 self.settingsBox = Gtk.HBox()
28 self.pack_start(self.settingsBox, True, True, 0)
27 self.settingsBox = gtk.HBox()
28 self.pack_start(self.settingsBox)
2929
30 self.fixed = Gtk.Fixed()
31 self.settingsBox.pack_start(self.fixed, True, True, 0)
30 self.fixed = gtk.Fixed()
31 self.settingsBox.pack_start(self.fixed)
3232
33 self.mainBox = Gtk.VBox()
33 self.mainBox = gtk.VBox()
3434
35 self.controlsBox = Gtk.HBox()
35 self.controlsBox = gtk.HBox()
3636
3737 self.GUI = {}
3838
39 nameBox = Gtk.VBox()
40 self.nameEntry = Gtk.Entry()
39 nameBox = gtk.VBox()
40 self.nameEntry = gtk.Entry()
4141 self.nameEntry.set_text("name_of_the_sound")
42 nameBox.pack_start(self.nameEntry, True, True, 0)
42 nameBox.pack_start(self.nameEntry)
4343 self.mainBox.pack_start(nameBox, False, False, 5)
4444
45 loopedBox = Gtk.HBox()
46 loopedLabel = Gtk.Label("Looped sound: ")
47 loopedBox.pack_start(loopedLabel, True, True, 0)
45 loopedBox = gtk.HBox()
46 loopedLabel = gtk.Label("Looped sound: ")
47 loopedBox.pack_start(loopedLabel)
4848 loopedToggle = ImageToggleButton('checkOff.png', 'checkOn.png')
4949 loopedToggle.connect('button-press-event', self.handleLooped )
50 loopedBox.pack_start(loopedToggle, True, True, 0)
50 loopedBox.pack_start(loopedToggle)
5151 self.mainBox.pack_start(loopedBox, False, False, 5)
5252
53 categoryBox = Gtk.HBox()
54 categoryMenu = Gtk.MenuBar()
55 cmenu = Gtk.Menu()
53 categoryBox = gtk.HBox()
54 categoryMenu = gtk.MenuBar()
55 cmenu = gtk.Menu()
5656 for cat in Config.CATEGORIES:
5757 if cat != 'all':
58 entry = Gtk.MenuItem(cat)
58 entry = gtk.MenuItem(cat)
5959 cmenu.append(entry)
6060 entry.connect("activate", self.handleCategory, cat)
6161 entry.show()
62 self.categoryButton = Gtk.Button("Category")
62 self.categoryButton = gtk.Button("Category")
6363 self.categoryButton.connect_object("event", self.categoryBtnPress, cmenu)
64 categoryBox.pack_end(self.categoryButton, True, True, 0)
64 categoryBox.pack_end(self.categoryButton)
6565 #self.mainBox.pack_start(categoryBox, False, False, 5)
6666
67 registerBox = Gtk.HBox()
68 registerMenu = Gtk.MenuBar()
69 rmenu = Gtk.Menu()
67 registerBox = gtk.HBox()
68 registerMenu = gtk.MenuBar()
69 rmenu = gtk.Menu()
7070 self.registerList = ['LOW', 'MID', 'HIGH', 'PUNCH']
7171 for reg in self.registerList:
72 entry = Gtk.MenuItem(reg)
72 entry = gtk.MenuItem(reg)
7373 rmenu.append(entry)
7474 entry.connect("activate", self.handleRegister, self.registerList.index(reg))
7575 entry.show()
76 self.registerButton = Gtk.Button("Register")
76 self.registerButton = gtk.Button("Register")
7777 self.registerButton.connect_object("event", self.registerBtnPress, rmenu)
78 registerBox.pack_end(self.registerButton, True, True, 0)
78 registerBox.pack_end(self.registerButton)
7979 self.mainBox.pack_start(registerBox, False, False, 5)
8080
81 startBox = Gtk.VBox()
82 self.startAdjust = Gtk.Adjustment( 0.01, 0, 1., .001, .001, 0)
81 startBox = gtk.VBox()
82 self.startAdjust = gtk.Adjustment( 0.01, 0, 1., .001, .001, 0)
8383 self.GUI['startSlider'] = ImageVScale('sliderEditVolume.png',
8484 self.startAdjust, 7)
8585 self.startAdjust.connect("value-changed", self.handleStart)
8686 self.GUI['startSlider'].set_inverted(True)
8787 self.GUI['startSlider'].set_size_request(50, 200)
88 self.startEntry = Gtk.Entry()
88 self.startEntry = gtk.Entry()
8989 self.startEntry.set_width_chars(5)
9090 self.handleStart( self.startAdjust )
9191 startBox.pack_start(self.GUI['startSlider'], True, True, 5)
9292 startBox.pack_start(self.startEntry, True, True, 5)
93 self.controlsBox.pack_start(startBox, True, True, 0)
93 self.controlsBox.pack_start(startBox)
9494
95 endBox = Gtk.VBox()
96 self.endAdjust = Gtk.Adjustment( 0.9, 0, 1, .001, .001, 0)
95 endBox = gtk.VBox()
96 self.endAdjust = gtk.Adjustment( 0.9, 0, 1, .001, .001, 0)
9797 self.GUI['endSlider'] = ImageVScale('sliderEditVolume.png',
9898 self.endAdjust, 7)
9999 self.endAdjust.connect("value-changed", self.handleEnd)
100100 self.GUI['endSlider'].set_inverted(True)
101101 self.GUI['endSlider'].set_size_request(50, 200)
102 self.endEntry = Gtk.Entry()
102 self.endEntry = gtk.Entry()
103103 self.endEntry.set_width_chars(5)
104104 self.handleEnd( self.endAdjust )
105105 endBox.pack_start(self.GUI['endSlider'], True, True, 5)
106106 endBox.pack_start(self.endEntry, True, True, 5)
107 self.controlsBox.pack_start(endBox, True, True, 0)
107 self.controlsBox.pack_start(endBox)
108108
109 durBox = Gtk.VBox()
110 self.durAdjust = Gtk.Adjustment( 0.01, 0, 0.2, .001, .001, 0)
109 durBox = gtk.VBox()
110 self.durAdjust = gtk.Adjustment( 0.01, 0, 0.2, .001, .001, 0)
111111 self.GUI['durSlider'] = ImageVScale('sliderEditVolume.png',
112112 self.durAdjust, 7)
113113 self.durAdjust.connect("value-changed", self.handleDur)
114114 self.GUI['durSlider'].set_inverted(True)
115115 self.GUI['durSlider'].set_size_request(50, 200)
116 self.durEntry = Gtk.Entry()
116 self.durEntry = gtk.Entry()
117117 self.durEntry.set_width_chars(5)
118118 self.handleDur( self.durAdjust )
119119 durBox.pack_start(self.GUI['durSlider'], True, True, 5)
120120 durBox.pack_start(self.durEntry, True, True, 5)
121 self.controlsBox.pack_start(durBox, True, True, 0)
121 self.controlsBox.pack_start(durBox)
122122
123123 self.mainBox.pack_start(self.controlsBox, False, False, 5)
124124
125 previewBox = Gtk.VBox()
125 previewBox = gtk.VBox()
126126 self.playStopButton = ImageToggleButton('miniplay.png', 'stop.png')
127127 self.playStopButton.connect('button-press-event' , self.handlePlayButton)
128 previewBox.pack_start(self.playStopButton, True, True, 0)
128 previewBox.pack_start(self.playStopButton)
129129 self.mainBox.pack_start(previewBox, False, False, 5)
130130
131 checkBox = Gtk.VBox()
131 checkBox = gtk.VBox()
132132 checkButton = ImageButton('check.png')
133133 checkButton.connect('clicked' , self.handleCheck)
134 checkBox.pack_start(checkButton, True, True, 0)
134 checkBox.pack_start(checkButton)
135135 self.mainBox.pack_start(checkBox, False, False, 5)
136136
137137 self.fixed.put( self.mainBox, 0, 0 )
174174 self.loopedSound = True
175175
176176 def categoryBtnPress(self, widget, event):
177 if event.type == Gdk.BUTTON_PRESS:
177 if event.type == gtk.gdk.BUTTON_PRESS:
178178 widget.popup(None, None, None, event.button, event.time)
179179 return True
180180 return False
184184 self.categoryButton.set_label(self.category)
185185
186186 def registerBtnPress(self, widget, event):
187 if event.type == Gdk.BUTTON_PRESS:
187 if event.type == gtk.gdk.BUTTON_PRESS:
188188 widget.popup(None, None, None, event.button, event.time)
189189 return True
190190 return False
218218 if self.ok:
219219 self.playFunction(widget.get_active(), self.loopedSound)
220220 if self.loopedSound == False and widget.get_active() == False:
221 self.timeoutStop = GObject.timeout_add(int(self.soundLength * 1000)+500, self.playButtonState)
221 self.timeoutStop = gobject.timeout_add(int(self.soundLength * 1000)+500, self.playButtonState)
222222
223223 def setButtonState(self):
224224 self.ok = False
228228 def playButtonState(self):
229229 self.ok = False
230230 self.playStopButton.set_active(False)
231 GObject.source_remove(self.timeoutStop)
231 gobject.source_remove(self.timeoutStop)
232232 self.ok = True
  
1818import random
1919
2020import time
21from gi.repository import Gtk
22from gi.repository import GObject
21import gtk
22import gobject
2323import common.Config as Config
2424
2525PORT = 24460
9292 continue
9393 else:
9494 break # exit thread
95 Gdk.threads_enter()
95 gtk.gdk.threads_enter()
9696 self.owner._processSockets( inputReady )
97 Gdk.threads_leave()
97 gtk.gdk.threads_leave()
9898 except socket.error, (value, message):
9999 print "Listener:: socket error: " + message
100 Gdk.threads_leave()
100 gtk.gdk.threads_leave()
101101 break
102102
103103class Connection:
292292 print "Network::introducePeer:: FAILED to open socket: " + message
293293 return
294294 if poke.connect_ex( (ip, WAIT_PORT) ): # failed to connect
295 GObject.timeout_add( 500, self._pokePeer, poke, ip, 0 )
295 gobject.timeout_add( 500, self._pokePeer, poke, ip, 0 )
296296 else: # connected
297297 if Config.DEBUG > 1: print "Netwtork:: introduction succeeded"
298298 poke.close()
302302 if retry > 120: # give up
303303 print "Network::introducePeer:: peer failed to respond after 60 seconds, giving up!"
304304 else:
305 GObject.timeout_add( 500, self._pokePeer, poke, ip, retry+1 )
305 gobject.timeout_add( 500, self._pokePeer, poke, ip, retry+1 )
306306 else: # connected
307307 if Config.DEBUG > 1: print "Netwtork:: introduction succeeded"
308308 poke.close()
539539 con.recvBuf = con.recvBuf[con.waitingForData:]
540540 con.waitingForData = 0
541541 for func in self.processMessage[con.message]:
542 GObject.idle_add( func, sock, con.message, data )
542 gobject.idle_add( func, sock, con.message, data )
543543 else:
544544 return # wait for more data
545545
548548 if MSG_SIZE[con.message] == 0:
549549 con.recvBuf = con.recvBuf[1:]
550550 for func in self.processMessage[con.message]:
551 GObject.idle_add( func, sock, con.message, "" )
551 gobject.idle_add( func, sock, con.message, "" )
552552 else:
553553 con.waitingForData = MSG_SIZE[con.message]
554554 con.recvBuf = con.recvBuf[1:]
  
88from sugar3.graphics.combobox import ComboBox
99from sugar3.graphics.palette import Palette, WidgetInvoker
1010
11def Gdk_color_to_cairo(color):
11def gdk_color_to_cairo(color):
1212 return (color.red/65536.0, color.green/65536.0, color.blue/65536.0)
1313
1414class ITYPE:
1717
1818class ImageHScale( Gtk.HScale ):
1919 def __init__( self, image_name, adjustment = None, slider_border = 0, insensitive_name = None, trough_color = "#3D403A", snap = False ):
20 GObject.GObject.__init__( self, adjustment )
20 Gtk.HScale.__init__( self, adjustment )
2121
2222 if snap: self.snap = 1/snap
2323 else: self.snap = False
4646}
4747widget "*%s*" style "scale_style"
4848 """ % ( self.sliderPixbuf.get_width(), self.sliderPixbuf.get_height(), name)
49 Gtk.rc_parse_string( rc_str )
49 gtk.rc_parse_string( rc_str )
5050
5151 self.pixbufWidth = self.sliderPixbuf.get_width()
5252 self.pixbufHeight = self.sliderPixbuf.get_height()
9797 sliderX = int((self.alloc.width - self.pixbufWidth)*(val-adj.lower)/(adj.upper - adj.lower))
9898
9999 if self.insensitivePixbuf != None and self.state == Gtk.StateType.INSENSITIVE:
100 self.window.draw_pixbuf( gc, self.insensitivePixbuf, 0, 0, self.alloc.x + sliderX, self.alloc.y + self.sliderY, self.pixbufWidth, self.pixbufHeight, Gdk.RGB_DITHER_NORMAL, 0, 0 )
100 self.window.draw_pixbuf( gc, self.insensitivePixbuf, 0, 0, self.alloc.x + sliderX, self.alloc.y + self.sliderY, self.pixbufWidth, self.pixbufHeight, gtk.gdk.RGB_DITHER_NORMAL, 0, 0 )
101101 else:
102 self.window.draw_pixbuf( gc, self.sliderPixbuf, 0, 0, self.alloc.x + sliderX, self.alloc.y + self.sliderY, self.pixbufWidth, self.pixbufHeight, Gdk.RGB_DITHER_NORMAL, 0, 0 )
102 self.window.draw_pixbuf( gc, self.sliderPixbuf, 0, 0, self.alloc.x + sliderX, self.alloc.y + self.sliderY, self.pixbufWidth, self.pixbufHeight, gtk.gdk.RGB_DITHER_NORMAL, 0, 0 )
103103
104104 return True
105105
113113 insensitive_name=None, trough_color="#3D403A", snap=False):
114114 image_name = imagefile(image_name)
115115
116 GObject.GObject.__init__( self, adjustment )
116 Gtk.VScale.__init__( self, adjustment )
117117
118118 if snap: self.snap = 1/snap
119119 else: self.snap = False
142142}
143143widget "*%s*" style "scale_style"
144144 """ % ( self.sliderPixbuf.get_width(), self.sliderPixbuf.get_height(), name)
145 Gtk.rc_parse_string( rc_str )
145 gtk.rc_parse_string( rc_str )
146146
147147 self.pixbufWidth = self.sliderPixbuf.get_width()
148148 self.pixbufHeight = self.sliderPixbuf.get_height()
190190 else:
191191 sliderY = int((self.alloc.height - self.pixbufHeight)*(val-adj.lower)/(adj.upper - adj.lower))
192192
193 if self.insensitivePixbuf != None and self.state == Gtk.STATE_INSENSITIVE:
194 self.window.draw_pixbuf( gc, self.insensitivePixbuf, 0, 0, self.alloc.x + self.sliderX, self.alloc.y + sliderY, self.pixbufWidth, self.pixbufHeight, Gdk.RGB_DITHER_NORMAL, 0, 0 )
193 if self.insensitivePixbuf != None and self.state == gtk.STATE_INSENSITIVE:
194 self.window.draw_pixbuf( gc, self.insensitivePixbuf, 0, 0, self.alloc.x + self.sliderX, self.alloc.y + sliderY, self.pixbufWidth, self.pixbufHeight, gtk.gdk.RGB_DITHER_NORMAL, 0, 0 )
195195 else:
196 self.window.draw_pixbuf( gc, self.sliderPixbuf, 0, 0, self.alloc.x + self.sliderX, self.alloc.y + sliderY, self.pixbufWidth, self.pixbufHeight, Gdk.RGB_DITHER_NORMAL, 0, 0 )
196 self.window.draw_pixbuf( gc, self.sliderPixbuf, 0, 0, self.alloc.x + self.sliderX, self.alloc.y + sliderY, self.pixbufWidth, self.pixbufHeight, gtk.gdk.RGB_DITHER_NORMAL, 0, 0 )
197197
198198 return True
199199
204204
205205class XYSlider( Gtk.EventBox ):
206206 def __init__( self, fixed, button, xadjustment, yadjustment, flipX = False, flipY = False ):
207 GObject.GObject.__init__( self )
207 Gtk.EventBox.__init__( self )
208208
209209 self.fixed = fixed
210210 self.button = button
221221 self.fWidth = self.fHeight = 1
222222 self.bWidth = self.bHeight = 1
223223
224 self.add_events(Gdk.POINTER_MOTION_HINT_MASK)
224 self.add_events(gtk.gdk.POINTER_MOTION_HINT_MASK)
225225 self.connect( "size-allocate", lambda w,a:self.updateAlloc() )
226226 self.connect( "button-press-event", self.handlePress )
227227 self.connect( "button-release-event", self.handleRelease )
229229 self.button.connect( "size-allocate", lambda w,a: self.updateButton() )
230230 self.button.connect( "button-press-event", self.handleButtonPress )
231231 self.button.connect( "button-release-event", self.handleButtonRelease )
232 self.button.add_events(Gdk.BUTTON_MOTION_MASK|Gdk.POINTER_MOTION_HINT_MASK)
232 self.button.add_events(gtk.gdk.BUTTON_MOTION_MASK|gtk.gdk.POINTER_MOTION_HINT_MASK)
233233 self.button.connect( "motion-notify-event", self.handleMotion )
234234 self.xadjustment.connect( "changed", lambda a1: self.updateAdjustemnt("x") )
235235 self.xadjustment.connect( "value-changed", lambda a1: self.updateLoc() )
310310
311311class RoundHBox( Gtk.HBox ):
312312 def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF", homogeneous = False, spacing = 0 ):
313 GObject.GObject.__init__( self, homogeneous, spacing )
313 Gtk.HBox.__init__( self, homogeneous, spacing )
314314 self.alloc = None
315315
316316 self.radius = radius
471471
472472class RoundVBox( Gtk.VBox ):
473473 def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF", homogeneous = False, spacing = 0 ):
474 GObject.GObject.__init__( self, homogeneous, spacing )
474 Gtk.VBox.__init__( self, homogeneous, spacing )
475475 self.alloc = None
476476
477477 self.radius = radius
544544 #TP.ProfileBegin( "Round*Box::expose" )
545545
546546 style = self.get_style()
547 gc = style.fg_gc[Gtk.STATE_NORMAL]
547 gc = style.fg_gc[gtk.STATE_NORMAL]
548548
549549 startX = event.area.x - self.alloc.x
550550 startY = event.area.y - self.alloc.y
612612
613613class RoundFixed( Gtk.Fixed ):
614614 def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF" ):
615 GObject.GObject.__init__( self )
615 Gtk.Fixed.__init__( self )
616616 self.alloc = None
617617
618618 self.radius = radius
691691 # Note: could maybe do some optimization to fill only areas that are within the dirty rect, but drawing
692692 # seems to be quite fast compared to python code, so just leave it at clipping by each geometry feature
693693
694 cr.set_source_rgb(*Gdk_color_to_cairo(self.bordercolor))
694 cr.set_source_rgb(*gdk_color_to_cairo(self.bordercolor))
695695 if self.borderW:
696696 if stopY > self.corner and startY < self.heightMINcorner:
697697 if startX < self.borderW: # draw left border
756756 #clickImg_path = imagefile(clickImg_path)
757757 #enterImg_path = imagefile(enterImg_path)
758758
759 GObject.GObject.__init__(self)
759 Gtk.Button.__init__(self)
760760 self.alloc = None
761761 self.image = {}
762762 self.itype = {}
778778 self.iheightDIV2[name] = self.iheight[name]//2
779779
780780 def prepareImage( name, path ):
781 pix = Gdk.pixbuf_new_from_file(path)
781 pix = gtk.gdk.pixbuf_new_from_file(path)
782782 if pix.get_has_alpha():
783783 if backgroundFill == None:
784784 self.image[name] = pix
785785 self.itype[name] = ITYPE.PIXBUF
786786 else:
787 self.image[name] = Gdk.Pixmap( win, pix.get_width(), pix.get_height() )
787 self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
788788 colormap = self.get_colormap()
789789 self.gc.foreground = colormap.alloc_color( backgroundFill, True, True )
790790 self.image[name].draw_rectangle( self.gc, True, 0, 0, pix.get_width(), pix.get_height() )
791 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), Gdk.RGB_DITHER_NONE )
791 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
792792 self.itype[name] = ITYPE.PIXMAP
793793 else:
794 self.image[name] = Gdk.Pixmap( win, pix.get_width(), pix.get_height() )
795 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), Gdk.RGB_DITHER_NONE )
794 self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
795 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
796796 self.itype[name] = ITYPE.PIXMAP
797797 self.iwidth[name] = pix.get_width()
798798 self.iwidthDIV2[name] = self.iwidth[name]//2
840840
841841 def expose(self, widget, event):
842842 if self.itype[self.curImage] == ITYPE.PIXBUF:
843 self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], Gdk.RGB_DITHER_NONE)
843 self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE)
844844 else:
845845 self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] )
846846 return True
857857 self.image[name] = pix
858858 self.itype[name] = ITYPE.PIXBUF
859859 else:
860 self.image[name] = Gdk.Pixmap( win, pix.get_width(), pix.get_height() )
860 self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
861861 colormap = self.get_colormap()
862862 self.gc.foreground = colormap.alloc_color( self.backgroundFill, True, True )
863863 self.image[name].draw_rectangle( self.gc, True, 0, 0, pix.get_width(), pix.get_height() )
864 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), Gdk.RGB_DITHER_NONE )
864 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
865865 self.itype[name] = ITYPE.PIXMAP
866866 else:
867 self.image[name] = Gdk.Pixmap( win, pix.get_width(), pix.get_height() )
868 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), Gdk.RGB_DITHER_NONE )
867 self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
868 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
869869 self.itype[name] = ITYPE.PIXMAP
870870 self.iwidth[name] = pix.get_width()
871871 self.iwidthDIV2[name] = self.iwidth[name]//2
890890 self.queue_draw()
891891
892892 def on_btn_enter(self, widget, event):
893 if event.mode == Gdk.CROSSING_NORMAL:
893 if event.mode == gtk.gdk.CROSSING_NORMAL:
894894 self.upImage = "enter"
895895 if self.down: self.curImage = "click"
896896 else: self.curImage = "enter"
897897 self.queue_draw()
898898
899899 def on_btn_leave(self, widget, event):
900 if event.mode == Gdk.CROSSING_NORMAL:
900 if event.mode == gtk.gdk.CROSSING_NORMAL:
901901 self.curImage = self.upImage = "main"
902902 self.queue_draw()
903903
918918 altImg_path = imagefile(altImg_path)
919919 enterImg_path = imagefile(enterImg_path)
920920
921 GObject.GObject.__init__(self)
921 Gtk.ToggleButton.__init__(self)
922922 self.alloc = None
923923 self.within = False
924924 self.clicked = False
994994 if self.itype[self.curImage] == ITYPE.PIXBUF:
995995 cr.set_source_surface(self.image[self.curImage], 0, 0)
996996 cr.paint()
997 #self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], Gdk.RGB_DITHER_NONE)
997 #self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE)
998998 else:
999999 cr.set_source_surface(self.image[self.curImage], 0, 0)
10001000 cr.paint()
10921092 altImg_path = imagefile(altImg_path)
10931093 enterImg_path = imagefile(enterImg_path)
10941094
1095 GObject.GObject.__init__(self, group)
1095 Gtk.RadioButton.__init__(self, group)
10961096 self.alloc = None
10971097 self.within = False
10981098 self.clicked = False
10991099
1100 win = Gdk.get_default_root_window()
1101 self.gc = Gdk.GC( win )
1100 win = gtk.gdk.get_default_root_window()
1101 self.gc = gtk.gdk.GC( win )
11021102 self.image = {}
11031103 self.itype = {}
11041104 self.iwidth = {}
11091109 self.backgroundFill = backgroundFill
11101110
11111111 def prepareImage( name, path ):
1112 pix = Gdk.pixbuf_new_from_file(path)
1112 pix = gtk.gdk.pixbuf_new_from_file(path)
11131113 if pix.get_has_alpha():
11141114 if backgroundFill == None:
11151115 self.image[name] = pix
11161116 self.itype[name] = ITYPE.PIXBUF
11171117 else:
1118 self.image[name] = Gdk.Pixmap( win, pix.get_width(), pix.get_height() )
1118 self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
11191119 colormap = self.get_colormap()
11201120 self.gc.foreground = colormap.alloc_color( backgroundFill, True, True )
11211121 self.image[name].draw_rectangle( self.gc, True, 0, 0, pix.get_width(), pix.get_height() )
1122 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), Gdk.RGB_DITHER_NONE )
1122 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
11231123 self.itype[name] = ITYPE.PIXMAP
11241124 else:
1125 self.image[name] = Gdk.Pixmap( win, pix.get_width(), pix.get_height() )
1126 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), Gdk.RGB_DITHER_NONE )
1125 self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
1126 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
11271127 self.itype[name] = ITYPE.PIXMAP
11281128 self.iwidth[name] = pix.get_width()
11291129 self.iwidthDIV2[name] = self.iwidth[name]//2
11631163
11641164 def expose(self, widget, event):
11651165 if self.itype[self.curImage] == ITYPE.PIXBUF:
1166 self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], Gdk.RGB_DITHER_NONE)
1166 self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE)
11671167 else:
11681168 self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] )
11691169 return True
11791179 self.image[name] = pix
11801180 self.itype[name] = ITYPE.PIXBUF
11811181 else:
1182 self.image[name] = Gdk.Pixmap( win, pix.get_width(), pix.get_height() )
1182 self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
11831183 colormap = self.get_colormap()
11841184 self.gc.foreground = colormap.alloc_color( self.backgroundFill, True, True )
11851185 self.image[name].draw_rectangle( self.gc, True, 0, 0, pix.get_width(), pix.get_height() )
1186 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), Gdk.RGB_DITHER_NONE )
1186 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
11871187 self.itype[name] = ITYPE.PIXMAP
11881188 else:
1189 self.image[name] = Gdk.Pixmap( win, pix.get_width(), pix.get_height() )
1190 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), Gdk.RGB_DITHER_NONE )
1189 self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
1190 self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE )
11911191 self.itype[name] = ITYPE.PIXMAP
11921192 self.iwidth[name] = pix.get_width()
11931193 self.iwidthDIV2[name] = self.iwidth[name]//2
12261226 self.toggleImage( self )
12271227
12281228 def on_btn_enter(self, widget, event):
1229 if event.mode == Gdk.CROSSING_NORMAL:
1229 if event.mode == gtk.gdk.CROSSING_NORMAL:
12301230 self.within = True
12311231 if not self.get_active() and not self.clicked:
12321232 self.curImage = "enter"
12351235 self.queue_draw()
12361236
12371237 def on_btn_leave(self, widget, event):
1238 if event.mode == Gdk.CROSSING_NORMAL:
1238 if event.mode == gtk.gdk.CROSSING_NORMAL:
12391239 self.within = False
12401240 if not self.get_active():
12411241 self.curImage = "main"
12511251class keyButton(Gtk.Button):
12521252 import cairo
12531253 def __init__(self, width, height, fillcolor, strokecolor):
1254 GObject.GObject.__init__(self)
1254 Gtk.Button.__init__(self)
12551255 self.alloc = None
1256 win = Gdk.get_default_root_window()
1257 self.gc = Gdk.GC(win)
1256 win = gtk.gdk.get_default_root_window()
1257 self.gc = gtk.gdk.GC(win)
12581258
12591259 self.connect('expose-event', self.expose)
12601260 self.connect('size-allocate', self.size_allocate)
13071307
13081308class BigComboBox(Gtk.ComboBox):
13091309 def __init__(self):
1310 GObject.GObject.__init__(self)
1310 Gtk.ComboBox.__init__(self)
13111311 self.model = Gtk.ListStore(int, str)
13121312 self.set_model(self.model)
13131313 self.text_renderer = Gtk.CellRendererText()