Changeset 622
- Timestamp:
- 04/30/07 14:39:18 (6 years ago)
- Location:
- branch/joao/umitMapper
- Files:
-
- 1 added
- 3 modified
-
Coordinate.py (modified) (2 diffs)
-
Interpolation.py (modified) (2 diffs)
-
RadialNet.py (modified) (19 diffs)
-
image/border.png (added)
Legend:
- Unmodified
- Added
- Removed
-
branch/joao/umitMapper/Coordinate.py
r594 r622 46 46 @return: Polar coordinates (r, t) 47 47 """ 48 return (self.__r, self.__t)48 return (self.__r, math.degrees(self.__t)) 49 49 50 50 … … 58 58 """ 59 59 self.__r = r 60 self.__t = t60 self.__t = math.radians(t) 61 61 62 62 -
branch/joao/umitMapper/Interpolation.py
r596 r622 71 71 (af, bf) = self.__finalPoint 72 72 73 return (a, bi + ((a - ai) * (bf - bi) / (af - ai))) 73 try: 74 result = (a, bi + ((a - ai) * (bf - bi) / (af - ai))) 75 except ZeroDivisionError: 76 result = (a, bf) 77 78 return result 74 79 75 80 … … 87 92 88 93 aPass = float(af - ai) / numberOfPass 89 aList = arange(ai+aPass, af+aPass, aPass) 94 95 self.__interpolatedPoints = range(numberOfPass) 90 96 91 97 for i in range(numberOfPass): 92 self.__interpolatedPoints .insert( i, self.interpolate(aList[i]))98 self.__interpolatedPoints[i] = self.interpolate(ai + (i + 1) * aPass) 93 99 94 100 return self.__interpolatedPoints -
branch/joao/umitMapper/RadialNet.py
r620 r622 19 19 import gtk 20 20 import math 21 import time 21 22 import pango 22 23 import drawing 23 24 import geometry 25 import gobject 24 26 from gtk import gdk 25 27 from Coordinate import PolarCoordinate 28 from Interpolation import Linear2DInterpolator 26 29 from Graph import Graph, Node 27 30 … … 31 34 Radial network visualization widget 32 35 """ 33 34 36 def __init__(self, numberOfRings=3): 35 37 """ … … 47 49 """Store the center of widget""" 48 50 self.__isInAnimation = False 51 """""" 52 self.exposedNodes = set([]) 53 """""" 54 self.__animationRate = 10 55 """""" 49 56 50 57 super(RadialNet, self).__init__() … … 53 60 self.connect("button_release_event", self.button_release) 54 61 self.connect("motion_notify_event", self.motion_notify) 62 self.connect("enter_notify_event", self.enter_notify) 63 self.connect("leave_notify_event", self.leave_notify) 55 64 56 65 self.add_events(gdk.BUTTON_PRESS_MASK | 57 66 gdk.BUTTON_RELEASE_MASK | 67 gdk.ENTER_NOTIFY | 68 gdk.LEAVE_NOTIFY | 58 69 gdk.POINTER_MOTION_MASK) 70 71 72 def notIsInAnimation(function): 73 """ 74 """ 75 def checkAnimationStatus(*args): 76 if args[0].__isInAnimation == True: 77 return True 78 return function(*args) 79 80 return checkAnimationStatus 59 81 60 82 … … 78 100 79 101 102 @notIsInAnimation 103 def enter_notify(self, widget, event): 104 """ 105 """ 106 107 108 @notIsInAnimation 109 def leave_notify(self, widget, event): 110 """ 111 """ 112 for id in range(self.__graph.getNumberOfNodes()): 113 node = self.__graph.getNodeByID(id) 114 node.setDrawInfo('over', False) 115 116 self.queue_draw() 117 118 119 @notIsInAnimation 80 120 def button_press(self, widget, event): 81 121 """ … … 90 130 event.window.set_cursor(gdk.Cursor(gtk.gdk.X_CURSOR)) 91 131 132 if event.button == 1: 133 result = self.__getNodeByCoordinate(self.get_pointer()) 134 135 if ( result != None ): 136 137 node, point = result 138 self.anim(node.getID()) 139 92 140 if event.button == 3: 93 141 … … 100 148 x, y = point 101 149 102 nodeView = NodeView(node, (int(xw + x), int(yw + y)), self) 103 nodeView.show_all() 150 if node.getID() not in self.exposedNodes: 151 152 nodeView = NodeView(node, (int(xw + x), int(yw + y)), self) 153 nodeView.show_all() 154 self.exposedNodes.add(node.getID()) 104 155 105 156 return True 106 157 107 158 159 @notIsInAnimation 108 160 def button_release(self, widget, event): 109 161 """ … … 121 173 122 174 175 @notIsInAnimation 123 176 def motion_notify(self, widget, event): 124 177 """ … … 165 218 self.context.clip() 166 219 167 self. draw()168 169 return False170 171 172 def draw(self):220 self.__draw() 221 222 return True 223 224 225 def __draw(self): 173 226 """ 174 227 Drawing method … … 191 244 192 245 # Drawing nodes and your connections 193 194 self.__calculateNodePositions()195 246 196 247 connectionsList = set() … … 307 358 308 359 theta = ((b - a) / 2) + a 309 child.setPolarCoordinate(radius, math.radians(theta))360 child.setPolarCoordinate(radius, theta) 310 361 311 362 locNodes.append(j) … … 321 372 322 373 374 def anim(self, node_id): 375 """ 376 """ 377 self.__isInAnimation = True # Lock main draw functions and events 378 379 initialCoordinates = range(self.__graph.getNumberOfNodes()) 380 finalCoordinates = range(self.__graph.getNumberOfNodes()) 381 interpolatedCoordinates = range(self.__graph.getNumberOfNodes()) 382 383 for id in range(self.__graph.getNumberOfNodes()): 384 385 node = self.__graph.getNodeByID(id) 386 initialCoordinates[id] = node.getPolarCoordinate() 387 388 old_main_node_id = self.__graph.getMainNodeID() 389 390 self.__graph.setMainNodeByID(node_id) 391 self.__calculateNodePositions() 392 393 for id in range(self.__graph.getNumberOfNodes()): 394 395 node = self.__graph.getNodeByID(id) 396 finalCoordinates[id] = node.getPolarCoordinate() 397 398 ri, ti = initialCoordinates[id] 399 rf, tf = finalCoordinates[id] 400 401 interpolator = Linear2DInterpolator() 402 interpolator.setInitialPoint(ri, ti) 403 interpolator.setFinalPoint(rf, tf) 404 points = interpolator.getInterpolatedPoints(self.__animationRate) 405 interpolatedCoordinates[id] = points 406 407 self.__isInAnimation = False # Unlock main draw functions and events 408 409 for i in range(self.__animationRate): 410 411 for id in range(self.__graph.getNumberOfNodes()): 412 413 r, t = interpolatedCoordinates[id][i] 414 node = self.__graph.getNodeByID(id) 415 node.setPolarCoordinate(r, t) 416 417 self.queue_draw() 418 419 420 323 421 def setGraph(self, graph): 324 422 """ … … 328 426 """ 329 427 self.__graph = graph 428 self.__calculateNodePositions() 330 429 331 430 … … 344 443 self.move(position[0], position[1]) 345 444 self.__button_press_position = self.get_pointer() 346 self.resize(200, 120) 347 self.modify_bg(gtk.STATE_NORMAL, gdk.color_parse("#ffffe0")) 445 self.resize(240, 120) 348 446 349 447 self.__node = node … … 370 468 """ 371 469 """ 372 body= gtk.VBox()373 body.set_spacing(5)374 body.set_border_width(5)375 head = gtk.HBox()376 head.set_spacing(5)377 head.set_border_width(5)378 379 bold_font = pango.FontDescription(' monospace bold 8')470 self.__content = gtk.VBox() 471 self.__content.set_spacing(2) 472 self.__content.set_border_width(3) 473 self.__body = gtk.VBox() 474 self.__head = gtk.HBox() 475 self.__head.set_spacing(2) 476 477 bold_font = pango.FontDescription('bold') 380 478 normal_font = pango.FontDescription('monospace 8') 381 479 382 color = gtk.EventBox() 383 color.set_size_request(15, 15) 480 color_event = gtk.EventBox() 481 color = gtk.Image() 482 color.set_from_file('image/border.png') 483 color_event.add(color) 484 color_event.set_size_request(15, 15) 384 485 r, g, b = drawing.cairoToGdkColor(self.__node.getDrawInfo('color')) 385 color.modify_bg(gtk.STATE_NORMAL, gdk.Color(r, g, b)) 386 486 color_event.modify_bg(gtk.STATE_NORMAL, gdk.Color(r, g, b)) 487 488 title_event = gtk.EventBox() 387 489 title = gtk.Label() 388 490 title.set_markup(self.__node.getInformation('ip')) … … 410 512 collapse_event.add_events(gdk.BUTTON_PRESS_MASK) 411 513 412 head.pack_start(color, False, False, 0) 413 head.pack_start(title, False, False, 0) 414 head.pack_end(close_event, False, False, 0) 415 head.pack_end(expand_event, False, False, 0) 416 head.pack_end(collapse_event, False, False, 0) 417 body.pack_start(head, False, False, 0) 418 419 self.add(body) 514 text_scroll = gtk.ScrolledWindow() 515 text_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 516 text = gtk.TextView() 517 text_scroll.add(text) 518 519 self.__head.pack_start(color_event, False, False, 0) 520 self.__head.pack_start(title, False, False, 0) 521 self.__head.pack_end(close_event, False, False, 0) 522 self.__head.pack_end(expand_event, False, False, 0) 523 self.__head.pack_end(collapse_event, False, False, 0) 524 self.__body.pack_start(text_scroll, True, True, 0) 525 526 self.__content.pack_start(self.__head, False, False, 0) 527 self.__content.pack_start(self.__body, True, True, 0) 528 529 self.add(self.__content) 420 530 421 531 … … 425 535 self.__node.setDrawInfo('over', False) 426 536 self.destroy() 537 self.__parent.exposedNodes.remove(self.__node.getID()) 427 538 self.__parent.queue_draw() 428 539 540 return True 541 429 542 430 543 def expand_window(self, widget, event): 431 544 """ 432 545 """ 546 self.present() 547 self.__body.show() 548 433 549 if self.__COMPACTED == 1: 434 self.resize(4 00, 240)550 self.resize(480, 240) 435 551 self.__COMPACTED = 0 436 552 else: 437 self.resize(2 00, 120)553 self.resize(240, 120) 438 554 self.__COMPACTED = 1 439 555 556 return True 557 440 558 441 559 def collapse_window(self, widget, event): 442 560 """ 443 561 """ 562 self.present() 563 444 564 if self.__COLLAPSED == 0: 445 self.resize(200, 30) 565 self.resize(240, 20) 566 self.__body.hide() 446 567 self.__COLLAPSED = 1 447 568 else: 448 569 if self.__COMPACTED == 0: 449 self.resize(4 00, 240)570 self.resize(480, 240) 450 571 else: 451 self.resize(200, 120) 572 self.resize(240, 120) 573 self.__body.show() 452 574 self.__COLLAPSED = 0 453 575 576 return True 577 454 578 455 579 def button_press(self, widget, event): 456 580 """ 457 581 """ 582 self.present() 458 583 self.__pressed = True 459 584 self.__button_press_position = self.get_pointer() … … 488 613 self.__node.setDrawInfo('over', True) 489 614 490 if event.is_hint == True: 491 492 x, y, button_state = event.window.get_pointer() 493 494 if button_state & gtk.gdk.BUTTON1_MASK and self.__pressed: 495 496 xw, yw = event.window.get_root_origin() 497 xd, yd = self.__button_press_position 498 self.move(x + xw - xd, y + yw - yd) 615 x, y, button_state = event.window.get_pointer() 616 617 if button_state & gtk.gdk.BUTTON1_MASK and self.__pressed: 618 619 xw, yw = event.window.get_root_origin() 620 xd, yd = self.__button_press_position 621 self.move(x + xw - xd, y + yw - yd) 499 622 500 623 return True … … 636 759 637 760 radialnet.setGraph(graph) 638 radialnet.set_size_request( 400, 400)761 radialnet.set_size_request(640, 480) 639 762 640 763 window.add(radialnet)
