comparison pyink/frameline.py @ 953:2346d3238e03

frame-button-press event of frameline
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 17 Nov 2010 11:58:45 +0800
parents 88bf64efcc1d
children 75bc6d9f4e0a
comparison
equal deleted inserted replaced
952:88bf64efcc1d 953:2346d3238e03
101 pass 101 pass
102 pass 102 pass
103 pass 103 pass
104 104
105 ## Show frame status of a layer 105 ## Show frame status of a layer
106 #
107 # \section frameline_sigs Signals
108 # - 'frame-button-pree' for user press on a frame.
109 # - callback(widget, frame_idx, button)
106 # 110 #
107 class frameline(gtk.DrawingArea): 111 class frameline(gtk.DrawingArea):
108 _type = 0 112 _type = 0
109 _frame_width = 10 # Width for each frame is 10 pixels 113 _frame_width = 10 # Width for each frame is 10 pixels
110 _select_color = 0xee2222 # color of border of selected frame 114 _select_color = 0xee2222 # color of border of selected frame
114 _tween_bgcolors = [0x80ff80, 0xff8080] # bg colors of tween frames 118 _tween_bgcolors = [0x80ff80, 0xff8080] # bg colors of tween frames
115 # Colors for normal frames 119 # Colors for normal frames
116 _normal_bgcolors = [0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xcccccc] 120 _normal_bgcolors = [0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xcccccc]
117 _normal_border = 0xaaaaaa # border color of normal frames. 121 _normal_border = 0xaaaaaa # border color of normal frames.
118 _active_border = 0xff3030 # border color of an active frame 122 _active_border = 0xff3030 # border color of an active frame
123
124 FRAME_BUT_PRESS = 'frame-button-press'
119 125
120 def __new__(clz, *args): 126 def __new__(clz, *args):
121 if not frameline._type: 127 if not frameline._type:
122 frameline._type = gobject.type_register(frameline) 128 frameline._type = gobject.type_register(frameline)
129 but_press = gobject.signal_new(frameline.FRAME_BUT_PRESS,
130 frameline._type,
131 gobject.SIGNAL_RUN_FIRST,
132 gobject.TYPE_NONE,
133 (gobject.TYPE_INT,
134 gobject.TYPE_INT))
135 frameline._sig_frame_but_press = but_press
123 pass 136 pass
124 fl_obj = gobject.new(frameline._type) 137 fl_obj = gobject.new(frameline._type)
125 return fl_obj 138 return fl_obj
126 139
127 def __init__(self, num_frames=20): 140 def __init__(self, num_frames=20):
131 self._keys = [] 144 self._keys = []
132 self._active_frame = -1 145 self._active_frame = -1
133 pass 146 pass
134 147
135 def _press_hdl(self, widget, event): 148 def _press_hdl(self, widget, event):
136 button = event.x / self._frame_width 149 frame = event.x / self._frame_width
137 print 'button %d - %d,%d' % (button, event.x, event.y) 150 but = event.button
151 self.emit(frameline.FRAME_BUT_PRESS, frame, but)
138 pass 152 pass
139 153
140 def _fl_expose(self, widget, event): 154 def _fl_expose(self, widget, event):
141 win = self.window 155 win = self.window
142 x, y, w, h, depth = win.get_geometry() 156 x, y, w, h, depth = win.get_geometry()
389 fl.tween(3) 403 fl.tween(3)
390 fl.tween(15, 1) 404 fl.tween(15, 1)
391 fl.active_frame(15) 405 fl.active_frame(15)
392 print 'num of frames: %d' % (len(fl)) 406 print 'num of frames: %d' % (len(fl))
393 407
408 def press_sig(fl, frame, but):
409 print 'press_sig button %d for frame %d' % (but, frame)
410 pass
411 fl.connect(frameline.FRAME_BUT_PRESS, press_sig)
412
394 box = gtk.VBox() 413 box = gtk.VBox()
395 414
396 box.pack_start(fr, False) 415 box.pack_start(fr, False)
397 box.pack_start(fl, False) 416 box.pack_start(fl, False)
398 window.add(box) 417 window.add(box)