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

Commit 3f792924ddf4dba301d06e496ac6e29296fbd4e9

  • avatar
  • flavio
  • Fri Nov 09 18:58:22 EST 2012
  • Tree SHA1: be8fa4c
  • Parent SHA1: d5dddee (Commit from Sugar Labs: Translation System by user cjl.: 45 of 45 messages translated (0 fuzzy).)
  • raw diff | raw patch
Gtk 3 Port Base
.gitignore
(3 / 0)
  
11.sweets
2*.pyc
3*.pyo
4*.bak
activity.py
(48 / 38)
  
1212# along with this program; if not, write to the Free Software
1313# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1414
15import gtk
15import gi
16from gi.repository import Gtk
1617from gettext import gettext as _
1718
18from sugar.graphics.toggletoolbutton import ToggleToolButton
19from sugar.graphics.toolbutton import ToolButton
19from sugar3.graphics.toggletoolbutton import ToggleToolButton
20from sugar3.graphics.toolbutton import ToolButton
21from sugar3.activity.widgets import ActivityToolbarButton
22from sugar3.activity.widgets import StopButton
2023
2124from toolkit.activity import SharedActivity
2225from toolkit.temposlider import TempoSlider
2326from toolkit.toolbarbox import ToolbarBox
24from toolkit.activity_widgets import *
27#from toolkit.activity_widgets import *
2528
2629import model
2730import montage
2831import lessons
32#import theme
2933from messenger import Messenger, SERVICE
30from theme import *
3134
35
3236class flipsticksActivity(SharedActivity):
37
3338 def __init__(self, handle):
34 self.notebook = gtk.Notebook()
39
40 self.notebook = Gtk.Notebook()
41
3542 SharedActivity.__init__(self, self.notebook, SERVICE, handle)
3643
3744 self.notebook.show()
4646 self.notebook.props.show_tabs = False
4747
4848 self.montage = montage.View(self)
49 self.notebook.append_page(self.montage)
49 self.notebook.append_page(self.montage, Gtk.Label(''))
5050 self.lessons = lessons.View()
5151 self.lessons.show()
52 self.notebook.append_page(self.lessons)
52 self.notebook.append_page(self.lessons, Gtk.Label(''))
5353
5454 toolbox = ToolbarBox()
5555 toolbox.show()
6161 lessons_button.set_tooltip(_('Lessons'))
6262 toolbox.toolbar.insert(lessons_button, -1)
6363
64 separator = gtk.SeparatorToolItem()
64 separator = Gtk.SeparatorToolItem()
6565 separator.set_draw(False)
6666 toolbox.toolbar.insert(separator, -1)
6767
68 self.notebook_toolbar = gtk.Notebook()
68 self.notebook_toolbar = Gtk.Notebook()
6969 self.notebook_toolbar.props.show_border = False
7070 self.notebook_toolbar.props.show_tabs = False
71 self.notebook_toolbar.append_page(MontageToolbar(self.montage))
72 self.notebook_toolbar.append_page(LessonsToolbar())
71 self.notebook_toolbar.append_page(MontageToolbar(self.montage), Gtk.Label(''))
72 self.notebook_toolbar.append_page(LessonsToolbar(), Gtk.Label(''))
7373 self.notebook_toolbar.show()
7474
75 notebook_item = gtk.ToolItem()
75 notebook_item = Gtk.ToolItem()
7676 notebook_item.set_expand(True)
7777 notebook_item.add(self.notebook_toolbar)
7878 notebook_item.show()
9898 self.notebook_toolbar.set_current_page(page)
9999 self.notebook.set_current_page(page)
100100
101class MontageToolbar(gtk.Toolbar):
101class MontageToolbar(Gtk.Toolbar):
102
102103 def __init__(self, montage):
103 gtk.Toolbar.__init__(self)
104
105 Gtk.Toolbar.__init__(self)
106
104107 self.montage = montage
105108
106109 # edit buttons
107110
108111 setframe = ToolButton('dialog-ok')
109112 setframe.connect('clicked', self._setframe_cb)
110 setframe.set_tooltip(_('Set frame'))
113 setframe.set_tooltip_text(_('Set frame'))
111114 self.insert(setframe, -1)
112115
113 clearframe = ToolButton('gtk-delete')
116 clearframe = ToolButton('Gtk-delete')
114117 clearframe.connect('clicked', self._clearframe_cb)
115 clearframe.set_tooltip(_('Clear frame'))
118 clearframe.set_tooltip_text(_('Clear frame'))
116119 self.insert(clearframe, -1)
117120
118 resetframe = ToolButton('gtk-cancel')
121 resetframe = ToolButton('Gtk-cancel')
119122 resetframe.connect('clicked', self._resetframe_cb)
120 resetframe.set_tooltip(_('Reset'))
123 resetframe.set_tooltip_text(_('Reset'))
121124 self.insert(resetframe, -1)
122125
123 separator = gtk.SeparatorToolItem()
126 separator = Gtk.SeparatorToolItem()
124127 self.insert(separator,-1)
125128
126129 # play/pause buttons
127130
128 play_img_1 = gtk.Image()
131 play_img_1 = Gtk.Image()
129132 play_img_1.set_from_icon_name('media-playback-start-back',
130 gtk.ICON_SIZE_LARGE_TOOLBAR)
131 pause_img_1 = gtk.Image()
133 Gtk.IconSize.LARGE_TOOLBAR)
134 pause_img_1 = Gtk.Image()
132135 pause_img_1.set_from_icon_name('media-playback-pause',
133 gtk.ICON_SIZE_LARGE_TOOLBAR)
136 Gtk.IconSize.LARGE_TOOLBAR)
134137
135 play_img_2 = gtk.Image()
138 play_img_2 = Gtk.Image()
136139 play_img_2.set_from_icon_name('media-playback-start',
137 gtk.ICON_SIZE_LARGE_TOOLBAR)
138 pause_img_2 = gtk.Image()
140 Gtk.IconSize.LARGE_TOOLBAR)
141 pause_img_2 = Gtk.Image()
139142 pause_img_2.set_from_icon_name('media-playback-pause',
140 gtk.ICON_SIZE_LARGE_TOOLBAR)
143 Gtk.IconSize.LARGE_TOOLBAR)
141144
142145 paly_1 = ToggleToolButton('media-playback-start-back')
143146 play_2 = ToggleToolButton('media-playback-start')
149149 (paly_1, play_2), (play_img_1, pause_img_1),
150150 self.montage.playbackwards)
151151 self.insert(paly_1, -1)
152 paly_1.set_tooltip(_('Play backward / Pause'))
152 paly_1.set_tooltip_text(_('Play backward / Pause'))
153153
154154 play_2.connect('toggled', self._play_cb,
155155 (play_2, paly_1), (play_img_2, pause_img_2),
156156 self.montage.playforwards)
157157 self.insert(play_2, -1)
158 play_2.set_tooltip(_('Play forward / Pause'))
158 play_2.set_tooltip_text(_('Play forward / Pause'))
159159
160160 # tempo button
161161
163163 tempo.adjustment.connect("value-changed", self._tempo_cb)
164164 tempo.set_size_request(200, -1)
165165 tempo.set_value(50)
166 tempo_item = gtk.ToolItem()
166 tempo_item = Gtk.ToolItem()
167167 tempo_item.add(tempo)
168168 self.insert(tempo_item, -1)
169169
170 separator = gtk.SeparatorToolItem()
170 separator = Gtk.SeparatorToolItem()
171171 self.insert(separator,-1)
172172
173173 # export buttons
174174
175175 exportframe = ToolButton('image')
176176 exportframe.connect('clicked', self._exportframe_cb)
177 exportframe.set_tooltip(_('Snapshot'))
177 exportframe.set_tooltip_text(_('Snapshot'))
178178 self.insert(exportframe, -1)
179179
180180 self.show_all()
192192 self.montage.reset()
193193
194194 def _tempo_cb(self, widget):
195 self.montage.setplayspeed(widget.value)
195 self.montage.setplayspeed(widget.get_value())
196196
197197 def _play_cb(self, widget, buttons, images, play):
198198 if widget.get_active():
205205 widget.set_icon_widget(images[0])
206206 self.montage.stop()
207207
208class LessonsToolbar(gtk.Toolbar):
208class LessonsToolbar(Gtk.Toolbar):
209209 def __init__(self):
210 gtk.Toolbar.__init__(self)
210 Gtk.Toolbar.__init__(self)
211211 self._mask = False
212212
213213 for lesson in lessons.THEMES:
214 button = gtk.ToggleToolButton()
214 button = Gtk.ToggleToolButton()
215215 button.set_label(lesson.name)
216216 button.connect('clicked', self._lessons_cb, lesson)
217217 self.insert(button, -1)
lessons.py
(16 / 14)
  
1313# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1414
1515import os
16import gtk
16import gi
17from gi.repository import Gtk
18from gi.repository import Gdk
1719import locale
1820import logging
1921from glob import glob
2022
21from sugar.activity.activity import get_bundle_path
23from sugar3.activity.activity import get_bundle_path
2224
2325import theme
2426
3838 def change(self):
3939 View.notebook.set_current_page(self.index)
4040
41class View(gtk.EventBox):
41class View(Gtk.EventBox):
4242 notebook = None
4343
4444 def __init__(self):
45 gtk.EventBox.__init__(self)
45 Gtk.EventBox.__init__(self)
4646
47 View.notebook = gtk.Notebook()
47 View.notebook = Gtk.Notebook()
4848 View.notebook.props.show_border = False
4949 View.notebook.props.show_tabs = False
5050 self.add(View.notebook)
5151
5252 for i in THEMES:
53 view = gtk.TextView()
53 view = Gtk.TextView()
5454 view.get_buffer().set_text(i.text)
55 view.set_wrap_mode(gtk.WRAP_WORD)
55 view.set_wrap_mode(Gtk.WrapMode.WORD)
5656 view.set_editable(False)
5757
58 view_box = gtk.EventBox()
58 view_box = Gtk.EventBox()
5959 view_box.add(view)
60 view_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(theme.WHITE))
60 view_box.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(theme.WHITE))
6161 view_box.props.border_width = 10
6262
63 border_box = gtk.EventBox()
63 border_box = Gtk.EventBox()
6464 border_box.add(view_box)
65 border_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(theme.WHITE))
65 border_box.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(theme.WHITE))
6666
67 scrolled_window = gtk.ScrolledWindow()
68 scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
67 scrolled_window = Gtk.ScrolledWindow()
68 scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
6969 scrolled_window.add_with_viewport(border_box)
7070
71 View.notebook.append_page(scrolled_window)
71 View.notebook.append_page(scrolled_window, Gtk.Label(''))
7272
7373 self.show_all()
7474
  
2424except (ImportError, AttributeError):
2525 import simplejson as json
2626
27from sugar.presence import presenceservice
27from sugar3.presence import presenceservice
2828
2929import model
3030
montage.py
(170 / 132)
  
1818### (c) 2007 World Wide Workshop Foundation
1919
2020import os
21import gtk
21import gi
22from gi.repository import Gtk
23from gi.repository import Gdk
24from gi.repository import GObject
2225import math
23import gobject
2426import logging
25from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
2627from gettext import gettext as _
2728
28from sugar.activity.activity import get_bundle_path
29from sugar3.activity.activity import get_bundle_path
2930
3031import model
3132import screenflip
3737logger = logging.getLogger('flipsticks')
3838
3939
40class View(gtk.EventBox):
40class View(Gtk.EventBox):
4141 __gsignals__ = {
42 'frame-changed': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT])}
42 'frame-changed': (GObject.SIGNAL_RUN_FIRST,
43 GObject.TYPE_NONE, [GObject.TYPE_PYOBJECT])}
4344
4445 def set_keyframe(self, value):
4546 i, key = value
5151 model.keys[i] = key
5252 self.restore()
5353
54 keyframe = gobject.property(type=object, getter=None, setter=set_keyframe)
54 keyframe = GObject.property(type=object, getter=None, setter=set_keyframe)
5555
5656 def reset(self):
5757 self.key.reset()
7171 def setplayspeed(self, value):
7272 self.waittime = int((100 - value) * 5)
7373 if self.playing:
74 gobject.source_remove(self.playing)
75 self.playing = gobject.timeout_add(self.waittime, self.playframe)
74 GObject.source_remove(self.playing)
75 self.playing = GObject.timeout_add(self.waittime, self.playframe)
7676
7777 def playbackwards(self):
7878 if self.playing:
79 gobject.source_remove(self.playing)
79 GObject.source_remove(self.playing)
8080
8181 self.frames = kinematic.makeframes()
8282 fsecs = self.frames.keys()
8888 self.playingbackwards = True
8989
9090 logger.debug('playbackwards speed=%s' % self.waittime)
91 self.playing = gobject.timeout_add(self.waittime, self.playframe)
91 self.playing = GObject.timeout_add(self.waittime, self.playframe)
9292
9393 def playforwards(self):
9494 if self.playing:
95 gobject.source_remove(self.playing)
95 GObject.source_remove(self.playing)
9696
9797 self.frames = kinematic.makeframes()
9898 fsecs = self.frames.keys()
104104
105105 logger.debug('playforwards speed=%s' % self.waittime)
106106 self.playingbackwards = False
107 self.playing = gobject.timeout_add(self.waittime, self.playframe)
107 self.playing = GObject.timeout_add(self.waittime, self.playframe)
108108
109109 def stop(self):
110110 if not self.playing:
111111 return
112112
113 gobject.source_remove(self.playing)
113 GObject.source_remove(self.playing)
114114 self.playing = None
115115
116116 # set the main window to the keyframe
120120 self.updateentrybox()
121121
122122 def exportframe(self):
123
123124 self.frames = kinematic.makeframes()
124125 fsecs = self.frames.keys()
125126 firstpixindex = fsecs[0]
126127
127 x, y, width, height = self.mfdraw.get_allocation()
128 pixmap = gtk.gdk.Pixmap(self.mfdraw.window, width, height)
129 self._draw_frame(fsecs[0], pixmap)
130 pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
131 gtk.gdk.Pixbuf.get_from_drawable(pixbuf, pixmap, pixmap.get_colormap(), 0, 0, 0, 0, width, height)
128 rect = self.mfdraw.get_allocation()
129 # FIXME: There is no longer Pixmap
130 #pixmap = Gdk.Pixmap(self.mfdraw.window, rect.width, rect.height)
131 #self._draw_frame(fsecs[0], pixmap)
132 #pixbuf = Gdk.Pixbuf(Gdk.RGBA, False, 8, rect.width, rect.height)
133 #Gdk.Pixbuf.get_from_drawable(pixbuf, pixmap, pixmap.get_colormap(),
134 #0, 0, 0, 0, rect.width, rect.height)
132135
133 model.screen_shot(pixbuf)
136 #model.screen_shot(pixbuf)
134137
135138 def restore(self):
136139 self.drawkeyframe()
137140 self.syncmaintokf()
138141 self.updateentrybox()
139142
140 def expose_event(self, widget, event):
141 x, y, width, height = event.area
142 widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL],
143 self.pixmap, x, y, x, y, width, height)
143 def expose_event(self, widget, context):
144
145 rect = widget.get_allocation()
146 # FIXME: AttributeError: 'X11Window' object has no attribute 'draw_drawable'
147 #widget.get_property('window').draw_drawable(widget.get_style().fg_gc[Gtk.StateType.NORMAL],
148 # self.pixmap, rect.x, rect.y,
149 # rect.x, rect.y, rect.width, rect.height)
144150 return False
145151
146 def kf_expose_event(self, widget, event):
147 x, y, width, height = event.area
148 widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL],
149 self.kfpixmap, x, y, x, y, width, height)
152 def kf_expose_event(self, widget, context):
153
154 rect = widget.get_allocation()
155 # FIXME: AttributeError: 'X11Window' object has no attribute 'draw_drawable'
156 #widget.window.draw_drawable(widget.get_style().fg_gc[Gtk.StateType.NORMAL],
157 # self.kfpixmap, rect.x, rect.y,
158 # rect.x, rect.y, rect.width, rect.height)
150159 return False
151160
152161 def configure_event(self, widget, event):
153 x, y, width, height = self.mfdraw.get_allocation()
154 self.pixmap = gtk.gdk.Pixmap(self.mfdraw.window, width, height)
162
163 rect = self.mfdraw.get_allocation()
164 # FIXME: AttributeError: 'gi.repository.Gdk' object has no attribute 'Pixmap'
165 #self.pixmap = Gdk.Pixmap(self.mfdraw.window, rect.width, rect.height)
155166 self.drawmainframe()
156167 return True
157168
171171 return True
172172
173173 def motion_notify_event(self, widget, event):
174
174175 if event.is_hint:
175 x, y, state = event.window.get_pointer()
176 # FIXME: ValueError: too many values to unpack
177 #x, y, state = event.window.get_pointer()
178 state = False
179
176180 else:
177181 x = event.x
178182 y = event.y
179183 state = event.state
180 if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:
184
185 if state & Gdk.EventMask.BUTTON1_MOTION_MASK and self.pixmap != None:
181186 if self.jointpressed:
182187 if _inarea(widget, x, y):
183188 #self.key.joints[self.jointpressed] = (x,y) # old hack way
256256 return True
257257
258258 def kf_motion_notify_event(self, widget, event):
259
259260 if event.is_hint:
260 x, y, state = event.window.get_pointer()
261 # FIXME: ValueError: too many values to unpack
262 # x, y, state = event.window.get_pointer()
263 state = False
264
261265 else:
262266 x = event.x
263267 y = event.y
264268 state = event.state
265 if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:
269
270 if state & Gdk.EventMask.BUTTON1_MOTION_MASK and self.pixmap != None:
266271 if self.kfpressed >= 0:
267272 if _inarea(widget, x, y):
268273 xdiff = int(x - self.kf_mouse_pos)
277277 frame.move(xdiff)
278278
279279 if self._emit_move_handle:
280 gobject.source_remove(self._emit_move_handle)
280 GObject.source_remove(self._emit_move_handle)
281281 if self._emit_move_key != self.kfpressed:
282282 self._emit_move(self._emit_move_key)
283283
284284 self._emit_move_key = self.kfpressed
285 self._emit_move_handle = gobject.timeout_add(
285 self._emit_move_handle = GObject.timeout_add(
286286 MOVEMIT_TIMEOUT, self._emit_move,
287287 self.kfpressed)
288288
414414 def drawmainframe(self):
415415 if not self.pixmap:
416416 return
417
417 # FIXME: AttributeError: 'flipsticksActivity' object has no attribute 'window'
418 #area = self.get_root_window()#self.toplevel.window
419 '''
418420 area = self.toplevel.window
419421 drawgc = area.new_gc()
420422 drawgc.line_width = 3
427427 black = cm.alloc_color('black')
428428 blue = cm.alloc_color('blue')
429429 green = cm.alloc_color('green')
430 drawgc.fill = gtk.gdk.SOLID
430 drawgc.fill = Gdk.SOLID
431431 x, y, width, height = self.mfdraw.get_allocation()
432 #self.pixmap = gtk.gdk.Pixmap(self.mfdraw.window, width, height)
432 #self.pixmap = Gdk.Pixmap(self.mfdraw.window, width, height)
433433 # clear area
434434 drawgc.set_foreground(white)
435435 self.pixmap.draw_rectangle(drawgc, True, 0, 0, width, height)
465465 drawgc.set_foreground(red)
466466 self.pixmap.draw_arc(drawgc, True, x - 5, y - 5, 10, 10, 0, 360 * 64)
467467 drawgc.set_foreground(black)
468 self.mfdraw.queue_draw()
468 self.mfdraw.queue_draw()'''
469 pass
469470
470471 def drawstickman(self, drawgc, pixmap, middle, joints, hsize, rhsize, lhsize):
471472 leftarm = [middle, joints['leftshoulder'], joints['leftelbow'], joints['lefthand']]
492492 pixmap.draw_arc(drawgc, True, x - int(lhsize / 2.0), y - int(lhsize / 2.0), lhsize, lhsize, 0, 360 * 64)
493493
494494 def drawkeyframe(self):
495 area = self.toplevel.window
495
496 # FIXME: AttributeError: 'flipsticksActivity' object has no attribute 'window'
497 #area = self.get_root_window()#self.toplevel.window
498 '''
496499 drawgc = area.new_gc()
497500 drawgc.line_width = 2
498501 cm = drawgc.get_colormap()
507507 pink = cm.alloc_color(PINK)
508508 bgcolor = cm.alloc_color(BACKGROUND)
509509 darkgreen = cm.alloc_color(BUTTON_BACKGROUND)
510 drawgc.fill = gtk.gdk.SOLID
510 drawgc.fill = Gdk.SOLID
511511 x, y, width, height = self.kfdraw.get_allocation()
512 self.kfpixmap = gtk.gdk.Pixmap(self.kfdraw.window, width, height)
512 self.kfpixmap = Gdk.Pixmap(self.kfdraw.window, width, height)
513513 # clear area
514514 drawgc.set_foreground(bgcolor)
515515 self.kfpixmap.draw_rectangle(drawgc, True, 0, 0, width, height)
546546 lhsize = int(model.keys[i].parts['LEFT HAND'] * 0.2)
547547 self.drawstickman(drawgc, self.kfpixmap, (x, y), model.keys[i].scaled_joints, hsize, rhsize, lhsize)
548548 #self.kfpixmap.draw_arc(drawgc,True,x-5,y-5,10,10,0,360*64)
549 self.kfdraw.queue_draw()
549 self.kfdraw.queue_draw()'''
550 pass
550551
551552 def drawfp(self):
552 area = self.toplevel.window
553 # FIXME: AttributeError: 'flipsticksActivity' object has no attribute 'window'
554 #area = self.get_root_window()#self.toplevel.window
555 '''
553556 drawgc = area.new_gc()
554557 drawgc.line_width = 1
555558 cm = drawgc.get_colormap()
564564 pink = cm.alloc_color(PINK)
565565 bgcolor = cm.alloc_color(BACKGROUND)
566566 darkgreen = cm.alloc_color(BUTTON_BACKGROUND)
567 drawgc.fill = gtk.gdk.SOLID
567 drawgc.fill = Gdk.SOLID
568568 x, y, width, height = self.fpdraw.get_allocation()
569 self.fppixmap = gtk.gdk.Pixmap(self.fpdraw.window, width, height)
569 self.fppixmap = Gdk.Pixmap(self.fpdraw.window, width, height)
570570 # clear area
571571 drawgc.set_foreground(white)
572572 self.fppixmap.draw_rectangle(drawgc, True, 0, 0, width, height)
573 self.fpdraw.queue_draw()
573 self.fpdraw.queue_draw()'''
574 pass
574575
575576 def selectstick(self, widget, event, data=None):
576577 if data:
577578 if self.stickselected:
578579 ebox = self.stickbuttons[self.stickselected]
579 ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_BACKGROUND))
580 ebox.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_BACKGROUND))
580581 label = ebox.get_child()
581 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_FOREGROUND))
582 label.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_FOREGROUND))
582583 self.stickselected = data
583584 self.selectstickebox()
584585
585586 def selectstickebox(self):
586587 ebox = self.stickbuttons[self.stickselected]
587 ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_FOREGROUND))
588 ebox.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_FOREGROUND))
588589 label = ebox.get_child()
589 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_BACKGROUND))
590 label.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_BACKGROUND))
590591
591592 if self.stickselected in self.key.sticks:
592593 size = self.key.sticks[self.stickselected][1]
609609 self.size_adj.set_value(size)
610610
611611 def __init__(self, activity):
612 gtk.EventBox.__init__(self)
612 Gtk.EventBox.__init__(self)
613613
614614 self.playing = False
615615 self.playingbackwards = False
635635
636636 # screen
637637
638 self.mfdraw = gtk.DrawingArea()
639 self.mfdraw.connect('expose_event', self.expose_event)
638 self.mfdraw = Gtk.DrawingArea()
639 self.mfdraw.connect('draw', self.expose_event)
640640 self.mfdraw.connect('configure_event', self.configure_event)
641641 self.mfdraw.connect('motion_notify_event', self.motion_notify_event)
642642 self.mfdraw.connect('button_press_event', self.button_press_event)
643643 self.mfdraw.connect('button_release_event', self.button_release_event)
644 self.mfdraw.set_events(gtk.gdk.EXPOSURE_MASK
645 | gtk.gdk.LEAVE_NOTIFY_MASK
646 | gtk.gdk.BUTTON_PRESS_MASK
647 | gtk.gdk.BUTTON_RELEASE_MASK
648 | gtk.gdk.POINTER_MOTION_MASK
649 | gtk.gdk.POINTER_MOTION_HINT_MASK)
644 self.mfdraw.set_events(Gdk.EventMask.EXPOSURE_MASK
645 | Gdk.EventMask.LEAVE_NOTIFY_MASK
646 | Gdk.EventMask.BUTTON_PRESS_MASK
647 | Gdk.EventMask.BUTTON_RELEASE_MASK
648 | Gdk.EventMask.POINTER_MOTION_MASK
649 | Gdk.EventMask.POINTER_MOTION_HINT_MASK)
650650 self.mfdraw.set_size_request(DRAWWIDTH, DRAWHEIGHT)
651651
652 screen_box = gtk.EventBox()
653 screen_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BACKGROUND))
652 screen_box = Gtk.EventBox()
653 screen_box.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BACKGROUND))
654654 screen_box.set_border_width(PAD / 2)
655655 screen_box.add(self.mfdraw)
656656
657 screen_pink = gtk.EventBox()
658 screen_pink.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(PINK))
657 screen_pink = Gtk.EventBox()
658 screen_pink.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(PINK))
659659 screen_pink.set_border_width(PAD)
660660 screen_pink.add(screen_box)
661661
662662 # keyframes
663663
664 self.kfdraw = gtk.DrawingArea()
664 self.kfdraw = Gtk.DrawingArea()
665665 self.kfdraw.set_size_request(KEYFRAMEWIDTH, KEYFRAMEHEIGHT)
666 self.kfdraw.connect('expose_event', self.kf_expose_event)
666 self.kfdraw.connect('draw', self.kf_expose_event)
667667 self.kfdraw.connect('configure_event', self.kf_configure_event)
668668 self.kfdraw.connect('motion_notify_event', self.kf_motion_notify_event)
669669 self.kfdraw.connect('button_press_event', self.kf_button_press_event)
670670 self.kfdraw.connect('button_release_event', self.kf_button_release_event)
671 self.kfdraw.set_events(gtk.gdk.EXPOSURE_MASK
672 | gtk.gdk.LEAVE_NOTIFY_MASK
673 | gtk.gdk.BUTTON_PRESS_MASK
674 | gtk.gdk.BUTTON_RELEASE_MASK
675 | gtk.gdk.POINTER_MOTION_MASK
676 | gtk.gdk.POINTER_MOTION_HINT_MASK)
671 self.kfdraw.set_events(Gdk.EventMask.EXPOSURE_MASK
672 | Gdk.EventMask.LEAVE_NOTIFY_MASK
673 | Gdk.EventMask.BUTTON_PRESS_MASK
674 | Gdk.EventMask.BUTTON_RELEASE_MASK
675 | Gdk.EventMask.POINTER_MOTION_MASK
676 | Gdk.EventMask.POINTER_MOTION_HINT_MASK)
677677
678 kfdraw_box = gtk.EventBox()
678 kfdraw_box = Gtk.EventBox()
679679 kfdraw_box.set_border_width(PAD)
680680 kfdraw_box.add(self.kfdraw)
681681
682682 # control box
683683
684 angle_box = gtk.HBox()
685 anglelabel = gtk.Label(_('Angle:'))
686 anglelabel.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_BACKGROUND))
684 angle_box = Gtk.HBox()
685 anglelabel = Gtk.Label(_('Angle:'))
686 anglelabel.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_BACKGROUND))
687687 anglelabel.set_size_request(60, -1)
688688 angle_box.pack_start(anglelabel, False, False, 5)
689 self.angleentry = gtk.Entry()
689 self.angleentry = Gtk.Entry()
690690 self.angleentry.set_max_length(3)
691691 self.angleentry.set_width_chars(3)
692692 self.angleentry.connect('activate', self.enterangle_callback, self.angleentry)
693 self.angleentry.modify_bg(gtk.STATE_INSENSITIVE,
694 gtk.gdk.color_parse(BUTTON_FOREGROUND))
693 self.angleentry.modify_bg(Gtk.StateType.INSENSITIVE,
694 Gdk.color_parse(BUTTON_FOREGROUND))
695695 angle_box.pack_start(self.angleentry, False, False, 0)
696 self.anglel_adj = gtk.Adjustment(0, 0, 360, 1, 60, 0)
696 self.anglel_adj = Gtk.Adjustment(0, 0, 360, 1, 60, 0)
697697 self.anglel_adj.connect('value_changed', self._anglel_adj_cb)
698 self.anglel_slider = gtk.HScale(self.anglel_adj)
698 self.anglel_slider = Gtk.HScale()
699 self.anglel_slider.set_adjustment(self.anglel_adj)
699700 self.anglel_slider.set_draw_value(False)
700701 for state, color in COLOR_BG_BUTTONS:
701 self.anglel_slider.modify_bg(state, gtk.gdk.color_parse(color))
702 angle_box.pack_start(self.anglel_slider)
702 self.anglel_slider.modify_bg(state, Gdk.color_parse(color))
703 angle_box.pack_start(self.anglel_slider, False, False, 0)
703704
704 size_box = gtk.HBox()
705 sizelabel = gtk.Label(_('Size:'))
706 sizelabel.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_BACKGROUND))
705 size_box = Gtk.HBox()
706 sizelabel = Gtk.Label(_('Size:'))
707 sizelabel.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_BACKGROUND))
707708 sizelabel.set_size_request(60, -1)
708709 size_box.pack_start(sizelabel, False, False, 5)
709 self.sizeentry = gtk.Entry()
710 self.sizeentry = Gtk.Entry()
710711 self.sizeentry.set_max_length(3)
711712 self.sizeentry.set_width_chars(3)
712713 self.sizeentry.connect('activate', self.enterlen_callback, self.sizeentry)
713 self.sizeentry.modify_bg(gtk.STATE_INSENSITIVE,
714 gtk.gdk.color_parse(BUTTON_FOREGROUND))
714 self.sizeentry.modify_bg(Gtk.StateType.INSENSITIVE,
715 Gdk.color_parse(BUTTON_FOREGROUND))
715716 size_box.pack_start(self.sizeentry, False, False, 0)
716 self.size_adj = gtk.Adjustment(0, 0, 200, 1, 30, 0)
717 self.size_adj = Gtk.Adjustment(0, 0, 200, 1, 30, 0)
717718 self.size_adj.connect('value_changed', self._size_adj_cb)
718 size_slider = gtk.HScale(self.size_adj)
719 size_slider = Gtk.HScale()
720 size_slider.set_adjustment(self.size_adj)
719721 size_slider.set_draw_value(False)
720722 for state, color in COLOR_BG_BUTTONS:
721 size_slider.modify_bg(state, gtk.gdk.color_parse(color))
722 size_box.pack_start(size_slider)
723 size_slider.modify_bg(state, Gdk.color_parse(color))
724 size_box.pack_start(size_slider, False, False, 0)
723725
724 control_head_box = gtk.VBox()
725 control_head_box.pack_start(angle_box)
726 control_head_box.pack_start(size_box)
726 control_head_box = Gtk.VBox()
727 control_head_box.pack_start(angle_box, False, False, 0)
728 control_head_box.pack_start(size_box, False, False, 0)
727729
728 control_head = gtk.EventBox()
729 control_head.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_FOREGROUND))
730 control_head = Gtk.EventBox()
731 control_head.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_FOREGROUND))
730732 control_head.add(control_head_box)
731733
732 control_options = gtk.VBox()
734 control_options = Gtk.VBox()
733735 self.stickbuttons = {}
734736 self.sticklabels = {}
735737 for stickpartname in LABELLIST:
736 label = gtk.Label(STRINGS[stickpartname])
737 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_FOREGROUND))
738 label = Gtk.Label(STRINGS[stickpartname])
739 label.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_FOREGROUND))
738740 self.sticklabels[stickpartname] = label
739 ebox = gtk.EventBox()
740 ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_BACKGROUND))
741 ebox.set_events(gtk.gdk.BUTTON_PRESS_MASK)
741 ebox = Gtk.EventBox()
742 ebox.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_BACKGROUND))
743 ebox.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
742744 ebox.connect('button_press_event', self.selectstick, stickpartname)
743745 ebox.add(label)
744746 self.stickbuttons[stickpartname] = ebox
745747 control_options.pack_start(ebox, False, False, 0)
746748 self.selectstickebox()
747749
748 control_scroll = gtk.ScrolledWindow()
749 control_scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
750 control_scroll = Gtk.ScrolledWindow()
751 control_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
750752 control_scroll.add_with_viewport(control_options)
751 control_options.get_parent().modify_bg(gtk.STATE_NORMAL,
752 gtk.gdk.color_parse(BUTTON_BACKGROUND))
753 control_options.get_parent().modify_bg(Gtk.StateType.NORMAL,
754 Gdk.color_parse(BUTTON_BACKGROUND))
753755
754 control_box = gtk.VBox()
756 control_box = Gtk.VBox()
755757 control_box.pack_start(control_head, False, False, 0)
756 control_box.pack_start(control_scroll)
758 control_box.pack_start(control_scroll, False, False, 0)
757759
758 control_bg = gtk.EventBox()
759 control_bg.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BUTTON_BACKGROUND))
760 control_bg = Gtk.EventBox()
761 control_bg.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_BACKGROUND))
760762 control_bg.set_border_width(PAD / 2)
761763 control_bg.add(control_box)
762764
763 control_pink = gtk.EventBox()
764 control_pink.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(PINK))
765 control_pink = Gtk.EventBox()
766 control_pink.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(PINK))
765767 control_pink.set_border_width(PAD)
766768 control_pink.add(control_bg)
767769
768770 # left control box
769771
770 logo = gtk.Image()
772 logo = Gtk.Image()
771773 logo.set_from_file(os.path.join(self.iconsdir, 'logo.png'))
772774
773 leftbox = gtk.VBox()
774 leftbox.pack_start(logo, False, False)
775 leftbox.pack_start(control_pink)
775 leftbox = Gtk.VBox()
776 leftbox.pack_start(logo, False, False, 0)
777 leftbox.pack_start(control_pink, False, False, 0)
776778
777779 # desktop
778780
779 hdesktop = gtk.HBox()
780 hdesktop.pack_start(leftbox, False)
781 hdesktop.pack_start(screen_pink, False, False)
781 hdesktop = Gtk.HBox()
782 hdesktop.pack_start(leftbox, False, False, 0)
783 hdesktop.pack_start(screen_pink, False, False, 0)
782784
783 desktop = gtk.VBox()
784 desktop.pack_start(hdesktop)
785 desktop = Gtk.VBox()
786 desktop.pack_start(hdesktop, False, False, 0)
785787 desktop.pack_start(kfdraw_box, False, False, 0)
786788
787 greenbox = gtk.EventBox()
788 greenbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BACKGROUND))
789 greenbox = Gtk.EventBox()
790 greenbox.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BACKGROUND))
789791 greenbox.set_border_width(PAD / 2)
790792 greenbox.add(desktop)
791793
792 self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(YELLOW))
794 self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(YELLOW))
793795 self.add(greenbox)
794796 self.show_all()
795797
796798 def _draw_frame(self, index, pixmap):
799 # FIXME: AttributeError: 'X11Window' object has no attribute 'new_gc'
800 '''
797801 joints = self.frames[index].joints
798802 parts = self.frames[index].parts
799803 # draw on the main drawing area
807807 cm = drawgc.get_colormap()
808808 white = cm.alloc_color('white')
809809 black = cm.alloc_color('black')
810 drawgc.fill = gtk.gdk.SOLID
810 drawgc.fill = Gdk.SOLID
811811 x, y, width, height = self.mfdraw.get_allocation()
812 #pixmap = gtk.gdk.Pixmap(self.mfdraw.window, width, height)
812 #pixmap = Gdk.Pixmap(self.mfdraw.window, width, height)
813813 # clear area
814814 drawgc.set_foreground(white)
815815 pixmap.draw_rectangle(drawgc, True, 0, 0, width, height)
819819 middle = self.frames[index].middle
820820 rhsize = parts['RIGHT HAND']
821821 lhsize = parts['LEFT HAND']
822 self.drawstickman(drawgc, pixmap, middle, joints, hsize, rhsize, lhsize)
822 self.drawstickman(drawgc, pixmap, middle, joints, hsize, rhsize, lhsize)'''
823 pass
823824
824825 def _inkeyframe(self, x, y):
825826 dy = math.pow(abs(y - KEYFRAMEHEIGHT / 2), 2)
836836 return -1
837837
838838 def _anglel_adj_cb(self, adj):
839 self.angleentry.set_text(str(int(adj.value)))
839 self.angleentry.set_text(str(int(adj.get_value())))
840840 self.enterangle_callback(None, self.angleentry)
841841
842842 def _size_adj_cb(self, adj):
843 self.sizeentry.set_text(str(int(adj.value)))
843 self.sizeentry.set_text(str(int(adj.get_value())))
844844 self.enterlen_callback(None, self.sizeentry)
845845
846846 def _emit_move(self, key):
setup.py
(1 / 1)
  
1616# along with this program; if not, write to the Free Software
1717# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
19from sugar.activity import bundlebuilder
19from sugar3.activity import bundlebuilder
2020bundlebuilder.start()
theme.py
(23 / 20)
  
1212# along with this program; if not, write to the Free Software
1313# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1414
15import gtk
15import gi
16from gi.repository import Gtk
17from gi.repository import GdkX11
1618from gettext import gettext as _
1719
18from sugar.graphics import style
20from sugar3.graphics import style
1921
2022GRAY = "#B7B7B7" # gray
2123PINK = "#FF0099" # pink
2828BUTTON_FOREGROUND = "#CCFB99" # very light green
2929BUTTON_BACKGROUND = "#027F01" # dark green
3030COLOR_FG_BUTTONS = (
31 (gtk.STATE_NORMAL,"#CCFF99"),
32 (gtk.STATE_ACTIVE,"#CCFF99"),
33 (gtk.STATE_PRELIGHT,"#CCFF99"),
34 (gtk.STATE_SELECTED,"#CCFF99"),
35 (gtk.STATE_INSENSITIVE,"#CCFF99"),
31 (Gtk.StateType.NORMAL,"#CCFF99"),
32 (Gtk.StateType.ACTIVE,"#CCFF99"),
33 (Gtk.StateType.PRELIGHT,"#CCFF99"),
34 (Gtk.StateType.SELECTED,"#CCFF99"),
35 (Gtk.StateType.INSENSITIVE,"#CCFF99"),
3636 ) # very light green
3737COLOR_BG_BUTTONS = (
38 (gtk.STATE_NORMAL,"#027F01"),
39 (gtk.STATE_ACTIVE,"#CCFF99"),
40 (gtk.STATE_PRELIGHT,"#016D01"),
41 (gtk.STATE_SELECTED,"#CCFF99"),
42 (gtk.STATE_INSENSITIVE,"#027F01"),
38 (Gtk.StateType.NORMAL,"#027F01"),
39 (Gtk.StateType.ACTIVE,"#CCFF99"),
40 (Gtk.StateType.PRELIGHT,"#016D01"),
41 (Gtk.StateType.SELECTED,"#CCFF99"),
42 (Gtk.StateType.INSENSITIVE,"#027F01"),
4343 )
4444OLD_COLOR_BG_BUTTONS = (
45 (gtk.STATE_NORMAL,"#027F01"),
46 (gtk.STATE_ACTIVE,"#014D01"),
47 (gtk.STATE_PRELIGHT,"#016D01"),
48 (gtk.STATE_SELECTED,"#027F01"),
49 (gtk.STATE_INSENSITIVE,"#027F01"),
45 (Gtk.StateType.NORMAL,"#027F01"),
46 (Gtk.StateType.ACTIVE,"#014D01"),
47 (Gtk.StateType.PRELIGHT,"#016D01"),
48 (Gtk.StateType.SELECTED,"#027F01"),
49 (Gtk.StateType.INSENSITIVE,"#027F01"),
5050 )
5151
5252STRINGS = { 'size' : _('Size'),
7878LOGO_WIDTH = 276
7979TOLLBAR_HEIGHT = style.LARGE_ICON_SIZE
8080
81KEYFRAMEWIDTH = gtk.gdk.screen_width() - PAD*3
81screen = GdkX11.X11Screen()
82KEYFRAMEWIDTH = int(screen.width()) - PAD*3
8283KEYFRAMEHEIGHT = 80
8384
84DRAWWIDTH = gtk.gdk.screen_width() - LOGO_WIDTH - PAD*4
85DRAWHEIGHT = gtk.gdk.screen_height() - KEYFRAMEHEIGHT - PAD*6 - TOLLBAR_HEIGHT
85DRAWWIDTH = int(screen.width()) - LOGO_WIDTH - PAD*4
86DRAWHEIGHT = int(screen.height()) - KEYFRAMEHEIGHT - PAD*6 - TOLLBAR_HEIGHT
8687
8788KEYFRAMES = []
8889KEYFRAMES_NUMBER = 5
  
1616
1717"""Extend sugar-toolkit activity class"""
1818
19import gtk
2019import logging
2120import telepathy
22import gobject
21import gi
22from gi.repository import Gtk
23from gi.repository import Gdk
2324
24from sugar.activity import activity
25from sugar.presence.sugartubeconn import SugarTubeConnection
26from sugar.graphics.alert import ConfirmationAlert, NotifyAlert
25from sugar3.activity import activity
26from sugar3.presence.sugartubeconn import SugarTubeConnection
27from sugar3.graphics.alert import ConfirmationAlert, NotifyAlert
2728
2829
2930_NEW_INSTANCE = 0
4141 self.__dict__ = self.__shared_state
4242
4343 def get_cursor(self, cur_type):
44
4445 if not self.cursors.has_key(cur_type):
45 cur = gtk.gdk.Cursor(cur_type)
46 cur = Gdk.Cursor(cur_type)
4647 self.cursors[cur_type] = cur
48
4749 return self.cursors[cur_type]
4850
4951
7979 Subclass should implement this method to save activity data.
8080 """
8181 raise NotImplementedError
82
82
8383 def on_save_instance(self, cb, *args):
8484 """ Register callback which will be invoked before save_instance """
8585 self.__on_save_instance.append((cb, args))
102102 pass
103103
104104 def set_toolbar_box(self, toolbox):
105
105106 if hasattr(activity.Activity, 'set_toolbar_box'):
106107 activity.Activity.set_toolbar_box(self, toolbox)
108
107109 else:
108110 self.set_toolbox(toolbox)
109111
110112 def get_toolbar_box(self):
113
111114 if hasattr(activity.Activity, 'get_toolbar_box'):
112115 return activity.Activity.get_toolbar_box(self)
116
113117 else:
114118 return self.get_toolbox()
115119
116120 toolbar_box = property(get_toolbar_box, set_toolbar_box)
117121
118122 def get_shared_activity(self):
123
119124 if hasattr(activity.Activity, 'get_shared_activity'):
120125 return activity.Activity.get_shared_activity(self)
126
121127 else:
122128 return self._shared_activity
123129
144144
145145 def response(alert, response_id, self, cb, *cb_args):
146146 self.remove_alert(alert)
147 if response_id is gtk.RESPONSE_OK:
147 if response_id is Gtk.ResponseType.OK:
148148 cb(*cb_args)
149149
150150 alert.connect('response', response, self, cb, *cb_args)
155155 return self._cursor
156156
157157 def set_cursor(self, cursor):
158 if not isinstance(cursor, gtk.gdk.Cursor):
158
159 if not isinstance(cursor, Gdk.Cursor):
159160 cursor = CursorFactory().get_cursor(cursor)
160161
161162 if self._cursor != cursor:
162163 self._cursor = cursor
163 self.window.set_cursor(self._cursor)
164 self.get_property('window').set_cursor(self._cursor)
164165
165166 def __init__(self, canvas, handle):
166167 """
178178
179179 if handle.object_id:
180180 self.__state = _NEW_INSTANCE
181
181182 else:
182183 self.__state = _NEW_INSTANCE
183184
187187 self.__on_save_instance = []
188188
189189 self._cursor = None
190 self.set_cursor(gtk.gdk.LEFT_PTR)
190 self.set_cursor(Gdk.CursorType.LEFT_PTR)
191191
192192 # XXX do it after(possible) read_file() invoking
193193 # have to rely on calling read_file() from map_cb in sugar-toolkit
194 canvas.connect_after('map', self.__map_canvasactivity_cb)
194 #canvas.connect_after('map', self.__map_canvasactivity_cb)
195195 self.set_canvas(canvas)
196
196
197197 def __instance(self):
198
198199 logging.debug('Activity.__instance')
199200
200201 if self.__resume_filename:
205205
206206 for i in self.__postponed_share:
207207 self.share_instance(*i)
208
208209 self.__postponed_share = []
209210
210211 self.__state = _POST_INSTANCE
218218
219219 if self.__state == _NEW_INSTANCE:
220220 self.__state = _PRE_INSTANCE
221
221222 elif self.__state == _PRE_INSTANCE:
222223 self.__instance();
223224
226226 """Subclass should not override this method"""
227227 for cb, args in self.__on_save_instance:
228228 cb(*args)
229
229230 self.save_instance(filepath)
230231
231232 def __map_canvasactivity_cb(self, widget):
233
232234 logging.debug('Activity.__map_canvasactivity_cb state=%s' % \
233235 self.__state)
234236
235237 if self.__state == _NEW_INSTANCE:
236238 self.__instance()
239
237240 elif self.__state == _NEW_INSTANCE:
238241 self.__state = _PRE_INSTANCE
242
239243 elif self.__state == _PRE_INSTANCE:
240244 self.__instance();
241245
242246 return False
243247
244248 def _share(self, tube_conn, initiator):
249
245250 logging.debug('Activity._share state=%s' % self.__state)
246251
247252 if self.__state == _NEW_INSTANCE:
248253 self.__postponed_share.append((tube_conn, initiator))
249254 self.__state = _PRE_INSTANCE
255
250256 elif self.__state == _PRE_INSTANCE:
251257 self.__postponed_share.append((tube_conn, initiator))
252 self.__instance();
258 self.__instance()
259
253260 elif self.__state == _POST_INSTANCE:
254261 self.share_instance(tube_conn, initiator)
255262
286286 self.connect('shared', self._shared_cb)
287287
288288 # Owner.props.key
289 if self._shared_activity:
289 if self.shared_activity:
290290 # We are joining the activity
291291 self.connect('joined', self._joined_cb)
292
292293 if self.get_shared():
293294 # We've already joined
294295 self._joined_cb()
295296
296297 def _shared_cb(self, activity):
298
297299 logging.debug('My activity was shared')
298300 self.__initiator = True
299301 self._sharing_setup()
305305 self.service, {})
306306
307307 def _joined_cb(self, activity):
308 if not self._shared_activity:
308
309 if not self.shared_activity:
309310 return
310311
311312 logging.debug('Joined an existing shared activity')
320320 error_handler=self._list_tubes_error_cb)
321321
322322 def _sharing_setup(self):
323 if self._shared_activity is None:
323
324 if self.shared_activity is None:
324325 logging.error('Failed to share or join activity')
325326 return
326 self._conn = self._shared_activity.telepathy_conn
327 self._tubes_chan = self._shared_activity.telepathy_tubes_chan
328 self._text_chan = self._shared_activity.telepathy_text_chan
327
328 self._conn = self.shared_activity.telepathy_conn
329 self._tubes_chan = self.shared_activity.telepathy_tubes_chan
330 self._text_chan = self.shared_activity.telepathy_text_chan
329331
330332 self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal(
331 'NewTube', self._new_tube_cb)
333 'NewTube', self._new_tube_cb)
332334
333335 def _list_tubes_reply_cb(self, tubes):
336
334337 for tube_info in tubes:
335338 self._new_tube_cb(*tube_info)
336339
341341 logging.error('ListTubes() failed: %s', e)
342342
343343 def _new_tube_cb(self, id, initiator, type, service, params, state):
344
344345 logging.debug('New tube: ID=%d initator=%d type=%d service=%s '
345 'params=%r state=%d', id, initiator, type, service,
346 params, state)
346 'params=%r state=%d', id, initiator, type, service,
347 params, state)
347348
348349 if (type == telepathy.TUBE_TYPE_DBUS and
349 service == self.service):
350 service == self.service):
351
350352 if state == telepathy.TUBE_STATE_LOCAL_PENDING:
351353 self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES] \
352 .AcceptDBusTube(id)
354 .AcceptDBusTube(id)
353355
354356 tube_conn = SugarTubeConnection(self._conn,
355357 self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES], id,
  
1515# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1616# Boston, MA 02111-1307, USA.
1717
18import gtk
19import gobject
18import gi
19from gi.repository import Gtk
20from gi.repository import Gdk
21from gi.repository import GObject
22from gi.repository import GdkX11
2023import gettext
2124
22from sugar import profile
23from sugar.graphics.toolbutton import ToolButton
24from sugar.graphics.radiotoolbutton import RadioToolButton
25from sugar.graphics.toolbox import Toolbox
26from sugar.graphics.xocolor import XoColor
27from sugar.graphics.icon import Icon
28from sugar.bundle.activitybundle import ActivityBundle
25from sugar3 import profile
26from sugar3.graphics.toolbutton import ToolButton
27from sugar3.graphics.radiotoolbutton import RadioToolButton
28from sugar3.graphics.toolbox import Toolbox
29from sugar3.graphics.xocolor import XoColor
30from sugar3.graphics.icon import Icon
31from sugar3.bundle.activitybundle import ActivityBundle
2932
30from toolkit.toolbarbox import ToolbarButton
31from toolkit.radiopalette import RadioPalette
32from toolkit.radiopalette import RadioMenuButton
33from sugar.graphics import style
33from toolbarbox import ToolbarButton
34from radiopalette import RadioPalette
35from radiopalette import RadioMenuButton
3436
35_ = lambda msg: gettext.dgettext('sugar-toolkit', msg)
37from sugar3.graphics import style
3638
39_ = lambda msg: gettext.dgettext('sugar3-toolkit', msg)
3740
41# FIXME: This module is not being used.
42
3843def _create_activity_icon(metadata):
44
3945 if metadata.get('icon-color', ''):
4046 color = XoColor(metadata['icon-color'])
47
4148 else:
4249 color = profile.get_color()
4350
44 from sugar.activity.activity import get_bundle_path
51 from sugar3.activity.activity import get_bundle_path
4552 bundle = ActivityBundle(get_bundle_path())
4653 icon = Icon(file=bundle.get_icon(), xo_color=color)
4754
5757
5858class ActivityButton(ToolButton):
5959
60 def __init__(self, activity, **kwargs):
61 ToolButton.__init__(self, **kwargs)
60 def __init__(self, activity):
61
62 ToolButton.__init__(self)
6263
6364 icon = _create_activity_icon(activity.metadata)
6465 self.set_icon_widget(icon)
7474
7575class ActivityToolbarButton(ToolbarButton):
7676
77 def __init__(self, activity, **kwargs):
77 def __init__(self, activity):
78
7879 toolbar = ActivityToolbar(activity, orientation_left=True)
7980 toolbar.stop.hide()
8081
8888
8989class StopButton(ToolButton):
9090
91 def __init__(self, activity, **kwargs):
91 def __init__(self, activity):
92
9293 ToolButton.__init__(self, 'activity-stop', **kwargs)
9394 self.props.tooltip = _('Stop')
9495 self.props.accelerator = '<Ctrl>Q'
101101
102102class UndoButton(ToolButton):
103103
104 def __init__(self, **kwargs):
105 ToolButton.__init__(self, 'edit-undo', **kwargs)
104 def __init__(self):
105
106 ToolButton.__init__(self, 'edit-undo')
106107 self.props.tooltip = _('Undo')
107108 self.props.accelerator = '<Ctrl>Z'
108109
109110
110111class RedoButton(ToolButton):
111112
112 def __init__(self, **kwargs):
113 ToolButton.__init__(self, 'edit-redo', **kwargs)
113 def __init__(self):
114
115 ToolButton.__init__(self, 'edit-redo')
114116 self.props.tooltip = _('Redo')
115117
116118
117119class CopyButton(ToolButton):
118120
119 def __init__(self, **kwargs):
120 ToolButton.__init__(self, 'edit-copy', **kwargs)
121 def __init__(self):
122
123 ToolButton.__init__(self, 'edit-copy')
121124 self.props.tooltip = _('Copy')
122125
123126
124127class PasteButton(ToolButton):
125128
126 def __init__(self, **kwargs):
127 ToolButton.__init__(self, 'edit-paste', **kwargs)
129 def __init__(self):
130
131 ToolButton.__init__(self, 'edit-paste')
128132 self.props.tooltip = _('Paste')
129133
130134
131135class ShareButton(RadioMenuButton):
132136
133 def __init__(self, activity, **kwargs):
137 def __init__(self, activity):
138
134139 palette = RadioPalette()
135140
136141 self.private = RadioToolButton(
152152 activity.connect('shared', self.__update_share_cb)
153153 activity.connect('joined', self.__update_share_cb)
154154
155 RadioMenuButton.__init__(self, **kwargs)
155 RadioMenuButton.__init__(self)
156156 self.props.palette = palette
157157 if activity.props.max_participants == 1:
158158 self.props.sensitive = False
161161 activity.share()
162162
163163 def __update_share_cb(self, activity):
164
164165 self.neighborhood.handler_block(self._neighborhood_handle)
166
165167 try:
166168 if activity.get_shared():
167169 self.private.props.sensitive = False
168170 self.neighborhood.props.sensitive = False
169171 self.neighborhood.props.active = True
172
170173 else:
171174 self.private.props.sensitive = True
172175 self.neighborhood.props.sensitive = True
173176 self.private.props.active = True
177
174178 finally:
175179 self.neighborhood.handler_unblock(self._neighborhood_handle)
176180
177181
178class TitleEntry(gtk.ToolItem):
182class TitleEntry(Gtk.ToolItem):
179183
180 def __init__(self, activity, **kwargs):
181 gtk.ToolItem.__init__(self)
184 def __init__(self, activity):
185
186 Gtk.ToolItem.__init__(self)
182187 self.set_expand(False)
183188 self._update_title_sid = None
184189
185 self.entry = gtk.Entry(**kwargs)
186 self.entry.set_size_request(int(gtk.gdk.screen_width() / 3), -1)
190 self.entry = Gtk.Entry()
191 screen = GdkX11.X11Screen()
192 self.entry.set_size_request(int(screen.width() / 3), -1)
187193 self.entry.set_text(activity.metadata['title'])
188194 self.entry.connect('changed', self.__title_changed_cb, activity)
189195 self.entry.show()
198198 activity.metadata.connect('updated', self.__jobject_updated_cb)
199199
200200 def modify_bg(self, state, color):
201 gtk.ToolItem.modify_bg(self, state, color)
201
202 Gtk.ToolItem.modify_bg(self, state, color)
202203 self.entry.modify_bg(state, color)
203204
204205 def __jobject_updated_cb(self, jobject):
205206 self.entry.set_text(jobject['title'])
206207
207208 def __title_changed_cb(self, entry, activity):
209
208210 if not self._update_title_sid:
209 self._update_title_sid = gobject.timeout_add_seconds(
210 1, self.__update_title_cb, activity)
211 self._update_title_sid = GObject.timeout_add_seconds(
212 1, self.__update_title_cb, activity)
211213
212214 def __update_title_cb(self, activity):
215
213216 title = self.entry.get_text()
214217
215218 activity.metadata['title'] = title
227227 return False
228228
229229
230class DescriptionItem(gtk.ToolItem):
230class DescriptionItem(Gtk.ToolItem):
231231
232 def __init__(self, activity, **kwargs):
233 gtk.ToolItem.__init__(self)
232 def __init__(self, activity):
233
234 Gtk.ToolItem.__init__(self)
234235
235236 description_button = ToolButton('edit-description')
236237 description_button.show()
237 description_button.set_tooltip(_('Description'))
238 description_button.set_tooltip_text(_('Description'))
238239 self._palette = description_button.get_palette()
239240
240 description_box = gtk.HBox()
241 sw = gtk.ScrolledWindow()
242 sw.set_size_request(int(gtk.gdk.screen_width() / 2),
241 description_box = Gtk.HBox()
242 sw = Gtk.ScrolledWindow()
243 screen = GdkX11.X11Screen()
244 sw.set_size_request(int(screen.width() / 2),
243245 2 * style.GRID_CELL_SIZE)
244 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
245 self._text_view = gtk.TextView()
246 sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
247 self._text_view = Gtk.TextView()
246248 self._text_view.set_left_margin(style.DEFAULT_PADDING)
247249 self._text_view.set_right_margin(style.DEFAULT_PADDING)
248 text_buffer = gtk.TextBuffer()
250 text_buffer = Gtk.TextBuffer()
251
249252 if 'description' in activity.metadata:
250253 text_buffer.set_text(activity.metadata['description'])
254
251255 self._text_view.set_buffer(text_buffer)
252256 self._text_view.connect('focus-out-event',
253 self.__description_changed_cb, activity)
257 self.__description_changed_cb, activity)
254258 sw.add(self._text_view)
255259 description_box.pack_start(sw, False, True, 0)
256260 self._palette.set_content(description_box)
262262
263263 self.add(description_button)
264264 description_button.connect('clicked',
265 self.__description_button_clicked_cb)
265 self.__description_button_clicked_cb)
266266
267267 activity.metadata.connect('updated', self.__jobject_updated_cb)
268268
269269 def _get_text_from_buffer(self):
270
270271 buf = self._text_view.get_buffer()
271272 start_iter = buf.get_start_iter()
272273 end_iter = buf.get_end_iter()
273274 return buf.get_text(start_iter, end_iter, False)
274275
275276 def __jobject_updated_cb(self, jobject):
277
276278 if self._text_view.has_focus():
277279 return
280
278281 if 'description' not in jobject:
279282 return
283
280284 if self._get_text_from_buffer() == jobject['description']:
281285 return
286
282287 buf = self._text_view.get_buffer()
283288 buf.set_text(jobject['description'])
284289
291291 self._palette.popup(immediate=True, state=1)
292292
293293 def __description_changed_cb(self, widget, event, activity):
294
294295 description = self._get_text_from_buffer()
295296 if 'description' in activity.metadata and \
296297 description == activity.metadata['description']:
302302 return False
303303
304304
305class ActivityToolbar(gtk.Toolbar):
305class ActivityToolbar(Gtk.Toolbar):
306306 """The Activity toolbar with the Journal entry title, sharing,
307307 and Stop buttons
308308
311311 """
312312
313313 def __init__(self, activity, orientation_left=False):
314 gtk.Toolbar.__init__(self)
314
315 Gtk.Toolbar.__init__(self)
315316
316317 self._activity = activity
317318
323323 self.title = title_button.entry
324324
325325 if orientation_left == False:
326 separator = gtk.SeparatorToolItem()
326 separator = Gtk.SeparatorToolItem()
327327 separator.props.draw = False
328328 separator.set_expand(True)
329329 self.insert(separator, -1)
343343 self.stop.show()
344344
345345
346class EditToolbar(gtk.Toolbar):
346class EditToolbar(Gtk.Toolbar):
347347 """Provides the standard edit toolbar for Activities.
348348
349349 Members:
378378 """
379379
380380 def __init__(self):
381 gtk.Toolbar.__init__(self)
381 Gtk.Toolbar.__init__(self)
382382
383383 self.undo = UndoButton()
384384 self.insert(self.undo, -1)
388388 self.insert(self.redo, -1)
389389 self.redo.show()
390390
391 self.separator = gtk.SeparatorToolItem()
391 self.separator = Gtk.SeparatorToolItem()
392392 self.separator.set_draw(True)
393393 self.insert(self.separator, -1)
394394 self.separator.show()
422422 """
423423
424424 def __init__(self, activity):
425
425426 Toolbox.__init__(self)
426427
427428 self._activity_toolbar = ActivityToolbar(activity)
  
1616
1717"""Object chooser method"""
1818
19import gtk
19import gi
20from gi.repository import Gtk
21
2022import logging
2123
22from sugar import mime
23from sugar.graphics.objectchooser import ObjectChooser
24from sugar3 import mime
25from sugar3.graphics.objectchooser import ObjectChooser
2426
2527TEXT = hasattr(mime, 'GENERIC_TYPE_TEXT') and mime.GENERIC_TYPE_TEXT or None
2628IMAGE = hasattr(mime, 'GENERIC_TYPE_IMAGE') and mime.GENERIC_TYPE_IMAGE or None
4141 * jobject, if object was choosen and cb is None
4242 * default, otherwise
4343
44 NOTE: 'what' makes sense only for sugar >= 0.84
44 NOTE: 'what' makes sense only for sugar3 >= 0.84
4545 """
4646 what = what and {'what_filter': what} or {}
4747 chooser = ObjectChooser(parent=parent, **what)
5050 out = None
5151
5252 try:
53 if chooser.run() == gtk.RESPONSE_ACCEPT:
53 if chooser.run() == Gtk.ResponseType.ACCEPT:
5454 jobject = chooser.get_selected_object()
5555 logging.debug('ObjectChooser: %r' % jobject)
5656
  
2020STABLE.
2121"""
2222
23import gobject
24import gtk
23import gi
24from gi.repository import GObject
25from gi.repository import Gtk
26from gi.repository import GdkPixbuf
2527
28# FIXME: This class is not being used.
2629
27class ComboBox(gtk.ComboBox):
30class ComboBox(Gtk.ComboBox):
2831
2932 def __init__(self):
30 gtk.ComboBox.__init__(self)
33
34 Gtk.ComboBox.__init__(self)
3135
3236 self._text_renderer = None
3337 self._icon_renderer = None
3438
35 model = gtk.ListStore(gobject.TYPE_PYOBJECT,
36 gobject.TYPE_STRING,
37 gtk.gdk.Pixbuf,
38 gobject.TYPE_BOOLEAN)
39 model = Gtk.ListStore(GObject.TYPE_PYOBJECT,
40 GObject.TYPE_STRING,
41 GdkPixbuf.Pixbuf,
42 GObject.TYPE_BOOLEAN)
3943 self.set_model(model)
4044
4145 self.set_row_separator_func(self._is_separator)
6060 return None
6161 return row[0]
6262
63 value = gobject.property(
63 value = GObject.property(
6464 type=object, getter=get_value, setter=None)
6565
6666 def _get_real_name_from_theme(self, name, size):
67 icon_theme = gtk.icon_theme_get_default()
68 width, height = gtk.icon_size_lookup(size)
67
68 icon_theme = Gtk.icon_theme_get_default()
69 width, height = Gtk.icon_size_lookup(size)
6970 info = icon_theme.lookup_icon(name, max(width, height), 0)
71
7072 if not info:
7173 raise ValueError("Icon '" + name + "' not found.")
74
7275 fname = info.get_filename()
7376 del info
7477 return fname
9797 self.get_model().append(item)
9898
9999 def set_item(self, action_id, text=None, icon_name=None, file_name=None):
100
100101 for i, value in enumerate(self.get_model()):
101102 if value[0] == action_id:
102103 item = self._item_new(action_id, text, icon_name, file_name)
103104 iter = self.get_model().iter_nth_child(None, i)
105
104106 if text is not None:
105107 self.get_model().set(iter, 1, item[1])
108
106109 if icon_name is not None or file_name is not None:
107110 self.get_model().set(iter, 2, item[2])
111
108112 return True
109113 return False
110114
111115 def select(self, action_id=None, text=None):
116
112117 if action_id is not None:
113118 column = 0
114119 value = action_id
120
115121 elif text is not None:
116122 column = 1
117123 value = text
124
118125 else:
119126 return
120127
121128 for i, item in enumerate(self.get_model()):
122129 if item[column] != value:
123130 continue
131
124132 self.set_active(i)
125133 break
126134
127135 def _item_new(self, action_id, text, icon_name, file_name):
136
128137 if not self._icon_renderer and (icon_name or file_name):
129 self._icon_renderer = gtk.CellRendererPixbuf()
138 self._icon_renderer = Gtk.CellRendererPixbuf()
130139
131140 settings = self.get_settings()
132 w, h = gtk.icon_size_lookup_for_settings(
133 settings, gtk.ICON_SIZE_MENU)
141 w, h = Gtk.icon_size_lookup_for_settings(
142 settings, Gtk.IconSize.MENU)
134143 self._icon_renderer.props.stock_size = max(w, h)
135144
136 self.pack_start(self._icon_renderer, False)
145 self.pack_start(self._icon_renderer, False, False, 0)
137146 self.add_attribute(self._icon_renderer, 'pixbuf', 2)
138147
139148 if not self._text_renderer and text:
140 self._text_renderer = gtk.CellRendererText()
141 self.pack_end(self._text_renderer, True)
149 self._text_renderer = Gtk.CellRendererText()
150 self.pack_end(self._text_renderer, True, True, 0)
142151 self.add_attribute(self._text_renderer, 'text', 1)
143152
144153 if icon_name or file_name:
145154 if text:
146 size = gtk.ICON_SIZE_MENU
155 size = Gtk.IconSize.MENU
147156 else:
148 size = gtk.ICON_SIZE_LARGE_TOOLBAR
149 width, height = gtk.icon_size_lookup(size)
157 size = Gtk.IconSize.LARGE_TOOLBAR
158 width, height = Gtk.icon_size_lookup(size)
150159
151160 if icon_name:
152161 file_name = self._get_real_name_from_theme(icon_name, size)
153162
154 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
155 file_name, width, height)
163 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
164 file_name, width, height)
156165 else:
157166 pixbuf = None
158167
  
2323
2424import logging
2525
26import gtk
27import gobject
28import hippo
26import gi
27from gi.repository import Gtk
28from gi.repository import Gdk
29from gi.repository import GObject
30# FIXME: We do not use hippo
31#import hippo
2932
30from sugar.graphics import palettegroup
31from sugar.graphics import animator
32from sugar.graphics import style
33from sugar3.graphics import palettegroup
34from sugar3.graphics import animator
35from sugar3.graphics import style
3336
3437
3538def _calculate_gap(a, b):
3639 """Helper function to find the gap position and size of widget a"""
3740 # Test for each side if the palette and invoker are
3841 # adjacent to each other.
42
3943 gap = True
4044
4145 if a.y + a.height == b.y:
42 gap_side = gtk.POS_BOTTOM
46 gap_side = Gtk.PositionType.BOTTOM
47
4348 elif a.x + a.width == b.x:
44 gap_side = gtk.POS_RIGHT
49 gap_side = Gtk.PositionType.RIGHT
50
4551 elif a.x == b.x + b.width:
46 gap_side = gtk.POS_LEFT
52 gap_side = Gtk.PositionType.LEFT
53
4754 elif a.y == b.y + b.height:
48 gap_side = gtk.POS_TOP
55 gap_side = Gtk.PositionType.TOP
56
4957 else:
5058 gap = False
5159
5260 if gap:
53 if gap_side == gtk.POS_BOTTOM or gap_side == gtk.POS_TOP:
61 if gap_side == Gtk.PositionType.BOTTOM or gap_side == Gtk.PositionType.TOP:
5462 gap_start = min(a.width, max(0, b.x - a.x))
5563 gap_size = max(0, min(a.width,
56 (b.x + b.width) - a.x) - gap_start)
57 elif gap_side == gtk.POS_RIGHT or gap_side == gtk.POS_LEFT:
64 (b.x + b.width) - a.x) - gap_start)
65
66 elif gap_side == Gtk.PositionType.RIGHT or gap_side == Gtk.PositionType.LEFT:
5867 gap_start = min(a.height, max(0, b.y - a.y))
5968 gap_size = max(0, min(a.height,
60 (b.y + b.height) - a.y) - gap_start)
69 (b.y + b.height) - a.y) - gap_start)
6170
6271 if gap and gap_size > 0:
6372 return (gap_side, gap_start, gap_size)
7474 return False
7575
7676
77class MouseSpeedDetector(gobject.GObject):
77class MouseSpeedDetector(GObject.GObject):
7878
7979 __gsignals__ = {
80 'motion-slow': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
81 'motion-fast': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
80 'motion-slow': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
81 'motion-fast': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
8282 }
8383
8484 _MOTION_SLOW = 1
8989 delay in msec
9090 threshold in pixels (per tick of 'delay' msec)"""
9191
92 gobject.GObject.__init__(self)
92 GObject.GObject.__init__(self)
9393
9494 self._threshold = thresh
9595 self._parent = parent
9999 self._mouse_pos = None
100100
101101 def start(self):
102
102103 self.stop()
103104
104105 self._mouse_pos = self._get_mouse_position()
105 self._timeout_hid = gobject.timeout_add(self._delay, self._timer_cb)
106 self._timeout_hid = GObject.timeout_add(self._delay, self._timer_cb)
106107
107108 def stop(self):
109
108110 if self._timeout_hid is not None:
109 gobject.source_remove(self._timeout_hid)
111 GObject.source_remove(self._timeout_hid)
112
110113 self._state = None
111114
112115 def _get_mouse_position(self):
113 display = gtk.gdk.display_get_default()
116
117 display = Gdk.display_get_default()
114118 screen_, x, y, mask_ = display.get_pointer()
119
115120 return (x, y)
116121
117122 def _detect_motion(self):
123
118124 oldx, oldy = self._mouse_pos
119125 (x, y) = self._get_mouse_position()
120126 self._mouse_pos = (x, y)
121127
122128 dist2 = (oldx - x)**2 + (oldy - y)**2
129
123130 if dist2 > self._threshold**2:
124131 return True
132
125133 else:
126134 return False
127135
128136 def _timer_cb(self):
137
129138 motion = self._detect_motion()
139
130140 if motion and self._state != self._MOTION_FAST:
131141 self.emit('motion-fast')
132142 self._state = self._MOTION_FAST
143
133144 elif not motion and self._state != self._MOTION_SLOW:
134145 self.emit('motion-slow')
135146 self._state = self._MOTION_SLOW
148148 return True
149149
150150
151class PaletteWindow(gtk.Window):
151class PaletteWindow(Gtk.Window):
152152
153153 __gsignals__ = {
154 'popup': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
155 'popdown': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
156 'activate': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
154 'popup': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
155 'popdown': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
156 'activate': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
157157 }
158158
159 def __init__(self, **kwargs):
159 def __init__(self):
160
160161 self._group_id = None
161162 self._invoker = None
162163 self._invoker_hids = []
173173 self._popdown_anim = animator.Animator(0.6, 10)
174174 self._popdown_anim.add(_PopdownAnimation(self))
175175
176 gobject.GObject.__init__(self, **kwargs)
176 GObject.GObject.__init__(self)
177177
178178 self.set_decorated(False)
179179 self.set_resizable(False)
180180 # Just assume xthickness and ythickness are the same
181181 self.set_border_width(self.get_style().xthickness)
182182
183 accel_group = gtk.AccelGroup()
183 accel_group = Gtk.AccelGroup()
184184 self.set_data('sugar-accel-group', accel_group)
185185 self.add_accel_group(accel_group)
186186
197197 self._mouse_detector.connect('motion-slow', self._mouse_slow_cb)
198198
199199 def __destroy_cb(self, palette):
200
200201 self.set_group_id(None)
201202
202203 def set_invoker(self, invoker):
204
203205 for hid in self._invoker_hids[:]:
204206 self._invoker.disconnect(hid)
205207 self._invoker_hids.remove(hid)
206208
207209 self._invoker = invoker
210
208211 if invoker is not None:
209212 self._invoker_hids.append(self._invoker.connect(
210213 'mouse-enter', self._invoker_mouse_enter_cb))
217217 'right-click', self._invoker_right_click_cb))
218218
219219 def get_invoker(self):
220
220221 return self._invoker
221222
222 invoker = gobject.property(type=object,
223 getter=get_invoker,
224 setter=set_invoker)
223 invoker = GObject.property(
224 type=object,
225 getter=get_invoker,
226 setter=set_invoker)
225227
226228 def __realize_cb(self, widget):
227 self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
229
230 #self.window.set_type_hint(Gdk.WINDOW_TYPE_HINT_DIALOG)
231 self.window.set_type_hint(Gdk.WindowType.POPUP)
228232
229233 def _mouse_slow_cb(self, widget):
234
230235 self._mouse_detector.stop()
231236 self._palette_do_popup()
232237
233238 def _palette_do_popup(self):
239
234240 immediate = False
235241
236242 if self.is_up():
252252 self.popup(immediate=immediate)
253253
254254 def is_up(self):
255
255256 return self._up
256257
257258 def set_group_id(self, group_id):
259
258260 if self._group_id:
259261 group = palettegroup.get_group(self._group_id)
260262 group.remove(self)
263
261264 if group_id:
262265 self._group_id = group_id
263266 group = palettegroup.get_group(group_id)
264267 group.add(self)
265268
266269 def get_group_id(self):
270
267271 return self._group_id
268272
269 group_id = gobject.property(type=str,
270 getter=get_group_id,
271 setter=set_group_id)
273 group_id = GObject.property(
274 type=str,
275 getter=get_group_id,
276 setter=set_group_id)
272277
273278 def do_size_request(self, requisition):
274 gtk.Window.do_size_request(self, requisition)
279
280 Gtk.Window.do_size_request(self, requisition)
275281 requisition.width = max(requisition.width, style.GRID_CELL_SIZE * 2)
276282
277283 def do_size_allocate(self, allocation):
278 gtk.Window.do_size_allocate(self, allocation)
284
285 Gtk.Window.do_size_allocate(self, allocation)
279286
280287 if self._old_alloc is None or \
281288 self._old_alloc.x != allocation.x or \
305305 palette = self.get_rect()
306306
307307 gap = _calculate_gap(palette, invoker)
308
308309 else:
309310 gap = False
310311
313313 wstyle = self.get_style()
314314
315315 if gap:
316 wstyle.paint_box_gap(event.window, gtk.STATE_PRELIGHT,
317 gtk.SHADOW_IN, event.area, self, "palette",
318 0, 0, allocation.width, allocation.height,
319 gap[0], gap[1], gap[2])
316 wstyle.paint_box_gap(event.window, Gtk.StateType.PRELIGHT,
317 Gtk.ShadowType.IN, event.area, self, "palette",
318 0, 0, allocation.width, allocation.height,
319 gap[0], gap[1], gap[2])
320
320321 else:
321 wstyle.paint_box(event.window, gtk.STATE_PRELIGHT,
322 gtk.SHADOW_IN, event.area, self, "palette",
323 0, 0, allocation.width, allocation.height)
322 wstyle.paint_box(event.window, Gtk.StateType.PRELIGHT,
323 Gtk.ShadowType.IN, event.area, self, "palette",
324 0, 0, allocation.width, allocation.height)
324325
325326 # Fall trough to the container expose handler.
326327 # (Leaving out the window expose handler which redraws everything)
327 gtk.Bin.do_expose_event(self, event)
328 Gtk.Bin.do_expose_event(self, event)
328329
329330 def update_position(self):
330331 invoker = self._invoker
399399 self.popup(immediate=True)
400400
401401 def __enter_notify_event_cb(self, widget, event):
402 if event.detail != gtk.gdk.NOTIFY_INFERIOR and \
403 event.mode == gtk.gdk.CROSSING_NORMAL:
402 if event.detail != Gdk.NotifyType.INFERIOR and \
403 event.mode == Gdk.CROSSING_NORMAL:
404404 self.on_enter(event)
405405
406406 def __leave_notify_event_cb(self, widget, event):
407 if event.detail != gtk.gdk.NOTIFY_INFERIOR and \
408 event.mode == gtk.gdk.CROSSING_NORMAL:
407 if event.detail != Gdk.NotifyType.INFERIOR and \
408 event.mode == Gdk.CROSSING_NORMAL:
409409 self.on_leave(event)
410410
411411 def __show_cb(self, widget):
432432 y = win_y + rectangle.y
433433 width, height = self.size_request()
434434
435 return gtk.gdk.Rectangle(x, y, width, height)
435 return Gdk.Rectangle(x, y, width, height)
436436
437437 def get_palette_state(self):
438438 return self._palette_state
468468 self._palette.popdown(immediate=True)
469469
470470
471class Invoker(gobject.GObject):
471class Invoker(GObject.GObject):
472472
473473 __gsignals__ = {
474 'mouse-enter': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
475 'mouse-leave': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
476 'right-click': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
477 'focus-out': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
474 'mouse-enter': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
475 'mouse-leave': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
476 'right-click': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
477 'focus-out': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ([])),
478478 }
479479
480480 ANCHORED = 0
486486 LEFT = [(-1.0, 0.0, 0.0, 0.0), (-1.0, -1.0, 0.0, 1.0)]
487487
488488 def __init__(self):
489 gobject.GObject.__init__(self)
489 GObject.GObject.__init__(self)
490490
491491 self.parent = None
492492
493 self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
494 gtk.gdk.screen_height())
493 self._screen_area = Gdk.Rectangle(0, 0,
494 Gdk.screen_width(),
495 Gdk.screen_height())
495496 self._position_hint = self.ANCHORED
496497 self._cursor_x = -1
497498 self._cursor_y = -1
514514 invoker_valign = alignment[3]
515515
516516 if self._cursor_x == -1 or self._cursor_y == -1:
517 display = gtk.gdk.display_get_default()
517 display = Gdk.display_get_default()
518518 screen_, x, y, mask_ = display.get_pointer()
519519 self._cursor_x = x
520520 self._cursor_y = y
523523 rect = self.get_rect()
524524 else:
525525 dist = style.PALETTE_CURSOR_DISTANCE
526 rect = gtk.gdk.Rectangle(self._cursor_x - dist,
527 self._cursor_y - dist,
528 dist * 2, dist * 2)
526 rect = Gdk.Rectangle(self._cursor_x - dist,
527 self._cursor_y - dist,
528 dist * 2, dist * 2)
529529
530530 palette_width, palette_height = palette_dim
531531
535535 y = rect.y + rect.height * invoker_valign + \
536536 palette_height * palette_valign
537537
538 return gtk.gdk.Rectangle(int(x), int(y),
539 palette_width, palette_height)
538 return Gdk.Rectangle(int(x), int(y),
539 palette_width, palette_height)
540540
541541 def _in_screen(self, rect):
542542 return rect.x >= self._screen_area.x and \
566566 return self.BOTTOM + self.RIGHT + self.TOP + self.LEFT
567567
568568 def get_position_for_alignment(self, alignment, palette_dim):
569
569570 rect = self._get_position_for_alignment(alignment, palette_dim)
570571 if self._in_screen(rect):
571572 return rect
573
572574 else:
573575 return None
574576
575577 def get_position(self, palette_dim):
578
576579 alignment = self.get_alignment(palette_dim)
577580 rect = self._get_position_for_alignment(alignment, palette_dim)
578581
591591 return rect
592592
593593 def get_alignment(self, palette_dim):
594
594595 best_alignment = None
595596 best_area = -1
597
596598 for alignment in self._get_alignments():
597599 pos = self._get_position_for_alignment(alignment, palette_dim)
598600 if self._in_screen(pos):
662662 self._cursor_y = -1
663663
664664 def _ensure_palette_exists(self):
665
665666 if self.parent and self.palette is None:
666667 palette = self.parent.create_palette()
668
667669 if palette is not None:
668670 self.palette = palette
669671
684684 return self._palette
685685
686686 def set_palette(self, palette):
687
687688 if self._palette is not None:
688689 self._palette.popdown(immediate=True)
689690
696696 if self._palette:
697697 self._palette.props.invoker = self
698698
699 palette = gobject.property(
699 palette = GObject.property(
700700 type=object, setter=set_palette, getter=get_palette)
701701
702702
703703class WidgetInvoker(Invoker):
704704
705705 def __init__(self, parent=None, widget=None):
706
706707 Invoker.__init__(self)
707708
708709 self._widget = None
715715 self.attach_widget(parent, widget)
716716
717717 def attach_widget(self, parent, widget=None):
718
718719 if widget:
719720 self._widget = widget
721
720722 else:
721723 self._widget = parent
722724
734734 self.attach(parent)
735735
736736 def detach(self):
737
737738 Invoker.detach(self)
738739 self._widget.disconnect(self._enter_hid)
739740 self._widget.disconnect(self._leave_hid)
740741 self._widget.disconnect(self._release_hid)
741742
742743 def get_rect(self):
744
743745 allocation = self._widget.get_allocation()
744746 if self._widget.window is not None:
745747 x, y = self._widget.window.get_origin()
748
746749 else:
747750 logging.warning(
748751 "Trying to position palette with invoker that's not realized.")
749752 x = 0
750753 y = 0
751754
752 if self._widget.flags() & gtk.NO_WINDOW:
755 if self._widget.flags() & Gtk.NO_WINDOW:
753756 x += allocation.x
754757 y += allocation.y
755758
756759 width = allocation.width
757760 height = allocation.height
758761
759 return gtk.gdk.Rectangle(x, y, width, height)
762 return Gdk.Rectangle(x, y, width, height)
760763
761764 def has_rectangle_gap(self):
762765 return True
763766
764767 def draw_rectangle(self, event, palette):
765 if self._widget.flags() & gtk.NO_WINDOW:
768
769 if self._widget.flags() & Gtk.NO_WINDOW:
766770 x, y = self._widget.allocation.x, self._widget.allocation.y
771
767772 else:
768773 x = y = 0
769774
776776 gap = _calculate_gap(self.get_rect(), palette.get_rect())
777777
778778 if gap:
779 wstyle.paint_box_gap(event.window, gtk.STATE_PRELIGHT,
780 gtk.SHADOW_IN, event.area, self._widget,
781 "palette-invoker", x, y,
782 self._widget.allocation.width,
783 self._widget.allocation.height,
784 gap[0], gap[1], gap[2])
779 wstyle.paint_box_gap(event.window, Gtk.SateType.PRELIGHT,
780 Gtk.ShadowType.IN, event.area, self._widget,
781 "palette-invoker", x, y,
782 self._widget.allocation.width,
783 self._widget.allocation.height,
784 gap[0], gap[1], gap[2])
785785 else:
786 wstyle.paint_box(event.window, gtk.STATE_PRELIGHT,
787 gtk.SHADOW_IN, event.area, self._widget,
788 "palette-invoker", x, y,
789 self._widget.allocation.width,
790 self._widget.allocation.height)
786 wstyle.paint_box(event.window, Gtk.StateType.PRELIGHT,
787 Gtk.ShadowType.IN, event.area, self._widget,
788 "palette-invoker", x, y,
789 self._widget.allocation.width,
790 self._widget.allocation.height)
791791
792792 def __enter_notify_event_cb(self, widget, event):
793793 self.notify_mouse_enter()
796796 self.notify_mouse_leave()
797797
798798 def __button_release_event_cb(self, widget, event):
799
799800 if event.button == 3:
800801 self.notify_right_click()
801802 return True
803
802804 else:
803805 return False
804806
817817
818818 def _get_widget(self):
819819 return self._widget
820 widget = gobject.property(type=object, getter=_get_widget, setter=None)
820 widget = GObject.property(type=object, getter=_get_widget, setter=None)
821821
822822
823823class CanvasInvoker(Invoker):
838838
839839 self._item = parent
840840 self._motion_hid = self._item.connect('motion-notify-event',
841 self.__motion_notify_event_cb)
841 self.__motion_notify_event_cb)
842842 self._release_hid = self._item.connect('button-release-event',
843 self.__button_release_event_cb)
843 self.__button_release_event_cb)
844844
845845 def detach(self):
846846 Invoker.detach(self)
855855 if context:
856856 x, y = context.translate_to_screen(self._item)
857857 width, height = self._item.get_allocation()
858 return gtk.gdk.Rectangle(x, y, width, height)
858 return Gdk.Rectangle(x, y, width, height)
859859 else:
860 return gtk.gdk.Rectangle()
860 return Gdk.Rectangle()
861861
862862 def __motion_notify_event_cb(self, button, event):
863 if event.detail == hippo.MOTION_DETAIL_ENTER:
864 self.notify_mouse_enter()
865 elif event.detail == hippo.MOTION_DETAIL_LEAVE:
866 self.notify_mouse_leave()
863 # FIXME: We do not use hippo
864 #if event.detail == hippo.MOTION_DETAIL_ENTER:
865 # self.notify_mouse_enter()
866 #elif event.detail == hippo.MOTION_DETAIL_LEAVE:
867 # self.notify_mouse_leave()
867868
868869 return False
869870
876876 return False
877877
878878 def get_toplevel(self):
879 return hippo.get_canvas_for_item(self._item).get_toplevel()
879 # FIXME: We do not use hippo
880 #return hippo.get_canvas_for_item(self._item).get_toplevel()
881 pass
880882
881883
882884class ToolInvoker(WidgetInvoker):
897897 if parent is None:
898898 return WidgetInvoker._get_alignments()
899899
900 if parent.get_orientation() is gtk.ORIENTATION_HORIZONTAL:
900 if parent.get_orientation() is Gtk.Orientation.HORIZONTAL:
901901 return self.BOTTOM + self.TOP
902902 else:
903903 return self.LEFT + self.RIGHT
906906class CellRendererInvoker(Invoker):
907907
908908 def __init__(self):
909
909910 Invoker.__init__(self)
910911
911912 self._position_hint = self.AT_CURSOR
922922 self._cell_renderer = cell_renderer
923923
924924 self._motion_hid = tree_view.connect('motion-notify-event',
925 self.__motion_notify_event_cb)
925 self.__motion_notify_event_cb)
926926 self._leave_hid = tree_view.connect('leave-notify-event',
927 self.__leave_notify_event_cb)
927 self.__leave_notify_event_cb)
928928 self._release_hid = tree_view.connect('button-release-event',
929 self.__button_release_event_cb)
929 self.__button_release_event_cb)
930930
931931 self.attach(cell_renderer)
932932
937937 self._tree_view.disconnect(self._release_hid)
938938
939939 def get_rect(self):
940
940941 allocation = self._tree_view.get_allocation()
941942 if self._tree_view.window is not None:
942943 x, y = self._tree_view.window.get_origin()
944
943945 else:
944946 logging.warning(
945947 "Trying to position palette with invoker that's not realized.")
946948 x = 0
947949 y = 0
948950
949 if self._tree_view.flags() & gtk.NO_WINDOW:
951 if self._tree_view.flags() & Gtk.NO_WINDOW:
950952 x += allocation.x
951953 y += allocation.y
952954
953955 width = allocation.width
954956 height = allocation.height
955957
956 return gtk.gdk.Rectangle(x, y, width, height)
958 return Gdk.Rectangle(x, y, width, height)
957959
958960 def __motion_notify_event_cb(self, widget, event):
961
959962 if event.window != widget.get_bin_window():
960963 return
964
961965 if self._point_in_cell_renderer(event.x, event.y):
962966
963967 tree_view = self._tree_view
964968 path, column_, x_, y_ = tree_view.get_path_at_pos(int(event.x),
965 int(event.y))
969 int(event.y))
970
966971 if path != self.path:
967972 if self.path is not None:
968973 self._redraw_path(self.path)
974
969975 if path is not None:
970976 self._redraw_path(path)
977
971978 if self.palette is not None:
972979 self.palette.popdown(immediate=True)
973980 self.palette = None
981
974982 self.path = path
975983
976984 self.notify_mouse_enter()
985
977986 else:
978987 if self.path is not None:
979988 self._redraw_path(self.path)
989
980990 self.path = None
981991 self.notify_mouse_leave()
982992
983993 def _redraw_path(self, path):
994
984995 for column in self._tree_view.get_columns():
985996 if self._cell_renderer in column.get_cell_renderers():
986997 break
998
987999 area = self._tree_view.get_background_area(path, column)
9881000 x, y = \
9891001 self._tree_view.convert_bin_window_to_widget_coords(area.x, area.y)
10051005 self.notify_mouse_leave()
10061006
10071007 def __button_release_event_cb(self, widget, event):
1008
10081009 if event.button == 1 and self._point_in_cell_renderer(event.x,
10091010 event.y):
10101011 tree_view = self._tree_view
10111012 path, column_, x_, y_ = tree_view.get_path_at_pos(int(event.x),
1012 int(event.y))
1013 int(event.y))
10131014 self._cell_renderer.emit('clicked', path)
10141015 # So the treeview receives it and knows a drag isn't going on
10151016 return False
1017
10161018 if event.button == 3 and self._point_in_cell_renderer(event.x,
10171019 event.y):
10181020 self.notify_right_click()
10191021 return True
1022
10201023 else:
10211024 return False
10221025
10231026 def _point_in_cell_renderer(self, event_x, event_y):
1027
10241028 pos = self._tree_view.get_path_at_pos(int(event_x), int(event_y))
10251029 if pos is None:
10261030 return False
10361036 cell_x, cell_width = column.cell_get_position(cell_renderer)
10371037 if x > cell_x and x < (cell_x + cell_width):
10381038 return True
1039
10391040 return False
10401041
10411042 return False
  
1818
1919import re
2020import cStringIO
21import gtk
22import rsvg
2321import cairo
2422import logging
2523
26from sugar.graphics import style
27from sugar.graphics.xocolor import XoColor, is_valid
28from sugar.util import LRU
24import gi
25from gi.repository import Gtk
26from gi.repository import GdkPixbuf
27from gi.repository import Rsvg
2928
29from sugar3.graphics import style
30from sugar3.graphics.xocolor import XoColor, is_valid
31from sugar3.util import LRU
3032
33
3134def to_file(pixbuf):
3235 """Convert pixbuf object to file object"""
3336
5050def from_str(str):
5151 """Convert string to pixbuf object"""
5252
53 loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/png')
53 loader = GdkPixbuf.PixbufLoader.new_with_mime_type('image/png')
5454
5555 try:
5656 loader.write(str)
57
5758 except Exception, e:
5859 logging.error('pixbuf.from_str: %s' % e)
5960 return None
61
6062 finally:
6163 loader.close()
6264
6365 return loader.get_pixbuf()
6466
6567
66def at_size_with_ratio(pixbuf, width, height, type=gtk.gdk.INTERP_BILINEAR):
68def at_size_with_ratio(pixbuf, width, height, type=GdkPixbuf.InterpType.BILINEAR):
69
6770 image_width = pixbuf.get_width()
6871 image_height = pixbuf.get_height()
6972
7777 if ratio_width != ratio:
7878 ratio_width = ratio
7979 width = int(image_width * ratio)
80
8081 elif ratio_height != ratio:
8182 ratio_height = ratio
8283 height = int(image_height * ratio)
8989 """Scale and load SVG into pixbuf"""
9090
9191 if not handle:
92 handle = rsvg.Handle(filename)
92 handle = Rsvg.Handle(filename)
9393
9494 dimensions = handle.get_dimension_data()
9595 icon_width = dimensions[0]
104104 if ratio_width != ratio:
105105 ratio_width = ratio
106106 width = int(icon_width * ratio)
107
107108 elif ratio_height != ratio:
108109 ratio_height = ratio
109110 height = int(icon_height * ratio)
117117 context.scale(ratio_width, ratio_height)
118118 handle.render_cairo(context)
119119
120 loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/png')
120 loader = GdkPixbuf.PixbufLoader.new_with_mime_type('image/png')
121121 surface.write_to_png(loader)
122122 loader.close()
123123
  
1515# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1616# Boston, MA 02111-1307, USA.
1717
18import gtk
18import gi
19from gi.repository import Gtk
1920
20from sugar.graphics.toolbutton import ToolButton
21from sugar.graphics.palette import Palette
21from sugar3.graphics.toolbutton import ToolButton
22from sugar3.graphics.palette import Palette
2223
2324
2425class RadioMenuButton(ToolButton):
2526
26 def __init__(self, **kwargs):
27 ToolButton.__init__(self, **kwargs)
27 def __init__(self):
28
29 ToolButton.__init__(self)
2830 self.selected_button = None
2931
3032 if self.props.palette:
3636 self.connect('notify::palette', self.__palette_cb)
3737
3838 def _do_clicked(self):
39
3940 if self.palette is None:
4041 return
42
4143 if self.palette.is_up() and \
4244 self.palette.palette_state == Palette.SECONDARY:
4345 self.palette.popdown(immediate=True)
46
4447 else:
4548 self.palette.popup(immediate=True)
4649 self.palette.props.invoker.emit('right-click')
4750
4851 def __palette_cb(self, widget, pspec):
52
4953 if not isinstance(self.props.palette, RadioPalette):
5054 return
55
5156 self.props.palette.update_button()
5257
5358 def __clicked_cb(self, button):
6161
6262class RadioToolsButton(RadioMenuButton):
6363
64 def __init__(self, **kwargs):
65 RadioMenuButton.__init__(self, **kwargs)
64 def __init__(self):
65
66 RadioMenuButton.__init__(self)
6667
6768 def _do_clicked(self):
69
6870 if not self.selected_button:
6971 return
7072 self.selected_button.emit('clicked')
7474
7575class RadioPalette(Palette):
7676
77 def __init__(self, **kwargs):
78 Palette.__init__(self, **kwargs)
77 def __init__(self):
78
79 Palette.__init__(self)
7980
80 self.button_box = gtk.HBox()
81 self.button_box = Gtk.HBox()
8182 self.button_box.show()
8283 self.set_content(self.button_box)
8384
8485 def append(self, button, label):
86
8587 children = self.button_box.get_children()
8688
8789 if button.palette is not None:
9191
9292 button.show()
9393 button.connect('clicked', self.__clicked_cb)
94 self.button_box.pack_start(button, fill=False)
94 self.button_box.pack_start(button, False, False, 0)
9595 button.palette_label = label
9696
9797 if not children:
9898 self.__clicked_cb(button)
9999
100100 def update_button(self):
101
101102 for i in self.button_box.get_children():
102103 self.__clicked_cb(i)
103104
104105 def __clicked_cb(self, button):
106
105107 if not button.get_active():
106108 return
107109
112112
113113 if self.props.invoker is not None:
114114 parent = self.props.invoker.parent
115
115116 else:
116117 parent = None
118
117119 if not isinstance(parent, RadioMenuButton):
118120 return
119121
  
1212# along with this program; if not, write to the Free Software
1313# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1414
15import gtk
15import gi
16from gi.repository import Gtk
17from gi.repository import Gdk
1618
17from sugar.graphics.icon import Icon
19from sugar3.graphics.icon import Icon
1820
19class ScrollButton(gtk.ToolButton):
21class ScrollButton(Gtk.ToolButton):
22
2023 def __init__(self, icon_name):
21 gtk.ToolButton.__init__(self)
24
25 Gtk.ToolButton.__init__(self)
2226
2327 icon = Icon(icon_name = icon_name,
24 icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR)
28 icon_size=Gtk.IconSize.SMALL_TOOLBAR)
2529 # The alignment is a hack to work around gtk.ToolButton code
2630 # that sets the icon_size when the icon_widget is a gtk.Image
27 alignment = gtk.Alignment(0.5, 0.5)
31 alignment = Gtk.Alignment()
32 alignment.set(0.0, 0.0, 0.5, 0.5)
2833 alignment.add(icon)
2934 self.set_icon_widget(alignment)
3035
31class ScrolledBox(gtk.EventBox):
36class ScrolledBox(Gtk.EventBox):
37
3238 def __init__(self, orientation,
33 arrows_policy=gtk.POLICY_AUTOMATIC,
34 scroll_policy=gtk.POLICY_AUTOMATIC):
39 arrows_policy=Gtk.PolicyType.AUTOMATIC,
40 scroll_policy=Gtk.PolicyType.AUTOMATIC):
3541
36 gtk.EventBox.__init__(self)
42 Gtk.EventBox.__init__(self)
43
3744 self.orientation = orientation
3845 self._viewport = None
3946 self._abox = None
5151 self._left = None
5252 self._right = None
5353
54 if orientation == gtk.ORIENTATION_HORIZONTAL:
55 box = gtk.HBox()
54 if orientation == Gtk.Orientation.HORIZONTAL:
55 box = Gtk.HBox()
56
5657 else:
57 box = gtk.VBox()
58 if self._arrows_policy == gtk.POLICY_AUTOMATIC:
58 box = Gtk.VBox()
59
60 if self._arrows_policy == Gtk.PolicyType.AUTOMATIC:
5961 box.connect("size-allocate", self._box_allocate_cb)
6062 self.add(box)
6163
62 if self._arrows_policy != gtk.POLICY_NEVER:
63 if orientation == gtk.ORIENTATION_HORIZONTAL:
64 if self._arrows_policy != Gtk.PolicyType.NEVER:
65 if orientation == Gtk.Orientation.HORIZONTAL:
6466 self._left = ScrollButton('go-left')
67
6568 else:
6669 self._left = ScrollButton('go-up')
70
6771 self._left.connect('clicked', self._scroll_cb,
68 gtk.gdk.SCROLL_LEFT)
72 Gdk.ScrollDirection.LEFT)
6973 box.pack_start(self._left, False, False, 0)
7074
71 self._scrolled = gtk.ScrolledWindow()
72 if orientation == gtk.ORIENTATION_HORIZONTAL:
73 self._scrolled.set_policy(scroll_policy, gtk.POLICY_NEVER)
75 self._scrolled = Gtk.ScrolledWindow()
76 if orientation == Gtk.Orientation.HORIZONTAL:
77 self._scrolled.set_policy(scroll_policy, Gtk.PolicyType.NEVER)
7478 else:
75 self._scrolled.set_policy(gtk.POLICY_NEVER, scroll_policy)
79 self._scrolled.set_policy(Gtk.PolicyType.NEVER, scroll_policy)
80
7681 self._scrolled.connect('scroll-event', self._scroll_event_cb)
7782 box.pack_start(self._scrolled, True, True, 0)
7883
79 if orientation == gtk.ORIENTATION_HORIZONTAL:
84 if orientation == Gtk.Orientation.HORIZONTAL:
8085 self._adj = self._scrolled.get_hadjustment()
86
8187 else:
8288 self._adj = self._scrolled.get_vadjustment()
89
8390 self._adj.connect('changed', self._scroll_changed_cb)
8491 self._adj.connect('value-changed', self._scroll_changed_cb)
8592
86 if self._arrows_policy != gtk.POLICY_NEVER:
87 if orientation == gtk.ORIENTATION_HORIZONTAL:
93 if self._arrows_policy != Gtk.PolicyType.NEVER:
94 if orientation == Gtk.Orientation.HORIZONTAL:
8895 self._right = ScrollButton('go-right')
96
8997 else:
9098 self._right = ScrollButton('go-down')
99
91100 self._right.connect('clicked', self._scroll_cb,
92 gtk.gdk.SCROLL_RIGHT)
101 Gdk.ScrollDirection.RIGHT)
93102 box.pack_start(self._right, False, False, 0)
94103
95104 def modify_fg(self, state, bg):
96 gtk.EventBox.modify_fg(self, state, bg)
105
106 Gtk.EventBox.modify_fg(self, state, bg)
97107 self._viewport.get_parent().modify_fg(state, bg)
98108
99109 def modify_bg(self, state, bg):
100 gtk.EventBox.modify_bg(self, state, bg)
110
111 Gtk.EventBox.modify_bg(self, state, bg)
101112 self._viewport.get_parent().modify_bg(state, bg)
102113
103114 def set_viewport(self, widget):
115
104116 if widget == self._viewport: return
117
105118 if self._viewport and self._aviewport_sig:
106119 self._viewport.disconnect(self._aviewport_sig)
120
107121 self._viewport = widget
108122
109 if self._arrows_policy == gtk.POLICY_AUTOMATIC:
123 if self._arrows_policy == Gtk.PolicyType.AUTOMATIC:
110124 self._aviewport_sig = self._viewport.connect('size-allocate',
111 self._viewport_allocate_cb)
125 self._viewport_allocate_cb)
112126
113127 self._scrolled.add_with_viewport(widget)
114128
115129 def get_viewport_allocation(self):
130
116131 alloc = self._scrolled.get_allocation()
117132 alloc.x -= self._adj.get_value()
118133 return alloc
136136 return self._adj
137137
138138 def _box_allocate_cb(self, w, a):
139
139140 self._abox = a
140141 self._update_arrows()
141142
147147 def _update_arrows(self):
148148 if not self._abox or not self._aviewport: return
149149
150 if self.orientation == gtk.ORIENTATION_HORIZONTAL:
150 if self.orientation == Gtk.Orientation.HORIZONTAL:
151151 show_flag = self._abox.width < self._aviewport.width
152
152153 else:
153154 show_flag = self._abox.height < self._aviewport.height
154155
155156 if show_flag:
156157 self._left.show()
157158 self._right.show()
159
158160 else:
159161 self._left.hide()
160162 self._right.hide()
161163
162164 def _scroll_event_cb(self, widget, event):
163 if self.orientation == gtk.ORIENTATION_HORIZONTAL:
164 if event.direction == gtk.gdk.SCROLL_UP:
165 event.direction = gtk.gdk.SCROLL_LEFT
166 if event.direction == gtk.gdk.SCROLL_DOWN:
167 event.direction = gtk.gdk.SCROLL_RIGHT
165
166 if self.orientation == Gtk.Orientation.HORIZONTAL:
167 if event.direction == Gdk.ScrollDirection.UP:
168 event.direction = Gdk.ScrollDirection.LEFT
169
170 if event.direction == Gdk.ScrollDirection.DOWN:
171 event.direction = Gdk.ScrollDirection.RIGHT
172
168173 else:
169 if event.direction == gtk.gdk.SCROLL_LEFT:
170 event.direction = gtk.gdk.SCROLL_UP
171 if event.direction == gtk.gdk.SCROLL_RIGHT:
172 event.direction = gtk.gdk.SCROLL_DOWN
174 if event.direction == Gdk.ScrollDirection.LEFT:
175 event.direction = Gdk.ScrollDirection.UP
176
177 if event.direction == Gdk.ScrollDirection.RIGHT:
178 event.direction = Gdk.ScrollDirection.DOWN
173179
174 if self._scroll_policy == gtk.POLICY_NEVER:
180 if self._scroll_policy == Gtk.PolicyType.NEVER:
175181 self._scroll_cb(None, event.direction)
176182
177183 return False
178184
179185 def _scroll_cb(self, widget, direction):
180 if direction in (gtk.gdk.SCROLL_LEFT, gtk.gdk.SCROLL_UP):
186
187 if direction in (Gdk.ScrollDirection.LEFT, Gdk.ScrollDirection.UP):
181188 val = max(self._adj.get_property('lower'), self._adj.get_value()
182 - self._adj.get_property('page_increment'))
189 - self._adj.get_property('page_increment'))
190
183191 else:
184192 val = min(self._adj.get_property('upper')
185 - self._adj.get_property('page_size'),
186 self._adj.get_value()
187 + self._adj.get_property('page_increment'))
193 - self._adj.get_property('page_size'),
194 self._adj.get_value()
195 + self._adj.get_property('page_increment'))
188196
189197 self._adj.set_value(val)
190198
191199 def _scroll_changed_cb(self, widget):
200
192201 val = self._adj.get_value()
202
193203 if self._left:
194204 if val == 0:
195205 self._left.set_sensitive(False)
206
196207 else:
197208 self._left.set_sensitive(True)
198209
211211 if val >= self._adj.get_property('upper') - \
212212 self._adj.get_property('page_size'):
213213 self._right.set_sensitive(False)
214
214215 else:
215216 self._right.set_sensitive(True)
216217
217218class HScrolledBox(ScrolledBox):
218 def __init__(self, **kwargs):
219 ScrolledBox.__init__(self, gtk.ORIENTATION_HORIZONTAL, **kwargs)
219
220 def __init__(self):
221 ScrolledBox.__init__(self, Gtk.Orientation.HORIZONTAL)
220222
221223class VScrolledBox(ScrolledBox):
222 def __init__(self, **kwargs):
223 ScrolledBox.__init__(self, gtk.ORIENTATION_VERTICAL, **kwargs)
224
225 def __init__(self):
226 ScrolledBox.__init__(self, Gtk.Orientation.VERTICAL)
  
2020import time
2121import tarfile
2222import cStringIO
23import gtk
2423import zipfile
2524import tempfile
2625import shutil
6363 """
6464
6565 def __init__(self, name=None, mode='r', mtime=None):
66
6667 if not mode.startswith('r') or tarfile.is_tarfile(name):
6768 self.__tar = tarfile.TarFile(name=name, mode=mode)
69
6870 else:
6971 # convert for tar
7072
8686 tar.close()
8787
8888 self.__tar = tarfile.TarFile(name=tmp_name, mode=mode)
89
8990 finally:
9091 tmp_fo.close()
9192 os.unlink(tmp_name)
9494
9595 if mtime:
9696 self.mtime = mtime
97
9798 else:
9899 self.mtime = time.time()
99100
109109 def read(self, arcname):
110110 """Returns sring with content of given file from tarball."""
111111 file_o = self.__tar.extractfile(arcname.encode('utf8'))
112
112113 if not file_o:
113114 return None
115
114116 out = file_o.read()
115117 file_o.close()
116118 return out
  
1414
1515# Widget was copy&pasted from TamTam activities
1616
17import gtk
18import rsvg
17import gi
18from gi.repository import Gtk
19from gi.repository import GdkPixbuf
20from gi.repository import Rsvg
21
1922import cairo
2023
21from sugar.graphics import style
24from sugar3.graphics import style
2225
23class TempoSlider(gtk.HBox):
26class TempoSlider(Gtk.HBox):
27
2428 def __init__(self, min_value, max_value):
25 gtk.HBox.__init__(self)
29
30 Gtk.HBox.__init__(self)
2631
2732 self._pixbuf = [None] * 8
28 self._image = gtk.Image()
33 self._image = Gtk.Image()
2934 self._image.show()
3035
3136 # used to store tempo updates while the slider is active
3237 self._delayed = 0
3338 self._active = False
3439
35 self.adjustment = gtk.Adjustment(min_value, min_value, max_value,
36 (max_value - min_value) / 8, (max_value - min_value) / 8, 0)
40 self.adjustment = Gtk.Adjustment(min_value, min_value, max_value,
41 (max_value - min_value) / 8, (max_value - min_value) / 8, 0)
3742 self._adjustment_h = self.adjustment.connect('value-changed',
3843 self._changed_cb)
3944
40 slider = gtk.HScale(adjustment = self.adjustment)
45 slider = Gtk.HScale(adjustment = self.adjustment)
4146 slider.show()
4247 slider.set_draw_value(False)
4348 slider.connect("button-press-event", self._press_cb)
4449 slider.connect("button-release-event", self._release_cb)
4550
46 self.pack_start(slider, True, True)
47 self.pack_end(self._image, False, False)
51 self.pack_start(slider, True, True, 0)
52 self.pack_end(self._image, False, False, 0)
4853
4954 def set_value(self, tempo, quiet = False):
55
5056 if self._active:
5157 self._delayed = tempo
58
5259 elif quiet:
5360 self.adjustment.handler_block(self._adjustment_h)
5461 self.adjustment.set_value(tempo)
5562 self._update(tempo)
5663 self.adjustment.handler_unblock(self._adjustment_h)
64
5765 else:
5866 self.adjustment.set_value(tempo)
5967
6969 self._update(widget.get_value())
7070
7171 def _update(self, tempo):
72
7273 def map_range(value, ilower, iupper, olower, oupper):
7374 if value == iupper:
7475 return oupper
76
7577 return olower + int((oupper-olower+1) * (value-ilower) /
76 float(iupper-ilower))
78 float(iupper-ilower))
7779
78 img = map_range(tempo, self.adjustment.lower,
79 self.adjustment.upper, 0, 7)
80 img = map_range(tempo, self.adjustment.get_lower(),
81 self.adjustment.get_upper(), 0, 7)
8082
8183 if not self._pixbuf[img]:
82 svg = rsvg.Handle(data=IMAGE[img])
84 svg = Rsvg.Handle()
85 svg.new_from_data(IMAGE[img])
8386 self._pixbuf[img] = _from_svg_at_size(handle=svg,
84 width=style.STANDARD_ICON_SIZE,
85 height=style.STANDARD_ICON_SIZE)
87 width=style.STANDARD_ICON_SIZE,
88 height=style.STANDARD_ICON_SIZE)
8689
8790 self._image.set_from_pixbuf(self._pixbuf[img])
8891
9393 self._active = True
9494
9595 def _release_cb(self, widget, event):
96
9697 self._active = False
9798 if self._delayed != 0:
9899 self.set_value(self._delayed, True)
104104 """ import from pixbuf.py """
105105
106106 if not handle:
107 handle = rsvg.Handle(filename)
107 svg = Rsvg.Handle()
108 svg.new_from_file(IMAGE[img])
108109
109 dimensions = handle.get_dimension_data()
110 icon_width = dimensions[0]
111 icon_height = dimensions[1]
112
113 if icon_width != width or icon_height != height:
110 dimensions = handle.get_dimensions()
111 icon_width = dimensions.height
112 icon_height = dimensions.width
113
114 if (icon_width != width or icon_height != height) and \
115 icon_width != 0 and icon_height != 0:
116
114117 ratio_width = float(width) / icon_width
115118 ratio_height = float(height) / icon_height
116119
117120 if keep_ratio:
118121 ratio = min(ratio_width, ratio_height)
122
119123 if ratio_width != ratio:
120124 ratio_width = ratio
121125 width = int(icon_width * ratio)
126
122127 elif ratio_height != ratio:
123128 ratio_height = ratio
124129 height = int(icon_height * ratio)
130
125131 else:
126132 ratio_width = 1
127133 ratio_height = 1
137137 context.scale(ratio_width, ratio_height)
138138 handle.render_cairo(context)
139139
140 loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/png')
140 loader = GdkPixbuf.PixbufLoader.new_with_mime_type('image/png')
141141 surface.write_to_png(loader)
142142 loader.close()
143143
  
1515# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1616# Boston, MA 02111-1307, USA.
1717
18import gtk
19import gobject
18import gi
19from gi.repository import Gtk
20from gi.repository import GObject
2021
21from sugar.graphics import style
22from sugar.graphics.toolbutton import ToolButton
23from sugar.graphics import palettegroup
22from sugar3.graphics import style
23from sugar3.graphics.toolbutton import ToolButton
24from sugar3.graphics import palettegroup
2425
2526from toolkit.internals.palettewindow import PaletteWindow
2627from toolkit.internals.palettewindow import ToolInvoker
3232
3333class ToolbarButton(ToolButton):
3434
35 def __init__(self, page=None, **kwargs):
36 ToolButton.__init__(self, **kwargs)
35 def __init__(self, page=None):
36
37 ToolButton.__init__(self)
3738
3839 self.page_widget = None
3940
4545 self.connect('size-allocate', self.__size_allocate_cb)
4646
4747 def get_toolbar_box(self):
48
4849 if not hasattr(self.parent, 'owner'):
4950 return None
51
5052 return self.parent.owner
5153
5254 toolbar_box = property(get_toolbar_box)
5355
5456 def get_page(self):
57
5558 if self.page_widget is None:
5659 return None
60
5761 return _get_embedded_page(self.page_widget)
5862
5963 def set_page(self, page):
64
6065 if page is None:
6166 self.page_widget = None
6267 return
6368
6469 self.page_widget, alignment_ = _embed_page(_Box, page)
65 w_, h = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR)
70 w_, h = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)
6671 page.show()
6772
6873 if self.props.palette is None:
6974 self.props.palette = _ToolbarPalette(invoker=ToolInvoker(self))
7075 self._move_page_to_palette()
7176
72 page = gobject.property(type=object, getter=get_page, setter=set_page)
77 page = GObject.property(type=object, getter=get_page, setter=set_page)
7378
7479 def is_in_palette(self):
7580 return self.page is not None and \
104104 if box.expanded_button.window is not None:
105105 # need to redraw it to erase arrow
106106 box.expanded_button.window.invalidate_rect(None, True)
107
107108 box.expanded_button.set_expanded(False)
108109 box.expanded_button = self
109110
110111 self._unparent()
111112
112 self.modify_bg(gtk.STATE_NORMAL, box.background)
113 self.modify_bg(Gtk.StateType.NORMAL, box.background)
113114 _setup_page(self.page_widget, box.background, box.props.padding)
114 box.pack_start(self.page_widget)
115 box.pack_start(self.page_widget, False, False, 0)
115116
116117 def _move_page_to_palette(self):
117118 if self.is_in_palette():
129129 self.page_widget.parent.remove(self.page_widget)
130130
131131 def do_expose_event(self, event):
132
132133 if not self.is_expanded() or self.props.palette is not None and \
133134 self.props.palette.is_up():
134135 ToolButton.do_expose_event(self, event)
135 _paint_arrow(self, event, gtk.ARROW_DOWN)
136 _paint_arrow(self, event, Gtk.ArrowType.DOWN)
136137 return
137138
138139 alloc = self.allocation
139140
140141 self.get_style().paint_box(event.window,
141 gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, self,
142 Gtk.StateType.NORMAL, Gtk.ShadowType.IN, event.area, self,
142143 'palette-invoker', alloc.x, 0,
143144 alloc.width, alloc.height + _LINE_WIDTH)
144145
145 if self.child.state != gtk.STATE_PRELIGHT:
146 if self.child.state != Gtk.StateType.PRELIGHT:
146147 self.get_style().paint_box(event.window,
147 gtk.STATE_NORMAL, gtk.SHADOW_NONE, event.area, self, None,
148 alloc.x + _LINE_WIDTH, _LINE_WIDTH,
149 alloc.width - _LINE_WIDTH * 2, alloc.height)
148 Gtk.StateType.NORMAL, Gtk.ShadowType.NONE, event.area, self, None,
149 alloc.x + _LINE_WIDTH, _LINE_WIDTH,
150 alloc.width - _LINE_WIDTH * 2, alloc.height)
150151
151 gtk.ToolButton.do_expose_event(self, event)
152 _paint_arrow(self, event, gtk.ARROW_UP)
152 Gtk.ToolButton.do_expose_event(self, event)
153 _paint_arrow(self, event, Gtk.ArrowType.UP)
153154
154155 def __size_allocate_cb(self, button, allocation):
155156 if self.page_widget is not None:
156157 self.page_widget.set_size_request(-1, allocation.height)
157158
158159
159class ToolbarBox(gtk.VBox):
160class ToolbarBox(Gtk.VBox):
160161
161162 def __init__(self, padding=style.TOOLBOX_HORIZONTAL_PADDING):
162 gtk.VBox.__init__(self)
163
164 Gtk.VBox.__init__(self)
165
163166 self._expanded_button_index = -1
164167 self.background = None
165168
166 self._toolbar = gtk.Toolbar()
169 self._toolbar = Gtk.Toolbar()
167170 self._toolbar.owner = self
168171 self._toolbar.connect('remove', self.__remove_cb)
169172
170173 self._toolbar_widget, self._toolbar_alignment = \
171 _embed_page(gtk.EventBox, self._toolbar)
172 self.pack_start(self._toolbar_widget)
174 _embed_page(Gtk.EventBox, self._toolbar)
175 self.pack_start(self._toolbar_widget, False, False, 0)
173176
174177 self.props.padding = padding
175 self.modify_bg(gtk.STATE_NORMAL,
178 self.modify_bg(Gtk.StateType.NORMAL,
176179 style.COLOR_TOOLBAR_GREY.get_gdk_color())
177180
178181 def get_toolbar(self):
184184 toolbar = property(get_toolbar)
185185
186186 def get_expanded_button(self):
187
187188 if self._expanded_button_index == -1:
188189 return None
190
189191 return self.toolbar.get_nth_item(self._expanded_button_index)
190192
191193 def set_expanded_button(self, button):
194
192195 if not button in self.toolbar:
193196 self._expanded_button_index = -1
194197 return
198
195199 self._expanded_button_index = self.toolbar.get_item_index(button)
196200
197201 expanded_button = property(get_expanded_button, set_expanded_button)
206206 def set_padding(self, pad):
207207 self._toolbar_alignment.set_padding(0, 0, pad, pad)
208208
209 padding = gobject.property(type=object,
209 padding = GObject.property(type=object,
210210 getter=get_padding, setter=set_padding)
211211
212212 def modify_bg(self, state, color):
213 if state == gtk.STATE_NORMAL:
213
214 if state == Gtk.StateType.NORMAL:
214215 self.background = color
216
215217 self._toolbar_widget.modify_bg(state, color)
216218 self.toolbar.modify_bg(state, color)
217219
218220 def __remove_cb(self, sender, button):
221
219222 if not isinstance(button, ToolbarButton):
220223 return
224
221225 button.popdown()
226
222227 if button == self.expanded_button:
223228 self.remove(button.page_widget)
224229 self._expanded_button_index = -1
231231
232232class _ToolbarPalette(PaletteWindow):
233233
234 def __init__(self, **kwargs):
235 PaletteWindow.__init__(self, **kwargs)
234 def __init__(self):
235
236 PaletteWindow.__init__(self)
236237 self.set_border_width(0)
237238 self._has_focus = False
238239
263263 self._set_focus(False)
264264
265265 def _set_focus(self, new_focus):
266
266267 self._has_focus = new_focus
268
267269 if not self._has_focus:
268270 group = palettegroup.get_group('default')
269271 if not group.is_up():
270272 self.popdown()
271273
272274 def do_size_request(self, requisition):
273 gtk.Window.do_size_request(self, requisition)
275
276 Gtk.Window.do_size_request(self, requisition)
274277 requisition.width = max(requisition.width,
275 gtk.gdk.screen_width())
278 Gdk.screen_width())
276279
277280 def popup(self, immediate=False):
281
278282 button = self.expanded_button
283
279284 if button.is_expanded():
280285 return
286
281287 box = button.toolbar_box
282288 _setup_page(button.page_widget, style.COLOR_BLACK.get_gdk_color(),
283 box.props.padding)
289 box.props.padding)
284290 PaletteWindow.popup(self, immediate)
285291
286292 def __group_popdown_cb(self, group):
294294 self.popdown(immediate=True)
295295
296296
297class _Box(gtk.EventBox):
297class _Box(Gtk.EventBox):
298298
299299 def __init__(self):
300 gtk.EventBox.__init__(self)
300
301 Gtk.EventBox.__init__(self)
301302 self.connect('expose-event', self.do_expose_event)
302303 self.set_app_paintable(True)
303304
304305 def do_expose_event(self, widget, event):
306
305307 if self.parent.expanded_button is None:
306308 return
309
307310 alloc = self.parent.expanded_button.allocation
308311 self.get_style().paint_box(event.window,
309 gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, self,
310 'palette-invoker', -_LINE_WIDTH, 0,
311 self.allocation.width + _LINE_WIDTH * 2,
312 self.allocation.height + _LINE_WIDTH)
312 Gtk.StateType.NORMAL, Gtk.ShadowType.IN, event.area, self,
313 'palette-invoker', -_LINE_WIDTH, 0,
314 self.allocation.width + _LINE_WIDTH * 2,
315 self.allocation.height + _LINE_WIDTH)
316
313317 self.get_style().paint_box(event.window,
314 gtk.STATE_NORMAL, gtk.SHADOW_NONE, event.area, self, None,
315 alloc.x + _LINE_WIDTH, 0,
316 alloc.width - _LINE_WIDTH * 2, _LINE_WIDTH)
318 Gtk.StateType.NORMAL, Gtk.ShadowType.NONE, event.area, self, None,
319 alloc.x + _LINE_WIDTH, 0,
320 alloc.width - _LINE_WIDTH * 2, _LINE_WIDTH)
317321
318322
319323def _setup_page(page_widget, color, hpad):
324
320325 vpad = _LINE_WIDTH
321326 page_widget.child.set_padding(vpad, vpad, hpad, hpad)
322327
323328 page = _get_embedded_page(page_widget)
324 page.modify_bg(gtk.STATE_NORMAL, color)
325 if isinstance(page, gtk.Container):
329 page.modify_bg(Gtk.StateType.NORMAL, color)
330
331 if isinstance(page, Gtk.Container):
326332 for i in page.get_children():
327 i.modify_bg(gtk.STATE_INSENSITIVE, color)
333 i.modify_bg(Gtk.StateType.INSENSITIVE, color)
328334
329 page_widget.modify_bg(gtk.STATE_NORMAL, color)
330 page_widget.modify_bg(gtk.STATE_PRELIGHT, color)
335 page_widget.modify_bg(Gtk.StateType.NORMAL, color)
336 page_widget.modify_bg(Gtk.StateType.PRELIGHT, color)
331337
332338
333339def _embed_page(box_class, page):
334340 page.show()
335341
336 alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
342 alignment = Gtk.Alignment()
343 alignment.set(0.0, 0.0, 1.0, 1.0)
337344 alignment.add(page)
338345 alignment.show()
339346
340347 page_widget = box_class()
341 page_widget.modify_bg(gtk.STATE_ACTIVE,
342 style.COLOR_BUTTON_GREY.get_gdk_color())
348 page_widget.modify_bg(Gtk.StateType.ACTIVE,
349 style.COLOR_BUTTON_GREY.get_gdk_color())
343350 page_widget.add(alignment)
344351 page_widget.show()
345352
363363 y = alloc.y + alloc.height - int(_ARROW_SIZE * .85)
364364
365365 widget.get_style().paint_arrow(event.window,
366 gtk.STATE_NORMAL, gtk.SHADOW_NONE, event.area, widget,
367 None, arrow_type, True, x, y, _ARROW_SIZE, _ARROW_SIZE)
366 Gtk.StateType.NORMAL, Gtk.ShadowType.NONE, event.area, widget,
367 None, arrow_type, True, x, y, _ARROW_SIZE, _ARROW_SIZE)
  
1717
1818"""A set of toolitem widets"""
1919
20import gtk
21import gobject
20import gi
21from gi.repository import Gtk
22from gi.repository import GObject
2223
23from sugar.graphics import style
24from sugar3.graphics import style
2425
25from toolkit.combobox import ComboBox
26# FIXME: This class is not being used.
27class ToolWidget(Gtk.ToolItem):
2628
27
28class ToolWidget(gtk.ToolItem):
29
30 def __init__(self, **kwargs):
29 def __init__(self):
30
3131 self._widget = None
3232 self._label = None
3333 self._label_text = None
34 self._box = gtk.HBox(False, style.DEFAULT_SPACING)
34 self._box = Gtk.HBox(False, style.DEFAULT_SPACING)
3535
36 gobject.GObject.__init__(self, **kwargs)
36 GObject.GObject.__init__(self)
3737 self.props.border_width = style.DEFAULT_PADDING
3838
3939 self._box.show()
4040 self.add(self._box)
4141
4242 if self.label is None:
43 self.label = gtk.Label()
43 self.label = Gtk.Label()
4444
4545 def get_label_text(self):
4646 return self._label_text
5050 if self.label is not None and value:
5151 self.label.set_text(self._label_text)
5252
53 label_text = gobject.property(getter=get_label_text, setter=set_label_text)
53 label_text = GObject.property(getter=get_label_text, setter=set_label_text)
5454
5555 def get_label(self):
5656 return self._label
5757
5858 def set_label(self, label):
59
5960 if self._label is not None:
6061 self._box.remove(self._label)
62
6163 self._label = label
62 self._box.pack_start(label, False)
64 self._box.pack_start(label, False, False, 0)
6365 self._box.reorder_child(label, 0)
6466 label.show()
6567 self.set_label_text(self._label_text)
6668
67 label = gobject.property(getter=get_label, setter=set_label)
69 label = GObject.property(getter=get_label, setter=set_label)
6870
6971 def get_widget(self):
7072 return self._widget
7173
7274 def set_widget(self, widget):
75
7376 if self._widget is not None:
7477 self._box.remove(self._widget)
78
7579 self._widget = widget
76 self._box.pack_end(widget)
80 self._box.pack_end(widget, False, False, 0)
7781 widget.show()
7882
79 widget = gobject.property(getter=get_widget, setter=set_widget)
83 widget = GObject.property(getter=get_widget, setter=set_widget)