source: subversion/applications/routing/pyroute/menuIcons.py @ 5730

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

Move the map tile code into its own module

Add headers and usage instructions to a bunch of modules

File size: 1.9 KB
Line 
1#!/usr/bin/python
2#-----------------------------------------------------------------------------
3# Menu graphics (icons)
4#
5# Usage:
6#   (library code for pyroute GUI, not for direct use)
7#-----------------------------------------------------------------------------
8# Copyright 2007, Oliver White
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22#-----------------------------------------------------------------------------
23import cairo
24import os
25class menuIcons:
26    def __init__(self):
27        self.images = {}
28        self.cantLoad = []
29    def load(self,name):
30        filename = "icons/bitmap/%s.png" % name
31        if(not os.path.exists(filename)):
32            return(0)
33        self.images[name] = cairo.ImageSurface.create_from_png(filename)
34        if(self.images[name]):
35            return(1)
36        return(0)
37    def draw(self,cr,name,x,y,w,h):
38        if not name in self.images.keys():
39            if(name in self.cantLoad):
40                return
41            if(not self.load(name)):
42                self.cantLoad.append(name)
43                return
44        imagesize = 120.0
45        cr.save()
46        cr.translate(x,y)
47        cr.scale(w / imagesize, h / imagesize)
48        cr.set_source_surface(self.images[name],0,0)
49        cr.paint()
50        cr.restore()
51   
Note: See TracBrowser for help on using the repository browser.