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

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

test for gps "select source" menu

File size: 2.0 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    self.load('blank')
30    self.load('generic')
31  def load(self,name):
32    filename = "icons/bitmap/%s.png" % name
33    if(not os.path.exists(filename)):
34      print "Can't load %s" % filename
35      return(0)
36   
37    image = cairo.ImageSurface.create_from_png(filename)
38    if(not image):
39      return(0)
40    w = float(image.get_width())
41    h = float(image.get_height())
42    #print "Loaded %s: %d x %d" % (name,w,h)
43    self.images[name] = {'image':image,'w':w,'h':h}
44    return(1)
45  def draw(self,cr,name,x,y,w,h):
46    if not name in self.images.keys():
47      if(name in self.cantLoad):
48        name = 'generic'
49      elif(not self.load(name)):
50        self.cantLoad.append(name)
51        name='generic'
52       
53    icon = self.images[name]
54    cr.save()
55    cr.translate(x,y)
56    cr.scale(w / icon['w'], h / icon['h'])
57    cr.set_source_surface(icon['image'],0,0)
58    cr.paint()
59    cr.restore()
60 
Note: See TracBrowser for help on using the repository browser.