CSSU's portrait mode support - WIP
[drlaunch] / drlaunch / src / iconw.py
1 #!/usr/bin/env python
2 # coding=UTF-8
3
4 # Copyright (C) 2010 Stefanos Harhalakis
5 #
6 # This file is part of wifieye.
7 #
8 # wifieye is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # wifieye is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with wifieye.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
22
23 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
24
25 from icon import Icon, getIcon
26 import apps
27
28 import gtk
29 import cairo
30 from gtk import gdk
31 import gobject
32
33 class IconWidget(gtk.Widget):
34     def __init__(self, isconfig, config):
35         gtk.Widget.__init__(self)
36
37         self.config=config
38         self.icon=Icon(isconfig, config)
39
40     def getMaxIconSizeFull(self):
41         c=self.config
42         w=c.getIconSizeRange()[1] + 2*c.getIconPaddingRange()[1] + \
43             2*c.getIconMarginRange()[1]
44
45         return(w)
46
47     def resetSize(self):
48         w=self.getMaxIconSizeFull()
49         self.set_size_request(2*w, 2*w)
50
51     def do_realize(self):
52         screen=self.get_screen()
53         self.set_colormap(screen.get_rgba_colormap())
54         self.set_app_paintable(True)
55
56         self.set_flags(self.flags() | gtk.REALIZED)
57
58         self.window=gdk.Window(
59             self.get_parent_window(),
60             width=self.allocation.width,
61             height=self.allocation.height,
62             window_type=gdk.WINDOW_CHILD,
63             wclass=gdk.INPUT_OUTPUT,
64             event_mask=self.get_events() | gdk.EXPOSURE_MASK)
65
66         self.window.set_user_data(self)
67
68         self.window.move_resize(*self.allocation)
69
70 #       style=self.get_style()
71 #       style.set_background(self.window, gtk.STATE_NORMAL)
72 #       self.gc=style.bg_gc[gtk.STATE_NORMAL]
73
74         self.icon.setWindow(self.window)
75         self.resetSize()
76
77     def do_unrealize(self):
78         self.window.destroy()
79         self.window.set_user_data(None)
80
81     def do_expose_event(self, event):
82         cr=self.window.cairo_create()
83
84         cr.rectangle(event.area.x, event.area.y,
85             event.area.width, event.area.height)
86
87         cr.clip()
88
89         cr.save()
90         # Paint the background
91         style=self.get_style()
92         col=style.bg[gtk.STATE_NORMAL]
93         cr.set_source_color(col)
94         cr.paint()
95
96         x2=self.config.getIconSizeFull()
97
98 #       col=style.fg[gtk.STATE_ACTIVE]
99 #       cr.set_source_color(col)
100 #       #cr.set_source_rgba(0,1,1,0.5)
101 #       cr.rectangle(1,1,x2+x2+2,x2+2)
102 #       cr.stroke()
103 #       cr.restore()
104
105         self.icon.draw(cr, 0, 0)
106         self.icon.draw(cr, x2, 0)
107         self.icon.draw(cr, 0, x2)
108         self.icon.draw(cr, x2, x2)
109
110     def setApp(self, app):
111         self.app=app
112         self.refresh()
113
114     def refresh(self):
115         if self.app!=None:
116             app=apps.readOne(self.app)
117             app['icon2']=getIcon(app['icon'], self.config.getIconSize())
118             self.icon.setApp(app)
119
120         self.queue_draw()
121
122 gobject.type_register(IconWidget)
123
124 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
125