def select_clipboard_menu_option(self, item=None, label="Disabled"): clipboardlog( "select_clipboard_menu_option(%s, %s) clipboard_change_pending=%s", item, label, self._clipboard_change_pending) if self._clipboard_change_pending: return clipboard = self.get_menu("Clipboard") if not clipboard: log.error("Error: cannot locate Clipboad menu object!") return all_items = clipboard.get_submenu().get_children() selected_items = [x for x in all_items if x == item ] + [x for x in all_items if x.get_label() == label] default_items = [x for x in all_items if x.get_label() == "Disabled"] options = selected_items + default_items if not options: log.error( "Error: cannot find any clipboard menu options to match!") return self._clipboard_change_pending = True sel = options[0] remote_clipboard = CLIPBOARD_LABEL_TO_NAME.get(sel.get_label()) clipboardlog( "will select clipboard menu item with label=%s, for remote_clipboard=%s", sel.get_label(), remote_clipboard) for x in all_items: x.set_active(x.get_label() == sel.get_label()) glib.timeout_add(0, self.do_clipboard_change, remote_clipboard)
def set_clipboard_menu(self, clipboard_menu): #find the menu item matching the current settings, #and select it try: assert self._can_handle_clipboard() remote_clipboard = self.client.clipboard_helper.remote_clipboard label = None except: remote_clipboard = None label = "Disabled" selected_menu_item = None for item in clipboard_menu.get_children(): if remote_clipboard and remote_clipboard == CLIPBOARD_LABEL_TO_NAME.get( item.get_label()): selected_menu_item = item break self.select_clipboard_menu_option(selected_menu_item, label)