class AbstractSettingsWindow :
- def __init__ ( self , config ) :
+ def __init__ ( self , config , handler=None ) :
self.set_title( "Wifihood Settings" )
scrollwin = self.MainArea()
maps.attach(button, 0, 1, 0, 1, gtk.EXPAND|gtk.FILL, 0, 0, 5)
zoomlevel = self.Button( "Zoom level" , config.zoom )
- zoomlevel.connect_object( "clicked", self.zoomdialog, config )
+ zoomlevel.connect_object( "clicked", self.zoomdialog, zoomlevel , config , handler )
zoomlevel.show()
maps.attach(zoomlevel, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0, 0, 5)
self.show()
- def zoomdialog ( self , widget) :
- dialog = ZoomDialog( widget )
+ def zoomdialog ( self , widget , config , extra=None ) :
+ dialog = ZoomDialog( config , widget.set_value , extra )
dialog.show_all()
if hildon :
class ZoomDialog ( hildon.TouchSelector ) :
- def __init__ ( self , config ) :
+ def __init__ ( self , config , handler=None , extra=None ) :
hildon.TouchSelector.__init__( self )
zooms = gtk.ListStore(str)
class SettingsWindow ( hildon.StackableWindow , AbstractSettingsWindow ) :
- def __init__ ( self , config ) :
+ def __init__ ( self , config , handler=None ) :
hildon.StackableWindow.__init__( self )
- AbstractSettingsWindow.__init__( self , config )
+ AbstractSettingsWindow.__init__( self , config , handler )
def MainArea ( self ) :
return hildon.PannableArea()
class ZoomDialog ( gtk.Dialog ) :
- def __init__ ( self , config ) :
+ def __init__ ( self , config , handler=None , extra=None ) :
gtk.Dialog.__init__( self , "Select zoom level",
None,
gtk.DIALOG_MODAL,
self.vbox.pack_start(combo , True, True, 0)
- self.connect_object( "response", self.response , combo , config )
+ self.connect_object( "response", self.response , combo , config , handler , extra )
- def response ( self , combo , response , config ) :
+ def response ( self , combo , response , config , handler , extra=None ) :
if response == gtk.RESPONSE_ACCEPT :
item = combo.get_active_iter()
model = combo.get_model()
+ handler( model.get(item,0)[0])
+ if extra : extra( model.get(item,0)[0])
config.zoom = model.get(item,0)[0]
self.destroy()
class SettingsWindow ( gtk.Window , AbstractSettingsWindow ) :
- def __init__ ( self , config ) :
+ def __init__ ( self , config , handler=None ) :
gtk.Window.__init__( self )
- AbstractSettingsWindow.__init__( self , config )
+ AbstractSettingsWindow.__init__( self , config , handler )
def MainArea ( self ) :
scrollwin = gtk.ScrolledWindow()
return gtk.Entry()
def Button ( self , text , value ) :
- return gtk.Button( "%s %s" % ( text , value ) )
+ class _button ( gtk.Button ) :
+ def __init__ ( self , text , value ) :
+ gtk.Button.__init__( self )
+ self._text = text
+ self.set_value( value )
+ def set_value ( self , value ) :
+ self._value = value
+ self.set_label( "%s -- %s" % ( self._text , self._value ) )
+ return _button( text , value )
def CheckButton ( self ) :
return gtk.CheckButton()
self.composeMap()
+ def tilex2lon ( self , ( tilex , pixx ) , zoom ) :
+ tilex = float(tilex)
+ pixx = float(pixx)
+ return ( tilex + pixx/self.tile_size ) / 2.0 ** zoom * 360.0 - 180.0
+
+ def tiley2lat ( self , ( tiley , pixy ) , zoom ) :
+ tiley = float(tiley)
+ pixy = float(pixy)
+ tiley = math.pi * ( 1 - 2 * ( tiley + pixy/self.tile_size ) / 2.0 ** zoom )
+ return math.degrees( math.atan( math.sinh( tiley ) ) )
+
+ def SetZoom( self , zoom ) :
+ self.hide()
+ lat = self.tiley2lat( ( self.reftile_y , self.refpix_y ) , self.conf.zoom )
+ lon = self.tilex2lon( ( self.reftile_x , self.refpix_x ) , self.conf.zoom )
+ self.reftile_x , self.refpix_x = self.lon2tilex( lon , zoom )
+ self.reftile_y , self.refpix_y = self.lat2tiley( lat , zoom )
+ self.conf.zoom = zoom
+ self.composeMap()
+ self.show()
+
def lon2tilex ( self , lon , zoom ) :
number = math.modf( ( lon + 180 ) / 360 * 2 ** zoom )
return int( number[1] ) , int( self.tile_size * number[0] )
class interactiveMapWidget :
- def tilex2lon ( self , ( tilex , pixx ) , zoom ) :
- tilex = float(tilex)
- pixx = float(pixx)
- return ( tilex + pixx/self.tile_size ) / 2.0 ** zoom * 360.0 - 180.0
-
- def tiley2lat ( self , ( tiley , pixy ) , zoom ) :
- tiley = float(tiley)
- pixy = float(pixy)
- tiley = math.pi * ( 1 - 2 * ( tiley + pixy/self.tile_size ) / 2.0 ** zoom )
- return math.degrees( math.atan( math.sinh( tiley ) ) )
-
def Shift( self , dx , dy ) :
self.hide()
self.composeMap()
self.show()
- def ZoomChange ( self , selector ) :
- model = selector.get_model(0)
- active = selector.get_active(0)
- value = model.get( model.get_iter(active) , 0 )
- self.SetZoom( int(value[0]) )
-
- def SetZoom( self , zoom ) :
- self.hide()
- lat = self.tiley2lat( ( self.reftile_y , self.refpix_y ) , self.conf.zoom )
- lon = self.tilex2lon( ( self.reftile_x , self.refpix_x ) , self.conf.zoom )
- self.reftile_x , self.refpix_x = self.lon2tilex( lon , zoom )
- self.reftile_y , self.refpix_y = self.lat2tiley( lat , zoom )
- self.conf.zoom = zoom
- self.composeMap()
- self.show()
-
def Up( self ) :
self.hide()
self.reftile_y -= 1
status = gtk.Label( "status bar ..." )
_scanner.status = status
_scanner.buffer = textview.get_buffer()
- _scanner.map = self.map
+ _scanner.map = self.map.child
bottom_box.pack_start( status , expand=False , padding=20 )
def run ( self ) :
gtk.main()
-def settings_cb ( widget , config ) :
- wifimap.config.SettingsWindow( config )
+def settings_cb ( widget , map ) :
+ window = wifimap.config.SettingsWindow( map.config , map.child.SetZoom )
if hildon :
hildon.BUTTON_ARRANGEMENT_VERTICAL,
"Settings",
None)
- settings.connect( "clicked", settings_cb , self.map.config )
+ settings.connect( "clicked", settings_cb , self.map )
menubar.append( settings )
menubar.show_all()
self.vbox.pack_start( menubar )
settings = gtk.MenuItem( "Settings" )
- settings.connect( "activate", settings_cb , self.map.config )
+ settings.connect( "activate", settings_cb , self.map )
menubar.append( settings )
menubar.show_all()