source: subversion/applications/routing/pyroute-dev/menuIcons.py @ 18454

Last change on this file since 18454 was 18454, checked in by buerste, 10 years ago

-further updates of spaces to tabs

  • Property svn:keywords set to Rev
File size: 1.8 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""Menu graphics (icons)
5
6Usage:
7        (library code for pyroute GUI, not for direct use)
8"""
9
10__version__ = "$Rev: 18454 $"
11__license__ = """This program is free software: you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation, either version 3 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program. If not, see <http://www.gnu.org/licenses/>."""
23_debug = 0
24
25
26import cairo
27import os
28class menuIcons:
29        def __init__(self):
30                self.images = {}
31                self.cantLoad = []
32                self.load('blank')
33                self.load('generic')
34        def load(self,name):
35                filename = os.path.join(os.path.dirname(__file__), "icons", "bitmap/%s.png" % name)
36                if(not os.path.exists(filename)):
37                        print "Can't load %s" % filename
38                        return(0)
39
40                image = cairo.ImageSurface.create_from_png(filename)
41                if(not image):
42                        return(0)
43                w = float(image.get_width())
44                h = float(image.get_height())
45                #print "Loaded %s: %d x %d" % (name,w,h)
46                self.images[name] = {'image':image,'w':w,'h':h}
47                return(1)
48        def draw(self,cr,name,x,y,w,h):
49                if not name in self.images.keys():
50                        if(name in self.cantLoad):
51                                name = 'generic'
52                        elif(not self.load(name)):
53                                self.cantLoad.append(name)
54                                name='generic'
55
56                icon = self.images[name]
57                cr.save()
58                cr.translate(x,y)
59                cr.scale(w / icon['w'], h / icon['h'])
60                cr.set_source_surface(icon['image'],0,0)
61                cr.paint()
62                cr.restore()
Note: See TracBrowser for help on using the repository browser.