Changeset 7d1b4b7


Ignore:
Timestamp:
02/05/12 02:46:59 (2 years ago)
Author:
xkolman2 <xkolman2@…>
Branches:
master
Children:
6963cec
Parents:
bf837e8
git-author:
xkolman2 <xkolman2@…> (02/05/12 02:46:59)
git-committer:
xkolman2 <xkolman2@…> (02/05/12 02:46:59)
Message:

make the QML and GTK GUIs live together

git-svn-id: https://nlp.fi.muni.cz/svn/gps_navigace/trunk@656 0858a4d0-ffff-46e5-938e-62b5ecb34222

Files:
2 added
1 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • modrana.py

    rbbe91da r7d1b4b7  
    3131startTimestamp = time.time() 
    3232import math 
     33import os 
     34import marshal 
    3335import traceback 
    34 import os 
    3536from math import radians 
    3637from configobj import ConfigObj 
    3738# import core modules/classes 
    38 from core import startup as startup 
    39  
     39from core import startup 
     40from core import paths 
     41from core import gs 
     42 
     43# record that imports-done timestamp 
    4044importsDoneTimestamp = time.time() 
    4145 
     
    6569 
    6670def simplePythagoreanDistance(x1, y1, x2, y2): 
    67     dx = x2 - x1 
    68     dy = y2 - y1 
    69     return math.sqrt(dx**2 + dy**2) 
     71  """convenience PyThagorean distance :)""" 
     72  dx = x2 - x1 
     73  dy = y2 - y1 
     74  return math.sqrt(dx**2 + dy**2) 
    7075 
    7176class ModRana: 
    7277  """ 
    73   This is the main modRana class. 
     78  This is THE main modRana class. 
    7479  """ 
    7580  def __init__(self): 
    76     start = startup.Startup(self) 
    77     self.args = start.getArgs() 
     81    self.timing = [] 
     82    self.addCustomTime("modRana start",startTimestamp) 
     83    self.addCustomTime("imports done", importsDoneTimestamp) 
     84 
     85    # constants & variable initilization 
    7886    self.dmod = None # device specific module 
    7987    self.gui = None 
     
    8391    self.watches = {} # List of data change watches 
    8492    self.maxWatchId = 0 
    85  
    86     # start timing the launch 
    87     self.timing = [] 
    88     self.addCustomTime("modRana start",startTimestamp) 
    89     self.addCustomTime("imports done", importsDoneTimestamp) 
    90     self.addTime("GUI creation") 
    9193 
    9294    self.mapRotationAngle = 0 # in radians 
     
    103105    # options module 
    104106    self.keyModifiers = {} 
     107 
     108    # start timing modRana launch 
     109    self.addTime("GUI creation") 
     110 
     111    # add the startup handling core module 
     112    start = startup.Startup(self) 
     113    self.args = start.getArgs() 
     114 
     115    # add the paths handling core module 
     116    self.paths = paths.Paths(self) 
     117 
     118    # load persistant options 
     119    self.optLoadingOK= self._loadOptions() 
     120 
    105121    # load map layer info 
    106122    self.loadMapLayerInfo() 
     
    133149             } 
    134150 
    135  
    136     # load the device specific module 
     151    # make shortcut for the loadModule function 
     152    loadModule = self._loadModule 
     153 
     154    ## load the device specific module 
     155 
    137156    # NOTE: other modules need the device and GUI modules 
    138157    # during init 
     
    155174      # GTK GUI fallback 
    156175      GUIString = "GTK" 
    157  
    158  
    159     # get possible module names 
    160     moduleNames = self._getModuleNamesFromFolder(modulesFolder) 
    161     loadModule = self._loadModule 
    162     # load if possible 
    163     for moduleName in moduleNames: 
    164         # filter out .py 
    165         moduleName = moduleName.split('.')[0] 
    166         loadModule(moduleName, moduleName[4:]) 
    167  
     176    gs.GUIString = GUIString 
    168177    # add the GUI module folder to path 
    169178    GUIModulesPath = os.path.join(modulesFolder, "gui_modules") 
     
    173182    elif GUIString == "QML": 
    174183      gui = loadModule("gui_qml", "gui") 
    175     # make device module available to the GUI module 
     184      # make device module available to the GUI module 
    176185    if gui: 
    177186      gui.dmod = dmod 
    178187    self.gui = gui 
     188 
     189 
     190    # get possible module names 
     191    moduleNames = self._getModuleNamesFromFolder(modulesFolder) 
     192    # load if possible 
     193    for moduleName in moduleNames: 
     194        # filter out .py 
     195        moduleName = moduleName.split('.')[0] 
     196        loadModule(moduleName, moduleName[4:]) 
    179197 
    180198    print "Loaded all modules in %1.2f ms, initialising" % (1000 * (time.clock() - start)) 
     
    287305    self.reportStartupTime() 
    288306 
     307    # check if loading options failed 
     308    if self.optLoadingOK: 
     309      self.gui.notify("Loading saved options failed", 7000) 
     310 
    289311    # start the mainloop or equivalent 
    290     print "starting main loop" 
    291312    self.gui.startMainLoop() 
    292     print "main loop started" 
    293313 
    294314  def shutdown(self): 
     
    599619      self._notifyWatcher(key, oldValue) 
    600620 
     621 
     622  def _removeNonPersistentOptions(self, inputDict): 
     623    """keys that begin with # are not saved 
     624    (as they mostly contain data that is either time sensitive or is 
     625    reloaded on startup) 
     626    ASSUMPTION: keys are strings of length>=1""" 
     627    try: 
     628      return dict((k, v) for k, v in inputDict.iteritems() if k[0] != '#') 
     629    except Exception, e: 
     630      print('options: error while filtering options\nsome nonpersistent keys might have been left in\nNOTE: keys should be strings of length>=1\n', e) 
     631      return self.d 
     632 
     633  def _saveOptions(self): 
     634    print("modRana: saving options") 
     635    try: 
     636      f = open(self.paths.getOptionsFilePath(), "w") 
     637      # remove keys marked as nonpersistent 
     638      self.d['keyModifiers'] = self.keyModifiers 
     639      d = self._removeNonPersistentOptions(self.d) 
     640      marshal.dump(d, f) 
     641      f.close() 
     642      print("modRana: options successfully saved") 
     643    except IOError: 
     644      print("modRana: Can't save options") 
     645    except Exception, e: 
     646      print("modRana: saving options failed:", e) 
     647 
     648  def _loadOptions(self): 
     649    print("modRana: loading options") 
     650    succcess = False 
     651    try: 
     652      f = open(self.paths.getOptionsFilePath(), "r") 
     653      newData = marshal.load(f) 
     654      print newData 
     655      f.close() 
     656      # TODO: check out if this is needed anymore 
     657      if 'tileFolder' in newData: #TODO: do this more elegantly 
     658        del newData['tileFolder'] 
     659      if 'tracklogFolder' in newData: #TODO: do this more elegantly 
     660        del newData['tracklogFolder'] 
     661      for k,v in newData.items(): 
     662        self.set(k,v) 
     663      succcess = True 
     664    except Exception, e: 
     665      print("modRana: exception while loading saved options:\n%s" % e) 
     666      #TODO: a yes/no dialog for clearing (renaming with timestamp :) the corrupted options file (options.bin) 
     667      succcess = False 
     668 
     669    self.overrideOptions() 
     670    return succcess 
     671 
     672  def overrideOptions(self): 
     673    """ 
     674    without this, there would not be any projection values at start, 
     675    because modRana does not know, what part of the map to show 
     676    """ 
     677    self.set('centred', True) # set centering to True at start to get setView to run 
     678    self.set('editBatchMenuActive', False) 
     679 
    601680  ## PROFILE PATH ## 
    602681 
  • modules/color.py

    r30bff6f1 r7d1b4b7  
    11# -*- coding: utf-8 -*- 
     2 
     3# only import GKT libs if GTK GUI is used 
     4from core import gs 
     5if gs.GUIString == "GTK": 
     6  import gtk 
    27 
    38class Color: 
     
    914     """ 
    1015 
    11   #TODO: use colormath ? 
     16  #TODO: use palette ? 
    1217 
    1318 
  • modules/gui_modules/gui_qml/gui_qml.py

    r30bff6f1 r7d1b4b7  
    169169    # quit the application 
    170170    self.app.exit() 
     171    self.modrana.shutdown() 
    171172 
    172173  def _notify(self, text, icon=""): 
  • modules/mod_cron.py

    r30bff6f1 r7d1b4b7  
    2222from base_module import ranaModule 
    2323import threading 
     24 
     25# only import GKT libs if GTK GUI is used 
     26from core import gs 
     27if gs.GUIString == "GTK": 
     28  import gobject 
     29  ready = True 
     30else: 
     31  ready = False 
     32# TODO: add Qt support 
    2433 
    2534def getModule(m,d,i): 
     
    4756    ranaModule.__init__(self, m, d, i) 
    4857    gui = self.modrana.gui 
    49     self.ready = False 
    50     if gui: 
    51       if gui.getIDString() == "GTK": 
    52         import gobject 
    53         self.ready = True 
    54       else: 
    55         pass 
    56         # add Qt support 
    5758 
    5859    self.nextId = 0 
     
    7273  def addIdle(self, callback, args): 
    7374    """add a callback that is called once the main loop becomes idle""" 
     75    if not ready: 
     76      return 
    7477    gobject.idle_add(callback, *args) 
    7578 
     
    7780    """the callback will be called timeout + time needed to execute the callback 
    7881    and other events""" 
    79     if not self.ready: 
     82    if not ready: 
    8083      return 
    8184    id = self._getID() 
    8285    # TODO: other backends 
    8386    realId = gobject.timeout_add(timeout, self._doTimeout, id, callback, args) 
    84     timeoutTupple = (callback, args, timeout, caller, description, realId) 
     87    timeoutTuple = (callback, args, timeout, caller, description, realId) 
    8588    with self.dataLock: 
    86       self.cronTab['timeout'][id] = timeoutTupple 
     89      self.cronTab['timeout'][id] = timeoutTuple 
    8790 
    8891  def removeTimeout(self, id): 
    8992    """remove timeout with a given id""" 
    90     if not self.ready: 
     93    if not ready: 
    9194      return 
    9295    with self.dataLock: 
     
    100103  def modifyTimeout(self,id, newTimeout): 
    101104    """modify the duration of a timeout in progress""" 
    102     if not self.ready: 
     105    if not ready: 
    103106      return 
    104107    with self.dataLock: 
  • modules/mod_display.py

    r30bff6f1 r7d1b4b7  
    2222import time 
    2323 
     24# only import GKT libs if GTK GUI is used 
     25from core import gs 
     26if gs.GUIString == "GTK": 
     27  import cairo 
     28  import gtk 
     29  import pycha.line 
     30 
    2431def getModule(m,d,i): 
    2532  return(display(m,d,i)) 
     
    3138    ranaModule.__init__(self, m, d, i) 
    3239    gui = self.modrana.gui 
    33     if gui and gui.getIDString() == "GTK": 
    34       import cairo 
    35       import gtk 
    36       import pycha.line 
     40 
    3741    self.fullscreen = False 
    3842    """according to documentation on: 
  • modules/mod_icons.py

    r30bff6f1 r7d1b4b7  
    2626from configobj import ConfigObj 
    2727 
     28# only import GKT libs if GTK GUI is used 
     29from core import gs 
     30if gs.GUIString == "GTK": 
     31  import gtk 
     32  import cairo 
     33 
    2834def getModule(m,d,i): 
    2935  return(icons(m,d,i)) 
     
    3440    ranaModule.__init__(self, m, d, i) 
    3541 
    36     # only import GKT libs if GTK GUI is used 
    37     gui = self.modrana.gui 
    38     if gui and gui.getIDString() == "GTK": 
    39         import cairo 
    40         import gtk 
    41  
    4242    self.images = {} 
     43 
    4344    self.cantLoad = [] 
    4445    self.imageOrderList = [] # for cache trimming 
  • modules/mod_keys.py

    r30bff6f1 r7d1b4b7  
    2121from base_module import ranaModule 
    2222 
     23# only import GKT libs if GTK GUI is used 
     24from core import gs 
     25if gs.GUIString == "GTK": 
     26  import gtk 
     27 
     28 
    2329def getModule(m,d,i): 
    2430  return(keys(m,d,i)) 
     
    2935  def __init__(self, m, d, i): 
    3036    ranaModule.__init__(self, m, d, i) 
    31     gui = self.modrana.gui 
    32     if gui and gui.getIDString() == "GTK": 
    33       import gtk 
    3437 
    3538  def firstTime(self): 
  • modules/mod_loadTracklogs.py

    r30bff6f1 r7d1b4b7  
    8383#        # start an entry box 
    8484 
    85   def _getTFP(self): 
    86     options = self.m.get('options', None) 
    87     if options: 
    88       tracklogFolder = options.getTracklogsFolderPath() 
    89       return tracklogFolder 
    90     else: 
    91       print("loadTracklogs:no options module, can't get tracklog folder path") 
    92       return None 
    93  
    9485  def _getTFSubPath(self, subPath): 
    9586    """return a tracklog folder sub path, 
    9687    assure the patch exists before returning it""" 
    97     tracklogFolderPath = self._getTFP() 
     88    tracklogFolderPath = self.modrana.paths.getTracklogsFolderPath() 
    9889    if tracklogFolderPath == None: 
    9990      print("loadTracklogs: can't get tracklog sub path - tracklog folder path is unknown") 
     
    110101    self._getTFSubPath("online") 
    111102    self._getTFSubPath("misc") 
    112     """if there is no examplef folder, create it 
     103    """if there is no example folder, create it 
    113104    and copy example tracklogs into it""" 
    114     examplesDestinationPath = os.path.join(self._getTFP(),'examples') 
     105    tfp = self.modrana.paths.getTracklogsFolderPath() 
     106    examplesDestinationPath = os.path.join(tfp,'examples') 
    115107    if not os.path.exists(examplesDestinationPath): 
    116108      modrana_utils.createFolderPath(examplesDestinationPath) 
     
    238230    print "** making a list of available tracklogs" 
    239231 
    240     tf = self._getTFP() 
     232    tf = self.modrana.paths.getTracklogsFolderPath() 
    241233    # does the tracklog folder exist ? 
    242234    if tf == None or not os.path.exists(tf): 
     
    277269 
    278270    print("*  using this tracklog folder:") 
    279     print(self._getTFP()) 
     271    print(self.modrana.paths.getTracklogsFolderPath()) 
    280272    print("*  does it exist ?") 
    281     print(os.path.exists(self._getTFP())) 
     273    print(os.path.exists(self.modrana.paths.getTracklogsFolderPath())) 
    282274    print("*  there are %d tracklogs available" % len(availableFiles)) 
    283275    self.tracklogPathList = pathList 
     
    456448  def storeTracklog(self,tracklog,filename,cat,type,refresh="True"): 
    457449    """store tracklog and return the resulting path""" 
    458     folder = self._getTFP() 
     450    folder = self.modrana.paths.getTracklogsFolderPath() 
    459451    if folder == None: 
    460452      print("loadTracklogs: can't store tracklog - path to tracklog folder is unknown or unusable") 
  • modules/mod_log.py

    r30bff6f1 r7d1b4b7  
    5151 
    5252  def getLogFilePath(self): 
    53     options = self.m.get('options', None) 
    54     if options: 
    55       logFolderPath = options.getLogFolderPath() 
    56       """ the options module should make sure that the folder exists""" 
    57       units = self.m.get('units', None) 
    58       if units: 
    59         timeHashString = units.getTimeHashString() 
    60         fileName = 'modrana_stdout_%s.log.txt' % timeHashString 
    61         return(os.path.join(logFolderPath, fileName)) 
    62       else: 
    63         print("log: units module missing") 
    64         return None 
     53    logFolderPath = self.modrana.paths.getLogFolderPath() 
     54    """modRana should make sure that the folder exists""" 
     55    units = self.m.get('units', None) 
     56    if units: 
     57      timeHashString = units.getTimeHashString() 
     58      fileName = 'modrana_stdout_%s.log.txt' % timeHashString 
     59      return(os.path.join(logFolderPath, fileName)) 
    6560    else: 
    66       print("log: options module missing") 
     61      print("log: units module missing") 
    6762      return None 
    6863 
     
    8075        print "**log: opening stdout log file" 
    8176        self.fsock = open(self.getLogFilePath(), 'w') 
    82       print "**log: redirectiong stdout to log file:\%s" % self.currentLogPath 
     77      print "**log: redirecting stdout to log file:\%s" % self.currentLogPath 
    8378      sys.stdout = self.fsock 
    8479      print "**log: stdout redirected to (this :) log file" 
     
    9085    #do whe have a usable saved stdout ? 
    9186    if self.savedStdout: 
    92       print "**log: redirectiong stdout back" 
     87      print "**log: redirecting stdout back" 
    9388      sys.stdout = self.savedStdout 
    9489 
  • modules/mod_mapData.py

    r30bff6f1 r7d1b4b7  
    7474  def firstTime(self): 
    7575    # cache the map folder path 
    76     options = self.m.get('options', None) 
    77     if options: 
    78       self.mapFolderPath = options.getMapFolderPath() 
     76    self.mapFolderPath = self.modrana.paths.getMapFolderPath() 
    7977 
    8078  def _getTileFolderPath(self): 
  • modules/mod_mapTiles.py

    r30bff6f1 r7d1b4b7  
    3636socket.setdefaulttimeout(timeout) 
    3737 
     38# only import GKT libs if GTK GUI is used 
     39from core import gs 
     40if gs.GUIString == "GTK": 
     41  import gtk 
     42  import gobject 
     43  import cairo 
    3844 
    3945#loadImage = None 
     
    4551def getModule(m,d,i): 
    4652  return(MapTiles(m,d,i)) 
    47    
     53 
    4854class MapTiles(ranaModule): 
    4955  """Display map images""" 
    5056  def __init__(self, m, d, i): 
    5157    ranaModule.__init__(self, m, d, i) 
    52  
    53     gui = self.modrana.gui 
    54     if gui: 
    55       if gui.getIDString() == "GTK": 
    56         import gtk 
    57         import gobject 
    58         import cairo 
    59  
    60     self.images = [{},{}] # the first dict contains normal image data, the seccond contains special tiles 
     58    self.images = [{},{}] # the first dict contains normal image data, the second contains special tiles 
    6159    self.imagesLock = threading.RLock() 
    6260    self.threads = {} 
     
    6563    self.imagesTrimmingAmmount = 30 # how many tiles to remove once the maximum is reached 
    6664    self.loadRequestCStackSize = 10 # size for the circular loading request stack 
    67     """so that trim does not run always run arter adding a tile""" 
     65    """so that trim does not run always run after adding a tile""" 
    6866    self.tileSide = 256 # by default, the tiles are squares, side=256 
    69     """ TODO: analyse memmory usage, 
    70               set approrpiate value, 
    71               platform dependendt value, 
     67    """ TODO: analyse memory usage, 
     68              set appropriate value, 
     69              platform dependent value, 
    7270              user configurable 
    7371    """ 
     
    8179 
    8280    self.shutdownAllThreads = False # notify the threads that shutdown is in progress 
    83      
     81 
    8482    specialTiles = [ 
    8583                    ('tileDownloading' , 'themes/default/tile_downloading.png'), 
     
    9189 
    9290    gui = self.modrana.gui 
    93     if gui and gui.getIDString() == "GTK": 
     91    if gui.getIDString() == "GTK": 
    9492      self.loadSpecialTiles(specialTiles) # load the special tiles to the special image cache 
    9593      self.loadingTile = self.images[1]['tileLoading'] 
     
    106104    self.mapViewModule = None 
    107105 
    108     self.mapFolderPath = None 
     106    # cache the map folder path 
     107    self.mapFolderPath = self.modrana.paths.getMapFolderPath() 
     108    print "mapTiles: map folder path: %s" % self.mapFolderPath 
    109109 
    110110  def firstTime(self): 
     
    114114    self.modrana.watch('mapScale', self._updateScalingCB) 
    115115    self.modrana.watch('z', self._updateScalingCB) 
    116  
    117     # cache the map folder path 
    118     options = self.m.get('options', None) 
    119     if options: 
    120       self.mapFolderPath = options.getMapFolderPath() 
    121       print "mapTiles: map folder path: %s" % self.mapFolderPath 
    122116 
    123117  def _updateScalingCB(self, key='mapScale', oldValue=1, newValue=1): 
  • modules/mod_menu.py

    r30bff6f1 r7d1b4b7  
    2525import modrana_utils 
    2626 
     27# only import GKT libs if GTK GUI is used 
     28from core import gs 
     29if gs.GUIString == "GTK": 
     30  import gtk 
     31  import pango 
     32  import pangocairo 
     33 
    2734def getModule(m,d,i): 
    2835  return(menus(m,d,i)) 
     
    3239  def __init__(self, m, d, i): 
    3340    ranaModule.__init__(self, m, d, i) 
    34  
    35     # only import GKT libs if GTK GUI is used 
    36     gui = self.modrana.gui 
    37     if gui and gui.getIDString() == "GTK": 
    38       import pango 
    39       import pangocairo 
    40       import gtk 
    41  
    4241    self.menus = {} 
    4342    self.lists = {} 
  • modules/mod_options.py

    r30bff6f1 r7d1b4b7  
    2121from base_module import ranaModule 
    2222import marshal 
    23 import os 
    2423import modrana_utils 
    2524 
     
    4039    modrana_utils.createFolderPath(self.profileFolderPath) 
    4140 
    42     # load persistant options 
    43     self.load() 
     41    # load persistent options 
     42#    self.load() 
    4443    self.on = '<span color="green">ON</span>' 
    4544    self.off = '<span color="red">OFF</span>' 
     
    5049    # item tools special menu name 
    5150    self.keyStateListGroupID = None 
    52  
    53   def getProfilePath(self): 
    54     """return path to the profile folder""" 
    55     # check if the path exists and create it if not 
    56     modrana_utils.createFolderPath(self.profileFolderPath) 
    57     return self.profileFolderPath 
    58  
    59   def getOptionsFilePath(self): 
    60     """return path to the options store filename""" 
    61     return os.path.join(self.getProfilePath(),"options.bin") 
    62  
    63   def getCacheFolderPath(self): 
    64     """return path to a folder used for various cache data""" 
    65     return self._assurePathFolder(self.getProfilePath(), "cache") 
    66  
    67   def getTracklogsFolderPath(self): 
    68     """return path to a folder for storing tracklogs""" 
    69     path = None 
    70     # first check if the user overrode the tracklog folder path 
    71     config = self.m.get('config', None) 
    72     if config: 
    73       path = config.getTracklogFolderPath() 
    74     if path == None: 
    75     # try to get the path from device module 
    76       if self.dmod: 
    77         path = self.dmod.getTracklogFolderPath() 
    78  
    79     if path == None: # this means there is no config or device path 
    80       # use default path & assure it exists 
    81       return self._assurePathFolder(self.getProfilePath(), "tracklogs") 
    82     else: 
    83       return self._assurePath(path) 
    84  
    85   def getMapFolderPath(self): 
    86     """return a path to folder for map data storage""" 
    87     path = None 
    88     # first check if the user overrode the map folder path 
    89     config = self.m.get('config', None) 
    90     if config: 
    91       path = config.getMapFolderPath() 
    92     if path == None: 
    93     # try to get the path from device module 
    94       if self.dmod: 
    95         path = self.dmod.getMapFolderPath() 
    96  
    97     if path == None: # this means there is no config or device path 
    98       # use default path & assure it exists 
    99       return self._assurePathFolder(self.getProfilePath(), "maps") 
    100     else: 
    101       return self._assurePath(path) 
    102  
    103   def getPOIFolderPath(self): 
    104     """return path to the POI folder""" 
    105     if self.dmod: 
    106       path = self.dmod.getPOIFolderPath() 
    107       if path != None: # None means there is no device dependent path 
    108         return self._assurePath(path) 
    109       else: 
    110         return self._assurePathFolder(self.getProfilePath(), "poi") 
    111     else: 
    112       return self._assurePathFolder(self.getProfilePath(), "poi") 
    113  
    114   def getPOIDatabasePath(self): 
    115     """return path to the POI database file""" 
    116     POIDBFilename = self.get('POIDBFilename', 'modrana_poi.db') 
    117     POIFolderPath = self.getPOIFolderPath() 
    118     return os.path.join(POIFolderPath,POIDBFilename) 
    119  
    120   def getLogFolderPath(self): 
    121     """return path to the POI folder""" 
    122     if self.dmod: 
    123       path = self.dmod.getLogFolderPath() 
    124       if path != None: # None means there is no device dependent path 
    125         return self._assurePath(path) 
    126       else: 
    127         return self._assurePathFolder(self.getProfilePath(), "debug_logs") 
    128     else: 
    129       return self._assurePathFolder(self.getProfilePath(), "debug_logs") 
    130    
    131   def _assurePathFolder(self, path, folder): 
    132     """combine the given path and folder and make sure the path exists, 
    133     return the resulting path""" 
    134     path = os.path.join(path, folder) 
    135     return self._assurePath(path) 
    136  
    137   def _assurePath(self, path): 
    138     """assure path exists and return it back""" 
    139     # check if the path exists and create it if not 
    140     modrana_utils.createFolderPath(path) 
    141     return path 
    14251 
    14352  def _getCategoryID(self, id): 
     
    932841      self.addRawOption(optionD) 
    933842 
    934   def save(self): 
    935     print "options: saving options" 
    936     try: 
    937       f = open(self.getOptionsFilePath(), "w") 
    938       # remove keys marked as nonpersistent 
    939       self.d['keyModifiers'] = self.modrana.keyModifiers 
    940       d = self._removeNonPersistent(self.d) 
    941       marshal.dump(d, f) 
    942       f.close() 
    943       print "options: successfully saved" 
    944     except IOError: 
    945       print "Can't save options" 
    946  
    947   def load(self): 
    948     try: 
    949       f = open(self.getOptionsFilePath(), "r") 
    950       newData = marshal.load(f) 
    951       f.close() 
    952       if 'tileFolder' in newData: #TODO: do this more elegantly 
    953         del newData['tileFolder'] 
    954       if 'tracklogFolder' in newData: #TODO: do this more elegantly 
    955         del newData['tracklogFolder'] 
    956       for k,v in newData.items(): 
    957         self.set(k,v) 
    958     except Exception, e: 
    959       print "options: exception while loading saved options:\n%s" % e 
    960       #TODO: a yes/no dialog for clearing (renaming with timestamp :) the corrupted options file (options.bin) 
    961       self.sendMessage('ml:notification:m:Loading saved options failed;7') 
    962  
    963     self.overrideOptions() 
    964  
    965   def overrideOptions(self): 
    966     """ 
    967     without this, there would not be any projection values at start, 
    968     because modRana does not know, what part of the map to show 
    969     """ 
    970     self.set('centred', True) # set centering to True at start to get setView to run 
    971     self.set('editBatchMenuActive', False) 
    972  
    973    
    974843  def handleMessage(self, message, type, args): 
    975844    if type=="ml" and message=="scroll": 
     
    984853        self.options[menuName][1] = newIndex 
    985854    elif(message == "save"): 
    986       self.save() 
     855      self.modrana._saveOptions() 
    987856 
    988857    elif type == 'ml' and message == "go2ItemToolsMenu": 
     
    12611130          self.menuModule.showText(cr, "%d/%d" % (index+1, numItems), indexX, y+dy*0.07, w * 0.10 - border, 20) 
    12621131 
    1263 #  def checkProfilePath(self): 
    1264 #    """check if the profile folder exists, try to create it if not""" 
    1265 #    if os.path.exists(self.getProfilePath()): 
    1266 #      return True 
    1267 #    else: 
    1268 #      try: 
    1269 #        os.makedirs(self.profileFolderPath) 
    1270 #        print "creating profile folder in: %s" % self.profileFolderPath 
    1271 #        return True 
    1272 #      except Exception, e: 
    1273 #        print "options:Creating profile folder in path: %s failed:\n%s" % (self.profileFolderPath, e) 
    1274 #        return False 
    1275  
    1276   def shutdown(self): 
    1277     """save the dictionary on exit""" 
    1278     self.save() 
    1279  
    12801132if(__name__ == "__main__"): 
    12811133  a = options({},{'viewport':(0,0,600,800)}) 
  • modules/mod_routeProfile.py

    r30bff6f1 r7d1b4b7  
    2121from base_module import ranaModule 
    2222import geo 
     23# only import GKT libs if GTK GUI is used 
     24from core import gs 
     25if gs.GUIString == "GTK": 
     26  import cairo 
     27  import pycha.line 
     28  import pycha.color 
    2329 
    2430def getModule(m,d,i): 
     
    3036  def __init__(self, m, d, i): 
    3137    ranaModule.__init__(self, m, d, i) 
    32     gui = self.modrana.gui 
    33     if gui and gui.getIDString() == "GTK": 
    34       import cairo 
    35       import pycha.line 
    36       import pycha.color 
    3738 
    3839  def drawMenu(self, cr, menuName, args=None): 
  • modules/mod_showGPX.py

    r30bff6f1 r7d1b4b7  
    2525import math 
    2626from time import clock 
     27# only import GKT libs if GTK GUI is used 
     28from core import gs 
     29if gs.GUIString == "GTK": 
     30  import gtk 
    2731 
    2832def getModule(m,d,i): 
     
    3438  def __init__(self, m, d, i): 
    3539    ranaModule.__init__(self, m, d, i) 
    36  
    37     # only import GKT libs if GTK GUI is used 
    38     gui = self.modrana.gui 
    39     if gui and gui.getIDString() == "GTK": 
    40       import gtk 
    4140 
    4241    self.linewidth = 7 #with of the line denoting GPX tracks 
  • modules/mod_showOSD.py

    r30bff6f1 r7d1b4b7  
    2222import time 
    2323import geo 
     24# only import GKT libs if GTK GUI is used 
     25from core import gs 
     26if gs.GUIString == "GTK": 
     27  import cairo 
     28  import gtk 
     29  import pycha.line 
    2430 
    2531def getModule(m,d,i): 
     
    3137  def __init__(self, m, d, i): 
    3238    ranaModule.__init__(self, m, d, i) 
    33     gui = self.modrana.gui 
    34     if gui and gui.getIDString() == "GTK": 
    35       import cairo 
    36       import gtk 
    37       import pycha.line 
    38  
    3939    self.items = None 
    4040    self.routeProfileData = None 
  • modules/mod_sketch.py

    r30bff6f1 r7d1b4b7  
    2121from base_module import ranaModule 
    2222from time import time 
     23# only import GKT libs if GTK GUI is used 
     24from core import gs 
     25if gs.GUIString == "GTK": 
     26  import cairo 
    2327 
    2428def getModule(m,d,i): 
     
    2933  def __init__(self, m, d, i): 
    3034    ranaModule.__init__(self, m, d, i) 
    31     gui = self.modrana.gui 
    32     if gui and gui.getIDString() == "GTK": 
    33       import cairo 
    34  
    3535    self.points = [] 
    3636 
  • modules/mod_storePOI.py

    r30bff6f1 r7d1b4b7  
    4848    options = self.m.get('options', None) 
    4949    if options: 
    50       DBPath = options.getPOIDatabasePath() 
     50      DBPath = self.modrana.paths.getPOIDatabasePath() 
    5151      if os.path.exists(DBPath): # connect to db 
    5252        try: 
  • modules/mod_storeTiles.py

    rbf837e8 r7d1b4b7  
    6767  def firstTime(self): 
    6868    # the config folder should set the tile folder path by now 
    69     options = self.m.get('options', None) 
    70     if options: 
    71       self.tileFolder = options.getMapFolderPath() 
     69    self.tileFolder = self.modrana.paths.getMapFolderPath() 
    7270    # testing: 
    7371    #self.test() 
  • modules/mod_textEntry.py

    r30bff6f1 r7d1b4b7  
    2121from base_module import ranaModule 
    2222 
     23# only import GKT libs if GTK GUI is used 
     24from core import gs 
     25if gs.GUIString == "GTK": 
     26  import gtk 
     27 
    2328def getModule(m,d,i): 
    2429  return(textEntry(m,d,i)) 
     
    2934  def __init__(self, m, d, i): 
    3035    ranaModule.__init__(self, m, d, i) 
    31     gui = self.modrana.gui 
    32     if gui and gui.getIDString() == "GTK": 
    33       import gtk 
    3436    self.entryBoxVisible = False 
    3537     
  • modules/mod_turnByTurn.py

    r30bff6f1 r7d1b4b7  
    2323import math 
    2424import time 
     25# only import GKT libs if GTK GUI is used 
     26from core import gs 
     27if gs.GUIString == "GTK": 
     28  import pango 
     29  import pangocairo 
    2530 
    2631def getModule(m,d,i): 
     
    3338    ranaModule.__init__(self, m, d, i) 
    3439    gui = self.modrana.gui 
    35     if gui and gui.getIDString() == "GTK": 
    36       import pango 
    37       import pangocairo 
    38  
    3940    # initial colors 
    4041    self.navigationBoxBackground = (0,0,1,0.3) # very transparent blue 
Note: See TracChangeset for help on using the changeset viewer.