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_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 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 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_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 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 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 __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 __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 __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()