source: subversion/applications/routing/pyroute/gui.py @ 5301

Last change on this file since 5301 was 5301, checked in by ojw, 12 years ago

First draft of outline GUI

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/usr/bin/env python
2import pygtk
3pygtk.require('2.0')
4import gobject
5import gtk
6from gtk import gdk
7import loadOsm
8import cairo
9
10def update(mapWidget):
11  return(True)
12
13class Rect:
14  def __init__(self,x,y,w,h):
15    self.x = x
16    self.y = y
17    self.w = w
18    self.h = h
19   
20class MapWidget(gtk.Widget):
21  __gsignals__ = { \
22    'realize': 'override',
23    'expose-event' : 'override',
24    'size-allocate': 'override',
25    'size-request': 'override'}
26  def __init__(self):
27    gtk.Widget.__init__(self)
28    self.draw_gc = None
29    self.timer = gobject.timeout_add(200, update, self)
30  def move(self,dx,dy):
31    pass
32  def draw(self, cr):
33    cr.set_source_rgb(0,0,0)
34    cr.move_to(self.rect.x,self.rect.y)
35    cr.line_to(self.rect.x + self.rect.width,self.rect.y + self.rect.height)
36    cr.stroke()
37    pass
38  def do_realize(self):
39    self.set_flags(self.flags() | gtk.REALIZED)
40    self.window = gdk.Window( \
41      self.get_parent_window(),
42      width = self.allocation.width,
43      height = self.allocation.height,
44      window_type = gdk.WINDOW_CHILD,
45      wclass = gdk.INPUT_OUTPUT,
46      event_mask = self.get_events() | gdk.EXPOSURE_MASK)
47    self.window.set_user_data(self)
48    self.style.attach(self.window)
49    self.style.set_background(self.window, gtk.STATE_NORMAL)
50    self.window.move_resize(*self.allocation)
51  def do_size_request(self, allocation):
52    pass
53  def do_size_allocate(self, allocation):
54    self.allocation = allocation
55    if self.flags() & gtk.REALIZED:
56      self.window.move_resize(*allocation)
57  def _expose_cairo(self, event, cr):
58    self.rect = self.allocation
59    self.draw(cr)
60  def do_expose_event(self, event):
61    self.chain(event)
62    cr = self.window.cairo_create()
63    return self._expose_cairo(event, cr)
64
65class GuiBase:
66  """Wrapper class for a GUI interface"""
67  def __init__(self):
68    # Create the window
69    win = gtk.Window()
70    win.set_title('map')
71    win.connect('delete-event', gtk.main_quit)
72    win.resize(600,800)
73    win.move(50, gtk.gdk.screen_height() - 850)
74   
75    # Events
76    event_box = gtk.EventBox()
77    event_box.connect("button_press_event", lambda w,e: self.pressed(e))
78    event_box.connect("button_release_event", lambda w,e: self.released(e))
79    event_box.connect("motion_notify_event", lambda w,e: self.moved(e))
80    win.add(event_box)
81   
82    # Create the map
83    self.mapWidget = MapWidget()
84    event_box.add(self.mapWidget)
85   
86    # Finalise the window
87    win.show_all()
88    gtk.main()
89   
90  def pressed(self, event):
91    self.dragx = event.x
92    self.dragy = event.y
93  def released(self, event):
94    pass
95  def moved(self, event):
96    """Drag-handler"""
97    self.mapWidget.move(event.x - self.dragx, event.y - self.dragy)
98    self.dragx = event.x
99    self.dragy = event.y
100
101if __name__ == "__main__":
102  program = GuiBase()
Note: See TracBrowser for help on using the repository browser.