(no commit message)
[drlaunch] / src / widget.py
index 34e73c7..878c063 100755 (executable)
 
 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
 
+# HACK
+# Add the current module's directory to sys.path to bypass
+# problems when running as widget.
+# Restore the path at the end of the imports
+import sys
+import os
+
+orig_path=sys.path[:]
+tmp_path=os.path.dirname( os.path.realpath( __file__ ) )
+sys.path.append(tmp_path)
+
+# End of hack
+
 import gtk
 import gobject
 import hildon
@@ -41,6 +54,9 @@ import apps
 from icon import Icon
 from icongrid import IconGrid
 
+# Restore path
+sys.path=orig_path
+
 # IconGrid must be before HomePluginItem for its connect()
 # and do_button_*() to override those of HomePluginItem
 class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation):
@@ -49,16 +65,31 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation):
        HomePluginItem.__init__(self)
        FremantleRotation.__init__(self, 'DrlaunchPlugin')
 
-       launcher.init()
-       config.load()
-       self.setSize(config.getSize())
-       self.reloadIcons()
+       self.winConfig=None
 
        self.set_settings(True)
        self.connect('show-settings', self.slot_show_settings)
        self.connect('long-press', self.signalLongpress)
+       self.connect('click', self.signalClick)
+
+    def get_id(self):
+       """If this is called from the constructor then the program
+       core dumps """
+       aid=self.get_applet_id()
+
+       ret="%s" % aid
+
+       return(ret)
 
     def do_realize(self):
+       #print "realize"
+
+       launcher.init()
+       config.init(self.get_id())
+       config.load()
+       self.setSize(config.getSize())
+       self.reloadIcons()
+
        screen=self.get_screen()
        self.set_colormap(screen.get_rgba_colormap())
        self.set_app_paintable(True)
@@ -66,7 +97,6 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation):
        HomePluginItem.do_realize(self)
 
     def on_orientation_changed(self, orientation):
-       print "orch:", orientation
        o=orientation[0]
        self.setMode(o)
 #      self.queue_draw()
@@ -75,37 +105,52 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation):
        IconGrid.do_expose_event(self, event)
        HomePluginItem.do_expose_event(self, event)
 
-    def do_buttonn_press_event(self, event):
-       print "press0"
-
     def slot_show_settings(self, dt):
-       print "settings", dt
+       if self.winConfig!=None:
+           # Doesn't work
+           # self.winConfig.show_all()
+           return
+
        s=WinConfig()
        s.show_all()
        s.connect('destroy', self.slotConfigDestroy)
+       self.winConfig=s
 
     def slotConfigDestroy(self, sender):
-       print "destroy", sender
+       self.winConfig=None
+
        dt=sender.getData()
-       print "dt:", dt
        config.setSize(dt['size'])
        config.setApps(dt['apps'])
+       config.setIndiv(dt['indiv'])
+       config.setLongpress(dt['longpress'])
        config.save()
        
        # Resize widget
        self.setSize(dt['size'])
        self.reloadIcons()
 
-#      self.queue_draw()
+       self.queue_draw()
+
+    def handle_click(self, sender, icon):
+       """ common handler for longpress and click """
+       if icon.name!=None and icon.name!='':
+           launcher.launch(icon.name)
 
     def signalLongpress(self, sender, icon):
-       print "launch:", icon.name
-       launcher.launch(icon.name)
+       if config.getLongpress():
+           self.handle_click(sender, icon)
+
+    def signalClick(self, sender, icon):
+       if not config.getLongpress():
+           self.handle_click(sender, icon)
 
     def resize(self):
-       w=(self.size * config.iconsize) + \
-           (self.size * config.iconspace)
-       self.set_size_request(w, w)
+       w=(self.size[0] * config.iconsize) + \
+           (self.size[0] * config.iconspace)
+       h=(self.size[1] * config.iconsize) + \
+           (self.size[1] * config.iconspace)
+       self.set_size_request(w, h)
 
     def setSize(self, size):
        IconGrid.setSize(self, size)
@@ -113,28 +158,12 @@ class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation):
 
 hd_plugin_type = DrlaunchPlugin
 
-def do1():
-#    gobject.type_register(MyQ)
+if __name__=="__main__":
     gobject.type_register(hd_plugin_type)
     obj=gobject.new(hd_plugin_type, plugin_id="plugin_id")
     obj.show_all()
     gtk.main()
 
-def do2():
-    win=DrlaunchPlugin()
-    win.connect('delete-event', gtk.main_quit)
-
-    print "win:", win
-
-#    t=DrlaunchPlugin()
-#    win.add(t)
-
-    win.show_all()
-    gtk.main()
-
-if __name__=="__main__":
-    do1()
-
 
 
 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: