def __init__(self, radialnet): """ """ gtk.DrawingArea.__init__(self) self.radialnet = radialnet self.__rotate_node = PolarCoordinate() self.__rotate_node.set_coordinate(40, 90) self.__center_of_widget = (50, 50) self.__moving = None self.__centering = False self.__rotating = False self.__move_pass = 100 self.__move_position = (0, 0) self.__move_addition = [(-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1)] self.__move_factor = 1 self.__move_factor_limit = 20 self.__rotate_radius = 6 self.__move_radius = 6 self.__rotate_clicked = False self.__move_clicked = None self.connect('expose_event', self.expose) self.connect('button_press_event', self.button_press) self.connect('button_release_event', self.button_release) self.connect('motion_notify_event', self.motion_notify) self.connect('enter_notify_event', self.enter_notify) self.connect('leave_notify_event', self.leave_notify) self.connect('key_press_event', self.key_press) self.connect('key_release_event', self.key_release) self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.ENTER_NOTIFY | gtk.gdk.LEAVE_NOTIFY | gtk.gdk.MOTION_NOTIFY | gtk.gdk.NOTHING | gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.POINTER_MOTION_MASK) self.__rotate_node.set_coordinate(40, self.radialnet.get_rotation())
def __move_is_clicked(self, pointer): """ """ xc, yc = self.__center_of_widget pc = PolarCoordinate() for i in range(8): pc.set_coordinate(23, 45 * i) x, y = pc.to_cartesian() center = (xc + x, yc - y) result = geometry.is_in_circle(pointer, self.__move_radius, center) if result == True: return i return None
def __draw(self): """ Drawing method """ # getting allocation reference allocation = self.get_allocation() self.__center_of_widget = (allocation.width / 2, allocation.height / 2) aw, ah = allocation.width, allocation.height xc, yc = self.__center_of_widget ax, ay = self.__translation # xc = 320 yc = 240 # -1.5 | -0.5 ( 480, 360) # -1.0 | 0.0 ( 320, 240) # -0.5 | 0.5 ( 160, 120) # 0.0 | 1.0 ( 0, 0) # 0.5 | 1.5 (-160, -120) # 1.0 | 2.0 (-320, -240) # 1.5 | 2.5 (-480, -360) # scaling and translate factor = -(self.__scale - 1) self.context.translate(xc * factor + ax, yc * factor - ay) if self.__scale != 1.0: self.context.scale(self.__scale, self.__scale) # drawing over node's region if self.__show_region and not self.__animating: for node in self.__sorted_nodes: not_grouped = not node.get_draw_info('grouped') if node.get_draw_info('region') != None and not_grouped: x, y = node.get_cartesian_coordinate() xc, yc = self.__center_of_widget r, g, b = REGION_COLORS[node.get_draw_info('region')] start, final = node.get_draw_info('range') i_radius = node.get_coordinate_radius() f_radius = self.__calc_radius(self.__number_of_rings - 1) is_fill_all = abs(final - start) == 360 final = math.radians(final + self.__rotate) start = math.radians(start + self.__rotate) self.context.move_to(xc, yc) self.context.set_source_rgba(r, g, b, 0.1) self.context.new_path() self.context.arc(xc, yc, i_radius, -final, -start) self.context.arc_negative(xc, yc, f_radius, -start, -final) self.context.close_path() self.context.fill() self.context.stroke() if not is_fill_all: self.context.set_source_rgb(r, g, b) self.context.set_line_width(1) xa, ya = PolarCoordinate(i_radius, final).to_cartesian() xb, yb = PolarCoordinate(f_radius, final).to_cartesian() self.context.move_to(xc + xa, yc - ya) self.context.line_to(xc + xb, yc - yb) self.context.stroke() xa, ya = PolarCoordinate(i_radius, start).to_cartesian() xb, yb = PolarCoordinate(f_radius, start).to_cartesian() self.context.move_to(xc + xa, yc - ya) self.context.line_to(xc + xb, yc - yb) self.context.stroke() # drawing network rings if self.__show_ring == True and self.__animating != True: for i in range(1, self.__number_of_rings): radius = self.__calc_radius(i) self.context.arc(xc, yc, radius, 0, 2 * math.pi) self.context.set_source_rgb(0.8, 0.8, 0.8) self.context.set_line_width(1) self.context.stroke() # drawing nodes and your connections for edge in self.__graph.get_edges(): # check group constraints for edges a, b = edge.get_nodes() a_is_grouped = a.get_draw_info('grouped') b_is_grouped = b.get_draw_info('grouped') a_is_group = a.get_draw_info('group') b_is_group = b.get_draw_info('group') a_group = a.get_draw_info('group_node') b_group = b.get_draw_info('group_node') a_is_child = a in b.get_draw_info('children') b_is_child = b in a.get_draw_info('children') last_group = self.__last_group_node groups = [a_group, b_group] if last_group in groups and last_group != None: self.__draw_edge(edge) elif not a_is_grouped or not b_is_grouped: if not (a_is_group and b_is_child or b_is_group and a_is_child): self.__draw_edge(edge) elif a_group != b_group: self.__draw_edge(edge) for node in self.__reverse_sorted_nodes: # check group constraints for nodes group = node.get_draw_info('group_node') grouped = node.get_draw_info('grouped') if group == self.__last_group_node or not grouped: self.__draw_node(node)