Python ui 模块,ListDataSource() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用ui.ListDataSource()

项目:OCT_iOS    作者:MilkShakeYoung    | 项目源码 | 文件源码
def __init__(self, path='/'):
        tv = ui.TableView()
        tv.frame = self.bounds
        tv.flex = 'WH'
        ds = ui.ListDataSource([])
        ds.action = self.item_selected
        tv.data_source = ds
        tv.delegate = ds
        self.tableview = tv
        self.add_subview(self.tableview)
        self.name = 'Dropbox'
        label = ui.Label(frame=self.bounds)
        label.flex = 'WH'
        label.background_color = (1, 1, 1, 0.95)
        label.text = 'Loading...'
        label.touch_enabled = True
        label.alignment = ui.ALIGN_CENTER
        self.path = path
        self.add_subview(label)
        self.status_label = label
        self.canceled = False
项目:qdh_pythonista    作者:quadrohedron    | 项目源码 | 文件源码
def __init__(self, path='/'):
        tv = ui.TableView()
        tv.frame = self.bounds
        tv.flex = 'WH'
        ds = ui.ListDataSource([])
        ds.action = self.item_selected
        tv.data_source = ds
        tv.delegate = ds
        self.tableview = tv
        self.add_subview(self.tableview)
        self.name = 'Dropbox'
        label = ui.Label(frame=self.bounds)
        label.flex = 'WH'
        label.background_color = (1, 1, 1, 0.95)
        label.text = 'Loading...'
        label.touch_enabled = True
        label.alignment = ui.ALIGN_CENTER
        self.path = path
        self.add_subview(label)
        self.status_label = label
        self.canceled = False
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def load(self):
        self.app.activity_indicator.start()
        try:
            self.categories_dict = self.app.repo.get_categories()
            categories_listdatasource = ui.ListDataSource(
                {'title': category_name, 'accessory_type': 'disclosure_indicator'}
                for category_name in sorted(self.categories_dict.keys())
            )
            categories_listdatasource.action = self.category_item_tapped
            categories_listdatasource.delete_enabled = False

            self.view.data_source = categories_listdatasource
            self.view.delegate = categories_listdatasource
            self.view.reload()
        except Exception as e:
            console.hud_alert('Failed to load Categories', 'error', 1.0)
        finally:
            self.app.activity_indicator.stop()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def bt_picture_action(self, sender):
        lst = ui.ListDataSource([{'title':'none','accessory_type':'none'},
                                 {'title':'checkmark','accessory_type':'checkmark'},
                                 {'title':'detail_button','accessory_type':'detail_button'},
                                 {'title':'detail_disclosure_button','accessory_type':'detail_disclosure_button'},
                                 {'title':'disclosure_indicator','accessory_type':'disclosure_indicator'},
                                 {'title':'image24 and checkmark','image':'ionicons-images-24','accessory_type':'checkmark'},
                                 {'title':'image32','image':'ionicons-alert-32'},
                                 {'title':'image256','image':'ionicons-alert-circled-256'},
                                 {'title':'frog','image':'Frog_Face'},
                                 {'title':'OwnImage','image':'Image/OwnImage.png'}])
        tv1 = self.view['tableview1']
        tv1.data_source = tv1.delegate = lst
        tv1.data_source.delete_enabled = tv1.editing = False
        lst.action = self.tv1_action
        tv1.reload_data()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def open_finder(self,sender):
        # expand out a view/dialog from sender
        root=self.find_root()
        overlay=ui.Button(frame=(0,0)+tuple(root.frame)[2:],bg_color=(0,0,0,0.25),name='overlay')
        dialog=ui.View(frame=sender.frame,bg_color='white',name='dialog')
        self.tbl=ui.TableView()
        self.tbl.width=dialog.width
        self.tbl.height=dialog.height
        self.listsource=ui.ListDataSource(items=[])
        self.tbl.data_source=self.listsource
        self.tbl.delegate=self.listsource
        self.listsource.action=self.stop_populating
        self.tbl.flex='wh'
        dialog.add_subview(self.tbl)
        overlay.add_subview(dialog)
        overlay.action=self.stop_populating
        root.add_subview(overlay)
        self.dialog=dialog
        def ani():
            dialog.x,dialog.y=ui.convert_point((self.textfield.x,self.textfield.y+self.textfield.height),self,root)
            dialog.width=self.textfield.width
            dialog.height=min(400,root.height-ui.convert_point((0,dialog.y),self,root)[1])
        ui.delay(self.start_populating,0.16)
        ui.animate(ani,0.15)
项目:py-search    作者:vieira-rafael    | 项目源码 | 文件源码
def init_size(self): # initialize with correct size when landscape      orientation = ui.WebView(frame=(0,0,100,200)).eval_js('window.orientation') if orientation in (-90, 90): self.frame = (0, 0, self.height, self.width)
 def did_load(self): self.init_buttons() self.init_webbrowser() self.init_addressbar() self.init_size() self.flex = 'WH' self.bookmarks = self.load_bookmarks() self.history = self.load_history() self.addressbar_is_editing = False self.webpage_has_loaded = False self.favourite_images = {True :ui.Image.named('ionicons-ios7-star-32'), False:ui.Image.named('ionicons-ios7-star-outline-32')}
 def save_history(self, filename=filename_history): with open(filename, 'w') as f:          url = self.get_url() if url in self.history: self.history.remove(url) self.history.append(url)          f.seek(0)           pickle.dump(self.history, f)  def clear_history(self, sender, filename=filename_history): with open(filename, 'w') as f: self.history = []          f.seek(0)           pickle.dump(self.history, f)            sender.superview.superview['history'].data_source.items = self.history          sender.superview.superview['history'].reload()
 def save_bookmark(self, filename=filename_bookmarks): with open(filename, 'w') as f:           url = self.get_url()            title = self.get_title() or self.parse_url(url) self.bookmarks[title] = url         f.seek(0)           json.dump(self.bookmarks, f, indent=4) self['controlpanel']['favourite'].image = self.favourite_images[True]
 def remove_bookmark(self, title=None, filename=filename_bookmarks): with open(filename, 'w') as f:         title = title or self.get_title() del self.bookmarks[title]         f.seek(0)           json.dump(self.bookmarks, f, indent=4) self['controlpanel']['favourite'].image = self.favourite_images[False]
 def popup_menu(self):      popup = ui.View(name='menu', frame=(0, 0, 320, 500))        toolbar = ui.View(frame=(-5, 0, 330, 100), name='toolbar')      toolbar.border_width = 0.5      toolbar.border_color = '#B2B2B2'        label = ui.Label()      label.text = 'Bookmarks'        label.alignment = ui.ALIGN_CENTER       label.frame = (0, 0, 320, 50)       label.name = 'title'        segment_ctrl = ui.SegmentedControl(name='segctrl')      segment_ctrl.segments = ['Bookmarks', 'History']        segment_ctrl.width = 170        segment_ctrl.center = popup.center      segment_ctrl.y = label.height       segment_ctrl.selected_index = 0     segment_ctrl.action = self.bookmarks_or_history         button = ui.Button()        button.frame = (segment_ctrl.x*3.5, segment_ctrl.y, 60, 30)     button.font = ('<system>', 15)      button.title= 'Clear'       button.name = 'clear'       button.action = self.clear_history      button.hidden = True        toolbar.add_subview(label)      toolbar.add_subview(segment_ctrl)       toolbar.add_subview(button)         popup.add_subview(toolbar)      data_source = ui.ListDataSource(sorted(self.bookmarks.keys()))      popup.add_subview(self.list_bookmarks_and_history(data_source, width=320,height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='bookmarks'))       x, y = self['controlpanel']['bookmarks'].center     popup.present('popover', popover_location=(x, y), hide_title_bar=True)
 def bookmarks_or_history(self, sender):        toolbar = sender.superview if sender.selected_index == 0:           toolbar['clear'].hidden = True          toolbar['title'].text = 'Bookmarks'         data_source = ui.ListDataSource(sorted(self.bookmarks.keys()))          tv = self.list_bookmarks_and_history(data_source, width=320, height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='bookmarks')            toolbar.superview.remove_subview(toolbar.superview['history']) else:            toolbar['clear'].hidden = False             toolbar['title'].text = 'History'           data_source = ui.ListDataSource(self.history[::-1])         tv = self.list_bookmarks_and_history(data_source, width=320, height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='history')          toolbar.superview['bookmarks'].hidden=True          toolbar.superview.remove_subview(toolbar.superview['bookmarks'])        sender.superview.superview.add_subview(tv)
 def list_bookmarks_and_history(self, data_source, **kwargs):       tv = ui.TableView()     tv.data_source = data_source        tv.delegate = self for k, v in kwargs.items(): setattr(tv, k, v) return tv
 def show_more_menu(self):      popup = ui.TableView()      popup.width = 250       popup.height = 500      popup.name = 'More'     popup.data_source = popup.delegate = self       button = self['controlpanel']['more']       popup.present('popover', popover_location=(button.x, button.y+button.height))
 def button_tapped(self, sender): if sender.name == 'favourite': if self.get_url() in self.bookmarks.values(): self.remove_bookmark() else: self.save_bookmark() elif sender.name == 'bookmarks': self.popup_menu() elif sender.name == 'more': self.show_more_menu() else: eval("self['webview'].{}()".format(sender.name))
 def tableview_number_of_rows(self, tableview, section): if tableview.name == 'Bookmarks': return len(self.bookmarks) elif tableview.name == 'More': return 1
 def tableview_cell_for_row(self, tableview, section, row): if tableview.name == 'Bookmarks':           cell = ui.TableViewCell()           cell.text_label.text = sorted(self.bookmarks.keys())[row]           cell.image_view.image = ui.Image.named('ionicons-ios7-bookmarks-outline-32')            cell.image_view.tint_color = '#66CCFF' return cell elif tableview.name == 'More':           cell = ui.TableViewCell()           cell.text_label.text = 'Settings'           cell.image_view.image = ui.Image.named('ionicons-wrench-32') return cell
 @ui.in_background def tableview_did_select(self, tableview, section, row): if tableview.name == 'bookmarks':           url = self.bookmarks[sorted(self.bookmarks.keys())[row]] self.load_url(url)         tableview.superview.close() elif tableview.name == 'history':           url = tableview.data_source.items[row]          tableview.superview.close() self.load_url(url) elif tableview.name == 'More':           tableview.close()           console.hud_alert('No settings yet...', 'error', 1)
 def tableview_can_delete(self, tableview, section, row): return True
 def tableview_delete(self, tableview, section, row):       item = sorted(self.bookmarks.keys())[row] self.remove_bookmark(item)        tableview.reload()
 def textfield_did_begin_editing(self, textfield): self.addressbar_is_editing = True self.set_url() self['controlpanel']['reload'].hidden = True
 def textfield_did_end_editing(self, textfield): self.addressbar_is_editing = False self['controlpanel']['reload'].hidden = False self.set_url()
 def textfield_should_return(self, textfield):      url = self['controlpanel']['addressbar'].text self.load_url(url)        textfield.end_editing() return True
 def webview_did_start_load(self, webview): self.webpage_has_loaded = False
 def webview_did_finish_load(self, webview): if not self.addressbar_is_editing: self.set_url() self.webpage_has_loaded = True       page_is_bookmarked = unicode(self.get_url()) in self.bookmarks.values() self['controlpanel']['favourite'].image = self.favourite_images[page_is_bookmarked] self.save_history()
项目:mediawiki_ui    作者:allanburleson    | 项目源码 | 文件源码
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()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, items=None):
        ui.ListDataSource.__init__(self, items)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def bt_dir_action(self, sender):
        dir_items = os.listdir(os.getcwd())
        tv1 = self.view['tableview1']
        tv1.data_source = tv1.delegate = ui.ListDataSource(dir_items)
        tv1.data_source.delete_enabled = tv1.editing = False
        tv1.reload_data()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def bt_empty_action(self, sender):
        lst = ui.ListDataSource([])
        tv1 = self.view['tableview1']
        tv1.data_source = tv1.delegate = ui.ListDataSource([])
        tv1.data_source.delete_enabled = tv1.editing = False
        tv1.reload_data()