| 63 | | #self.connect("motion_notify_event", self.motion_notify) |
| 64 | | #self.connect("enter_notify_event", self.enter_notify) |
| 65 | | #self.connect("leave_notify_event", self.leave_notify) |
| 66 | | #self.connect("key_press_event", self.key_press) |
| 67 | | #self.connect("key_release_event", self.key_release) |
| | 66 | self.connect("motion_notify_event", self.motion_notify) |
| | 67 | |
| | 68 | self.add_events(gdk.BUTTON_PRESS_MASK | |
| | 69 | gdk.BUTTON_RELEASE_MASK | |
| | 70 | gdk.MOTION_NOTIFY | |
| | 71 | gdk.POINTER_MOTION_HINT_MASK | |
| | 72 | gdk.POINTER_MOTION_MASK) |
| | 73 | |
| | 74 | gobject.idle_add(self.verify_value) |
| | 75 | |
| | 76 | |
| | 77 | def verify_value(self): |
| | 78 | """ |
| | 79 | """ |
| | 80 | if self.__value() != self.__last_value: |
| | 81 | |
| | 82 | self.__last_value = self.__value() |
| | 83 | self.queue_draw() |
| | 84 | |
| | 85 | return True |
| | 86 | |
| | 87 | |
| | 88 | def button_press(self, widget, event): |
| | 89 | """ |
| | 90 | """ |
| | 91 | self.__active_increment = False |
| | 92 | pointer = self.get_pointer() |
| | 93 | |
| | 94 | if self.__button_is_clicked(pointer) and event.button == 1: |
| | 95 | |
| | 96 | event.window.set_cursor(gdk.Cursor(gtk.gdk.HAND2)) |
| | 97 | self.__active_increment = True |
| | 98 | self.__increment_value() |
| | 99 | |
| | 100 | |
| | 101 | def button_release(self, widget, event): |
| | 102 | """ |
| | 103 | """ |
| | 104 | event.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)) |
| | 105 | |
| | 106 | self.__active_increment = False |
| | 107 | self.__pointer_position = 0 |
| | 108 | |
| | 109 | self.queue_draw() |
| | 110 | |
| | 111 | |
| | 112 | def motion_notify(self, widget, event): |
| | 113 | """ |
| | 114 | Drawing callback |
| | 115 | @type widget: GtkWidget |
| | 116 | @param widget: Gtk widget superclass |
| | 117 | @type event: GtkEvent |
| | 118 | @param event: Gtk event of widget |
| | 119 | @rtype: boolean |
| | 120 | @return: Indicator of the event propagation |
| | 121 | """ |
| | 122 | if self.__active_increment == True: |
| | 123 | |
| | 124 | xc, yc = self.__centerOfWidget |
| | 125 | x, _ = self.get_pointer() |
| | 126 | |
| | 127 | if x - self.__button_radius > 0 and x + self.__button_radius < 2 * xc: |
| | 128 | self.__pointer_position = x - xc |
| | 129 | |
| | 130 | self.queue_draw() |
| | 131 | |
| | 132 | |
| | 133 | def expose(self, widget, event): |
| | 134 | """ |
| | 135 | Drawing callback |
| | 136 | @type widget: GtkWidget |
| | 137 | @param widget: Gtk widget superclass |
| | 138 | @type event: GtkEvent |
| | 139 | @param event: Gtk event of widget |
| | 140 | @rtype: boolean |
| | 141 | @return: Indicator of the event propagation |
| | 142 | """ |
| | 143 | self.set_size_request(100, 22) |
| | 144 | |
| | 145 | self.context = widget.window.cairo_create() |
| | 146 | self.__draw() |
| | 147 | |
| | 148 | return True |
| | 149 | |
| | 150 | |
| | 151 | def __draw(self): |
| | 152 | """ |
| | 153 | """ |
| | 154 | allocation = self.get_allocation() |
| | 155 | |
| | 156 | self.__centerOfWidget = (allocation.width / 2, |
| | 157 | allocation.height / 2) |
| | 158 | |
| | 159 | xc, yc = self.__centerOfWidget |
| | 160 | |
| | 161 | self.context.set_line_width(1) |
| | 162 | self.context.set_dash([1,2]) |
| | 163 | self.context.move_to(self.__button_radius, |
| | 164 | 2 * yc - self.__button_radius - 2) |
| | 165 | self.context.line_to(2 * xc - self.__button_radius, |
| | 166 | 2 * yc - self.__button_radius - 2) |
| | 167 | self.context.stroke() |
| | 168 | |
| | 169 | self.context.set_dash([1,0]) |
| | 170 | self.context.set_font_size(10) |
| | 171 | |
| | 172 | width = self.context.text_extents(self.__variable_name)[2] |
| | 173 | self.context.move_to(2, 8) |
| | 174 | self.context.show_text(self.__variable_name) |
| | 175 | |
| | 176 | width = self.context.text_extents(str(self.__value()))[2] |
| | 177 | self.context.move_to(2 * xc - width - 2, 8) |
| | 178 | self.context.show_text(str(self.__value())) |
| | 179 | |
| | 180 | self.context.set_line_width(1) |
| | 181 | self.context.stroke() |
| | 182 | |
| | 183 | self.context.arc(xc + self.__pointer_position, |
| | 184 | 2 * yc - self.__button_radius - 2, |
| | 185 | self.__button_radius, 0, 2 * math.pi) |
| | 186 | self.context.set_source_rgb(1.0, 1.0, 1.0) |
| | 187 | self.context.fill_preserve() |
| | 188 | self.context.set_source_rgb(0.0, 0.0, 0.0) |
| | 189 | self.context.stroke() |
| | 190 | |
| | 191 | |
| | 192 | def __button_is_clicked(self, pointer): |
| | 193 | """ |
| | 194 | """ |
| | 195 | xc, yc = self.__centerOfWidget |
| | 196 | center = (xc, yc + 2) |
| | 197 | |
| | 198 | if geometry.pointIsInCircle(pointer, 6, center) == True: |
| | 199 | return True |
| | 200 | |
| | 201 | return False |
| | 202 | |
| | 203 | |
| | 204 | def __increment_value(self): |
| | 205 | """ |
| | 206 | """ |
| | 207 | self.__update(self.__value() + self.__pointer_position / 4) |
| | 208 | |
| | 209 | self.queue_draw() |
| | 210 | |
| | 211 | if self.__active_increment == True: |
| | 212 | |
| | 213 | gobject.timeout_add(self.__increment_time, |
| | 214 | self.__increment_value) |
| | 215 | |
| | 216 | |
| | 217 | |
| | 218 | class ControlParams(HIGVBox): |
| | 219 | """ |
| | 220 | """ |
| | 221 | def __init__(self, widget=None): |
| | 222 | """ |
| | 223 | """ |
| | 224 | super(ControlParams, self).__init__() |
| | 225 | |
| | 226 | if widget != None: |
| | 227 | |
| | 228 | self.set_widget(widget) |
| | 229 | |
| | 230 | |
| | 231 | def set_widget(self, widget): |
| | 232 | """ |
| | 233 | """ |
| | 234 | self.__radial = widget |
| | 235 | |
| | 236 | self.__scale_zoom = ControlVariable("Zoom", |
| | 237 | self.__radial.get_zoom, |
| | 238 | self.__radial.set_zoom) |
| | 239 | self.__scale_radius = ControlVariable("Radius", |
| | 240 | self.__radial.get_ring_gap, |
| | 241 | self.__radial.set_ring_gap) |
| | 242 | |
| | 243 | self._pack_noexpand_nofill(self.__scale_zoom) |
| | 244 | self._pack_noexpand_nofill(self.__scale_radius) |
| | 245 | |
| | 246 | |
| | 247 | |
| | 248 | class ControlNavigation(gtk.DrawingArea): |
| | 249 | """ |
| | 250 | """ |
| | 251 | def __init__(self): |
| | 252 | """ |
| | 253 | """ |
| | 254 | self.__rotate_node = PolarCoordinate() |
| | 255 | self.__rotate_node.setCoordinate(40, 90) |
| | 256 | self.__centerOfWidget = (50, 50) |
| | 257 | self.__moving = None |
| | 258 | self.__centering = False |
| | 259 | self.__rotating = False |
| | 260 | self.__move_pass = 100 |
| | 261 | |
| | 262 | self.__move_position = (0, 0) |
| | 263 | self.__move_addition = [(-1, 0), |
| | 264 | (-1,-1), |
| | 265 | ( 0,-1), |
| | 266 | ( 1,-1), |
| | 267 | ( 1, 0), |
| | 268 | ( 1, 1), |
| | 269 | ( 0, 1), |
| | 270 | (-1, 1)] |
| | 271 | |
| | 272 | self.__move_factor = 1 |
| | 273 | self.__move_factor_limit = 20 |
| | 274 | |
| | 275 | self.__rotate_radius = 8 |
| | 276 | self.__move_radius = 6 |
| | 277 | |
| | 278 | self.__rotate_clicked = False |
| | 279 | self.__move_clicked = None |
| | 280 | |
| | 281 | super(ControlNavigation, self).__init__() |
| | 282 | |
| | 283 | self.connect("expose_event", self.expose) |
| | 284 | self.connect("button_press_event", self.button_press) |
| | 285 | self.connect("button_release_event", self.button_release) |
| | 286 | self.connect("motion_notify_event", self.motion_notify) |
| | 287 | self.connect("enter_notify_event", self.enter_notify) |
| | 288 | self.connect("leave_notify_event", self.leave_notify) |
| | 289 | self.connect("key_press_event", self.key_press) |
| | 290 | self.connect("key_release_event", self.key_release) |
| 113 | | self.set_size_request(100, 22) |
| 114 | | |
| 115 | | self.context = widget.window.cairo_create() |
| 116 | | self.__draw() |
| 117 | | |
| 118 | | return False |
| 119 | | |
| 120 | | |
| 121 | | def __draw(self): |
| 122 | | """ |
| 123 | | """ |
| 124 | | allocation = self.get_allocation() |
| 125 | | |
| 126 | | self.__centerOfWidget = (allocation.width / 2, |
| 127 | | allocation.height / 2) |
| 128 | | |
| 129 | | xc, yc = self.__centerOfWidget |
| 130 | | |
| 131 | | self.context.set_line_width(1) |
| 132 | | self.context.set_dash([1,2]) |
| 133 | | self.context.move_to(self.__button_radius, yc) |
| 134 | | self.context.line_to(2 * xc - self.__button_radius, yc) |
| 135 | | self.context.stroke() |
| 136 | | |
| 137 | | self.context.set_dash([1,0]) |
| 138 | | |
| 139 | | self.context.set_font_size(10) |
| 140 | | width = self.context.text_extents(self.__variable_name)[2] |
| 141 | | self.context.move_to(xc - width / 2, 8) |
| 142 | | self.context.show_text(self.__variable_name) |
| 143 | | width = self.context.text_extents(str(self.__value))[2] |
| 144 | | self.context.move_to(xc - width / 2, 20) |
| 145 | | self.context.show_text(str(self.__value)) |
| 146 | | self.context.set_line_width(1) |
| 147 | | self.context.stroke() |
| 148 | | |
| 149 | | self.context.arc(self.__button_radius * 2, yc, |
| 150 | | self.__button_radius, 0, 2 * math.pi) |
| 151 | | self.context.set_source_rgb(1.0, 1.0, 1.0) |
| 152 | | self.context.fill_preserve() |
| 153 | | self.context.set_source_rgb(0.0, 0.0, 0.0) |
| 154 | | self.context.stroke() |
| 155 | | |
| 156 | | self.context.arc(2 * (xc - self.__button_radius), yc, |
| 157 | | self.__button_radius, 0, 2 * math.pi) |
| 158 | | self.context.set_source_rgb(1.0, 1.0, 1.0) |
| 159 | | self.context.fill_preserve() |
| 160 | | self.context.set_source_rgb(0.0, 0.0, 0.0) |
| 161 | | self.context.stroke() |
| 162 | | |
| 163 | | |
| 164 | | def __button_is_clicked(self, pointer): |
| 165 | | """ |
| 166 | | """ |
| 167 | | xc, yc = self.__centerOfWidget |
| 168 | | |
| 169 | | center = (self.__button_radius * 2, yc) |
| 170 | | |
| 171 | | if geometry.pointIsInCircle(pointer, 6, center) == True: |
| 172 | | |
| 173 | | return True |
| 174 | | |
| 175 | | center = (2 * (xc - self.__button_radius), yc) |
| 176 | | |
| 177 | | if geometry.pointIsInCircle(pointer, 6, center) == True: |
| 178 | | |
| 179 | | return False |
| 180 | | |
| 181 | | return None |
| 182 | | |
| 183 | | |
| 184 | | def __increment_value(self, result, accel=1): |
| 185 | | """ |
| 186 | | """ |
| 187 | | if result == True: |
| 188 | | self.set_value(self.__value - self.__increment_pass) |
| 189 | | |
| 190 | | else: |
| 191 | | self.set_value(self.__value + self.__increment_pass) |
| 192 | | |
| 193 | | print result, '\t', self.__value |
| 194 | | self.queue_draw() |
| 195 | | |
| 196 | | if 2 * accel < self.__increment_time / 1.25: |
| 197 | | new_accel = accel * 10 |
| 198 | | else: |
| 199 | | new_accel = self.__increment_time - 100 |
| 200 | | |
| 201 | | if self.__active_increment == True: |
| 202 | | |
| 203 | | gobject.timeout_add(self.__increment_time - accel, |
| 204 | | self.__increment_value, |
| 205 | | result, |
| 206 | | new_accel) |
| 207 | | |
| 208 | | |
| 209 | | def set_value(self, value): |
| 210 | | """ |
| 211 | | """ |
| 212 | | min, max = self.__limits |
| 213 | | self.__value = value |
| 214 | | |
| 215 | | #if max == None and min == None: |
| 216 | | # self.__value = value |
| 217 | | # return True |
| 218 | | |
| 219 | | #if max == None: |
| 220 | | |
| 221 | | # if value >= min: |
| 222 | | # self.__value = value |
| 223 | | # return True |
| 224 | | |
| 225 | | # return False |
| 226 | | |
| 227 | | #if min == None: |
| 228 | | |
| 229 | | # if value <= max: |
| 230 | | # self.__value = value |
| 231 | | # return True |
| 232 | | |
| 233 | | # return False |
| 234 | | |
| 235 | | #if value <= max and value >= min: |
| 236 | | # self.__value = value |
| 237 | | # return True |
| 238 | | |
| 239 | | #return False |
| 240 | | |
| 241 | | |
| 242 | | |
| 243 | | class ControlParams(HIGVBox): |
| 244 | | """ |
| 245 | | """ |
| 246 | | def __init__(self): |
| 247 | | """ |
| 248 | | """ |
| 249 | | super(ControlParams, self).__init__() |
| 250 | | |
| 251 | | self.__scale_zoom = ControlVariable("Scale", 1, 0.01, (0.01, 10)) |
| 252 | | self.__scale_radius = ControlVariable("Radius", 40, 1, (1, 100)) |
| 253 | | |
| 254 | | self._pack_noexpand_nofill(self.__scale_zoom) |
| 255 | | self._pack_noexpand_nofill(self.__scale_radius) |
| 256 | | |
| 257 | | |
| 258 | | def setRadialWidget(self, widget): |
| 259 | | """ |
| 260 | | """ |
| 261 | | self.__radial = widget |
| 262 | | |
| 263 | | |
| 264 | | |
| 265 | | class ControlNavigation(gtk.DrawingArea): |
| 266 | | """ |
| 267 | | """ |
| 268 | | def __init__(self): |
| 269 | | """ |
| 270 | | """ |
| 271 | | self.__rotate_node = PolarCoordinate() |
| 272 | | self.__rotate_node.setCoordinate(40, 90) |
| 273 | | self.__centerOfWidget = (50, 50) |
| 274 | | self.__moving = None |
| 275 | | self.__centering = False |
| 276 | | self.__rotating = False |
| 277 | | self.__move_pass = 100 |
| 278 | | |
| 279 | | self.__move_position = (0, 0) |
| 280 | | self.__move_addition = [(-1, 0), |
| 281 | | (-1,-1), |
| 282 | | ( 0,-1), |
| 283 | | ( 1,-1), |
| 284 | | ( 1, 0), |
| 285 | | ( 1, 1), |
| 286 | | ( 0, 1), |
| 287 | | (-1, 1)] |
| 288 | | |
| 289 | | self.__move_factor = 1 |
| 290 | | self.__move_factor_limit = 20 |
| 291 | | |
| 292 | | self.__rotate_radius = 8 |
| 293 | | self.__move_radius = 6 |
| 294 | | |
| 295 | | self.__rotate_clicked = False |
| 296 | | self.__move_clicked = None |
| 297 | | |
| 298 | | super(ControlNavigation, self).__init__() |
| 299 | | |
| 300 | | self.connect("expose_event", self.expose) |
| 301 | | self.connect("button_press_event", self.button_press) |
| 302 | | self.connect("button_release_event", self.button_release) |
| 303 | | self.connect("motion_notify_event", self.motion_notify) |
| 304 | | self.connect("enter_notify_event", self.enter_notify) |
| 305 | | self.connect("leave_notify_event", self.leave_notify) |
| 306 | | self.connect("key_press_event", self.key_press) |
| 307 | | self.connect("key_release_event", self.key_release) |
| 308 | | |
| 309 | | self.add_events(gdk.BUTTON_PRESS_MASK | |
| 310 | | gdk.BUTTON_RELEASE_MASK | |
| 311 | | gdk.ENTER_NOTIFY | |
| 312 | | gdk.LEAVE_NOTIFY | |
| 313 | | gdk.MOTION_NOTIFY | |
| 314 | | gdk.NOTHING | |
| 315 | | gdk.KEY_PRESS_MASK | |
| 316 | | gdk.KEY_RELEASE_MASK | |
| 317 | | gdk.POINTER_MOTION_HINT_MASK | |
| 318 | | gdk.POINTER_MOTION_MASK) |
| 319 | | |
| 320 | | |
| 321 | | def key_press(self, widget, event): |
| 322 | | """ |
| 323 | | """ |
| 324 | | key = gdk.keyval_name(event.keyval) |
| 325 | | |
| 326 | | self.queue_draw() |
| 327 | | |
| 328 | | return True |
| 329 | | |
| 330 | | |
| 331 | | def key_release(self, widget, event): |
| 332 | | """ |
| 333 | | """ |
| 334 | | key = gdk.keyval_name(event.keyval) |
| 335 | | |
| 336 | | self.queue_draw() |
| 337 | | |
| 338 | | return True |
| 339 | | |
| 340 | | |
| 341 | | def enter_notify(self, widget, event): |
| 342 | | """ |
| 343 | | """ |
| 344 | | return False |
| 345 | | |
| 346 | | |
| 347 | | def leave_notify(self, widget, event): |
| 348 | | """ |
| 349 | | """ |
| 350 | | self.queue_draw() |
| 351 | | |
| 352 | | return False |
| 353 | | |
| 354 | | |
| 355 | | def button_press(self, widget, event): |
| 356 | | """ |
| 357 | | Drawing callback |
| 358 | | @type widget: GtkWidget |
| 359 | | @param widget: Gtk widget superclass |
| 360 | | @type event: GtkEvent |
| 361 | | @param event: Gtk event of widget |
| 362 | | @rtype: boolean |
| 363 | | @return: Indicator of the event propagation |
| 364 | | """ |
| 365 | | event.window.set_cursor(gdk.Cursor(gtk.gdk.HAND2)) |