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