def check_all_active_alarms_have_a_corresponding_item(kwargs): leftovers = set() for alarm in wxalarms_api.get_active_alarms(): if alarm['filename'] not in \ organism_alarms_api.get_supported_open_databases() or \ alarm['id'] not in core_api.get_items_ids(alarm['filename']): leftovers.add((alarm['filename'], str(alarm['id']))) if leftovers: msgboxes.warn_generic('The following active alarms don\'t have a ' 'corresponding item any more:\n{}'.format( '\n'.join([' '.join(a) for a in leftovers])) ).ShowModal()
def check_all_active_alarms_have_a_corresponding_item(kwargs): leftovers = set() for alarm in wxalarms_api.get_active_alarms(): if alarm['filename'] not in \ organism_alarms_api.get_supported_open_databases() or \ alarm['id'] not in core_api.get_items_ids(alarm['filename']): leftovers.add((alarm['filename'], str(alarm['id']))) if leftovers: msgboxes.warn_generic('The following active alarms don\'t have a ' 'corresponding item any more:\n{}'.format( '\n'.join([' '.join(a) for a in leftovers ]))).ShowModal()
def populate_tree(self, event): if core_api.block_databases(): filename = wxgui_api.get_selected_database_filename() # This method may be launched even if no database is open if filename: group = core_api.get_next_history_group(filename) description = 'Populate tree' i = 0 while i < 10: dbitems = core_api.get_items_ids(filename) try: itemid = random.choice(dbitems) except IndexError: # No items in the database yet itemid = 0 mode = 'child' else: mode = random.choice(('child', 'sibling')) # See the comment in wxgui.tree.expand_item_ancestors # for the reason why calling this method is necessary wxgui_api.expand_item_ancestors(filename, itemid) text = self._populate_tree_text() id_ = self._populate_tree_item(mode, filename, itemid, group, text, description) # It should also be checked if the database supports # organism_basicrules (bug #330) if organism_api and wxscheduler_basicrules_api and \ filename in \ organism_api.get_supported_open_databases(): self._populate_tree_rules(filename, id_, group, description) if links_api and wxlinks_api and len(dbitems) > 0 and \ filename in \ links_api.get_supported_open_databases(): self._populate_tree_link(filename, id_, dbitems, group, description) i += 1 wxgui_api.refresh_history(filename) core_api.release_databases()
def _select_items(many): filename = wxgui_api.get_selected_database_filename() ids = core_api.get_items_ids(filename) if ids: w = 0 if many else 1 modes = ((40, 80)[w] * ['select_one'] + (10, 0)[w] * ['reselect_many'] + (10, 0)[w] * ['select_some'] + (10, 0)[w] * ['select_all'] + (20, 0)[w] * ['unselect_some'] + (10, 20)[w] * ['unselect_all']) mode = random.choice(modes) if mode == 'unselect_some': selection = wxgui_api.get_tree_selections(filename) if selection: sids = [ wxgui_api.get_tree_item_id(filename, i) for i in selection ] remids = random.sample(ids, random.randint(1, len(ids))) wxgui_api.simulate_remove_items_from_selection( filename, remids) else: if mode in ('select_one', 'reselect_many', 'unselect_all'): wxgui_api.simulate_unselect_all_items(filename) addids = { 'select_one': (random.choice(ids), ), 'reselect_many': random.sample( ids, random.randint(2 if len(ids) > 1 else 1, len(ids))), 'select_some': random.sample(ids, random.randint(1, len(ids))), 'select_all': ids, 'unselect_all': (), } wxgui_api.simulate_add_items_to_selection(filename, addids[mode]) return wxgui_api.get_tree_selections(filename)
def _select_items(many): filename = wxgui_api.get_selected_database_filename() ids = core_api.get_items_ids(filename) if ids: w = 0 if many else 1 modes = ( (40, 80)[w] * ['select_one'] + (10, 0)[w] * ['reselect_many'] + (10, 0)[w] * ['select_some'] + (10, 0)[w] * ['select_all'] + (20, 0)[w] * ['unselect_some'] + (10, 20)[w] * ['unselect_all'] ) mode = random.choice(modes) if mode == 'unselect_some': selection = wxgui_api.get_tree_selections(filename) if selection: sids = [wxgui_api.get_tree_item_id(filename, i) for i in selection] remids = random.sample(ids, random.randint(1, len(ids))) wxgui_api.simulate_remove_items_from_selection(filename, remids) else: if mode in ('select_one', 'reselect_many', 'unselect_all'): wxgui_api.simulate_unselect_all_items(filename) addids = { 'select_one': (random.choice(ids), ), 'reselect_many': random.sample(ids, random.randint( 2 if len(ids) > 1 else 1, len(ids))), 'select_some': random.sample(ids, random.randint(1, len(ids))), 'select_all': ids, 'unselect_all': (), } wxgui_api.simulate_add_items_to_selection(filename, addids[mode]) return wxgui_api.get_tree_selections(filename)