Rotation is now done by dragging in open space (doesn't draw names while dragging to get speed up)
svn: r11684
This commit is contained in:
parent
89f1ec69c9
commit
409063ae94
@ -93,8 +93,9 @@ class FanChartWidget(gtk.Widget):
|
|||||||
Highly experimental... documents forthcoming...
|
Highly experimental... documents forthcoming...
|
||||||
"""
|
"""
|
||||||
gtk.Widget.__init__(self)
|
gtk.Widget.__init__(self)
|
||||||
self.connect("button_release_event", self.button_release)
|
self.last_x, self.last_y = None, None
|
||||||
self.connect("motion_notify_event", self.motion_notify)
|
self.connect("button_release_event", self.on_mouse_up)
|
||||||
|
self.connect("motion_notify_event", self.on_mouse_move)
|
||||||
self.connect("button-press-event", self.on_mouse_down)
|
self.connect("button-press-event", self.on_mouse_down)
|
||||||
self.right_click_callback = right_click_callback
|
self.right_click_callback = right_click_callback
|
||||||
self.add_events(gdk.BUTTON_PRESS_MASK |
|
self.add_events(gdk.BUTTON_PRESS_MASK |
|
||||||
@ -112,14 +113,6 @@ class FanChartWidget(gtk.Widget):
|
|||||||
self.layout = self.create_pango_layout('cairo')
|
self.layout = self.create_pango_layout('cairo')
|
||||||
self.layout.set_font_description(pango.FontDescription("sans serif 8"))
|
self.layout.set_font_description(pango.FontDescription("sans serif 8"))
|
||||||
|
|
||||||
def button_release(self, widget, event):
|
|
||||||
#print "up!"
|
|
||||||
return True
|
|
||||||
|
|
||||||
def motion_notify(self, widget, event):
|
|
||||||
#print "move!"
|
|
||||||
return True
|
|
||||||
|
|
||||||
def reset_generations(self):
|
def reset_generations(self):
|
||||||
"""
|
"""
|
||||||
Reset all of the data on where slices appear, and if they are expanded.
|
Reset all of the data on where slices appear, and if they are expanded.
|
||||||
@ -270,8 +263,9 @@ class FanChartWidget(gtk.Widget):
|
|||||||
else: # EXPANDED
|
else: # EXPANDED
|
||||||
cr.set_line_width(3)
|
cr.set_line_width(3)
|
||||||
cr.stroke()
|
cr.stroke()
|
||||||
self.draw_text(cr, name, radius - self.pixels_per_generation/2,
|
if self.last_x == None or self.last_y == None:
|
||||||
start, stop)
|
self.draw_text(cr, name, radius - self.pixels_per_generation/2,
|
||||||
|
start, stop)
|
||||||
|
|
||||||
def text_degrees(self, text, radius):
|
def text_degrees(self, text, radius):
|
||||||
"""
|
"""
|
||||||
@ -422,18 +416,44 @@ class FanChartWidget(gtk.Widget):
|
|||||||
self.NORMAL]
|
self.NORMAL]
|
||||||
self.show_parents(generation+1, selected-1, start, slice/2.0)
|
self.show_parents(generation+1, selected-1, start, slice/2.0)
|
||||||
|
|
||||||
def on_mouse_down(self, widget, e):
|
def on_mouse_up(self, widget, event):
|
||||||
|
# Done with mouse movement
|
||||||
|
if self.last_x == None or self.last_y == None: return True
|
||||||
|
self.queue_draw()
|
||||||
|
self.last_x, self.last_y = None, None
|
||||||
|
return True
|
||||||
|
|
||||||
|
def on_mouse_move(self, widget, event):
|
||||||
|
if self.last_x == None or self.last_y == None: return False
|
||||||
|
x, y, w, h = self.allocation
|
||||||
|
cx = w/2
|
||||||
|
cy = h/2
|
||||||
|
# get the angles of the two points from the center:
|
||||||
|
start_angle = math.atan2(event.y - cy, event.x - cx)
|
||||||
|
end_angle = math.atan2(self.last_y - cy, self.last_x - cx)
|
||||||
|
if start_angle < 0: # second half of unit circle
|
||||||
|
start_angle = math.pi + (math.pi + start_angle)
|
||||||
|
if end_angle < 0: # second half of unit circle
|
||||||
|
end_angle = math.pi + (math.pi + end_angle)
|
||||||
|
# now look at change in angle:
|
||||||
|
diff_angle = (end_angle - start_angle) % (math.pi * 2.0)
|
||||||
|
self.rotate_value -= diff_angle * 180.0/ math.pi
|
||||||
|
self.queue_draw()
|
||||||
|
self.last_x, self.last_y = event.x, event.y
|
||||||
|
return True
|
||||||
|
|
||||||
|
def on_mouse_down(self, widget, event):
|
||||||
# compute angle, radius, find out who would be there (rotated)
|
# compute angle, radius, find out who would be there (rotated)
|
||||||
x, y, w, h = self.allocation
|
x, y, w, h = self.allocation
|
||||||
cx = w/2
|
cx = w/2
|
||||||
cy = h/2
|
cy = h/2
|
||||||
radius = math.sqrt((e.x - cx) ** 2 + (e.y - cy) ** 2)
|
radius = math.sqrt((event.x - cx) ** 2 + (event.y - cy) ** 2)
|
||||||
if radius < self.center:
|
if radius < self.center:
|
||||||
generation = 0
|
generation = 0
|
||||||
else:
|
else:
|
||||||
generation = int((radius - self.center) /
|
generation = int((radius - self.center) /
|
||||||
self.pixels_per_generation) + 1
|
self.pixels_per_generation) + 1
|
||||||
rads = math.atan2( (e.y - cy), (e.x - cx) )
|
rads = math.atan2( (event.y - cy), (event.x - cx) )
|
||||||
if rads < 0: # second half of unit circle
|
if rads < 0: # second half of unit circle
|
||||||
rads = math.pi + (math.pi + rads)
|
rads = math.pi + (math.pi + rads)
|
||||||
pos = ((rads/(math.pi * 2) - self.rotate_value/360.) * 360.0) % 360
|
pos = ((rads/(math.pi * 2) - self.rotate_value/360.) * 360.0) % 360
|
||||||
@ -446,26 +466,19 @@ class FanChartWidget(gtk.Widget):
|
|||||||
if start <= pos <= stop:
|
if start <= pos <= stop:
|
||||||
selected = p
|
selected = p
|
||||||
break
|
break
|
||||||
if selected == None:
|
if selected == None: # click in open area
|
||||||
|
# save the mouse location for movements
|
||||||
if radius < self.center:
|
if radius < self.center:
|
||||||
print "TODO: select children"
|
print "TODO: select children"
|
||||||
elif e.x > cx: # on right
|
self.queue_draw()
|
||||||
if e.y > cy: # bottom right, rotate clockwise
|
return True
|
||||||
self.rotate_value += 45.0
|
else:
|
||||||
else: # top right, rotate counter clockwise
|
self.last_x, self.last_y = event.x, event.y
|
||||||
self.rotate_value -= 45.0
|
return True
|
||||||
else: # on left
|
# Do things based on state, event.state, or button, event.button
|
||||||
if e.y > cy: # bottom left, rotate counter clockwise
|
if event.button == 1: # left mouse
|
||||||
self.rotate_value -= 45.0
|
|
||||||
else: # top left, rotate clockwise
|
|
||||||
self.rotate_value += 45.0
|
|
||||||
self.rotate_value %= 360
|
|
||||||
self.queue_draw()
|
|
||||||
return True
|
|
||||||
# Do things based on state, e.state, or button, e.button
|
|
||||||
if e.button == 1: # left mouse
|
|
||||||
self.change_slice(generation, selected)
|
self.change_slice(generation, selected)
|
||||||
elif e.button == 3: # right mouse
|
elif event.button == 3: # right mouse
|
||||||
person = self.data[generation][selected]
|
person = self.data[generation][selected]
|
||||||
if person and self.right_click_callback:
|
if person and self.right_click_callback:
|
||||||
self.right_click_callback(person)
|
self.right_click_callback(person)
|
||||||
|
Loading…
Reference in New Issue
Block a user