def add_path(self, path): "Adds path to recent documents" recent = self.read_paths() # Make the path absolute, resolving any symlinks. path = self._resolved_if_possible(Path(path)) # Remove the existing occurrence of path, if present. # A linear scan is acceptable here because the list will always # be very short try: recent.remove(path) except ValueError: # path is not currently in recent pass # Prepend the path recent.insert(0, str(path)) # Limit to MAX_RECENT_DOCS recent = recent[:self.MAX_RECENT_DOCS] debug_print('Writing {0} recent document paths'.format(len(recent))) settings = QSettings() settings.beginWriteArray(self.KEY, len(recent)) try: for index, path in enumerate(recent): settings.setArrayIndex(index) settings.setValue('path', str(path)) finally: settings.endArray()
def run(self): settings = QSettings('Khertan Software', 'Khweeteur') statuses = [] logging.debug("Thread for '%s' running" % self.call) try: since = settings.value(self.account.token_key + '_' + self.call) logging.debug('%s running' % self.call) if self.call == 'HomeTimeline': statuses = self.account.api.GetHomeTimeline(since_id=since) elif self.call == 'Mentions': statuses = self.account.api.GetMentions(since_id=since) elif self.call == 'DMs': statuses = self.account.api.GetDirectMessages(since_id=since) elif self.call.startswith('Search:'): statuses = self.account.api.GetSearch(since_id=since, term=self.call.split(':', 1)[1]) elif self.call == 'RetrieveLists': # Get the list subscriptions lists = self.account.api.GetSubscriptions( user=self.account.me_user) settings.beginWriteArray('lists') for (index, list_instance) in enumerate(lists): settings.setArrayIndex(index) settings.setValue('id', list_instance.id) settings.setValue('user', list_instance.user.screen_name) settings.setValue('name', list_instance.name) settings.endArray() # Get the status of list settings.sync() elif self.call.startswith('List:'): user, id = self.call.split(':', 2)[1:] statuses = self.account.api.GetListStatuses( user=user, id=id, since_id=since) #Near GPS elif self.call.startswith('Near:'): geocode = self.call.split(':', 2)[1:] + ['1km'] logging.debug('geocode=(%s)', str(geocode)) statuses = self.account.api.GetSearch( since_id=since, term='', geocode=geocode) else: logging.error('Unknown call: %s' % (self.call, )) success = True except Exception, err: success = False logging.debug('Retriever %s: %s' % (self.call, str(err))) if settings.value('ShowInfos') == '2': self.error.emit('Khweeteur Error : %s' % str(err))
def mruSaveList(self): """ Saves the list of MRU files to the application settings file. """ qs = QSettings() qs.remove("mru") qs.beginWriteArray("mru") for i, m in enumerate(self.mru_list): (path, description) = m qs.setArrayIndex(i) qs.setValue("path", path) qs.setValue("description", description) qs.endArray()
def mruLoadList(self): """ Loads the list of MRU files from the pplication settings file. """ self.mru_list = list() qs = QSettings() count = qs.beginReadArray("mru") for i in range(count): qs.setArrayIndex(i) path = qs.value("path") description = qs.value("description") if os.path.exists(path): self.mru_list.append((path, description)) qs.endArray()
def read_paths(self): """Returns a list of up to MAX_RECENT_DOCS Paths. The most recently opened path is the first element in the list. """ settings = QSettings() n_recent = settings.beginReadArray(self.KEY) try: n_recent = min(n_recent, self.MAX_RECENT_DOCS) recent = [] debug_print('Reading {0} recent document paths'.format(n_recent)) for index in xrange(n_recent): settings.setArrayIndex(index) path = settings.value("path") if path: recent.append(self._resolved_if_possible(Path(path))) finally: settings.endArray() return recent