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

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

项目:mediawiki_ui    作者:allanburleson    | 项目源码 | 文件源码
def showResults(self, search):
        soup = BeautifulSoup(requests.get(search).text, 'html5lib')
        # Figure out what class the search results are in
        if 'wikia.com' in self.wikiurl:
            elems = soup.findAll('a', attrs={'class': 'result-link'})
        else:
            elems = soup.findAll('div',
                                 attrs={'class': 'mw-search-result-heading'})
        self.results = []
        if elems is not None:
            for elem in elems:
                # Remove URLs from result list
                if 'http' not in elem.get_text():
                    self.results.append(elem.get_text())
        if len(self.results) == 0:
            console.hud_alert('No results', 'error')
            return
        itemlist = [{'title': result, 'accessory_type': 'none'}
                    for result in self.results]
        vdel = SearchTableViewDelegate(itemlist, self.webview, self,
                                       self.wikiurl, self.results)
        self.tv = ui.TableView()
        self.tv.name = soup.title.text.split(' -')[0]
        self.tv.delegate = self.tv.data_source = vdel
        self.tv.present('fullscreen')
项目: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 __init__(self):
        self.dirs = []
        self.files = []
        self.select_color = 'lightgrey'
        self.unselect_color = 'white'
        self.active_button = None
        self.button_height = 50
        self.btn_name = self.make_buttons('Name')
        self.btn_size = self.make_buttons('Size')
        self.btn_date = self.make_buttons('Date')
        self.tv = ui.TableView()
        self.tv.row_height = 30
        self.tv.data_source = MyTableViewDataSource(self.tv.row_height)
        self.get_dir()
        self.all_items = self.dirs + self.files
        self.tv.data_source.items = self.all_items
        self.name = 'TableView-Test'
        #self.tv.delegate = MyTableViewDelegate()
        self.tv.allows_selection = False
        self.add_subview(self.tv)
        self.present('full_screen')
项目: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)
项目: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()
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def get_view(theme_manager):
    tv = ui.TableView()
    w,h = ui.get_screen_size()
    tv.width = w
    tv.height = h
    tv.flex = 'WH'
    tv.name = 'PyDoc'
    data = DocsetView(theme_manager)
    tv.delegate = data
    tv.data_source = data
    return tv
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def get_view(theme_manger, stackOverflowOnlineCallback):
    tv = ui.TableView()
    w,h = ui.get_screen_size()
    tv.width = w
    tv.height = h
    tv.flex = 'WH'
    tv.name = 'PyDoc'
    data = DocsetIndexView(theme_manger, stackOverflowOnlineCallback)
    tv.delegate = data
    tv.data_source = data
    return tv
项目: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, app, category_name, category_url):
        self.app = app
        self.category_name = category_name
        self.category_url = category_url
        self.view = ui.TableView(frame=(0, 0, 640, 640))
        self.view.name = category_name

        self.tools_dict = self.app.repo.get_tools_from_md(category_url)
        self.tool_names = sorted(self.tools_dict.keys())

        self.view.data_source = self
        self.view.delegate = self
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, app):
        self.app = app
        self.view = ui.TableView(frame=(0, 0, 640, 640))
        self.view.name = 'Categories'
        self.categories_dict = {}
        self.load()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
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()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, high_scores=high_scores):
        self.name = 'Cloud Jump 2 - Leaderboard'
        self.frame=(0, 0, 500, 500)
        tv = ui.TableView()
        tv.frame=(0, 0, 500, 500)
        tv.data_source = Data(items=self.scores_list(high_scores))
        tv.allows_selection = tv.data_source.delete_enabled = False 
        self.add_subview(tv)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self,setter, base_dir = '.', *args, **kargs):
        self.table = ui.TableView(*args, **kargs)
        self.name=os.path.split(os.path.abspath(base_dir))[1]
        self.src = MyTableViewDataSource(setter, base_dir)
        self.table.data_source = self.src
        self.table.delegate = self.src
        self.table.flex = 'WHTBLR'
        self.setter=setter
        #self.view = ui.View(name = base_dir)
        self.background_color = 'white'
        self.add_subview(self.table)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def get_view(elements, cb, thememanager):
    dbo = ElementListView(elements = elements, selectedCallBack = cb, thememanager = thememanager)
    table_view = ui.TableView()
    table_view.name = 'Elements'
    table_view.data_source = dbo
    table_view.delegate = dbo
    table_view.background_color = thememanager.main_background_colour
    return table_view
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def create_table_view(self):
        table_view = ui.TableView()
        table_view.name = 'tableview'
        table_view.flex = 'WH'
        table_view.width = self.width
        table_view.height = self.height
        table_view.delegate = self
        table_view.data_source = self
        self.add_subview(table_view)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def get_view(elements, thememanager):
    dbo = ElementManagementView(elements = elements, thememanager = thememanager)
    table_view = ui.TableView()
    table_view.name = 'Elements'
    table_view.data_source = dbo
    table_view.delegate = dbo
    table_view.background_color = thememanager.main_background_colour
    return table_view
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
        self.schema_v = ui.TableView('grouped')
        self.data_v = ui.TableView()
        self.nbutton = ui.Button(title='Next')
        self.pbutton = ui.Button(title='Prev')
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def get_view(dir, cb, filetypes):
    test = FilebrowserController(dir=dir, cb=cb, filetypes=filetypes)
    table_view = ui.TableView()
    table_view.name = 'Files'
    table_view.data_source = test
    table_view.delegate = test
    return table_view
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def main(r):

    L=log_table(r)
    t=ui.TableView()
    t.row_height=75
    t.data_source=L
    t.delegate=L
    t.frame=(44.0, 44.0, 540.0, 576.0)
    t.present('sheet')
项目:ccMVC    作者:polymerchm    | 项目源码 | 文件源码
def __init__(self,  frame=(0,0,150,32),
                                        buttonSize = (32,32),
                                        data = "this is a test".split(),
                                        font = None,
                                        initialItem = 0,
                                        offset_eps = 0,
                                        action = None,
                                        fullSize = 300,
                                        name = 'dropdown'):
        self.frame = frame  
        self._position = [ self.frame[x] for x in (0,1)]
        self.smallSize = frame[3]
        self.bg_color = None    
        self.border_width = 0
        self.border_color = 'black'
        self.buttonSize = buttonSize    
        self._data = data           
        self.delegate = _DropDownDelegate(self)
        if action:
            if inspect.isfunction(action) and len(inspect.getargspec(action).args) == 2:
                self.action = action
            else:
                raise TypeError('single argument function') 
        self.tvFrame = (0,0, self.frame[2] - self.buttonSize[0], self.buttonSize[1])
        self.tv = ui.TableView(frame=self.tvFrame)
        self.tv.row_height = self.smallSize
        self.tv.name = 'tableview'
        self.tv.allows_selection = True
        self.tv.delegate = self.tv.data_source = self.delegate
        self.tv.border_color = 'black'
        self.tv.border_width = 1
        self.button = ui.Button(frame = (self.frame[2]-self.buttonSize[0], 0) + self.buttonSize)
        self.button.bg_color = 'white'
        self.button.name = 'button'
        self.button.action = self.onArrow
        self.button.border_width = 1
        self.button.border_color = 'black'
        self.button.image=ui.Image.named('ionicons-arrow-down-b-24')
        self.expanded = False
        self.add_subview(self.tv)
        self.tv.frame = self.tvFrame
        self.add_subview(self.button)
        self.fullSize = fullSize
        self.smallSize = self.frame[3]
        self.offset_eps = offset_eps
        self.name = name
        self._hidden = False
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def get_view(self, dbpath, tablename):
        self.schema_v = ui.TableView('grouped')
        self.data_v = ui.TableView()
        schema_view = self.schema_v
        data_view = self.data_v
        dbo = tableobjectsview(dbpath, tablename)
        self.ov = dataobjectview(dbpath, tablename)
        w, h = ui.get_screen_size()
        schema_view.name = tablename
        schema_view.data_source = dbo
        schema_view.delegate = dbo
        data_view.name = tablename
        data_view.data_source = self.ov
        data_view.delegate = self.ov
        seg = ui.SegmentedControl()
        seg.segments = ['Schema','Data']
        seg.selected_index = 0
        seg.action = self.test
        seg.width = w/3
        seg.x = w/2 - (seg.width/2)
        seg.y = seg.height / 2
        self.pbutton.y = seg.y
        self.nbutton.y = seg.y
        self.pbutton.x = seg.x - (seg.width/2)
        self.nbutton.x = seg.x + seg.width
        self.pbutton.width = seg.width/2
        self.nbutton.width = seg.width/2
        self.pbutton.hidden = True
        self.nbutton.hidden = True
        self.pbutton.action = self.prev
        self.nbutton.action = self.next
        self.nbutton.enabled, self.pbutton.enabled = self.ov.initial_button_config()
        t = ui.View(frame=(0,0,w,h))
        t.background_color = (0.92,0.92,0.95)
        t.width = w
        t.height = h
        schema_view.width = w
        schema_view.height = t.height * 0.9
        schema_view.y = 2 * seg.height
        data_view.width = w
        data_view.height = t.height * 0.9
        data_view.y = 2 * seg.height
        data_view.hidden = True
        schema_view.hidden = False
        self.schema_v = schema_view
        self.data_v = data_view
        t.add_subview(self.schema_v)
        t.add_subview(self.data_v)
        t.add_subview(seg)
        t.add_subview(self.pbutton)
        t.add_subview(self.nbutton)
        return t
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def __init__(self, **kwargs):
        super().__init__(**kwargs)

        if 'background_color' not in kwargs:
            self.background_color = 'white'

        if 'frame' not in kwargs:
            self.width = min(ui.get_window_size()[0] * 0.8, 700)
            self.height = ui.get_window_size()[1] * 0.8

        self._tableview = ui.TableView()
        self._textfield = ui.TextField()
        self._help_label = ui.Label()
        self._datasource = None
        self._handlers = None
        self.shift_enter_enabled = True
        self.did_select_item_action = None

        tf = LayoutProxy(self._textfield)
        self.add_subview(tf)
        tf.layout.align_left_with_superview.equal = 8
        tf.layout.align_top_with_superview.equal = 8
        tf.layout.align_right_with_superview.equal = -8
        tf.layout.height.equal = 31
        tf.delegate = self

        tv = LayoutProxy(self._tableview)
        self.add_subview(tv)
        tv.layout.align_left_to(tf).equal = 0
        tv.layout.align_right_to(tf).equal = 0
        tv.layout.top_offset_to(tf).equal = 8
        tv.allows_selection = True
        tv.allows_multiple_selection = False

        hl = LayoutProxy(self._help_label)
        self.add_subview(hl)
        hl.layout.align_left_to(tv).equal = 0
        hl.layout.align_right_to(tv).equal = 0
        hl.layout.top_offset_to(tv).equal = 8
        hl.layout.align_bottom_with_superview.equal = -8
        hl.layout.height.max = 66
        hl.font = ('<system>', 13.0)
        hl.alignment = ui.ALIGN_CENTER
        hl.text_color = (0, 0, 0, 0.5)
        hl.number_of_lines = 2

        if is_in_hardware_keyboard_mode:
            tf.view.begin_editing()

        self._register_key_event_handlers()
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def __init__(self):
        global _datasource

        self.name = 'Drag & Drop'

        self.width = min(ui.get_window_size()[0] * 0.8, 700)
        self.height = ui.get_window_size()[1] * 0.8

        path = editor.get_path()
        if path:
            expanded_folder = os.path.dirname(path)
            files = tab.get_paths()
        else:
            expanded_folder = None
            files = None

        root_node = FileNode(os.path.expanduser('~/Documents'), ignore=ignore)
        _datasource = FolderPickerDataSource(root_node, expanded_folder, files)

        tv = ui.TableView(frame=self.bounds, flex='WH')
        tv.delegate = _datasource
        tv.data_source = _datasource
        tv.allows_multiple_selection = False
        tv.allows_selection = True
        tv.allows_multiple_selection_during_editing = False
        tv.allows_selection_during_editing = False
        tv.separator_color = 'clear'
        self.add_subview(tv)

        methods = [tableView_itemsForBeginningDragSession_atIndexPath_]
        protocols = ['UITableViewDragDelegate']
        DragDelegate = create_objc_class('DragDelegate', methods=methods, protocols=protocols)
        self._drag_delegate = DragDelegate.alloc().init()

        methods = [
            tableView_canHandleDropSession_,
            tableView_dropSessionDidUpdate_withDestinationIndexPath_,
            tableView_performDropWithCoordinator_
        ]
        protocols = ['UITableViewDropDelegate']
        DropDelegate = create_objc_class('DropDelegate', methods=methods, protocols=protocols)
        self._drop_delegate = DropDelegate.alloc().init()

        tv_objc = ObjCInstance(tv)
        tv_objc.setDragDelegate_(self._drag_delegate)
        tv_objc.setDropDelegate_(self._drop_delegate)

        def handle_escape():
            self.close()

        self._handlers = [
            register_key_event_handler(UIEventKeyCode.escape, handle_escape),
            register_key_event_handler(UIEventKeyCode.dot, handle_escape,
                                       modifier=UIKeyModifier.command)
        ]