Allow wifiscanner to run smoothly in non-maemo systems
authorjaviplx <javiplx@gmail.com>
Sun, 10 Oct 2010 11:29:51 +0000 (11:29 +0000)
committerjaviplx <javiplx@gmail.com>
Sun, 10 Oct 2010 11:29:51 +0000 (11:29 +0000)
git-svn-id: file:///svnroot/wifihood/trunk/wifiscanner@35 c51dfc6a-5949-4919-9c8e-f207a149c383

wifimap/gps.py
wifimap/ui.py
wifimap/wifiscan.py
wifiscanner [new file with mode: 0755]

index 03743cd..409400c 100644 (file)
@@ -2,7 +2,10 @@
 
 import location
 
-import hildon
+try :
+    import hildon
+except :
+    hildon = False
 import gobject
 
 class GPSObject ( gobject.GObject ) :
@@ -16,7 +19,7 @@ class GPSObject ( gobject.GObject ) :
         self.method = location.METHOD_GNSS
         self.device = None
         self.gps_state = False
-        self.gps_info = None
+        self.gps_info = "NO_FIX 0 0 NaN NaN NaN NaN NaN NaN NaN"
         self.update_handler = None
         self.satellites = None
         self.cell_info = None
@@ -52,7 +55,8 @@ class GPSObject ( gobject.GObject ) :
             self.control.set_properties(preferred_method=self.method)
             self.device = location.GPSDevice()
         if self.update_handler :
-            hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS already started" )
+            if hildon :
+                hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS already started" )
         else :
             self.update_handler = self.device.connect_object("changed", GPSObject.do_update , self)
             self.control.start()
@@ -71,11 +75,13 @@ class GPSObject ( gobject.GObject ) :
         if self.device :
             if self.device.status == location.GPS_DEVICE_STATUS_NO_FIX :
             #    if self.gps_state == "FIX" or self.gps_state == "DGPS" :
+            #      if hildon :
             #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Lost GPS fix" )
             #        banner.set_timeout( 1500 )
                 self.gps_state = "NO_FIX"
             elif self.device.status == location.GPS_DEVICE_STATUS_FIX :
             #    if self.gps_state == "NO_FIX" :
+            #      if hildon :
             #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Got GPS fix" )
             #        banner.set_timeout( 1500 )
                 self.gps_state = "FIX"
@@ -83,6 +89,7 @@ class GPSObject ( gobject.GObject ) :
                 self.refresh_infowin()
             elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
             #    if self.gps_state == "NO_FIX" :
+            #      if hildon :
             #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Got differential GPS fix" )
             #        banner.set_timeout( 1500 )
                 self.gps_state = "DGPS"
@@ -92,6 +99,7 @@ class GPSObject ( gobject.GObject ) :
             self.cell_info = self.device.cell_info
 
         #    if self._debug :
+        #      if hildon :
         #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS info : %s" % self.gps_info )
         #        banner.set_timeout( 300 )
 
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
+
index 83acfd7..98c33ee 100644 (file)
@@ -65,9 +65,7 @@ class Scanner ( gps.GPSObject ) :
             self.aplist[ items[0] ] = 1
         self.refresh_infowin()
         if self._debug :
-        # Use osso or hildon for notes ???
             osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
-        #    hildon.hildon_banner_show_information( self._parent , "icon_path" , "Found %d APs" % len(scan_out) )
         else :
             fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' )
             fd.write( "%s %s%s\n" % ( timestamp , self.gps_info , out_str ) )
diff --git a/wifiscanner b/wifiscanner
new file mode 100755 (executable)
index 0000000..a9bf8d2
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/python
+
+import wifimap.ui
+
+if __name__ == "__main__":
+    window = wifimap.ui.Wifiscanner()
+    window.run()
+