Changeset 617

Show
Ignore:
Timestamp:
04/29/07 22:47:37 (6 years ago)
Author:
ignotus21
Message:

Various interface improvemets.

Location:
branch/joao/umitMapper
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branch/joao/umitMapper/Graph.py

    r605 r617  
    162162        @param : List of connections 
    163163        """ 
    164         if nodeIDA > nodeIDB: 
    165             connection = (nodeIDB, nodeIDA) 
    166         else: 
    167             connection = (nodeIDA, nodeIDB) 
    168  
     164        connection = (nodeIDA, nodeIDB) 
    169165        self.__connections.add(connection) 
    170166 
     
    180176        """ 
    181177        nodeID = node.getID() 
    182         connections = set() 
     178        connections = [] 
    183179 
    184180        for (a, b) in self.__connections: 
    185181            if a == nodeID and b not in exceptNodes: 
    186                 connections.add(b) 
     182                connections.append(b) 
    187183            if b == nodeID and a not in exceptNodes: 
    188                 connections.add(a) 
     184                connections.append(a) 
    189185 
    190186        return connections 
  • branch/joao/umitMapper/RadialNet.py

    r604 r617  
    1919import gtk 
    2020import math 
     21import pango 
     22import drawing 
     23import geometry 
     24from gtk import gdk 
    2125from Coordinate import PolarCoordinate 
    2226from Graph import Graph, Node 
     
    4246        self.__centerOfWidget = (0, 0) 
    4347        """Store the center of widget""" 
    44  
    45         gtk.DrawingArea.__init__(self) 
     48        self.__isInAnimation = False 
     49 
     50        super(RadialNet, self).__init__() 
    4651        self.connect("expose_event", self.expose) 
    47  
    48  
    49     def expose(self, widget, event): 
     52        self.connect("button_press_event", self.button_press) 
     53        self.connect("button_release_event", self.button_release) 
     54        self.connect("motion_notify_event", self.motion_notify) 
     55 
     56        self.add_events(gdk.BUTTON_PRESS_MASK | 
     57                        gdk.BUTTON_RELEASE_MASK | 
     58                        gdk.POINTER_MOTION_MASK) 
     59 
     60 
     61    def __getNodeByCoordinate(self, point): 
     62        """ 
     63        """ 
     64        xc, yc = self.__centerOfWidget 
     65 
     66        for id in range(self.__graph.getNumberOfNodes()): 
     67 
     68            node = self.__graph.getNodeByID(id) 
     69 
     70            xn, yn = node.getCartesianCoordinate() 
     71            center = (xc + xn, yc - yn) 
     72            radius = node.getDrawInfo('radius') 
     73 
     74            if ( geometry.pointIsInCircle(point, radius, center) == True ): 
     75                return node, center 
     76 
     77        return None 
     78 
     79 
     80    def button_press(self, widget, event): 
    5081        """ 
    5182        Drawing callback 
     
    5788        @return: Indicator of the event propagation 
    5889        """ 
     90        event.window.set_cursor(gdk.Cursor(gtk.gdk.X_CURSOR)) 
     91 
     92        if event.button == 3: 
     93 
     94            result = self.__getNodeByCoordinate(self.get_pointer()) 
     95 
     96            if ( result != None ): 
     97 
     98                xw, yw = self.window.get_origin() 
     99                node, point = result 
     100                x, y = point 
     101 
     102                nodeView = NodeView(node, (int(xw + x), int(yw + y)), self) 
     103                nodeView.show_all() 
     104         
     105        return True 
     106 
     107 
     108    def button_release(self, widget, event): 
     109        """ 
     110        Drawing callback 
     111        @type  widget: GtkWidget 
     112        @param widget: Gtk widget superclass 
     113        @type  event: GtkEvent 
     114        @param event: Gtk event of widget 
     115        @rtype: boolean 
     116        @return: Indicator of the event propagation 
     117        """ 
     118        event.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)) 
     119 
     120        return True 
     121 
     122 
     123    def motion_notify(self, widget, event): 
     124        """ 
     125        Drawing callback 
     126        @type  widget: GtkWidget 
     127        @param widget: Gtk widget superclass 
     128        @type  event: GtkEvent 
     129        @param event: Gtk event of widget 
     130        @rtype: boolean 
     131        @return: Indicator of the event propagation 
     132        """ 
     133        xc, yc = self.__centerOfWidget 
     134        pointer = self.get_pointer() 
     135 
     136        for id in range(self.__graph.getNumberOfNodes()): 
     137            node = self.__graph.getNodeByID(id) 
     138            node.setDrawInfo('over', False) 
     139 
     140        result = self.__getNodeByCoordinate(self.get_pointer()) 
     141 
     142        if result != None: 
     143            result[0].setDrawInfo('over', True) 
     144 
     145        self.queue_draw() 
     146         
     147        return True 
     148 
     149 
     150    def expose(self, widget, event): 
     151        """ 
     152        Drawing callback 
     153        @type  widget: GtkWidget 
     154        @param widget: Gtk widget superclass 
     155        @type  event: GtkEvent 
     156        @param event: Gtk event of widget 
     157        @rtype: boolean 
     158        @return: Indicator of the event propagation 
     159        """ 
    59160        self.context = widget.window.cairo_create() 
    60161 
    61         self.context.rectangle(event.area.x, event.area.y, 
    62                                event.area.width, event.area.height) 
     162        self.context.rectangle(*event.area) 
    63163        self.context.set_source_rgb(1.0, 1.0, 1.0) 
    64164        self.context.fill_preserve() 
     
    142242        @param : The node will be draw 
    143243        """ 
    144         (x, y) = node.getCartesianCoordinate() 
    145         (r, g, b) = node.getDrawInfo('color') 
    146         (xc, yc) = self.__centerOfWidget 
    147  
    148         self.context.arc(xc + x, yc - y, 6, 0, 2 * math.pi) 
     244        x, y = node.getCartesianCoordinate() 
     245        r, g, b = node.getDrawInfo('color') 
     246        xc, yc = self.__centerOfWidget 
     247 
     248        radius = node.getDrawInfo('radius') 
     249 
     250        if node.getDrawInfo('over') == True: 
     251            self.context.arc(xc + x, yc - y, radius + 2, 0, 2 * math.pi) 
     252            self.context.set_source_rgba(0.0, 0.0, 1.0, 0.3) 
     253            self.context.fill_preserve() 
     254            self.context.stroke() 
     255 
     256        self.context.arc(xc + x, yc - y, radius, 0, 2 * math.pi) 
    149257        self.context.set_source_rgb(r, g, b) 
    150258        self.context.fill_preserve() 
     
    161269        Make some operations to determine the initial node positions 
    162270        """ 
    163         newNodes = set([self.__graph.getMainNodeID()]) 
    164         oldNodes = set([]) 
     271        newNodes = [self.__graph.getMainNodeID()] 
     272        oldNodes = [] 
    165273 
    166274        angleRange = range(self.__graph.getNumberOfNodes()) 
     
    171279        for i in range(self.__numberOfRings): 
    172280 
    173             locNodes = set([]) 
     281            locNodes = [] 
    174282 
    175283            for nodeID in newNodes: 
    176284 
    177                 oldNodes.add(nodeID) 
     285                oldNodes.append(nodeID) 
    178286 
    179287                node = self.__graph.getNodeByID(nodeID) 
     
    184292                radius = self.__ringGap * (i + 2) 
    185293 
    186                 print connections 
    187  
    188294                for j in connections: 
    189295 
     
    203309                    child.setPolarCoordinate(radius, math.radians(theta)) 
    204310 
    205                     locNodes.add(j) 
     311                    locNodes.append(j) 
    206312 
    207313            for j in locNodes: 
    208                 newNodes.add(j) 
     314                newNodes.append(j) 
    209315 
    210316            for j in oldNodes: 
     
    222328        """ 
    223329        self.__graph = graph 
     330 
     331 
     332 
     333class NodeView(gtk.Window): 
     334    """ 
     335    """ 
     336    def __init__(self, node, position, parent): 
     337        """ 
     338        """ 
     339        gtk.Window.__init__(self, gtk.WINDOW_POPUP) 
     340        self.move(position[0], position[1]) 
     341        self.__button_press_position = self.get_pointer() 
     342        self.set_size_request(200, 120) 
     343        self.modify_bg(gtk.STATE_NORMAL, gdk.color_parse("#fbffc1")) 
     344 
     345        self.__node = node 
     346        self.__pressed = False 
     347        self.__parent = parent 
     348 
     349        self.connect("button_press_event", self.button_press) 
     350        self.connect("button_release_event", self.button_release) 
     351        self.connect("enter_notify_event", self.enter_notify) 
     352        self.connect("leave_notify_event", self.leave_notify) 
     353        self.connect("motion_notify_event", self.motion_notify) 
     354 
     355        self.add_events(gdk.BUTTON_PRESS_MASK | 
     356                        gdk.BUTTON_RELEASE_MASK | 
     357                        gdk.POINTER_MOTION_MASK | 
     358                        gdk.ENTER_NOTIFY | 
     359                        gdk.LEAVE_NOTIFY | 
     360                        gdk.POINTER_MOTION_HINT_MASK) 
     361 
     362        self.__draw_compact_layout() 
     363 
     364 
     365    def __draw_compact_layout(self): 
     366        """ 
     367        """ 
     368        self.__body = gtk.VBox() 
     369        self.__body.set_spacing(5) 
     370        self.__body.set_border_width(5) 
     371        self.__head = gtk.HBox() 
     372        self.__head.set_spacing(5) 
     373        self.__head.set_border_width(5) 
     374 
     375        self.__boldFont = pango.FontDescription('monospace bold 8') 
     376        self.__boldFont = pango.FontDescription('monospace 8') 
     377 
     378        self.__title = gtk.Label() 
     379        self.__title.set_markup(self.__node.getInformation('ip')) 
     380        self.__title.modify_font(self.__boldFont) 
     381 
     382        self.__event = gtk.EventBox() 
     383        self.__event.set_size_request(15, 15) 
     384        r, g, b = drawing.cairoToGdkColor(self.__node.getDrawInfo('color')) 
     385        self.__event.modify_bg(gtk.STATE_NORMAL, gdk.Color(r, g, b)) 
     386 
     387        self.__head.pack_start(self.__event, False, False, 0) 
     388        self.__head.pack_start(self.__title, False, False, 0) 
     389        self.__body.pack_start(self.__head, False, False, 0) 
     390 
     391        self.add(self.__body) 
     392 
     393 
     394    def button_press(self, widget, event): 
     395        """ 
     396        """ 
     397        self.__pressed = True 
     398        self.__button_press_position = self.get_pointer() 
     399 
     400        return True 
     401 
     402 
     403    def button_release(self, widget, event): 
     404        """ 
     405        """ 
     406        if event.button == 3: 
     407            self.__node.setDrawInfo('over', False) 
     408            self.destroy() 
     409            self.__parent.queue_draw() 
     410 
     411        self.__pressed = False 
     412 
     413        return True 
     414 
     415 
     416    def enter_notify(self, widget, event): 
     417        """ 
     418        """ 
     419        self.__node.setDrawInfo('over', True) 
     420        self.__parent.queue_draw() 
     421 
     422 
     423    def leave_notify(self, widget, event): 
     424        """ 
     425        """ 
     426        self.__node.setDrawInfo('over', False) 
     427 
     428 
     429    def motion_notify(self, widget, event): 
     430        """ 
     431        """ 
     432        self.__node.setDrawInfo('over', True) 
     433 
     434        if event.is_hint == True: 
     435 
     436            x, y, button_state = event.window.get_pointer() 
     437 
     438            if button_state & gtk.gdk.BUTTON1_MASK and self.__pressed: 
     439 
     440                xw, yw = event.window.get_root_origin() 
     441                xd, yd = self.__button_press_position 
     442                self.move(x + xw - xd, y + yw - yd) 
     443 
     444        return True 
    224445 
    225446 
     
    235456        """Hash with draw information""" 
    236457        self.__coordinate = PolarCoordinate() 
    237         """Coordinate of node""" 
    238458 
    239459        super(NetNode, self).__init__(id) 
     
    277497        @return: The requested information 
    278498        """ 
    279         return self.__drawInfo[ info ] 
    280  
    281  
    282     def setDrawInfo(self, info): 
     499        try: 
     500            return self.__drawInfo[ info ] 
     501        except: 
     502            return None 
     503 
     504 
     505    def setDrawInfo(self, info, value=None): 
    283506        """ 
    284507        Set draw information 
     
    286509        @param : Draw information dictionary 
    287510        """ 
    288         self.__drawInfo = info 
     511        if value == None: 
     512            self.__drawInfo = info 
     513        else: 
     514            self.__drawInfo[info] = value 
    289515 
    290516 
     
    296522 
    297523    window = gtk.Window() 
     524    radialnet = RadialNet(5) 
    298525 
    299526    # Creating nodes 
     
    301528 
    302529    nodes[0] = NetNode(0) 
    303     nodes[0].setDrawInfo({"color":(0,1,0)}) 
     530    nodes[0].setDrawInfo({"color":(0,1,0), "radius":10}) 
    304531    nodes[0].setInformation({"ip":"192.168.1.1", "host":"joao.test.net"}) 
    305532 
    306533    nodes[1] = NetNode(1) 
    307     nodes[1].setDrawInfo({"color":(1,1,0)}) 
     534    nodes[1].setDrawInfo({"color":(1,1,0), "radius":8}) 
    308535    nodes[1].setInformation({"ip":"192.168.1.2", "host":"luis.test.net"}) 
    309536 
    310537    nodes[2] = NetNode(2) 
    311     nodes[2].setDrawInfo({"color":(1,0,0)}) 
     538    nodes[2].setDrawInfo({"color":(1,0,0), "radius":6}) 
    312539    nodes[2].setInformation({"ip":"192.168.1.3", "host":"polo.test.net"}) 
    313540 
    314541    nodes[3] = NetNode(3) 
    315     nodes[3].setDrawInfo({"color":(0,1,0)}) 
     542    nodes[3].setDrawInfo({"color":(0,1,0), "radius":10}) 
    316543    nodes[3].setInformation({"ip":"192.168.2.5", "host":"mara.test.net"}) 
    317544 
    318545    nodes[4] = NetNode(4) 
    319     nodes[4].setDrawInfo({"color":(1,0,0)}) 
     546    nodes[4].setDrawInfo({"color":(1,0,0), "radius":12}) 
    320547    nodes[4].setInformation({"ip":"192.168.3.2", "host":"nara.test.net"}) 
    321548 
    322549    nodes[5] = NetNode(5) 
    323     nodes[5].setDrawInfo({"color":(0,1,0)}) 
     550    nodes[5].setDrawInfo({"color":(0,1,0), "radius":8}) 
    324551    nodes[5].setInformation({"ip":"192.168.3.3", "host":"luca.test.net"}) 
    325552 
    326553    nodes[6] = NetNode(6) 
    327     nodes[6].setDrawInfo({"color":(1,1,0)}) 
     554    nodes[6].setDrawInfo({"color":(1,1,0), "radius":8}) 
    328555    nodes[6].setInformation({"ip":"192.168.3.1", "host":"jose.test.net"}) 
    329556 
    330557    nodes[7] = NetNode(7) 
    331     nodes[7].setDrawInfo({"color":(1,1,0)}) 
     558    nodes[7].setDrawInfo({"color":(1,1,0), "radius":10}) 
    332559    nodes[7].setInformation({"ip":"192.168.1.8", "host":"mark.test.net"}) 
    333560 
    334561    nodes[8] = NetNode(8) 
    335     nodes[8].setDrawInfo({"color":(1,1,0)}) 
     562    nodes[8].setDrawInfo({"color":(1,1,0), "radius":8}) 
    336563    nodes[8].setInformation({"ip":"192.168.1.7", "host":"mama.test.net"}) 
    337564 
    338565    nodes[9] = NetNode(9) 
    339     nodes[9].setDrawInfo({"color":(1,0,0)}) 
     566    nodes[9].setDrawInfo({"color":(1,0,0), "radius":6}) 
    340567    nodes[9].setInformation({"ip":"192.168.4.7", "host":"papa.test.net"}) 
    341568 
     
    352579    graph.setConnections(5, 9) 
    353580 
    354     radialnet = RadialNet(5) 
    355581    radialnet.setGraph(graph) 
    356582    radialnet.set_size_request(400, 400)