Allow wifiscanner to run smoothly in non-maemo systems
[wifihood] / wifimap / ui.py
index 7f7903a..1444529 100755 (executable)
@@ -2,7 +2,10 @@
 import wifimap
 
 import gtk , pango
-import hildon
+try :
+    import hildon
+except :
+    hildon = False
 
 import gobject
 
@@ -28,7 +31,8 @@ def scana(widget, data):
     if not data._timer :
         data._timer = gobject.timeout_add( 5000 , data.scan )
     else :
-        hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning was already active" )
+        if hildon :
+            hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning was already active" )
     if widget.handler_id :
         widget.disconnect( widget.handler_id )
         widget.handler_id = widget.connect("clicked", scano, data)
@@ -36,25 +40,23 @@ def scana(widget, data):
 
 def scano(widget, data):
     if data._timer :
-        hildon.hildon_banner_show_information( widget , "icon_path" , "Timer was running, stopping it" )
+        if hildon :
+            hildon.hildon_banner_show_information( widget , "icon_path" , "Timer was running, stopping it" )
         gobject.source_remove( data._timer )
         data._timer = None
         data.stop()
     else :
-        hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning is not active" )
+        if hildon :
+            hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning is not active" )
     if widget.handler_id :
         widget.disconnect( widget.handler_id )
         widget.handler_id = widget.connect("clicked", scana, data)
         widget.set_label("Start scanning now !!")
 
-class Wifiscanner ( hildon.Window ) :
+class AbstractWifiscanner :
 
     def __init__ ( self ) :
 
-        hildon.Window.__init__( self )
-        program = hildon.Program.get_instance()
-        program.add_window(self)
-
         self.gpsdev = wifimap.Scanner( self )
 
         self.connect("delete_event", gtk.main_quit, None)
@@ -83,26 +85,20 @@ class Wifiscanner ( hildon.Window ) :
         buttons = gtk.VBox(homogeneous=False, spacing=0)
         hbox.pack_end(buttons, expand=False)
 
-        textview = hildon.TextView()
-        textview.set_placeholder( "Scan results ..." )
-        textview.set_editable( False )
-        textview.set_cursor_visible( False )
-        textview.modify_font( pango.FontDescription("Courier 12") )
+        textview = self.TextView( "Scan results ..." )
         scrollview.add( textview )
         scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
 
         # Buttons creation
-        button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch On!")
+        button = self.Button( "Switch On!")
         button.handler_id = button.connect("clicked", hello, self.gpsdev)
         buttons.pack_start(button, expand=False)
 
-        button_scan = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Start scanning now !!")
+        button_scan = self.Button( "Start scanning now !!")
         button_scan.handler_id = button_scan.connect("clicked", scana, self.gpsdev)
         buttons.pack_start(button_scan, expand=False)
 
-        toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT )
-        toggle_button.set_label( "Use Assisted GPS" )
+        toggle_button = self.CheckButton( "Use Assisted GPS" )
         toggle_button.connect("toggled", enable_agps)
         buttons.pack_start(toggle_button, expand=False)
 
@@ -116,3 +112,62 @@ class Wifiscanner ( hildon.Window ) :
         self.gpsdev.start()
         gtk.main()
 
+if hildon :
+
+    class Wifiscanner ( AbstractWifiscanner , hildon.Window ) :
+
+        def __init__ ( self ) :
+            hildon.Window.__init__( self )
+            program = hildon.Program.get_instance()
+            program.add_window(self)
+
+            AbstractWifiscanner.__init__( self )
+
+        def TextView ( self , placeholder=None ) :
+            textview = hildon.TextView()
+            if  placeholder :
+                textview.set_placeholder(  placeholder )
+            textview.set_editable( False )
+            textview.set_cursor_visible( False )
+            textview.modify_font( pango.FontDescription("Courier 12") )
+            return textview
+        def Button ( self , label="" ) :
+            button = hildon.Button(hildon.HILDON_SIZE_AUTO_WIDTH | hildon.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, label)
+            return button
+
+        def CheckButton ( self , label=None ) :
+            toggle_button = hildon.CheckButton( hildon.HILDON_SIZE_AUTO_WIDTH | hildon.HILDON_SIZE_FINGER_HEIGHT )
+            if label :
+                toggle_button.set_label( label )
+            return toggle_button
+
+else :
+
+    class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :
+
+        def __init__ ( self ) :
+            gtk.Window.__init__( self )
+            self.window.resize(640,400)
+
+            AbstractWifiscanner.__init__( self )
+
+        def TextView ( self , placeholder=None ) :
+            textview = gtk.TextView()
+            if placeholder :
+                textview.get_buffer().set_text( placeholder )
+            textview.set_editable( False )
+            textview.set_cursor_visible( False )
+            textview.modify_font( pango.FontDescription("Courier 12") )
+            return textview
+        def Button ( self , label="" ) :
+            button = gtk.Button( label )
+            return button
+
+        def CheckButton ( self , label=None ) :
+            toggle_button = gtk.CheckButton()
+            if label :
+                toggle_button.set_label( label )
+            return toggle_button
+