Extend hildon wrappers to scanning application
authorjaviplx <javiplx@gmail.com>
Sat, 14 May 2011 21:49:03 +0000 (21:49 +0000)
committerjaviplx <javiplx@gmail.com>
Sat, 14 May 2011 21:49:03 +0000 (21:49 +0000)
git-svn-id: file:///svnroot/wifihood/trunk@181 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiscanner/hildongtk/hildon.py
wifiscanner/wifiscanner

index 9fdb6db..70c0c51 100644 (file)
@@ -45,6 +45,10 @@ class Entry ( gtk.Entry ) :
         gtk.Entry.__init__( self )
 
 class TextView ( gtk.TextView ) :
+    def __init__ ( self , placeholder=None ) :
+        gtk.TextView.__init__( self )
+        if placeholder :
+            self.set_placeholder( placeholder )
     def set_placeholder( self , text ) :
         self.get_buffer().set_text( text )
 
index 70df6b9..5dcfe79 100755 (executable)
@@ -6,7 +6,7 @@ import gtk , pango
 try :
     import hildon
 except :
-    hildon = False
+    from hildongtk import hildon
 
 def global_start(button, scanner, config):
     scanner.start( int( 1000 * config.scan_period ) , config.store_log )
@@ -71,10 +71,15 @@ class scanner ( wifimap.Scanner ) :
             self.map.show()
 
 
-class AbstractWifiscanner :
+class Wifiscanner ( hildon.StackableWindow ) :
 
     def __init__ ( self ) :
 
+        hildon.StackableWindow.__init__( self )
+        self.set_title( "Wifihood Scanner" )
+        program = hildon.Program.get_instance()
+        program.add_window(self)
+
         config = wifimap.config.Configuration( 'scanner' )
         _scanner = scanner( config , "wlan0" )
 
@@ -109,20 +114,24 @@ class AbstractWifiscanner :
         buttons = gtk.VBox(homogeneous=False, spacing=0)
         hbox.pack_end(buttons, expand=False)
 
-        textview = self.TextView( "Scan results ..." )
+        textview = hildon.TextView( "Scan results ..." )
+        textview.set_editable( False )
+        textview.set_cursor_visible( False )
+        textview.modify_font( pango.FontDescription("Courier 12") )
         scrollview.add( textview )
         scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
 
         # Buttons creation
-        button = self.Button( "Switch GPS On")
+        button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch GPS On" )
         button._id = button.connect("clicked", global_start, _scanner, config)
         buttons.pack_start(button, expand=False)
 
-        button_scan = self.Button( "Start scanning")
+        button_scan = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Start scanning" )
         button_scan._id = button_scan.connect("clicked", start_scan, _scanner)
         buttons.pack_start(button_scan, expand=False)
 
-        toggle_button = self.CheckButton( "Use Assisted GPS" )
+        toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT )
+        toggle_button.set_label( "Use Assisted GPS" )
         toggle_button.connect("toggled", enable_agps)
         buttons.pack_start(toggle_button, expand=False)
 
@@ -133,58 +142,13 @@ class AbstractWifiscanner :
         _scanner.map = self.map.child
         bottom_box.pack_start( status , expand=False , padding=20 )
 
-    def run ( self ) :
-        gtk.main()
-
-def settings_cb ( widget , map ) :
-    window = wifimap.config.SettingsWindow( map.config , map.child.SetZoom )
-
-
-if hildon :
-
-    class MapWindow ( gtk.Frame ) :
-
-        def __init__( self , config ):
-            gtk.Frame.__init__( self )
-
-            self.config = config
-            self.add( wifimap.simpleMapWidget( self.config ) )
-
-    class Wifiscanner ( AbstractWifiscanner , hildon.StackableWindow ) :
-
-        def __init__ ( self ) :
-            hildon.StackableWindow.__init__( self )
-            self.set_title( "Wifihood Scanner" )
-            program = hildon.Program.get_instance()
-            program.add_window(self)
-
-            AbstractWifiscanner.__init__( self )
-            self.add(self.vbox)
-
-            self.create_menu( )
-
-            self.show_all()
+        self.add(self.vbox)
 
-        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(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, label)
-            return button
+        self.create_menu( )
 
-        def CheckButton ( self , label=None ) :
-            toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT )
-            if label :
-                toggle_button.set_label( label )
-            return toggle_button
+        self.show_all()
 
-        def create_menu ( self ) :
+    def create_menu ( self ) :
 
             menubar = hildon.AppMenu()
             self.set_app_menu( menubar )
@@ -198,58 +162,22 @@ if hildon :
 
             menubar.show_all()
 
-else :
-
-    class MapWindow ( gtk.Frame ) :
-
-        def __init__( self , config ):
-            gtk.Frame.__init__( self )
-
-            self.config = config
-            self.add( wifimap.simpleMapWidget( self.config , (640,400) ) )
-
-    class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :
-
-        def __init__ ( self ) :
-            gtk.Window.__init__( self )
-            self.resize(640,400)
-
-            AbstractWifiscanner.__init__( self )
-            self.add(self.vbox)
-
-            self.create_menu()
+    def run ( self ) :
+        gtk.main()
 
-            self.show_all()
 
-        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 settings_cb ( widget , map ) :
+    window = wifimap.config.SettingsWindow( map.config , map.child.SetZoom )
 
-        def CheckButton ( self , label=None ) :
-            toggle_button = gtk.CheckButton()
-            if label :
-                toggle_button.set_label( label )
-            return toggle_button
 
-        def create_menu ( self ) :
+class MapWindow ( gtk.Frame ) :
 
-            menubar = gtk.MenuBar()
-            self.vbox.pack_start( menubar )
+        def __init__( self , config ):
+            gtk.Frame.__init__( self )
 
-            settings = gtk.MenuItem( "Settings" )
-            settings.connect( "activate", settings_cb , self.map )
-            menubar.append( settings )
+            self.config = config
+            self.add( wifimap.simpleMapWidget( self.config ) )
 
-            menubar.show_all()
 
 window = Wifiscanner()
 window.run()