source: subversion/applications/routing/pyroute/overlay.py @ 5709

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

Split overlay module into helper files

File size: 11.4 KB
Line 
1import cairo
2import os
3from base import pyrouteModule
4from pyrouteMenu import *
5from menuIcons import menuIcons
6from overlayArea import overlayArea
7
8class guiOverlay(pyrouteModule):
9    def __init__(self, modules):
10        pyrouteModule.__init__(self, modules)
11        self.modules = modules
12        self.icons = menuIcons()
13        self.menus = loadMenus('Menus')
14
15    def fullscreen(self):
16        """Asks if the menu is fullscreen -- if it is, then the
17        map doesn't need to be drawn underneath"""
18        return(self.get('menu'))
19   
20    def handleClick(self,x,y):
21        """return 1 if click was handled"""
22        for cell in self.clickable:
23            if(cell.contains(x,y)):
24                if(cell.handleClick(x,y)):
25                    return(1)
26        if(self.fullscreen()):
27            return(1)
28        return(0)
29    def draw(self, cr, rect):
30        self.cr = cr
31        self.rect = overlayArea(cr,rect.x,rect.y,rect.width,rect.height,self.modules,self.icons)
32        nx = 3
33        ny = 4
34        self.clickable = []
35        self.cells = {}
36        dx = rect.width / nx
37        dy = rect.height / ny
38        for i in range(0,nx):
39            x1 = rect.x + i * dx
40            self.cells[i] = {}
41            for j in range(0,ny):
42                y1 = rect.y + j * dy
43                self.cells[i][j] = overlayArea(cr,x1,y1,dx,dy,self.modules, self.icons)
44                self.clickable.append(self.cells[i][j])
45        currentMenu = self.get('menu')
46        if(currentMenu):
47            self.drawMenu(currentMenu)
48        else:
49            self.cells[0][0].mainMenuButton()
50            self.cr.set_line_width(2)
51            self.cr.set_dash((2,2,2), 0);
52            self.cr.set_source_rgba(0.4,0,0)
53            y = 100
54            self.cr.move_to(0,y)
55            self.cr.line_to(rect.width,y)
56            self.cr.stroke()
57                   
58    def drawMenu(self, menu):
59        menuName = 'menu_%s' % menu
60        try:
61            function = getattr(self, menuName)
62        except AttributeError:
63            print "Error: %s not defined" % menuName
64            self.set('menu',None)
65            return
66        function()
67    def backButton(self,i,j):
68        self.cells[i][j].button("","menu:","up")
69       
70    def menu_main(self):
71        self.backButton(0,0)
72        self.cells[1][0].button("Mark",None,"map_pin")
73        self.cells[2][0].button("Draw",None,"sketch")
74       
75        self.cells[0][1].button("View","menu:view","viewMenu")
76        self.cells[1][1].button("GPS","menu:gps","gps")
77        self.cells[2][1].button("Download","menu:download","download")
78
79        self.cells[0][2].button()
80        self.cells[1][2].button()
81        self.cells[2][2].button()
82       
83        self.cells[0][3].button("Centre","option:toggle:centred","centre")
84        self.cells[1][3].button("Options","menu:options","options")
85        self.cells[2][3].button("Mode", "menu:mode","transport")
86
87    def menu_mode(self):
88        self.backButton(0,0)
89        self.cells[1][0].button("Cycle","mode:cycle","bike")
90        self.cells[2][0].button("Walk","mode:foot","hike")
91       
92        self.cells[0][1].button("MTB","mode:cycle","mtb")
93        self.cells[1][1].button("Car","mode:car","car")
94        self.cells[2][1].button("Hike","mode:foot","hike")
95
96        self.cells[0][2].button("Fast cycle","mode:cycle","fastbike")
97
98        self.cells[0][3].button("HGV","mode:hgv","hgv")
99    def menu_feeds(self):
100      self.menu_list("rss")
101    def menu_geonames(self):
102      self.menu_list("geonames")
103     
104    def menu_list(self, module):
105        self.backButton(0,0)
106        n = 9
107        offset = 0
108        selectedFeed = int(self.modules['data'].getOption('selectedFeed',0))
109        titlebar = self.rect.copyself(1.0/3.0,0,1,0.25)
110        line1, line2 = titlebar.ysplit(0.5)
111        back = line1.copyself(0,0,0.25,1)
112        next = line1.copyself(0.75,0,1,1)
113        back.button("","option:add:selectedFeed:-1","back")
114        next.button("","option:add:selectedFeed:1","next")
115        self.clickable.append(back)
116        self.clickable.append(next)
117
118        line1.copyself(0.25,0,0.75,1).drawText("Feed %d of %d" % (selectedFeed + 1, len(self.modules['plugins'][module].groups)))
119
120        try:
121            group = self.modules['plugins'][module].groups[selectedFeed]
122        except KeyError:
123            return
124        except IndexError:
125            return
126       
127        line2.drawText(group.name)
128       
129        listrect = self.rect.ysplitn(0, 0.25, 0.8, 1, n)
130        ownpos = self.modules['position'].get()
131        for i in range(0,n):
132            textarea, button = listrect[i].xsplit(0.8)
133            if(i > 0):
134                self.cr.set_line_width(0.5)
135                self.cr.set_dash((2,2,2), 0);
136                self.cr.set_source_rgb(0,0,0)
137                self.cr.move_to(textarea.x1,textarea.y1)
138                self.cr.line_to(textarea.x2,textarea.y1)
139                self.cr.stroke()
140            try:
141                item = group.items[i + offset]
142                textarea.drawTextSomewhere(item.formatText(), 0.1,0.1,0.9,0.5)
143                textarea.drawTextSomewhere(item.formatPos(ownpos), 0.1,0.6,0.9,0.9)
144                button.button("", "route:%1.5f:%1.5f" % (item.lat, item.lon), "goto")
145                self.clickable.append(button)
146            except IndexError:
147                pass
148
149    def menu_search_eat(self):
150        self.backButton(0,0)
151        self.cells[1][0].button("Pub food", "search:amenity=pub;food=yes", None)
152        self.cells[2][0].button("Restaurant", "search:amenity=restaurant", None)
153       
154        self.cells[0][1].button("Cafe", "search:amenity=cafe",None)
155        self.cells[1][1].button("Fast food","search:amenity=fast_food",None)
156        self.cells[2][1].button("Takeaway",None,None)
157   
158    def menu_search_sleep(self):
159        self.backButton(0,0)
160        self.cells[1][0].button("Hotel", "search:tourism=hotel",None)
161        self.cells[2][0].button("Hostel", "search:tourism=hostel",None)
162       
163    def menu_search_repair(self):
164        self.backButton(0,0)
165        self.cells[1][0].button("Bike shop","search:amenity=bike_shop",None)
166        self.cells[2][0].button("Garage","search:amenity=garage",None)
167       
168    def menu_search_buy(self):
169        self.backButton(0,0)
170        self.cells[1][0].button("Supermarket","search:amenity=supermarket",None)
171        self.cells[2][0].button("Mall",None,None)
172       
173        self.cells[0][1].button("High street",None,None)
174        self.cells[1][1].button("Dep't Store",None,None)
175        self.cells[2][1].button("Outdoor","search:shop=outdoor",None)
176       
177        self.cells[0][2].button("DIY","search:tourism=diy",None)
178        self.cells[1][2].button("",None,None)
179        self.cells[2][2].button("",None,None)
180   
181    def menu_search_help(self):
182        self.backButton(0,0)
183        self.cells[1][0].button("Police Stn", "search:amenity=police", None)
184        self.cells[2][0].button("Fire Stn", "search:amenity=fire", None)
185       
186        self.cells[0][1].button("Hospital", "search:amenity=hospital",None)
187        self.cells[1][1].button("Ranger", "search:amenity=ranger_station", None)
188        self.cells[2][1].button("Pharmacy", "search:amenity=pharmacy", None)
189       
190    def menu_search_park(self):
191        self.backButton(0,0)
192        self.cells[1][0].button("Car park", "search:amenity=parking", None)
193        self.cells[2][0].button("Free car park","search:amenity=parking;cost=free",None)
194       
195        self.cells[0][1].button("Bike park", "search:amenity=cycle_parking", None)
196        self.cells[1][1].button("Lay-by", "search:amenity=layby", None)
197       
198    def menu_search_hire(self):
199        self.backButton(0,0)
200        self.cells[1][0].button("Car hire", "search:amenity=car_hire", None)
201        self.cells[2][0].button("Bike hire", "search:amenity=bike_hire",None)
202       
203        self.cells[0][1].button("Ski hire","search:amenity=ski_hire",None)
204
205    def menu_search(self):
206        self.backButton(0,0)
207        self.cells[1][0].button("Eat","menu:search_eat",None)
208        self.cells[2][0].button("Sleep","menu:search_sleep",None)
209
210        self.cells[0][1].button("Fuel","menu:search_fuel",None)
211        self.cells[1][1].button("Repair","menu:search_repair",None)
212        self.cells[2][1].button("Buy","menu:search_buy",None)
213
214        self.cells[0][2].button("Help","menu:search_help",None)
215        self.cells[1][2].button("Park","menu:search_park",None)
216        self.cells[2][2].button("Hire","menu:search_hire",None)
217       
218        self.cells[0][3].button("",None,None)
219
220    def menu_view(self):
221        self.backButton(0,0)
222        self.cells[1][0].button("People",None,"people")
223        self.cells[2][0].button("Wiki","menu:geonames","wiki")
224
225        self.cells[0][1].button("Business","menu:search","business")
226        self.cells[1][1].button("RSS","menu:feeds","rss")
227        self.cells[2][1].button("Bookmarks",None,"bookmark")
228
229        self.cells[0][2].button("Routes",None,"route")
230        self.cells[1][2].button("Waypoints",None,"waypoints")
231        self.cells[2][2].button("Drawings",None,"sketch")
232       
233        self.cells[0][3].button("Events",None,"events")
234   
235    def menu_download(self):
236        self.backButton(0,0)
237        self.cells[1][0].button("",None,None)
238        self.cells[2][0].button("",None,None)
239
240        self.cells[0][1].button("",None,None)
241        self.cells[1][1].button("",None,None)
242        self.cells[2][1].button("Route data","download:osm:0.2","download")
243
244        self.cells[0][2].button("",None,None)
245        self.cells[1][2].button("",None,None)
246        self.cells[2][2].button("",None,None)
247       
248        self.cells[0][3].button("",None,None)
249        self.cells[1][3].button("",None,None)
250        self.cells[2][3].button("",None,None)
251
252    def menu_click(self):
253        self.backButton(0,0)
254       
255        latlonRect = self.rect.copyself(0.33,0,1,0.25)
256        latRect = latlonRect.copyself(0,0,1,0.5)
257        lonRect = latlonRect.copyself(0,0.5,1,1)
258       
259        lat,lon = self.get('clicked')
260       
261        NS = lat > 0 and 'N' or 'S'
262        EW = lon > 0 and 'E' or 'W'
263       
264        latRect.drawTextSomewhere('%1.4f %s' % (abs(lat), NS), 0.05, 0.05, 0.7, 0.95)
265        lonRect.drawTextSomewhere('%1.4f %s' % (abs(lon), EW), 0.3, 0.05, 0.95, 0.95)
266        #def drawTextSomewhere(self,text,px1,py1,px2,py2):
267        #innerBox = self.copyself(px1,py1,px2,py2)
268        #innerBox.drawText(text)
269   
270        #self.cells[1][0].button("(lat)",None,None)
271        #self.cells[2][0].button("(lon)",None,None)
272
273        self.cells[0][1].button("set pos","ownpos:clicked","set_pos")
274        self.cells[1][1].button("route to","route:clicked","route_to")
275        self.cells[2][1].button("direct to","direct:clicked","direct_to")
276
277        self.cells[0][2].button("waypoint", "waypoint:clicked", "bookmark")
278        self.cells[1][2].button("extend route", "extend:route:clicked", "extend_route")
279        self.cells[2][2].button("extend direct", "extend:direct:clicked", "extend_direct")
280
281        self.cells[0][3].button("",None,None)
282        self.cells[1][3].button("",None,None)
283        self.cells[2][3].button("",None,None)
284
285    def menu_options(self):
286        view,scroll = self.rect.xsplit(0.8)
287        view.fill(1,0,0)
288        scroll.fill(0,1,0)
289        self.backButton(0,0)
290
291
292if __name__ == "__main__":
293    a = guiOverlay(None,None)
294    print dir(a)
Note: See TracBrowser for help on using the repository browser.