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

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

Generic icon if none supplied

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        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            return(0)
35        self.images[name] = cairo.ImageSurface.create_from_png(filename)
36        if(self.images[name]):
37            return(1)
38        return(0)
39    def draw(self,cr,name,x,y,w,h):
40        if not name in self.images.keys():
41            if(name in self.cantLoad):
42                name = 'generic'
43            elif(not self.load(name)):
44                self.cantLoad.append(name)
45                name='generic'
46        imagesize = 120.0
47        cr.save()
48        cr.translate(x,y)
49        cr.scale(w / imagesize, h / imagesize)
50        cr.set_source_surface(self.images[name],0,0)
51        cr.paint()
52        cr.restore()
53   
Note: See TracBrowser for help on using the repository browser.