4 # Copyright (C) 2010 Stefanos Harhalakis
6 # This file is part of wifieye.
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.
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.
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/>.
21 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
23 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
26 # Add the current module's directory to sys.path to bypass
27 # problems when running as widget.
28 # Restore the path at the end of the imports
34 tmp_path=os.path.dirname( os.path.realpath( __file__ ) )
35 sys.path.append(tmp_path)
40 from hildondesktop import *
47 from subprocess import Popen,PIPE
49 from portrait import FremantleRotation
51 from xdg.IconTheme import getIconPath
52 from win_config import WinConfig
57 from icongrid import IconGrid
58 from sig import Disconnector
65 # IconGrid must be before HomePluginItem for its connect()
66 # and do_button_*() to override those of HomePluginItem
67 class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation, Disconnector):
68 __gtype_name__ = "DrlaunchPlugin"
71 IconGrid.__init__(self)
72 HomePluginItem.__init__(self)
73 FremantleRotation.__init__(self, 'DrlaunchPlugin',
74 mode=FremantleRotation.AUTOMATIC, dontrotate=True)
75 Disconnector.__init__(self)
79 self.gconf=gconf.client_get_default()
81 self.set_settings(True)
89 """If this is called from the constructor then the program
91 aid=self.get_applet_id()
93 # Get desktop activity if D.A.M. is present
95 act="/usr/bin/activity"
97 if os.path.exists(act):
98 r=Popen([act, "current"], stdout=PIPE).communicate()
103 ret="%s-%s" % (aid, activity)
109 self.id=self.get_id0()
113 def get_config(self):
114 if self.config==None:
116 self.config=config.Config(id)
120 def get_desktop_orientation(self):
122 Return desktop orientation
124 NOTE: This is the desktop orientation as it was introduced in CSSU.
125 Not the device orientation.
127 @return "portrait" or "landscape"
130 sw=gdk.screen_width()
131 sh=gdk.screen_height()
140 def is_rotating_desktop(self):
142 Check whether the desktop will change to portrait mode, as
150 # This returns False if the key doesn't exist
151 ret=c.get_bool('/apps/osso/hildon-desktop/ui_can_rotate')
155 def do_realize(self):
157 config=self.get_config()
160 IconGrid.do_realize(self, config)
162 self.setSize(config.getSize())
165 screen=self.get_screen()
166 self.set_colormap(screen.get_rgba_colormap())
167 self.set_app_paintable(True)
169 self.c(self, 'show-settings', self.slot_show_settings)
170 self.c(self, 'long-press', self.signalLongpress)
171 self.c(self, 'click', self.signalClick)
172 self.c(self, 'notify', self.signalNotify)
174 HomePluginItem.do_realize(self)
176 def on_orientation_changed(self, orientation):
178 if orientation==None or len(orientation)==0:
181 # Get the first character of the string (l/p)
184 # Get desktop orientation
185 #do=self.get_desktop_orientation()
187 # Is desktop rotation (per CSSU) enabled?
188 rd=self.is_rotating_desktop()
190 #print "desktop: %s / %s, device: %s" % (do, rd, o)
192 # In case of a rotating desktop, force orientation to be
195 # CSSU Portrait mode?
203 self.setCSSUPortrait(csp)
212 def do_expose_event(self, event):
213 IconGrid.do_expose_event(self, event)
214 HomePluginItem.do_expose_event(self, event)
217 def slot_show_settings(self, dt):
218 if self.winConfig!=None:
220 # self.winConfig.show_all()
223 s=WinConfig(self.get_config())
225 #s.c(s, 'delete-event', self.slotConfigDestroy)
226 self.c(s, 'delete-event', self.slotConfigDestroy)
227 #s.connect('destroy', self.slotConfigDestroy)
230 def slotConfigDestroy(self, sender, event):
231 # print "Sender:", sender
234 # Disconnect signals for that object in order to be deleted
235 self.dis_finish(self.winConfig)
236 #self.winConfig.finish()
237 #self.winConfig.destroy()
241 cfg=self.get_config()
243 cfg.setSize(dt['size'])
244 cfg.setApps(dt['apps'])
245 cfg.setIndiv(dt['indiv'])
246 cfg.setLongpress(dt['longpress'])
247 cfg.setAnimate(dt['animate'])
248 cfg.setNoBg(dt['nobg'])
249 cfg.setThemeBg(dt['themebg'])
250 cfg.setIconSize(dt['iconsize'])
251 cfg.setIconPadding(dt['iconpadding'])
252 cfg.setIconMargin(dt['iconmargin'])
256 self.icons.resizeMax()
257 self.setSize(dt['size'])
260 # Free memory that is used for animations if animations are disabled
261 if not dt['animate']:
262 self.clearAnimationCache()
264 # Free memory of backgrounds in case they changed
269 # print "slot-config-destroy-end"
273 def handle_click(self, sender, icon):
274 """ common handler for longpress and click """
275 if icon.appname!=None and icon.appname!='':
276 launcher.launch(icon.appname)
278 def signalLongpress(self, sender, icon):
279 self.handle_click(sender, icon)
281 def signalClick(self, sender, icon):
282 config=self.get_config()
284 if not config.getLongpress():
285 self.handle_click(sender, icon)
287 def signalNotify(self, sender, property):
288 if property.name=='is-on-current-desktop':
289 v=self.get_property(property.name)
290 if v and self.draw_pending:
294 config=self.get_config()
296 w=(self.size[0] * config.iconsize) + \
297 (self.size[0] * config.getIconSpace())
298 h=(self.size[1] * config.iconsize) + \
299 (self.size[1] * config.getIconSpace())
301 if self.cssuportrait:
305 self.set_size_request(w, h)
309 def setSize(self, size):
310 IconGrid.setSize(self, size)
313 hd_plugin_type = DrlaunchPlugin
315 if __name__=="__main__":
319 #gobject.type_register(hd_plugin_type)
320 obj=gobject.new(hd_plugin_type, plugin_id="plugin_id")
326 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: