def on_search_done(self, results, error, query, entry, *args, **kwargs): if query == entry.get_text(): print("EntityPopover: search", query, 'complete') try: listbox = self.results_listbox listbox.foreach(listbox.remove) set_text(self.variable_title, query, query) pango_label(self.variable_title, 'bold') if self.variables != None: self.variables_set_results(listbox, query=query) if self.variables or results: self.results_stack.set_visible_child_name("results") else: set_text(self.results_nope_query, query, query) self.entity_new.connect("clicked", self.entity_new_clicked_cb, query) self.results_stack.set_visible_child_name("results_nope") for r in results: if r['URI'] != self.entity['URI']: entity = SidebarEntity(r, URI=False, button=True) entity.image_button.set_from_icon_name('focus-windows-symbolic', IconSize.BUTTON) entity.button.connect("clicked", self.new_window_clicked_cb, r) row = ListBoxRow() row.child = entity row.add(entity) listbox.add(row) listbox.show_all() self.set_search_placeholder(False) except Exception as e: raise e
def on_row_complete(self, entity, **kwargs): # Build entity if not entity['Label']: entity['Label'] = self.wikidata.get_label(entity['Data'], language='en') if not entity['Description']: entity['Description'] = self.wikidata.get_description(entity['Data']) sidebar_entity = SidebarEntity(entity, description=True, URI=True) sidebar_entity.button.connect("clicked", self.entity_close_clicked_cb, sidebar_entity) row = ListBoxRow() row.child = sidebar_entity row.add(sidebar_entity) current_row = self.sidebar_list.get_selected_row() rows = self.sidebar_list.get_children() i = 0 for i, r in enumerate(rows): if r == current_row: break if (i < len(rows) - 2): self.sidebar_list.insert(row, i+1) else: self.sidebar_list.add(row) self.sidebar_list.show_all() if 'select' in kwargs and kwargs['select']: self.sidebar_list.select_row(row)
def __init__(self, widget, top_widget=None, halign=Align.END, valign=Align.FILL): ListBoxRow.__init__(self) self.top_widget = top_widget self.eventbox = EventBox() self.overlay = Overlay() self.revealer = Revealer() self.add(self.eventbox) self.eventbox.add(self.overlay) self.overlay.add_overlay(self.revealer) self.add_widget(widget) self.revealer.set_transition_type(RevealerTransitionType.NONE) self.revealer.set_reveal_child(False) self.revealer.set_property("halign", halign) self.revealer.set_property("valign", valign) self.enter_connection = self.eventbox.connect( "enter-notify-event", self.enter_notify_event_cb) self.leave_connection = self.eventbox.connect( "leave-notify-event", self.leave_notify_event_cb) if top_widget: self.revealer.add(self.top_widget)
def on_search_done(self, results, error, query): if error: self.set_search_placeholder(False) self.results.set_visible_child_name("results_no_internet") print("connection error") else: if query == self.search_entry.get_text(): self.results_listbox.foreach(self.results_listbox.remove) if results == []: self.results.set_visible_child_name("results_nope") set_text(self.results_nope_query, query, query) else: self.results.set_visible_child_name("results_scrolled_window") for r in results: if self.titlebar.get_selection_mode(): entity = EntitySelectable(r, selected=self.entities, open_button=self.open_button, select_entities=self.select_entities) else: entity = SidebarEntity(r, button=False) row = ListBoxRow() row.child = entity row.add(entity) self.results_listbox.add(row) #row.child() self.results_listbox.show_all() self.set_search_placeholder(False)
def on_download_done(self, URI, entity, error): if not entity: print("problematic URI", URI) else: entity = SidebarEntity(entity, button=False) row = ListBoxRow() row.child = entity row.add(entity) self.results_listbox.add(row) self.results_listbox.show_all()
def on_auth_chooser_row_activated(self, _widget: Gtk.ListBox, row: Gtk.ListBoxRow) -> None: if row.get_name() == "password": self.stack.set_visible_child_name("password-creation") self.password_creation_input.grab_focus() elif row.get_name() == "keyfile": self.keyfile_generation_page() elif row.get_name() == "composite": self.composite = True self.stack.set_visible_child_name("password-creation") self.password_creation_input.grab_focus()
def languages_callback(self, results): languages = self.config.data['languages'] self.language_results = results['results']['bindings'] for lang in languages: for r in self.language_results: if r['c']['value'] == lang: row = ListBoxRow() label = Label() label.set_text(r['itemLabel']['value']) label.props.halign = Align(1) row.add(label) self.languages.add(row) self.languages.show_all()
def add(self, row, select=False): """Add widget to a new row Overrides Gtk.Container.add Args: widget (Gtk.Widget): the widget to add to the new row. """ # If the list has rows if self.get_children(): # Pick the last one last_row = self.get_children()[-1] # If it has no children, it is the ending separator, so remove it if not last_row.get_children(): self.remove(last_row) super(SidebarList, self).add(row) # Select if 'autoselect' if (len(self.get_children()) >= 1 and self.autoselect) or select: self.select_row(row) # The final empty row that acts as separator row = ListBoxRow() row.props.activatable = False row.props.selectable = False super(SidebarList, self).add(row)
def selected(box, row: Gtk.ListBoxRow): # show correct chat sidebar_element = row.get_children()[0] conv_id = sidebar_element.get_id() # open correct box self.__open_message_box(None, GLib.Variant("s", conv_id))
def __init__(self, languages, *args, **kwargs): Window.__init__(self, *args, **kwargs) icon = lambda x: IconTheme.get_default().load_icon((name), x, 0) icons = [icon(size) for size in [32, 48, 64, 96]] self.set_icon_list(icons) self.languages.set_header_func(self.update_header) for language in languages: row = ListBoxRow() label = Label() label.set_text(language['itemLabel']['value']) label.code = language['c']['value'] row.child = label row.add(label) self.languages.add(row) self.languages.show_all()
def _on_categories_list_box_row_selected(self, box, row: Gtk.ListBoxRow): self._grid_view.props.visible = row is not None if row is None: self._grid_view.set_model(None) return category = self._categories[row.get_index()] self._grid_view.set_model( Gtk.NoSelection.new(category.command_definitions))
def __init__(self, *args, **kwargs): Window.__init__(self, *args, **kwargs) icon = lambda x: IconTheme.get_default().load_icon((name), x, 0) icons = [icon(size) for size in [32, 48, 64, 96]] self.set_icon_list(icons) self.credentials.set_header_func(self.update_header) self.languages.set_header_func(self.update_header) for key in self.config.data['credentials']: row = ListBoxRow() grid = Grid() grid.props.column_homogeneous = True label = Label() label.set_text(key) label.props.halign = Align(1) context = label.get_style_context() resource = "/ml/prevete/Daty/gtk/value.css" set_style(context, resource, "dim-label", True) entry = Entry() entry.set_text(self.config.data['credentials'][key]) context = entry.get_style_context() set_style(context, resource, "flat", True) grid.attach(label, 0, 0, 1, 1) grid.attach(entry, 1, 0, 2, 1) row.add(grid) self.credentials.add(row) self.credentials.show_all() query = """SELECT ?item ?itemLabel ?c { ?item wdt:P424 ?c . MINUS{?item wdt:P31/wdt:P279* wd:Q14827288} #exclude Wikimedia projects MINUS{?item wdt:P31/wdt:P279* wd:Q17442446} #exclude Wikimedia internal stuff SERVICE wikibase:label { bd:serviceParam wikibase:language "your_first_language". } } """ query = sub("your_first_language", self.config.data['languages'][0], query) self.retrieve(query, self.languages_callback)
def variables_set_results(self, listbox, query=""): listbox.foreach(listbox.remove) if hasattr(self.variable_record, 'connection'): self.variable_record.disconnect(self.variable_record.connection) exact_match = [v for v in self.variables if v["Label"] == query] if exact_match: label = "Select variable" self.variable_record.connection = self.variable_record.connect("clicked", self.object_selected_cb, exact_match[-1]) selected = any(v["Variable"] for v in exact_match) if selected: pango_label(self.variable_title, 'ultrabold') else: label = "Record new variable" self.variable_record.connection = self.variable_record.connect("clicked", self.variable_record_clicked_cb) set_text(self.variable_subtitle, label, label) for v in [v for v in self.variables if v["Label"] and "Variable" in v]: if query in v["Label"] and not query == v["Label"]: row = ListBoxRow() if query: entity = SidebarEntity(v, URI=False) else: entity = SidebarEntity(v, URI=False, button1=True) entity.button1.connect("clicked", self.variable_row_set_default_clicked_cb, v) entity.image_button1.set_from_icon_name('edit-select-symbolic', IconSize.BUTTON) entity.button1.set_tooltip_text("Select variable for the query") entity.button.connect("clicked", self.delete_variable_clicked_cb, row, v) entity.button.set_tooltip_text("Delete variable") row.child = entity if v["Variable"]: pango_label(entity.label, 'ultrabold') entity.label.props.attributes = None row.add(entity) listbox.add(row) listbox.show_all()
def _on_texture_row_selected(self, listbox: Gtk.ListBox, row: Gtk.ListBoxRow): """ Triggers when a texture row is selected, updating RamData with the currently selected texture. :param listbox: Gtk.ListBox object, ignored. :param row: Gtk.ListBoxRow object, used to get the label containing the texture name. :return: """ for child in row.get_child(): if isinstance(child, Gtk.Label): self._ram_data.selected_texture = child.get_label().strip()
def add(self, widget): row = ListBoxRow() context = row.get_style_context() widget.context = context widget.set_references() row.child = widget row.add(widget) super(Values, self).add(row)
def on_patient_selected(self, list_box: Gtk.ListBox, row: Gtk.ListBoxRow): """React to the user selecting a patient. This will switch to the page 'pain_evaluation'. Args: list_box (Gtk.ListBox): The Gtk.ListBox that is the row's parent row (Gtk.ListBoxRow): The Gtk.ListBoxRow that was selected """ if row is not None: self.get_toplevel().active_patient = row.get_child().patient self.get_toplevel().switch_page("pain_evaluation") list_box.unselect_all()
def __init__(self, config, *args, **kwargs): Assistant.__init__(self) icon = lambda x: IconTheme.get_default().load_icon((name), x, 0) icons = [icon(size) for size in [32, 48, 64, 96]]; self.set_icon_list(icons); self.config = config self.credentials.set_header_func(self.update_header) elements = [("user", self.username_label, self.username), ("bot_user", self.bot_username_label, self.bot_username), ("bot_password", self.bot_password_label, self.bot_password)] for key, label, entry in elements: row = ListBoxRow() grid = Grid() grid.props.column_homogeneous = True label.props.halign = Align(1) grid.attach(label, 0, 0, 1, 1) grid.attach(entry, 1, 0, 2, 1) row.add(grid) self.credentials.add(row) self.credentials.show_all() lc, encoding = getdefaultlocale() if (lc): language = lc.split("_")[0] else: language = environ.get("LANGUAGE", None) if language: language = language.split(":")[0] self.config.data['languages'] = [language] self.connect('destroy', main_quit) self.show_all()
def f(reference): if state: row = ListBoxRow() row_context = row.get_style_context() set_style(row_context, resource, 'expanded', state) row.add(reference) row.show() self.insert(row, i + j) else: print("removing widget") row = self.get_row_at_index(i) print(reference) print(row.get_children()) row.remove(reference) row.destroy()
def show_row(self, row: Gtk.ListBoxRow, non_empty: bool, add_all: bool) -> None: if non_empty or add_all: row.set_visible(True) else: row.set_visible(False)