79e02815df4198a55ff18e1ea4e6fa4c0fa6feea
[drlaunch] / test.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 import gtk
26 from hildondesktop import *
27 from gtk import gdk
28 import cairo
29
30 class Icons:
31     def __init__(self):
32         self.mode='l'
33
34         self.size=3
35         self.iconsize=64
36
37         self.icons=[]
38
39         fn=["maegirls.png", "mc.png"]*3
40         for f in fn:
41             #p=gtk.gdk.pixbuf_new_from_file(f)
42             p=gtk.gdk.pixbuf_new_from_file_at_size(f, self.iconsize,
43                 self.iconsize)
44             print "pix:", p
45             self.icons.append(p)
46
47         print "end of Icons init"
48
49     def setMode(self, mode):
50         self.mode=mode
51
52 class MyQ(gtk.DrawingArea, Icons):
53     def __init__(self):
54         Icons.__init__(self)
55         gtk.DrawingArea.__init__(self)
56
57 #       self.set_size_request(-1, -1)
58
59 #       self.connect('size-request', self.do_size_request)
60 #       self.connect('size-allocate', self.do_size_allocate)
61         self.connect('expose-event', self.expose)
62         self.connect('button-press-event', self.butpress)
63
64 #       self.show_all()
65         print "MyQ init"
66
67     def butpress(self, widget, ev):
68         if ev.type==gdk.BUTTON_PRESS:
69             print "press", ev.type
70             if self.mode=='p':
71                 self.setMode('l')
72             else:
73                 self.setMode('p')
74             widget.queue_draw()
75         return True
76
77     def expose(self, widget, event):
78         print "expose"
79
80         x=0
81         y=0
82
83         print "mode:", self.mode
84         for i in self.icons:
85             if self.mode=='l':
86                 widget.window.draw_pixbuf(None, i, 0, 0, x*self.iconsize,
87                     y*self.iconsize)
88             else:
89                 x2=y*self.iconsize
90                 y2=(self.size-x-1)*self.iconsize
91                 print x,y,x2,y2
92                 i2=i.rotate_simple(gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE)
93                 widget.window.draw_pixbuf(None, i2, 0, 0, x2, y2)
94
95             x+=1
96             if x>=self.size:
97                 x=0
98                 y+=1
99
100         return(True)
101
102 #    def do_size_request(self, requisition, param):
103 #       print "szreq"
104 #       requisition.width = self.size*self.iconsize
105 #       requisition.height = self.size*self.iconsize
106
107 #    def do_size_allocate(self, allocation, param):
108 #       print "szalloc", allocation.width, allocation.height
109 #
110 #       if self.flags() & gtk.REALIZED:
111 #           self.window.move_resize(*allocation)
112
113 class TestPlugin(HomePluginItem, Icons):
114     def __init__(self):
115         HomePluginItem.__init__(self)
116         Icons.__init__(self)
117
118         self.setMode('l')
119
120         self.set_size_request(self.size * self.iconsize,
121             self.size * self.iconsize)
122
123 ##      myq=MyQ()
124 #       myq.show_all()
125 #       self.add(myq)
126
127 #       self.show_all()
128
129     def _draw(self, cr):
130         cr.save()
131         cr.set_source_rgba(0.5, 0.5, 0.5, 0.5)
132         cr.set_operator(cairo.OPERATOR_SOURCE)
133         cr.paint()
134         cr.restore()
135
136 #       cr.save()
137
138         x=0
139         y=0
140
141         print "mode:", self.mode
142         for i in self.icons:
143             print x,y
144
145             if self.mode=='l':
146                 x2=x*self.iconsize
147                 y2=y*self.iconsize
148                 i2=i
149             else:
150                 x2=y*self.iconsize
151                 y2=(self.size-x-1)*self.iconsize
152                 #print x,y,x2,y2
153                 i2=i.rotate_simple(gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE)
154
155             cr.save()
156             cr.set_source_pixbuf(i2, x2, y2)
157             cr.paint()
158             cr.restore()
159
160             x+=1
161             if x>=self.size:
162                 x=0
163                 y+=1
164
165     def do_expose_event(self, event):
166         print "do_expose"
167
168         cr=self.window.cairo_create()
169
170         cr.rectangle(event.area.x, event.area.y,
171             event.area.width, event.area.height)
172
173         cr.clip()
174
175         self._draw(cr)
176
177 #       HomePluginItem.do_expose_event(self, event)
178
179     def do_realize(self):
180         screen=self.get_screen()
181         self.set_colormap(screen.get_rgba_colormap())
182         self.set_app_paintable(True)
183
184         HomePluginItem.do_realize(self)
185
186     def do_button_press_event(self, event):
187         print "press"
188         if event.type==gdk.BUTTON_PRESS:
189             print "press", event.type
190             if self.mode=='p':
191                 self.setMode('l')
192             else:
193                 self.setMode('p')
194             self.queue_draw()
195         return True
196
197     def butTest(self, arg):
198         print "but", arg
199
200 hd_plugin_type = TestPlugin
201
202 def do1():
203     import gobject
204 #    gobject.type_register(MyQ)
205     gobject.type_register(hd_plugin_type)
206     obj=gobject.new(hd_plugin_type, plugin_id="plugin_id")
207     obj.show_all()
208     gtk.main()
209
210 def do2():
211     win=TestPlugin()
212     win.connect('delete-event', gtk.main_quit)
213
214     print "win:", win
215
216 #    t=TestPlugin()
217 #    win.add(t)
218
219     win.show_all()
220     gtk.main()
221
222 if __name__=="__main__":
223     do1()
224
225
226
227 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
228