def edit_items(self): sel = self.listview.GetFirstSelected() exists = False warning = False while sel > -1: filename, id_ = self.itemdatamap[self.listview.GetItemData(sel)] # Check whether the database is still open and the item # still exists because the search results are retrieved in # a separate thread and are not updated together with the # database if core_api.is_database_open(filename) and \ core_api.is_item(filename, id_): wxgui_api.open_editor(filename, id_) exists = True else: warning = True sel = self.listview.GetNextSelected(sel) if warning: if exists: msgboxes.some_items_not_found().ShowModal() else: msgboxes.all_items_not_found().ShowModal()
def _append(self, filename, id_, alarmid, start, end, alarm): a = self.make_alarmid(filename, alarmid) # Check whether the database is still open because this method is # called with wx.CallAfter in _handle_alarm, thus running in a # different thread; this way it can happen that, when _handle_alarm is # called, a database is still open, but when this method is called, # that database has been already closed; this would happen for example # when closing all the databases: after each database is closed (in # rapid succession), all the remaining alarms are searched and # signalled again, and when this method would be run (in a different # thread) the alarm's database would have already been closed, thus # raising an exception later when looking information for the item # (e.g. core_api.get_item_text) # Also, for the same reason, check if the item exists, as for example # performing several undos/redos of the database in rapid succession # (e.g. using CTRL+Z/Y) would cause the same issue if core_api.is_database_open(filename) and \ core_api.is_item(filename, id_) and \ a not in self.alarms: self.alarms[a] = Alarm(self, filename, id_, alarmid, start, end, alarm) if len(self.alarms) < self.LIMIT + 1: self.alarms[a].show() else: self.hiddenalarms.add(a) # Besides being much slower, calling Layout and the other # functions at every append would raise an exception for # excessive recursions in case of too many alarms are signalled # at once self.timer.Stop() self.timer = wx.CallLater(self.DELAY, self._display_append)
def _append(self, filename, id_, alarmid, start, end, alarm): a = self.make_alarmid(filename, alarmid) # Check whether the database is still open because this method is # called with wx.CallAfter in _handle_alarm, thus running in a # different thread; this way it can happen that, when _handle_alarm is # called, a database is still open, but when this method is called, # that database has been already closed; this would happen for example # when closing all the databases: after each database is closed (in # rapid succession), all the remaining alarms are searched and # signalled again, and when this method would be run (in a different # thread) the alarm's database would have already been closed, thus # raising an exception later when looking information for the item # (e.g. core_api.get_item_text) # Also, for the same reason, check if the item exists, as for example # performing several undos/redos of the database in rapid succession # (e.g. using CTRL+Z/Y) would cause the same issue if core_api.is_database_open(filename) and core_api.is_item(filename, id_) and a not in self.alarms: self.alarms[a] = Alarm(self, filename, id_, alarmid, start, end, alarm) if len(self.alarms) < self.LIMIT + 1: self.alarms[a].show() else: self.hiddenalarms.add(a) # Besides being much slower, calling Layout and the other # functions at every append would raise an exception for # excessive recursions in case of too many alarms are signalled # at once self.timer.Stop() self.timer = wx.CallLater(self.DELAY, self._display_append)
def find_in_tree(self): sel = self.listview.GetFirstSelected() if sel > -1: for filename in core_api.get_open_databases(): wxgui_api.unselect_all_items(filename) seldb = None warning = False # [1]: line repeated in the loop because of # wxgui_api.select_database_tab filename, id_ = self.itemdatamap[self.listview.GetItemData(sel)] while True: # It's necessary to repeat this line (see [1]) because # wxgui_api.select_database_tab must be executed only once # for the first selected item filename, id_ = self.itemdatamap[self.listview.GetItemData( sel)] # Check whether the database is still open and the item # still exists because the search results are retrieved in # a separate thread and are not updated together with the # database if core_api.is_database_open(filename) and \ core_api.is_item(filename, id_): wxgui_api.add_item_to_selection(filename, id_) if seldb is None: seldb = filename else: warning = True sel = self.listview.GetNextSelected(sel) if sel < 0: break if seldb: wxgui_api.select_database_tab(seldb) if warning: msgboxes.some_items_not_found().ShowModal() elif warning: msgboxes.all_items_not_found().ShowModal()
def open_database(): testfilesd = coreaux_api.get_plugin_configuration('wxdevelopment')( 'TestFiles') testfiles = [os.path.expanduser(testfilesd[key]) for key in testfilesd] random.shuffle(testfiles) while testfiles: filename = testfiles.pop() if not core_api.is_database_open(filename) and \ os.path.isfile(filename): log.debug('Simulate open database') # Databases are blocked in simulator._do_action core_api.release_databases() wxgui_api.simulate_open_database(filename) break else: # Databases are blocked in simulator._do_action core_api.release_databases() return False
def create_database(): testfilesd = coreaux_api.get_plugin_configuration('wxdevelopment')( 'TestFiles') testfiles = [os.path.expanduser(testfilesd[key]) for key in testfilesd] random.shuffle(testfiles) while testfiles: filename = testfiles.pop() if not core_api.is_database_open(filename): try: os.remove(filename) except OSError: # filename doesn't exist yet pass log.debug('Simulate create database') # Databases are blocked in simulator._do_action core_api.release_databases() wxgui_api.simulate_create_database(filename) break else: # Databases are blocked in simulator._do_action core_api.release_databases() return False