Changeset ec56a8a


Ignore:
Timestamp:
07/21/10 16:26:59 (4 years ago)
Author:
xkolman2 <xkolman2@…>
Branches:
master
Children:
6aa3ea3
Parents:
5494918
git-author:
xkolman2 <xkolman2@…> (07/21/10 16:26:59)
git-committer:
xkolman2 <xkolman2@…> (07/21/10 16:26:59)
Message:

replace active tracklog index by active tracklog path variable
-> fix the mess resulting from inconsistent indexes
make all modules load the tracklogs throught a method, not directly
-> safer, more transparent

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

Files:
7 added
2 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • modules/mod_loadTracklogs.py

    r3c4c9cf rec56a8a  
    5959    if message == 'loadActive': 
    6060      # load the active tracklog 
    61       index = int(self.get('activeTracklog', None)) 
    62       if index != None and self.tracklogList: 
    63         activeTracklog = self.tracklogList[index] 
    64         filename = activeTracklog['filename'] 
    65         path = activeTracklog['path'] 
    66         print "loading tracklog: %s" % filename 
     61      path = self.get('activeTracklogPath', None) 
     62      if path != None and self.tracklogList: 
     63        print "loading tracklog: %s" % path 
    6764 
    6865        # Zeroeth, is the tracklog already loaded ? 
     
    107104  def cleanCache(self): 
    108105    """remove files that are not present from the cache""" 
    109     paths = [x['path'] for x in self.tracklogList] 
     106    paths = self.tracklogPathList 
    110107    garbage = filter(lambda x: x not in paths, self.cache) 
    111108    print garbage 
     
    116113  def deleteTrackFromCache(self, file): 
    117114    # self explanatory 
    118     del self.cache[file] 
     115    if file in self.cache: 
     116      del self.cache[file] 
    119117 
    120118  def getActiveTracklog(self): 
    121119    path = self.getActiveTracklogPath() 
     120    # is the tracklog loaded ? 
     121    if path not in self.tracklogs.keys(): 
     122      self.loadTracklog(path) 
     123      self.save() 
    122124    return self.tracklogs[path] 
    123125# 
     
    145147 
    146148  def getActiveTracklogPath(self): 
    147     index = int(self.get('activeTracklog', 0)) 
    148     path = self.tracklogList[index]['path'] 
     149    path = self.get('activeTracklogPath', None) 
    149150    return path 
    150151 
    151152  def setTracklogPathCathegory(self,path,cathegory): 
     153    """set a cathegory for tracklog identified by path""" 
     154    # does the path/tracklog exist ? 
     155    if path not in self.tracklogPathList: 
     156      # we try to reload the tracklog list 
     157      self.listAvailableTracklogs() 
     158      if path not in self.tracklogPathList: 
     159        return # tracklog does not exist, so we return 
     160 
     161    # tracklog exists so we can set its cathegory 
    152162    catData = self.get('tracklogPathCathegory', {}) 
    153163    catData[path] = cathegory 
     
    268278#  def saveClusters(self, clusters): 
    269279 
     280  def setPathAsActiveTracklog(self): 
     281    pass 
     282 
    270283  def loadPathList(self, pathList): 
    271284    print "loading path list" 
     
    294307    start = clock() 
    295308    self.filename = path 
    296     file = open(path, 'r') 
     309 
     310    file = None 
     311 
     312    try: 
     313      file = open(path, 'r') 
     314    except: 
     315      print "loading tracklo failed: %s" % path 
    297316 
    298317    if notify: 
     
    312331      self.sendMessage('notification:loaded in %1.2f ms' % (1000 * (clock() - start))) 
    313332 
    314   def storeRoute(self, route, name=""): 
     333  def storeRouteAndSetActive(self, route, name='', cat='misc'): 
     334    path = self.storeRoute(route, name, cat) 
     335    self.set('activeTracklogPath', path) 
     336 
     337  def storeRoute(self, route, name="", cat='misc'): 
    315338    """store a route, found by Google Directions to a GPX file, then load this file to tracklogs list""" 
    316339    newTracklog = gpx.Trackpoints() 
     
    329352     
    330353    self.listAvailableTracklogs() 
    331     self.setTracklogPathCathegory(path, 'online') 
    332     index = self.tracklogPathList.index(path) 
    333     self.set('activeTracklog', index) 
     354    self.setTracklogPathCathegory(path, cat) 
     355    return path 
    334356    # TODO: incremental addition of new tracklogs 
    335357 
  • modules/mod_mapData.py

    r3c4c9cf rec56a8a  
    713713 
    714714      def describeTracklog(index, category, tracks): 
    715  
     715        """describe a tracklog list item""" 
    716716        track = tracks[index] 
    717717 
    718         action = "set:activeTracklog:%d|loadTracklogs:loadActive" % index 
     718        action = "set:activeTracklogPath:%s|loadTracklogs:loadActive" % track['path'] 
    719719 
    720720        status = self.get('editBatchMenuActive', False) 
  • modules/mod_notification.py

    rde0de9b rec56a8a  
    3434    self.expirationTimestamp = time.time() 
    3535    self.draw = False 
     36    self.redrawn = None 
    3637 
    3738     
     
    5758        print "notification: wrong timeout, using default 5 secconds" 
    5859    self.expirationTimestamp = time.time() + timeout 
     60    self.set('needRedraw', True) # make sure the notification is displayed 
    5961 
    6062 
  • modules/mod_options.py

    rde0de9b rec56a8a  
    186186 
    187187  def save(self): 
     188    print "saving options" 
    188189    try: 
    189190      f = open(self.optionsFilename(), "w") 
    190191      marshal.dump(self.d, f) 
    191192      f.close() 
     193      print "success" 
    192194    except IOError: 
    193195      print "Can't save options" 
  • modules/mod_route.py

    rfcdb171 rec56a8a  
    198198        return 
    199199 
    200       loadTracklogs.storeRoute(self.route) # TODO: rewrite this when we support more routing providers 
    201  
    202       length = len(loadTracklogs.tracklogs) 
    203       self.set('activeTracklog', "%d" % (length-1)) # jump to the new tracklog 
     200      loadTracklogs.storeRouteAndSetActive(self.route, '', 'online') # TODO: rewrite this when we support more routing providers 
    204201 
    205202 
     
    630627 
    631628      menus.clearMenu('currentRouteTools', "set:menu:currentRoute") 
    632       menus.addItem('currentRouteTools', 'tracklog#save as', 'generic', 'route:storeRoute|set:menu:tracklogInfo') 
     629      menus.addItem('currentRouteTools', 'tracklog#save as', 'generic', 'route:storeRoute|set:currentTracCat:online|set:menu:tracklogInfo') 
    633630 
    634631    if menuName == "showAdressRoute": 
  • modules/mod_routeProfile.py

    rde0de9b rec56a8a  
    6464    menus = self.m.get("menu",None) 
    6565    loadTl = self.m.get('loadTracklogs', None) # get the tracklog module 
    66 #    loadedTracklogs = loadTl.tracklogs # get list of all tracklogs 
    67     #tracklistsWithElevation = filter(lambda x: x.elevation == True, loadedTracklogs) 
    68 #    activeTracklogIndex = int(self.get('activeTracklog', 0)) 
    69     tracklog = loadTl.tracklogs[loadTl.getActiveTracklogPath()] 
     66    tracklog = loadTl.getActiveTracklog() 
    7067    if tracklog.elevation == True: 
    7168      self.lineChart(cr, tracklog, 0, 0, w, h) 
  • modules/mod_search.py

    r6e47c2e rec56a8a  
    261261    action = "set:menu:searchResultsItem" 
    262262    action += "|set:searchResultsItemNr:%d" % list[index][2] # here we use the ABSOLUTE index, not the relative one 
    263 #    action += "|set:activeTracklog:%d|set:menu:tracklogInfo" % list['responseData']['results'][item]['titleNoFormatting'] 
    264263#    action += "|set:menu:" 
    265264#    name = item.getTracklogName().split('/').pop() 
  • modules/mod_showGPX.py

    r0f17f26 rec56a8a  
    7878#    cr.fill() 
    7979 
    80     visibleTracklogs = self.get('visibleTracklogs', set()) 
     80    visibleTracklogs = set(self.get('visibleTracklogs', set())) 
    8181    loadTl = self.m.get('loadTracklogs', None) # get the tracklog module 
    8282    loadedTracklogs = loadTl.tracklogs # get list of all loaded tracklogs 
     
    119119       
    120120      # from the persistent list 
    121       visibleTracklogs = self.get('visibleTracklogs', set()) 
    122       visibleTracklogs = filter(lambda x: x not in nonexistent, visibleTracklogs) 
     121      visibleTracklogs = set(self.get('visibleTracklogs', set())) 
     122      visibleTracklogs = set(filter(lambda x: x not in nonexistent, visibleTracklogs)) 
    123123      self.set('visibleTracklogs', visibleTracklogs) 
    124124 
  • modules/mod_showOSD.py

    r6692625 rec56a8a  
    108108      units = self.m.get('units', None) # get the unit conversion module 
    109109      avgSpeedMPS = units.currentSpeedUnitToMS(avgSpeed) 
    110       currentLength = (self.routeProfileData[self.nearestIndex][0])*1000 # rem. length in meters 
    111       timeString = self.timeString(currentLength/avgSpeedMPS) 
     110      currentLength = (self.routeProfileData[self.nearestIndex][0])*1000.0 # rem. length in meters 
     111      if avgSpeedMPS == 0 or avgSpeedMPS == 0.0: 
     112        timeString = "start moving" 
     113      else: 
     114        timeString = self.timeString(currentLength/avgSpeedMPS) 
    112115      text = 'to start:|%s h:m' % timeString 
    113116      self.drawMultilineTextWidget(cr, item, text) 
     
    126129      currentLength = self.routeProfileData[self.nearestIndex][0] 
    127130      remainingLength = (self.routeProfileData[-1][0] - currentLength)*1000 # rem. length in meters 
    128       timeString = self.timeString(remainingLength/avgSpeedMPS) 
     131      if avgSpeedMPS == 0 or avgSpeedMPS == 0.0: 
     132        timeString = "start moving" 
     133      else: 
     134        timeString = self.timeString(remainingLength/avgSpeedMPS) 
    129135      text = 'to destination|%s h:m' % timeString 
    130136      self.drawMultilineTextWidget(cr, item, text) 
     
    244250    """draw a dynamic route profile as a part of the osd""" 
    245251    if self.routeProfileData == None: 
    246       text = "activate a trackglog|to show route profile" 
     252      text = "activate a tracklog|to show route profile" 
    247253      item['font_size'] = 20 
    248254      self.drawMultilineTextWidget(cr, item, text) 
  • modules/mod_tracklog.py

    r5494918 rec56a8a  
    7474        print "resuming the logging" 
    7575        self.loggingPaused = False 
     76      self.set('needRedraw', True) 
    7677 
    7778    elif message == "pauseLogging": 
     
    7980      self.saveLogIncrement() 
    8081      self.loggingPaused = True 
     82      self.set('needRedraw', True) 
    8183 
    8284    elif message == "stopLogging": 
    8385      print "stopping the logging" 
    8486      self.stopLogging() 
     87      self.set('needRedraw', True) 
    8588       
    8689    elif message == "setNewLoggingInterval": 
    8790      print "setting new log interval" 
    8891      self.logInterval=int(self.get('tracklogLogInterval', 1)) 
     92      self.set('needRedraw', True) 
    8993 
    9094    elif message == "setNewSavingInterval": 
    9195      print "setting new save interval" 
    9296      self.saveInterval=int(self.get('tracklogSaveInterval', 10)) 
     97      self.set('needRedraw', True) 
    9398 
    9499    elif(message == 'nameInput'): 
     
    101106        entryText = logNameEntry 
    102107      entry.entryBox(self ,'logNameEntry','Write tracklog name',entryText) 
     108      self.set('needRedraw', True) 
    103109#      self.expectTextEntry = 'start' 
    104110 
     
    150156        self.saveLogIncrement() 
    151157        self.lastSavedTimestamp = currentTimestamp 
     158        self.set('needRedraw', True) 
    152159 
    153160  def initLog(self,type='gpx',name=None): 
     
    215222      if loadTl: 
    216223        # we also set the correct cathegory ('log') 
     224        print path 
    217225        loadTl.setTracklogPathCathegory(path, 'log') 
    218         # refresh the list of available tracklogs 
    219         # the list also includes info abotut the category 
    220         # therefore we set the cathegory first 
    221         loadTl.listAvailableTracklogs() 
     226        # this procedure autorefreshes the list 
    222227 
    223228 
     
    433438        text+= "||distance traveled %s" % distanceString 
    434439 
    435       box = (text , "set:menu:showPOIDetail") 
     440      box = (text , "set:menu:tracklog") 
    436441      menus.drawSixPlusOneMenu(cr, menuName, parent, fiveButtons, box) 
    437442 
  • modules/mod_tracklogManager.py

    ra6d3456 rec56a8a  
    6666      print "getting elevation info" 
    6767      online = self.m.get("onlineServices",None) 
    68 #      loadTl = self.m.get('loadTracklogs', None) # get the tracklog module 
    69 #      loadedTracklogs = loadTl.tracklogs # get list of all tracklogs 
    70 #      index = int(self.get('activeTracklog', 0)) # get the active tracklog 
    71       activeTracklog = self.getActiveTracklog() 
     68      activeTracklog = self.LTModule.getActiveTracklog() 
    7269      # generate a list of (lat,lon) tupples 
    7370      latLonList = map(lambda x: (x.latitude,x.longitude), activeTracklog.trackpointsList[0]) 
     
    8784#      loadedTracklogs = loadTl.tracklogs 
    8885#      track = filter(lambda x: x.tracklogFilename == filename, loadedTracklogs).pop() 
    89       track = self.getActiveTracklog() 
     86      track = self.LTModule.getActiveTracklog() 
    9087      self.m.get('showOSD', None).routeProfileData = track.perElevList 
    9188 
     
    105102      if path: 
    106103        self.deleteTracklog(path) 
    107         self.set('activeTracklog', None) 
     104        self.set('activeTracklogPath', None) 
    108105 
    109106    elif message == 'setActiveTracklogToCurrentCat': 
     
    240237    elif menuName == 'tracklogInfo': 
    241238      menus = self.m.get("menu",None) 
    242       track = self.getActiveTracklog() 
     239      track = self.LTModule.getActiveTracklog() 
    243240      profile = self.m.get('routeProfile', None) 
    244241 
     
    284281 
    285282 
    286 #      online = self.m.get('onlineServices', None) 
    287 #      online.getGmapsInstance() 
    288  
    289  
    290   def getActiveTracklog(self): 
    291     path = self.LTModule.getActiveTracklogPath() 
    292     if path not in self.LTModule.tracklogs: 
    293       self.LTModule.loadTracklog(path) 
    294       self.LTModule.save() 
    295     return self.LTModule.tracklogs[path] 
    296  
    297  
    298283  def describeTracklog(self, item, category): 
    299284    # describe a tracklog item 
    300285    action = "" 
    301     action += "set:activeTracklog:%s|loadTracklogs:loadActive|set:menu:tracklogInfo" % item['index'] 
    302 #    action += "|set:menu:poi" 
     286    action += "set:activeTracklogPath:%s|loadTracklogs:loadActive|set:menu:tracklogInfo" % item['path'] 
    303287    name = item['filename'] 
    304288    description = 'type: ' + item['type'] + '   size:' + item['size'] + '   last modified:' + item['lastModified'] 
  • user_config.conf

    r2339b92 rec56a8a  
    126126## a widget showing route profile/elevation graph 
    127127## to show this in the OSD, ju must set a tracklog active 
    128 ## tracklog-> select trackglog -> set active 
     128## tracklog-> select tracklog -> set active 
    129129[[[route_profile]]]  
    130130px=0.67 
Note: See TracChangeset for help on using the changeset viewer.