Changeset 918171b
- Timestamp:
- 04/15/12 20:50:07 (14 months ago)
- Branches:
- master
- Children:
- c484fad
- Parents:
- 11ef0cd
- git-author:
- Martin Kolman <martin.kolman@…> (04/15/12 20:50:07)
- git-committer:
- Martin Kolman <martin.kolman@…> (04/15/12 20:50:07)
- File:
-
- 1 edited
-
modrana.py (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
modrana.py
r7f6b0e4 r918171b 2 2 # -*- coding: utf-8 -*- 3 3 #---------------------------------------------------------------------------- 4 # Rana main GUI. Displays maps, for use on a mobile device4 # modRana main GUI. Displays maps & much more, for use on a mobile device. 5 5 # 6 6 # Controls: 7 # * click on the overlay text to change fields displayed7 # Start by clicking on the main menu icon. 8 8 #---------------------------------------------------------------------------- 9 9 # Copyright 2007-2008, Oliver White … … 52 52 def createFolderPath(newPath): 53 53 """ 54 Creat a path for a directory and all needed parent forlders55 -> parent director yies will be created54 Create a path for a directory and all needed parent forlders 55 -> parent directories will be created 56 56 -> if directory already exists, then do nothing 57 -> if there is another fil system object (like a file) with the same name, raise an exception57 -> if there is another filesystem object (like a file) with the same name, raise an exception 58 58 """ 59 59 if not newPath: … … 89 89 self.addCustomTime("imports done", importsDoneTimestamp) 90 90 91 # constants & variable initi lization91 # constants & variable initialization 92 92 self.dmod = None # device specific module 93 93 self.gui = None 94 94 95 self.d = {} # persist ant dictionary of data95 self.d = {} # persistent dictionary of data 96 96 self.m = {} # dictionary of loaded modules 97 97 self.watches = {} # List of data change watches … … 124 124 self.configs = configs.Configs(self) 125 125 126 # load persist ant options126 # load persistent options 127 127 self.optLoadingOK= self._loadOptions() 128 128 … … 158 158 """Load all modules from the specified directory""" 159 159 160 # get the devic me module string160 # get the device module string 161 161 # (a unique device module string identificator) 162 162 # make sure there is some argument provided … … 245 245 246 246 # add last timing checkpoint 247 self.addTime("all modules initi laized")247 self.addTime("all modules initialized") 248 248 249 249 def _getModuleNamesFromFolder(self,folder): … … 275 275 """to only update values needed for map drawing when something changes 276 276 * window is resized 277 * user switches something rel eated in options277 * user switches something related in options 278 278 * etc. 279 279 we use the key watching mechanism … … 350 350 self._saveOptions() 351 351 time.sleep(2) # leave some times for threads to shut down 352 print("Shut tdown complete")352 print("Shutdown complete") 353 353 354 354 ## OPTIONS SETTING AND WATCHING ## … … 365 365 # get the dictionary with per mode values 366 366 multiDict = self.d.get('%s#multi' % name , {}) 367 # ret run the value for current mode367 # return the value for current mode 368 368 return multiDict.get(mode,default) 369 369 else: … … 391 391 except KeyError: # key not yet created 392 392 self.d['%s#multi' % name] = {mode : value} 393 else: # just save to the key as usual l393 else: # just save to the key as usual 394 394 self.d[name] = value 395 else: # just save to the key as usual l395 else: # just save to the key as usual 396 396 self.d[name] = value 397 397 … … 399 399 """options are normally saved on shutdown, 400 400 but for some data we want to make sure they are stored and not 401 los for example bec uase of power outage/empty battery, etc."""401 los for example because of power outage/empty battery, etc.""" 402 402 if save: 403 403 options = self.m.get('options') … … 410 410 411 411 def purgeKey(self, key): 412 """remove a key from the p resistant dictionary,412 """remove a key from the persistent dictionary, 413 413 including possible key modifiers and alternate values""" 414 414 if key in self.d: … … 426 426 return True 427 427 else: 428 print("modrana: can't purge a not present key: %s" % key)428 print("modrana: can't purge a not-present key: %s" % key) 429 429 430 430 def watch(self, key, callback, *args): … … 456 456 """run callbacks registered on an options key 457 457 HOW IT WORKS 458 * the watcher is notified before the key is written to the persist ant458 * the watcher is notified before the key is written to the persistent 459 459 dictionary, so that it can react before the change is visible 460 460 * the watcher gets the key and both the new and old values … … 478 478 dependent on the current mode""" 479 479 options = self.m.get('options', None) 480 # reme ber the old value, if not se use default from options480 # remember the old value, if not se use default from options 481 481 # if available 482 482 if options: … … 523 523 # get the previous value 524 524 options = self.m.get('options', None) 525 # reme ber the old value, if not se use default from options525 # remember the old value, if not se use default from options 526 526 # if available 527 527 if options: … … 605 605 elif shiftDirection == "right": 606 606 x = + sw * 0.5 * floatShiftAmount 607 """ we don t need to do anything if direction is set to don't shift (False)607 """ we don't need to do anything if direction is set to don't shift (False) 608 608 - 0,0 will be used """ 609 609 self.centerShift = (x,y) … … 617 617 (centerX,centerY) = ((sw/2.0),(sh/2.0)) 618 618 ulCenterDistance = simplePythagoreanDistance(0, 0, centerX, centerY) 619 centerLL distance = simplePythagoreanDistance(centerX, centerY, sw, sh)620 diagonal = max(ulCenterDistance, centerLL distance)619 centerLLDistance = simplePythagoreanDistance(centerX, centerY, sw, sh) 620 diagonal = max(ulCenterDistance, centerLLDistance) 621 621 add = int(math.ceil(float(diagonal)/tileSide)) 622 622 self.expandViewportTiles = add … … 635 635 # try to get some value if the old value is not available 636 636 options = self.m.get('options', None) 637 # reme ber the old value, if not se use default from options637 # remember the old value, if not se use default from options 638 638 # if available 639 639 if options: … … 674 674 def _loadOptions(self): 675 675 print("modRana: loading options") 676 succ cess = False676 success = False 677 677 try: 678 678 f = open(self.paths.getOptionsFilePath(), "r") … … 686 686 for k,v in newData.items(): 687 687 self.set(k,v) 688 succ cess = True688 success = True 689 689 except Exception, e: 690 690 print("modRana: exception while loading saved options:\n%s" % e) 691 691 #TODO: a yes/no dialog for clearing (renaming with timestamp :) the corrupted options file (options.bin) 692 succ cess = False692 success = False 693 693 694 694 self.overrideOptions() 695 return succ cess695 return success 696 696 697 697 def overrideOptions(self):
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/trac/gps_navigace/chrome/site/nlp-logo.png)