def main_sample(): lst = ui.ListDataSource(['Item 1', 'Item 2', 'Item 3', 'Item 4']) table_view = ui.TableView(flex='WHLRTB') table_view.allows_selection = True table_view.allows_multiple_selection = False table_view.right_button_items = ui.ButtonItem(image=ui.Image.named("typb:Plus")), table_view.left_button_items = ui.ButtonItem(image=ui.Image.named('typb:Edit')), table_view.name = 'Table View Name' table_view.data_source = table_view.delegate = lst nav = ui.NavigationView(table_view) nav.navigation_bar_hidden = False nav.name = "Master List" nav.flex = "WHLRTB" nav.present('sheet')
def update_table(self, new_ac_res, new_etime_res): self.table.reload() new_sorted_etime = sorted(list(new_etime_res)) dt_list = [] orig_dt_list = [] for i in new_sorted_etime: dt_list.append(i.strftime("%b %d, %Y, %I:%M %p")) for i in new_etime_res: orig_dt_list.append(i.strftime("%b %d, %Y, %I:%M %p")) results = [] for i in dt_list: results.append(i + ' ' + str( round(new_ac_res[np.where( np.array(orig_dt_list) == i)[0][0]], 1)) + ' ppm') self.table.data_source = ui.ListDataSource(reversed(results))
def __init__(self, title, items, move_enabled, delete_enabled, done_button_title='Done'): self.was_canceled = True self.items = items self.view = ui.TableView() self.view.name = title self.view.editing = True done_button = ui.ButtonItem(title=done_button_title) done_button.action = self.done_action self.view.right_button_items = [done_button] ds = ui.ListDataSource(items) ds.move_enabled = move_enabled ds.delete_enabled = delete_enabled self.view.data_source = ds self.view.delegate = ds self.view.frame = (0, 0, 500, 500)
def __init__(self, title, items, multiple=False, done_button_title='Done'): self.items = items self.selected_item = None self.view = ui.TableView() self.view.name = title self.view.allows_multiple_selection = multiple if multiple: done_button = ui.ButtonItem(title=done_button_title) done_button.action = self.done_action self.view.right_button_items = [done_button] ds = ui.ListDataSource(items) ds.action = self.row_selected self.view.data_source = ds self.view.delegate = ds self.view.frame = (0, 0, 500, 500)
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()
def add_tag(sender=None, pop_loc=None): if not pop_loc: pop_loc = (0, 0) v = ui.TableView() v.data_source = ui.ListDataSource(TAGS) if sender: pass else: we = ui.WebView() v.delegate = TagDelegate(we.eval_js) v.name = "Add Tag" v.width = 350 v.height = 500 v.present("popover", popover_location=pop_loc) v.wait_modal()
def bt_okay_po_action(self, sender): if self.view_po['tf_new_category'].text != '': self.categories.append(self.view_po['tf_new_category'].text) lst = ui.ListDataSource(self.categories) self.view['tv_category'].data_source = lst self.view['tv_category'].delegate = lst lst.action = self.tableview_tapped_category self.view['tv_category'].reload() self.conn = sqlite3.connect('vocab.db') self.curs = self.conn.cursor() self.curs.execute("INSERT INTO categories(category) VALUES(?)", (self.view_po['tf_new_category'].text, )) self.conn.commit() self.curs.close() self.conn.close() self.view_po.close()
def update_page(self): """ Update the tasks currently in the page """ self.remove_subview(self.task_list) self.remove_subview(self.add) self.remove_subview(self.next_page) self.remove_subview(self.last_page) # Only display tasks_per_page tasks at a time start, end = self.page * self.tasks_per_page, (self.page + 1) * self.tasks_per_page self.task_list = ui.TableView(action=self.select_task, data_source=ui.ListDataSource(items=self.task_names[start:end]), corner_radius=10) self.add_subview(self.task_list) self.add_subview(self.add) self.add_subview(self.next_page) self.add_subview(self.last_page)
def connect(a,b): if sender.title == a: view_to_push = b pushed_view = ui.load_view(view_to_push) v.navigation_view.push_view(pushed_view) if sender.title == 'Web': web = pushed_view['webview1'] with open('Files/index.html','r') as infile: web.load_html(infile.read()) if sender.title=='File': table=pushed_view['view1']['tableview1'] table_items = os.listdir('./Files') # You can use a list or a class as the data source for the tableview list_source = ui.ListDataSource(table_items) table.data_source = list_source
def add_tag(sender): v = ui.TableView() v.data_source = ui.ListDataSource(tag_manager.TAGS) try: we = sender.superview.superview["contentContainer"][ "editor_view"]["WebEditor"]["web_view"] except IndexError as e: print exception_str(e) we = ui.WebView() v.delegate = tag_manager.TagDelegate(we.eval_js) v.name = "Add Tag" v.width = 350 v.height = 500 v.present("popover", popover_location=( sender.superview.x, sender.superview.y)) v.wait_modal()
def getDirListing(self, curpath, folders_only=False): try: all = os.listdir(curpath) except OSError: return folders = [ i + "/" for i in all if os.path.isdir(os.path.join(curpath, i)) ] files = [i for i in all if os.path.isfile(os.path.join(curpath, i))] if folders_only: all = ["../"] + folders else: all = ["../"] + folders + files lst = ui.ListDataSource(all) lst.font = ('Courier', 18) return lst
def select(list, current_id, dim=(500, 500)): popup = ui.TableView(frame=(0, 0, dim[0], dim[1])) def on_selected(sender): nonlocal current_id current_id = sender.selected_row popup.close() popup.data_source = ui.ListDataSource(list) popup.delegate = popup.data_source popup.data_source.action = on_selected popup.selected_row = (0, current_id) popup.present('sheet') popup.wait_modal() return current_id
def setup(self, theme): self.dir = TWITTERRIFIC_PATH % theme with open(self.dir, 'rb') as f: self.data = plistlib.readPlist(f) dataSource = ui.ListDataSource(sorted(self.data.keys())) dataSource.action = self.cell_tapped dataSource.delete_enabled = False v = self self.tableView = v['tableview1'] self.tableView.data_source = dataSource self.tableView.delegate = dataSource self.switch = v['switch1'] self.switch.action = self.switch_action self.switch.hidden = True self.setColorButton = v['button1'] self.setColorButton.action = self.set_color self.groupView = v['groupView'] self.pickerView = ColorPicker(frame=(self.groupView.frame)) self.pickerView.autoresizing = 'WH' self.groupView.add_subview(self.pickerView) self.slider1 = self.groupView['slider1'] self.slider1.action = self.slider_action self.slider2 = self.groupView['slider2'] self.slider2.action = self.slider_action self.slider3 = self.groupView['slider3'] self.slider3.action = self.slider_action self.colorModeSegmentedControl = v['segmentedcontrol1'] self.colorModeSegmentedControl.action = self.set_color_mode self.colorModeSegmentedControl.selected_index = 1 self.set_color_mode(self.colorModeSegmentedControl) self.textField = v['textfield1'] self.textField.delegate = MyTextFieldDelegate() self.tableView.data_source.tableview_did_select(self.tableView, 0, 0)
def history_present(self, history): """ Present a history popover. :param history: history to present :type history: ShHistory """ listsource = ui.ListDataSource(history.getlist()) listsource.action = self.history_popover_tapped table = ui.TableView() listsource.font = self.BUTTON_FONT table.data_source = listsource table.delegate = listsource table.width = 300 table.height = 300 table.row_height = self.BUTTON_FONT[1] + 4 table.present('popover') table.wait_modal()
def init_list(self): d = self.fileManager.get_current_dir() files = d[0] dirs = d[1] fdlist = [] for file_name, file_data in files.iteritems(): data = { "title": file_name, "image": "ionicons-document-text-24", "accessory_type": "none", "d_type": FILE, "d_data": file_data, "d_path": "/" + file_name } fdlist.append(data) for dir_name, dir_data in dirs.iteritems(): data = { "title": dir_name, "image": "ionicons-folder-24", "accessory_type": "disclosure_indicator", "d_type": FOLDER, "d_data": dir_data, "d_path": "/" + dir_name } fdlist.append(data) self.listview.data_source = ui.ListDataSource(fdlist) self.listview.data_source.tableview_cell_for_row =\ self.tableview_cell_for_row self.listview.reload() def reload_action(): self.init_list() add_act = AddAction(reload_action, self.listview, d, self.fileManager) add_btn = ui.ButtonItem( action=add_act.invoke, image=ui.Image.named("ionicons-ios7-compose-outline-24") ) edit_act = EditAction( reload_action, self.listview, d, self.fileManager) edit_btn = ui.ButtonItem( action=edit_act.invoke, image=ui.Image.named("ionicons-hammer-24") ) self.listview.right_button_items = [edit_btn, add_btn]
def load(self): self.app.activity_indicator.start() try: self.article_list = api.fetch_news_list() data = [{ 'title': i['title'], 'id': i['id'], 'accessory_type': 'disclosure_indicator'} for i in self.article_list['stories']] articles_listdatasource = ui.ListDataSource(data) articles_listdatasource.delete_enabled = False articles_listdatasource.action = self.article_item_tabbed self.view.data_source = articles_listdatasource self.view.delegate = articles_listdatasource self.view.reload() finally: self.app.activity_indicator.stop()
def update_info(self, id): d = self.mgr.proxy.d f = self.mgr.proxy.f size = d.get_size_chunks(id) self.info['nameLabel'].text = self.mgr.get_name(id) self.info['sizeLabel'].text = '%.2f Mb' % (d.get_size_bytes(id) / 1024.0 / 1024.0) prio = d.get_priority(id) self.show_torrent_priority(prio) self.info['prioritySlider'].value = 1.0 * prio / 3 files = [f.get_path(id, n) for n in xrange(d.get_size_files(id))] data = ui.ListDataSource(files) self.info['filesTableView'].delegate = data self.info['filesTableView'].data_source = data self.info['filesTableView'].reload() self.show_pause_button(d.is_active(id)) self.update_percents(id, size)
def newItem(sender): pview = ui.View() ptable = ui.TableView() ptable.flex = "WH" ptable.data_source = ui.ListDataSource([ "New folder", "New file", "Script with ui", "Scene with layers", "Basic scene" ]) ptable.delegate = NDelegate(table) sx, sy = ui.get_screen_size() x, y, w, h = view["nbutton"].frame pos = (x + (sx / 2 - view.width / 2) + w / 2, y + (sy / 2 - view.height / 2) + h) pview.add_subview(ptable) pview.width, pview.height = 300, 150 pview.present("popover", True, pos, True)
def make_time_view(): v = ui.View(frame=(0, 0, sz[0], sz[1] - banner)) v.name = 'time' v.background_color = 'white' done = ui.ButtonItem('Schedule') v.right_button_items = [done] tab = ui.TableView() tab.frame = (0, 0, sz[0], 150) lst = ui.ListDataSource(['time 1', 'time 2']) tab.data_source = lst tab.delegate = lst v.add_subview(tab) wid = 120 custip = ui.TextField() custip.frame = (20 + wid, 160, sz[0] - wid - 30, 36) custip.clear_button_mode = 'while_editing' custip.text = '1' custip.keyboard_type = ui.KEYBOARD_NUMBER_PAD custip.delegate = MyTextFieldDelegate(done) v.add_subview(custip) label = ui.Label() label.text = 'Number of runs' label.frame = (10, 160, wid + 10, 36) v.add_subview(label) custip = ui.TextField() custip.frame = (20 + wid, 206, sz[0] - wid - 30, 36) custip.clear_button_mode = 'while_editing' custip.text = '24' custip.keyboard_type = ui.KEYBOARD_DECIMAL_PAD custip.delegate = MyTextFieldDelegate(done) v.add_subview(custip) label = ui.Label() label.text = 'Length (hours)' label.frame = (10, 206, wid + 10, 36) v.add_subview(label) dt = ui.DatePicker() dt.frame = (0, 240, sz[0], sz[1] - 240) v.add_subview(dt) return v
def loadFolder(sender): selection = sender.items[sender.selected_row] path = os.path.join(sender.path, selection) if os.path.isdir(path): # Go a level deeper in the folder tree new_view = ui.TableView() new_view.width = width new_view.height = height new_view.name = selection new_data = ui.ListDataSource(os.listdir(path)) new_data.action = loadFolder new_data.path = path new_view.data_source = new_data new_view.delegate = new_data main.push_view(new_view) else: main.close() clipboard.set(path) return path
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()
def load_apps_tableview(self, items): self.tba = ui.TableView() self.right_button_items = [] b1 = ui.ButtonItem('Select App To Export Data To:', tint_color = 'black') b2 = ui.ButtonItem('Cancel', action = self.cancel_app_tbl_view, tint_color = 'red') self.right_button_items = [b2, b1] self.tba.width, self.tba.height = ui.get_screen_size() self.tba.height = self.tba.height -60 self.tba.data_source = ui.ListDataSource(items) self.tba.delegate = self.tba.data_source self.tba.data_source.font = ('<system-bold>', 11) self.tba.row_height = 30 self.tba.data_source.highlight_color = 'cyan' self.tba.data_source.text_color = 'blue' self.tba.data_source.delete_enabled = False self.tba.data_source.action = self.app_selected self.tba.scroll_enabled = True self.add_subview(self.tba)
def show_list_dialog(items=None, *args, **kwargs): items = items or [] # hmmmm thanks @ccc tbl = ui.TableView(**kwargs) tbl.data_source = ui.ListDataSource(items) selection = None class MyTableViewDelegate (object): def tableview_did_select(self, tableview, section, row): nonlocal selection selection = tableview.data_source.items[row] tableview.close() tbl.delegate = MyTableViewDelegate() tbl.present(style='sheet') tbl.wait_modal() # This method is what makes this a dialog(modal) return selection
def __init__(self, search_phrases, favcat_nums_titles, **kwargs): self.favcat_nums_titles = favcat_nums_titles self.background_color = 'white' self.update_interval = 0.1 self.width = kwargs.get('width', 603) self.height = kwargs.get('height', 44 * 4 + 10 + 29) tableview1 = ui.TableView(frame=(0, 0, self.width, 44 * 4), name='tableview1') self.add_subview(tableview1) self.lds = ui.ListDataSource(items=search_phrases) self['tableview1'].data_source = self.lds self['tableview1'].delegate = self.lds segmentedcontrol1 = ui.SegmentedControl( frame=(2, 44 * 4 + 10, self.width - 4, 29), name='segmentedcontrol1', segments=['Home', 'Watched', 'Favorites', 'Downloads'], action=self.show_aso) self.add_subview(segmentedcontrol1)
def fillFolderPopupValues(): global filePopupDialog templateA = ['aaa', 'bbb'] adventures = [] for entry in os.scandir("./"): if not entry.name.startswith('.') and not entry.is_file(): adventures.append(entry.name) tv = filePopupDialog['folderListUI'] tv.data_source = ui.ListDataSource(templateA) tv.data_source.items = adventures tv.action = selectFolderAction tv.data_source.delete_enabled = False tv.reload_data()
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 change_mode(sender): v = ui.TableView() v.data_source = ui.ListDataSource([{ "title": x } for x in list_themes()]) v.delegate = v.data_source def select_mode(sender): i = sender.items[sender.selected_row] if select_func: select_func(i) v.close() v.width = 200 v.height = 500 v.present(style="popover", hide_title_bar=True, popover_location=(300, 100)) v.data_source.action = select_mode
def __init__(self): self.present() self.name = 'SegNav' seg = ui.SegmentedControl() seg.action = self.seg_view_action seg.background_color = 'white' seg.flex = 'W' seg.height = 40 seg.segments = 'even', 'odd' seg.selected_index = 0 # set the highlight seg.width = self.bounds.w self.add_subview(seg) x, y, w, h = self.bounds self.table_view = ui.TableView() self.table_view.data_source = ui.ListDataSource(range(0, 42, 2)) self.table_view.flex = 'WH' self.table_view.frame = x, y + seg.height, w, h - seg.height self.add_subview(self.table_view)
def load(self): self.app.activity_indicator.start() try: categories_listdatasource = ui.ListDataSource( { 'title': category_name, 'accessory_type': 'disclosure_indicator' } for category_name in sorted(self.categories_dict.keys()) + ['***Update Cache***']) 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: print_msg('Failed to load Categories', e) finally: self.app.activity_indicator.stop()
def folder_picker(): #Initialize the folder picker home_dir = os.getcwd().split('Documents/')[0] + 'Documents/' top = ui.TableView() top.name = '~/Documents' top_data = ui.ListDataSource(next(os.walk(home_dir))[1]) top_data.action = loadFolder top_data.path = home_dir top.data_source = top_data top.delegate = top_data select_button = ui.ButtonItem(action=makeSelection, title='Select') main = ui.NavigationView(top) main.right_button_items = [select_button] main.current_view = home_dir return main