我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用ui.ButtonItem()。
def __init__(self, elements, saveCallBack, addElementAction, saveFlowAction, runFlowAction, showElementRuntimeView, thememanager, flowType, flowTypeSelection): self.flowType = flowType self.elements = elements self.saveCallBack = saveCallBack self.flowTypeSelection = flowTypeSelection self.showElementRuntimeView = showElementRuntimeView self.extraRows = 2 self.adminRow = 0 self.typeRow = 1 self.title = '' self.currentElementNumber = -1 self.addElementButton = ui.ButtonItem(title = 'Add Element', action = addElementAction) self.saveFlowButton = ui.ButtonItem(title='Save', action=saveFlowAction) self.runFlowButton = ui.ButtonItem(title='Run', action=runFlowAction) self.titleButton = ui.Button(title='Change Title') self.editButtonsRight = [self.addElementButton] self.editButtonsLeft = [self.saveFlowButton] self.runButtonsRight = [self.runFlowButton] self.runButtonsLeft = [] self.thememanager = thememanager
def getReloadButtons(self): rightBarButtons = [] rightBarButtons.append(ui.ButtonItem(image = ui.Image.named('iob:ios7_refresh_empty_32'), action = self.reload, tint_color = self.tintColour)) rightBarButtons.append(ui.ButtonItem(image = ui.Image.named('iob:ios7_arrow_forward_32'), action = self.forward, tint_color = self.tintColour)) rightBarButtons.append(ui.ButtonItem(image = ui.Image.named('iob:ios7_arrow_back_32'), action= self.back, tint_color = self.tintColour)) if self.showButtons: return rightBarButtons else: return []
def getStopButtons(self): rightBarButtons = [] rightBarButtons.append(ui.ButtonItem(image = ui.Image.named('iob:close_round_24'), action = self.stop, tint_color = self.tintColour)) rightBarButtons.append(ui.ButtonItem(image = ui.Image.named('iob:ios7_arrow_forward_32'), action = self.forward, tint_color = self.tintColour)) rightBarButtons.append(ui.ButtonItem(image = ui.Image.named('iob:ios7_arrow_back_32'), action= self.back, tint_color = self.tintColour)) if self.showButtons: return rightBarButtons else: return []
def getButton(self): title = '' action = None if self.transfer_manager.running: title = 'Stop Server' action = self.stopServer else: title = 'Start Server' action = self.startServer return ui.ButtonItem(title=title, action=action)
def setup_main_view(self): docsets = self.docset_manager.getDownloadedDocsets() cheatsheets = self.cheatsheet_manager.getDownloadedCheatsheets() usercontributed = self.usercontributed_manager.getDownloadedUserContributed() stackoverflows = self.stackoverflow_manager.getDownloadedStackOverflows() transfers = self.transfer_manager.getInstalledDocsets() main_view = UISearchControllerWrapper.get_view(DocsetListView.get_view(docsets, cheatsheets, usercontributed, stackoverflows, transfers, self.docset_selected_for_viewing, self.cheatsheet_selected_for_viewing, self.usercontributed_selected_for_viewing, self.stackoverflow_selected_for_viewing, self.transfer_selected_for_viewing, self.theme_manager), self.search_all_docsets, self.docset_index_selected_for_viewing, self.theme_manager, self.build_offline_index_stackoverflow_selected_for_viewing) settings_button = ui.ButtonItem(title='Settings') settings_button.action = self.show_settings_view main_view.left_button_items = [settings_button] return main_view
def setup_docset_management_view(self): docsets = self.docset_manager.getAvailableDocsets() docset_management_view = DocsetManagementView.get_view(docsets, self.docset_manager.downloadDocset, self.docset_manager.getAvailableDocsets, self.docset_manager.deleteDocset, self.refresh_main_view_data, self.theme_manager) docset_management_view.right_button_items = [ui.ButtonItem(action=self.checkStandardDocsetsForUpdate, title='Check for Update')] docset_management_view.background_color = self.theme_manager.currentTheme.backgroundColour docset_management_view.bar_tint_color = self.theme_manager.currentTheme.tintColour docset_management_view.bg_color = self.theme_manager.currentTheme.backgroundColour docset_management_view.tint_color = self.theme_manager.currentTheme.tintColour docset_management_view.title_color = self.theme_manager.currentTheme.textColour return docset_management_view
def setup_usercontributedmanagement_view(self): view = UserContributedManagementView.get_view(self.usercontributed_manager.downloadUserContributed, self.refresh_main_view_data, self.usercontributed_manager.deleteUserContributed, self.usercontributed_manager.getAvailableUserContributed, self.theme_manager) view.right_button_items = [ui.ButtonItem(action=self.checkUserContributedForUpdate, title='Check for Update')] view.background_color = self.theme_manager.currentTheme.backgroundColour view.bar_tint_color = self.theme_manager.currentTheme.tintColour view.bg_color = self.theme_manager.currentTheme.backgroundColour view.tint_color = self.theme_manager.currentTheme.tintColour view.title_color = self.theme_manager.currentTheme.textColour return view
def setup_stackoverflowmanagement_view(self): view = StackOverflowManagementView.get_view(self.stackoverflow_manager.downloadStackOverflow, self.refresh_main_view_data, self.stackoverflow_manager.deleteStackOverflow, self.stackoverflow_manager.getAvailableStackOverflows, self.theme_manager) view.right_button_items = [ui.ButtonItem(action=self.checkStackOverflowForUpdate, title='Check for Update')] view.background_color = self.theme_manager.currentTheme.backgroundColour view.bar_tint_color = self.theme_manager.currentTheme.tintColour view.bg_color = self.theme_manager.currentTheme.backgroundColour view.tint_color = self.theme_manager.currentTheme.tintColour view.title_color = self.theme_manager.currentTheme.textColour return view
def __init__(self, wikis): addbtn = ui.ButtonItem(image=ui.Image.named('iob:ios7_plus_empty_32'), action=self.add) # self.editbtn so it can be used in WikiList.edit self.editbtn = ui.ButtonItem(title='Edit', action=self.edit) items = None # If save file exists use it if os.path.isfile(os.path.expanduser('~/.mwsave.dat')): s = shelve.open(os.path.expanduser('~/.mwsave')) try: wikis = s['wikis'] except KeyError: pass s.close() self.tv = ui.TableView(name='Wikis') self.nv = ui.NavigationView(self.tv) self.tv.delegate = TableViewDelegate(wikis) items = [] # Create data source from dictionary of wikis for wiki in wikis: items.append({'title': wiki, 'accessory_type': 'detail_disclosure_button'}) self.tv.data_source = ui.ListDataSource(items) self.tv.data_source.move_enabled = True self.tv.data_source.edit_action = self.removeFromWikis self.tv.right_button_items = [addbtn] self.tv.left_button_items = [self.editbtn] self.nv.present('fullscreen', hide_title_bar=True) # Wait until the view closes to save app data self.nv.wait_modal() self.save()
def edit(self, sender): '''Go into wiki edit mode''' def done(sender): self.tv.editing = False # Change button labeled "Done" to "Edit" self.tv.left_button_items = [self.editbtn] # Change button labeled "Edit" to "Done" donebtn = ui.ButtonItem(title='Done', action=done) self.tv.left_button_items = [donebtn] self.tv.editing = True
def __init__(self, root_node, allow_multi=False, async_mode=False): self.async_mode = async_mode self.allow_multi = allow_multi self.selected_entries = None self.table_view = ui.TableView() self.table_view.frame = (0, 0, 500, 500) self.table_view.data_source = self self.table_view.delegate = self self.table_view.flex = 'WH' self.table_view.allows_multiple_selection = True self.table_view.tint_color = 'gray' self.view = ui.View(frame=self.table_view.frame) self.view.add_subview(self.table_view) self.view.name = root_node.title self.busy_view = ui.View(frame=self.view.bounds, flex='WH', background_color=(0, 0, 0, 0.35)) hud = ui.View(frame=(self.view.center.x - 50, self.view.center.y - 50, 100, 100)) hud.background_color = (0, 0, 0, 0.7) hud.corner_radius = 8.0 hud.flex = 'TLRB' spinner = ui.ActivityIndicator() spinner.style = ui.ACTIVITY_INDICATOR_STYLE_WHITE_LARGE spinner.center = (50, 50) spinner.start_animating() hud.add_subview(spinner) self.busy_view.add_subview(hud) self.busy_view.alpha = 0.0 self.view.add_subview(self.busy_view) self.done_btn = ui.ButtonItem(title='Done', action=self.done_action) if self.allow_multi: self.view.right_button_items = [self.done_btn] self.done_btn.enabled = False self.root_node = root_node self.entries = [] self.flat_entries = [] if self.async_mode: self.set_busy(True) t = threading.Thread(target=self.expand_root) t.start() else: self.expand_root()
def make_button_item(action, image_name): return ui.ButtonItem(action=action, image=ui.Image.named(image_name))
def getFile(setter=None,base_dir='.'): fv = FileViewer(setter,base_dir) fv.height=700 nv = ui.NavigationView(fv) def openDocuments(sender,path): def setme(fv,value): # set and bubble up setters fv.src.sel[0]=value if fv.src.setter is not None: fv.src.setter(value) newfv = FileViewer(setter=lambda value:setme(fv,value),base_dir=path) nv.push_view(newfv) nv.right_button_items=[ ui.ButtonItem(title='Documents', action=lambda sender:openDocuments(sender,os.path.expanduser('~/Documents'))), ui.ButtonItem(title='Library', action=lambda sender:openDocuments(sender,os.path.split(os.__file__)[0]))] nv.height=800 nv.width=500 nv.name = 'File Selector' nv.present('popover') ui.in_background(nv.wait_modal) nv.wait_modal() return fv.src.sel[0]
def setup_navigationview(self, initview): initview.right_button_items = [ui.ButtonItem(title='Add Flow', action=self.show_flowcreationview)] initview.left_button_items = [ui.ButtonItem(title='Elements', action=self.show_elementmanagementview)] self.navigation_view = ui.NavigationView(initview) self.navigation_view.bar_tint_color=self.theme_manager.main_bar_colour self.navigation_view.tint_color = self.theme_manager.main_tint_colour self.navigation_view.background_color = self.theme_manager.main_background_colour self.navigation_view.title_color = self.theme_manager.main_title_text_colour
def get_view(thememanager, dictionary={}, title='Dictionary', cb=None): dicti = dictionary if dicti == None: dicti = {} dbo.dictionary=dicti dbo.thememanager = thememanager table_view.name = title table_view.data_source = dbo table_view.delegate = dbo table_view.right_button_items = [ui.ButtonItem(title='Add', action = add_item), ui.ButtonItem(title='Save', action=cb)] table_view.background_color=thememanager.main_background_colour return table_view
def load_button_items(self): if self.is_main(): self.left_button_items = [ui.ButtonItem('Cancel', action=lambda s: self.navigation_view.close())] else: self.right_button_items = [ui.ButtonItem('Done', action=lambda s: self.navigation_view.close())]
def get_view(savecb, apcb, capcb, thememanager): dbo = ElementCreationView(saveCallBack = savecb, showAssetPickerCallBack = apcb, closeAssetPickerCallBack = capcb, thememanager = thememanager) table_view.name = 'Element' table_view.data_source = dbo table_view.delegate = dbo table_view.right_button_items = [ui.ButtonItem(title='Save Element', action=dbo.create_element)] table_view.background_color = thememanager.main_background_colour return table_view
def __init__(self, change_set, *args, **kwargs): super().__init__(*args, **kwargs) self.name = 'Preview' self.apply_changes = False def apply(sender): self.apply_changes = True self.close() button = ui.ButtonItem('Apply', action=apply) self.right_button_items = [button] textview = ui.TextView(frame=self.bounds, flex='WH') textview.editable = False diff = _change_set_diff(change_set) attributed_string = _diff_to_attributed_string(diff) _set_attributed_text(textview, attributed_string) self.add_subview(textview) def cancel(): self.close() self.handlers = [ register_key_event_handler(UIEventKeyCode.escape, cancel), register_key_event_handler(UIEventKeyCode.dot, cancel, modifier=UIKeyModifier.command), register_key_event_handler(UIEventKeyCode.enter, lambda: apply(None)) ]
def __init__(self, wikiname, basewikiurl, wikiurl): self.modulepath = os.path.dirname(os.path.abspath(__file__)) os.chdir(self.modulepath) self.wikidir = os.path.expanduser('~/.mw-' + wikiname) if not os.path.isdir(self.wikidir): os.mkdir(self.wikidir) self.webdelegate = WebViewDelegate(self) self.SearchTableViewDelegate = SearchTableViewDelegate if not wikiurl.endswith('/'): wikiurl += '/' # Create URLs assert not wikiurl.startswith('http'), 'must be end of wiki url' if basewikiurl.endswith('/'): basewikiurl = basewikiurl[:-1] self.basewikiurl = basewikiurl self.wikiurl = self.basewikiurl + wikiurl self.searchurl = self.wikiurl + 'Special:Search?search=' self.history = [] self.histIndex = 0 self.back = False self.closed = False if len(sys.argv) > 2: self.args = True else: self.args = False # Create WebView self.webview = ui.WebView() self.mainSource = '' self.webview.delegate = WebViewDelegate self.loadPage(self.wikiurl) self.searchButton = ui.ButtonItem(image=ui.Image.named( 'iob:search_24'), action=self.searchTapped) self.reloadButton = ui.ButtonItem(image=ui.Image.named( 'iob:refresh_24'), action=self.reloadTapped) self.backButton = ui.ButtonItem(image=ui.Image.named( 'iob:arrow_left_c_24'), action=self.backTapped) self.fwdButton = ui.ButtonItem(image=ui.Image.named( 'iob:arrow_right_c_24'), action=self.fwdTapped) self.homeButton = ui.ButtonItem(image=ui.Image.named('iob:home_24'), action=self.home) self.shareButton = ui.ButtonItem(image=ui.Image.named( 'iob:ios7_upload_outline_32'), action=self.share) self.safariButton = ui.ButtonItem(image=ui.Image.named( 'iob:compass_24'), action=self.safari) self.webview.right_button_items = [self.searchButton, self.reloadButton, self.fwdButton, self.backButton, self.homeButton] self.webview.left_button_items = [self.shareButton, self.safariButton] self.webview.present('fullscreen', animated=True) self.previousSearch = '' if len(sys.argv) > 1: self.search(sys.argv[1]) closeThread = threading.Thread(target=self.waitForClose) closeThread.start()