'reps': '3x10', 'weight_mikael': 0, 'weight_oskari': 0, }) self.tableview.reload() if __name__ == '__main__': exercises = tinysync.track([], name='gym-program') v = ui.View(background_color='black', ) day_table = ui.TableView( background_color='black', frame=v.bounds, flex='WH', ) day_source = DaySource(day_table, exercises) day_table.data_source = day_source day_table.delegate = day_source n = anchor.NavigationView(day_table, navigation_bar_hidden=False, background_color='black', title_color='black', tint_color='grey', bar_tint_color='black', frame=v.bounds, flex='WH')
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()
def __init__(self, w, h): global store self.width = w self.height = h # EKEventStore = calendar database store = ObjCClass('EKEventStore').alloc().init() # Once Pythonista has been authorized, this code does not need to be executed #------- begin of commented code #access_granted = threading.Event() #def completion(_self, granted, _error): # access_granted.set() #completion_block = ObjCBlock(completion, argtypes=[c_void_p, c_bool, c_void_p]) #store.requestAccessToEntityType_completion_(0, completion_block) #access_granted.wait() #------- end of commented #cal = ObjCClass('NSCalendar').currentCalendar() # Button: end end_button = ui.Button(name='end_button') #end_button.border_color = 'black' #end_button.border_width = 1 end_button.width = 32 end_button.height = 32 end_button.x = 10 end_button.y = 20 end_button.background_image = ui.Image.named('iob:close_circled_256') end_button.title = '' end_button.action = self.end_action self.add_subview(end_button) # Button: dates dat_button = ui.Button(name='dat_button') #dat_button.border_color = 'black' #dat_button.border_width = 1 dat_button.width = 32 dat_button.height = 32 dat_button.x = self.width - dat_button.width - 10 dat_button.y = end_button.y dat_button.background_image = ui.Image.named('iob:calendar_256') dat_button.title = '' dat_button.action = self.dat_action self.add_subview(dat_button) # Label: titre titlbl = ui.Label(name='titlbl') titlbl.width = w - end_button.width - dat_button.width - 3 * 10 titlbl.height = 32 titlbl.x = 10 titlbl.y = end_button.y titlbl.text = 'Add Alarm After Begin to Calendar Event' titlbl.alignment = ui.ALIGN_CENTER titlbl.font = ('Courier-Bold', 20) titlbl.text_color = 'blue' self.add_subview(titlbl) # TableView: Events evttab = ui.TableView() evttab.name = 'evttab' evttab.x = 10 evttab.y = titlbl.y + titlbl.height + 10 evttab.width = self.width - 20 evttab.height = self.height - evttab.y - 10 evttab.row_height = 20 evttab.border_color = 'black' evttab.border_width = 1 evttab.delegate = self self.add_subview(evttab)
def __init__(self,app,father): self.app=app self.father=father self.count_apps=0 self.count_categorys=0 self.count_stars=0 self.count_prices=0 self.count_totalValue=0 self.cfg_runtimes=0 self.cfg_notice=1 self.cfg_downloadimg=1 self.cfg_log=1 self.datasize_img=0 self.datasize_log=0 self.datasize_database=0 self.name="设置" self.flex="WHRLTB" self.fontcolor_pastal="#999999" self.fontcolor_deep="#4c4c4c" self.fontcolor_warnning="#cf0000" self.scrollView=ui.ScrollView() self.count_titleLabel=ui.Label() self.count_tableView=ui.TableView() self.count_appsLabel=ui.Label() self.count_starsLabel=ui.Label() self.count_categorysLabel=ui.Label() self.count_runtimesLabel=ui.Label() self.count_pricesLabel=ui.Label() self.count_totalValueLabel=ui.Label() self.count_tableView.add_subview(self.count_runtimesLabel) self.count_tableView.add_subview(self.count_appsLabel) self.count_tableView.add_subview(self.count_starsLabel) self.count_tableView.add_subview(self.count_categorysLabel) self.count_tableView.add_subview(self.count_pricesLabel) self.count_tableView.add_subview(self.count_totalValueLabel) self.scrollView.add_subview(self.count_titleLabel) self.scrollView.add_subview(self.count_tableView) self.setting_titleLabel=ui.Label() self.setting_tableView=ui.TableView() self.settingDelegate=SettingDelegate(self.app,self) self.setting_noticeBtn=ui.Switch() self.setting_downloadBtn=ui.Switch() self.setting_logBtn=ui.Switch() self.setting_tableView.add_subview(self.setting_noticeBtn) self.setting_tableView.add_subview(self.setting_downloadBtn) self.setting_tableView.add_subview(self.setting_logBtn) self.scrollView.add_subview(self.setting_titleLabel) self.scrollView.add_subview(self.setting_tableView) self.clear_titleLabel=ui.Label() self.clear_tableView=ui.TableView() self.clearDelegate=ClaerDelegate(self.app,self) self.datasize_imgLabel=ui.Label() self.datasize_logLabel=ui.Label() self.datasize_sumLabel=ui.Label() self.clear_tableView.add_subview(self.datasize_imgLabel) self.clear_tableView.add_subview(self.datasize_logLabel) self.clear_tableView.add_subview(self.datasize_sumLabel) self.scrollView.add_subview(self.clear_titleLabel) self.scrollView.add_subview(self.clear_tableView) self.add_subview(self.scrollView) self.loadData()
def __init__(self, _superview, *args, **kwargs): # ui.View kwargs kwargs.setdefault('bg_color', 'white') kwargs.setdefault('border_width', 1.0) kwargs.setdefault('border_color', '#e5e5e5') kwargs.setdefault('corner_radius', 3.5) kwargs.setdefault('name', 'ComboBox') # custom kwargs self.font = kwargs.pop('font', ('<System>', 20)) self.text_color = kwargs.pop('text_color', "black") self.highlight_color = kwargs.pop('highlight_color', 'grey') self.button_tint = kwargs.pop('button_tint', "grey") self.display_count = kwargs.pop('display_count', 5) self.selected_index = kwargs.pop('selected_index', 0) self.choices = kwargs.pop('choices', [""]) # init super ui.View.__init__(self, *args, **kwargs) x, y, w, h = self.frame row_sizes = [ ui.measure_string(i, font=self.font) for i in self.choices ] w = max([w] + [i[0] for i in row_sizes]) h = max([h] + [i[1] for i in row_sizes]) # button for the dropbox self.drop_button = ui.Button(name='drop_button', frame=(w - h - 3, 3, h, h - 6), image=ui.Image('iow:arrow_down_b_24'), tint_color=self.button_tint, action=self.do_dropbox) # label for selected item self.selected_label = ui.Label(name='selected_label', alignment=ui.ALIGN_CENTER, text=self.choices[self.selected_index], frame=(3, 3, w - self.drop_button.width - 6, h), corner_radius=self.corner_radius) # dropbox lbl_w = self.selected_label.width ds = ComboBoxDataSource(self.choices, self.font, self.text_color, self.bg_color, self.index_changed, self.selected_index, self.highlight_color) self.dropbox = ui.TableView(name='dropbox', bg_color=self.bg_color, data_source=ds, delegate=ds, selected_row=(0, self.selected_index), seperator_color=self.border_color, allows_selection=True, row_height=30, frame=(x, y + h - 1, lbl_w, self.display_count * h), border_color=self.border_color, border_width=self.border_width, corner_radius=self.corner_radius, hidden=True) # complete the lines on the table self.dropbox.objc_instance.setSeparatorInset_(UIEdgeInsets(0)) # clip to rounded corners obj = self.objc_instance obj.setClipsToBounds_(True) # add subviews self.add_subview(self.selected_label) self.add_subview(self.drop_button) _superview.add_subview(self.dropbox)
def __make_tv(self): self.__tv = ui.TableView() self.__tv.data_source = self.__lds self.__tv.delegate = self.__lds self.add_subview(self.__tv)
def __init__(self, items_toAdd, frame=None, tabs_contents=None, patient_id=None, extra_data=None): #SETUP VIEW self.view = ui.View() self.view.background_color = 'white' if frame: self.view.frame = frame else: self.view.frame = (0, 0, 500, 500) height = self.view.height width = self.view.width self.patient_id = patient_id #SETUP THE TOP SEGMENTED TABS AND CONTAINER self.tab_container = ui.View() self.tabs = ui.SegmentedControl() self.tab_container.frame = (0, 0, width, 50) self.tab_container.add_subview(self.tabs) self.tabs.frame = (10, 10, width - 20, self.tab_container.height - 10) self.tabs.segments = tabs_contents self.tabs.selected_index = 0 #SETUP EXTRA DATA CONTAINER self.extra_container = ui.View() self.extra_container.frame = (0, self.tab_container.height, width, 50) self.extra_container.background_color = 'white' self.extra_data = extra_data if self.extra_data: self.extra_container.add_subview(extra_data) if self.extra_data.name == 'todaytab': self.extra_data.selected_index = 0 self.extra_data.enabled = False self.extra_data.center = (self.extra_container.width * 0.5, self.extra_container.height * 0.5) #SETUP THE TABLE LISTING THE ITEMS self.table = ui.TableView() self.LDS = modListDataSource([2, 3, 4, 5]) self.LDS.accessory = 'detail_button' self.LDS.font = ('Courier', 16) self.table.data_source = self.table.delegate = self.LDS self.table.frame = (0, self.tab_container.height + self.extra_container.height + 10, width, height) #SETUP THE ADD BUTTON self.addButton = ui.Button() self.addButton.background_color = 'salmon' self.addButton.title = 'Add' bt_height = self.addButton.height = 60 self.addButton.frame = (0, height - bt_height, width, bt_height) #ADD ALL SUBVIEWS self.view.add_subview(self.tab_container) self.view.add_subview(self.extra_container) self.view.add_subview(self.table) self.view.add_subview(self.addButton) #SETUP UI ITEMS ACTIONS def parse_segments(sender): self.parse_segments() def add_item(sender): if self.patient_id: pt_id = self.patient_id self.add_item(self.items_toAdd, pt_id=pt_id) else: self.add_item(self.items_toAdd) def show_options(sender): show_all_options(self) def show_data(sender): show_full_data(self) self.tabs.action = parse_segments self.items_toAdd = items_toAdd self.addButton.action = add_item self.LDS.accessory_action = show_data self.LDS.action = show_options
if section == self.pydoc_updates_section_number: return 'Update PyDoc' if section == self.theme_section_number: return 'Themes' if section == self.websearch_section_number: return 'Manage Web Search' def tableview_title_for_footer(self, tableview, section): if section == self.pydoc_updates_section_number: return 'Current Version - v' + self.updater.currentVersion elif section == self.theme_section_number: return 'Current Theme - ' + self.theme_manager.currentTheme.themeName def open_url(self, url): UIApplication = ObjCClass('UIApplication') sharedApplication = UIApplication.sharedApplication() internalurl = NSURL.URLWithString_(ns(url)) sharedApplication.openURL_(internalurl) tv = ui.TableView('grouped') def get_view(show_docset_management_view, show_cheatsheet_management_view, show_usercontributed_management_view, theme_manager, show_stackoverflow_management_view,websearch_manager): w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'Settings' data = SettingsView(show_docset_management_view, show_cheatsheet_management_view, show_usercontributed_management_view, theme_manager, show_stackoverflow_management_view,websearch_manager) tv.delegate = data tv.data_source = data return tv
tableview.navigation_view.push_view(webview) def tableview_number_of_sections(self, tableview): return len(self.dates) def tableview_number_of_rows(self, tableview, section): return len(self.dates[self.date_indices[section]]) def tableview_cell_for_row(self, tableview, section, row): cell = ui.TableViewCell() cell.text_label.text = self.dates[self.date_indices[section]][row]['title'] return cell def tableview_title_for_header(self, tableview, section): return str(self.date_indices[section]) add_button_item = ui.ButtonItem('添加订阅', None, add_feed) table_view = ui.TableView() table_view.name = '订阅列表' table_view.allows_multiple_selection_during_editing = True table_view.data_source = feed_list_controller table_view.delegate = feed_list_controller navigation_view = ui.NavigationView(table_view) navigation_view.right_button_items = [add_button_item] navigation_view.name = 'RSS 阅读器' navigation_view.present('fullscreen')
slide_percent = self.detail.x / self.master.width self.master.alpha = slide_percent def touch_ended(self, touch): def slide_left(): self.detail.x = 0 self.master.alpha = 0 def slide_right(): self.detail.x = self.master.width self.master.alpha = 1 if self.x_movement == 'right': ui.animate(slide_right, duration=0.4) elif self.x_movement == 'left': ui.animate(slide_left, duration=0.4) master = ui.TableView() L = ui.ListDataSource(['A', 'B']) master.flex = 'WH' master.data_source = L master.delegate = L detail = ui.WebView() detail.load_url('http://www.google.com/') detail.flex = 'WH' detail.scales_page_to_fit = False a = SideMenuSlideView(master, detail)
get_code(key) return True except: return False def auto_reload(): global countdown while main_ui.on_screen or r: countdown -= 1 if countdown == 0: get_all_accounts() else: time_button_item.title = '%s' % str(countdown) main_ui.reload() time.sleep(1) countdown = 30 r = False main_ui = ui.TableView() main_ui.name = 'AUFPY' add_button_item = ui.ButtonItem() add_button_item.title = 'ADD' add_button_item.action = add_button_tapped time_button_item = ui.ButtonItem() time_button_item.title = '%s' % countdown main_ui.right_button_items = [add_button_item, time_button_item] # conn = ConnSqlite() get_all_accounts()
'UITableViewRowAction').rowActionWithStyle_title_handler_( 0, ns('Trash it!'), block_handler) action.setBackgroundColor(yellow) # return ns([]) <- crash # return ns([action]) <- crash #return None # ok return ns([action]).ptr def make_table_view_delegate(): methods = [tableView_editActionsForRowAtIndexPath_] protocols = ['UITableViewDelegate'] delegate = create_objc_class('CustomTableViewDelegate', methods=methods, protocols=protocols) return delegate.alloc().init() # # UITableView # table_view = ui.TableView(name='Custom Action', frame=(0, 0, 300, 480)) table_view.data_source = ui.ListDataSource(['Hallo', 'Hi', 'Ciao']) table_view_objc = ObjCInstance(table_view) table_view_objc.setDelegate(make_table_view_delegate()) table_view.present('sheet')
def setupsnippetslistview(self): dbo = snippetlistview(self.snippets, self.snippetselectaction) self.snippetslistview = ui.TableView() self.snippetslistview.data_source = dbo self.snippetslistview.delegate = dbo self.snippetslistview.right_button_items = [ui.ButtonItem(image=ui.Image.named('iob:ios7_plus_empty_32'),action=self.addsnippet)]
def tableview_number_of_sections(self, tableview): # Return the number of sections (defaults to 1) return 1 def tableview_number_of_rows(self, tableview, section): # Return the number of rows in the section return len(self.data) def tableview_cell_for_row(self, tableview, section, row): # Create and return a cell for the given section/row return make_cell(self.colors[row], self.data[row]) def tableview_title_for_header(self, tableview, section): # Return a title for the given section. # If this is not implemented, no section headers will be shown if section == 0: return 'Color table' def tableview_did_select(self, tableview, section, row): if section == 0: table_tapped((section, row, self.data[row], self.colors[row])) datasource = MyTableViewDataSource() datasource.action = table_tapped tv = ui.TableView(frame=(0,0, 400, 400)) tv.data_source = tv.delegate = datasource tv.present('sheet')
textfield.delegate = TextfieldDelegate() v.add_subview(textfield) refresh_button = ui.Button() refresh_button.image = ui.Image.named('iob:ios7_refresh_32') refresh_button.tint_color = '#21dc57' refresh_button.frame = (250, 3, 37, 37) refresh_button.action = clear_keywords refresh_button.enabled = False v.add_subview(refresh_button) rename_button = ui.Button() rename_button.title = '重名文件' rename_button.font = ('<System-Bold>', 14) rename_button.tint_color = '#000000' rename_button.frame = (295, 5, 70, 33) rename_button.bg_color = '#e6e6e6' rename_button.action = rename_file rename_button.enabled = False v.add_subview(rename_button) tableview = ui.TableView() tableview.frame = (0, 48, w, h) tableview.flex = 'WH' tableview.allows_selection = True tableview.data_source = TableViewDataSource() tableview.delegate = TableviewDelegate() v.add_subview(tableview) v.present()
def make_view(self): tv = ui.TableView() tv.data_source = ui.ListDataSource(_list) self.add_subview(tv) self.tv = tv tv.delegate = self
_ON_IPAD = platform.machine().startswith('iPad') desc_page = ui.View(flex='WH') desc_page.background_color = 0.8 desc_tv = ui.TextView(flex='W') desc_page.add_subview(desc_tv) desc_tv.editable = False desc_tv.font = ('AppleSDGothicNeo-Regular', 16) desc_tv.border_width = 1 psiclient = ui.View(flex='WH') psiclient.background_color = 'white' psiclient.name = 'Pythonista Script Index' psitable = ui.TableView(flex='WH') listsource = ui.ListDataSource(['Loading ...']) listsource.delete_enabled = False psitable.data_source = listsource psitable.delegate = listsource psiclient.add_subview(psitable) nav_view = ui.NavigationView(psiclient) nav_view.name = 'psiclient' if _ON_IPAD: psitable.width = 540 psitable.height = 575 else:
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.tv = ui.TableView(name='table') self.tv.flex = 'wh' self.add_subview(self.tv)
# coding: utf-8 # https://forum.omz-software.com/topic/2740/colors-for-listdatasource-items/6 import ui t = ui.TableView() t.background_color = 'black' t.tint_color = 'white' l = ui.ListDataSource(['One', 'Two']) l.text_color = 'cyan' l.highlight_color = 'blue' l.background_color = 'red' l.tint_color = 'green' t.data_source = l t.present() #============================== from ui import * #============================== self.background_color = None #============================== cell.background_color = self.background_color #============================== import ui
cell.border_width = 1 cell.bg_color = self.data[row] cell.text_label.alignment = 1 cell.text_label.font = ('<System-Bold>', 18) cell.text_label.text = self.data[row] return cell size = ui.get_screen_size() wd, ht = size view = ui.View() view.name = 'Color Names' view.frame = (0, 0, wd, ht) view.background_color = 'white' tv = ui.TableView() tv.frame = (0, 0, wd / 2.0, ht) tv.data_source = MyTableViewDataSource(data) view.add_subview(tv) tv1 = ui.TableView() tv1.frame = (wd / 2.0, 0, wd / 2.0, ht) # to make text black in 2nd table data1 = list(data) data1[-1] = 'black' tv1.data_source = MyTableViewDataSource(data1) view.add_subview(tv1) view.present('sheet') # --------------------
def __init__ (self): self.bg_color = SYSTEM_STYLE self.bookcase = ui.TableView() self.bookcase.bg_color = INFO_STYLE self.bookcase.name = '追书神器' self.bookcase.row_height = 80 self.bookcase.height = h-50 self.bookcase.data_source = BookCaseDataSource('local') self.bookcase.delegate = TableViewDelegate('local') self.refresh = ui.Label() self.refresh.name = 'refresh' self.refresh.frame = (w/2-30,80,60,12) self.refresh.font = ('<System-Bold>',12) self.refresh.text_color = 'red' self.refresh.text = '检查更新...' self.menubar = ui.View() self.menubar.frame = (0,h-50,w,50) self.button1 = ui.Button() self.button1.frame = (0,5,75,40) self.button1.tint_color = 'white' self.button1.image = ui.Image.named('typw:Search') self.button1.action = button1_tapped self.button2 = ui.Button() self.button2.frame = (75,5,75,40) self.button2.tint_color = 'white' self.button2.image = ui.Image.named('iow:ios7_bookmarks_32') self.button2.action = button2_tapped self.button3 = ui.Button() self.button3.frame = (150,5,75,40) self.button3.image = ui.Image.named('typw:Home') self.button3.tint_color = 'white' self.button3.action = button3_tapped self.button4 = ui.Button() self.button4.frame = (225,5,75,40) self.button4.image = ui.Image.named('iow:gear_b_32') self.button4.tint_color = 'white' self.button4.action = button4_tapped self.button5 = ui.Button() self.button5.frame = (300,5,75,40) self.button5.image = ui.Image.named('iow:ios7_close_32') self.button5.tint_color = 'white' self.button5.action = button5_tapped self.view = ui.NavigationView(self.bookcase) self.view.frame = (0,0,w,h-50) self.view.tint_color = 'white' self.view.title_color = 'white' self.network_status = ui.ActivityIndicator() self.network_status.center = (w/2,h/2) self.menubar.add_subview(self.button1) self.menubar.add_subview(self.button2) self.menubar.add_subview(self.button3) self.menubar.add_subview(self.button4) self.menubar.add_subview(self.button5) self.add_subview(self.menubar) self.add_subview(self.view) self.add_subview(self.network_status)
def __init__(self, cols, *args, **kwargs): """ Initialize all the variables, most importantly, initialize all of the viewable elements that will comprise the widget. :param cols: How many columns should be in the timer grid? Two to four suggested. Modify this by modifying the COLS cariable above. :param args: extra arguments can be passed, can be accessed through an indexed list, we won't need this :param kwargs: extra arguments can be passed with keywords, which can then be used to access them, we won't need this """ # Create an API variables object so we can access all of the variables from Toggl and Todoist self.api_vars = ApiVariables() # Setting up to craete the buttons to start the various timers, we need to do this here so we know how much # vertical space the widget will need. self.cols = cols self.row_height = 55 # Create a list of dictionaries, one for each timer, that includes the Toggl project name, id, and color self.timers = [{'title': p['name'], 'pid': p['id'], 'color': p['hex_color']} for p in self.api_vars.toggl_projects] # This sets the size of the widget, a frame size is set by (top right x, top right y, width, height) super().__init__(self, frame=(0, 0, 300, ceil(len(self.timers) / self.cols) * self.row_height + 50), *args, **kwargs) # ---TIMER SELECTION VIEW--- # # Creating the elements for the currently running timer, at the top of the widget # This will be set to the color of the project of the currently running Toggl timer, set color to a # placeholder self.current_color = ui.Label(title='', bg_color='#5f5f5f') self.add_subview(self.current_color) # This will be set to the name of the project of the currently running Toggl timer set no text displayed self.current_timer_name = ui.Label(text='', text_color='#fff', alignment=ui.ALIGN_CENTER) self.add_subview(self.current_timer_name) # This will be set to the time elapsed of the currently running Toggl timer, this button must be tapped to # update the elapsed time, set color to a placeholder self.current_time = ui.Button(title='', action=self.update_current_timer, bg_color='#fff', tint_color='#000000', corner_radius=9) self.add_subview(self.current_time) # Fill in placeholders and missing text values self.update_current_timer() # Actually creating the buttons, using the dictionaries created above, and adding them as subviews # '#55bcff' is the default color if for come reason none is provided. self.buttons = [] for s in self.timers: btn = ui.Button(title=s['title'], pid=s['pid'], action=self.timer_selected, bg_color=s.get('color', '#55bcff'), tint_color='#fff', corner_radius=9) self.add_subview(btn) self.buttons.append(btn) # ---TASK SELECTION VIEW--- # # Should the Task Selection View be displaying? Default is no self.task_selector = False # This variable keeps track of which Toggl project we've selected self.pid = -1 # These variables are for keeping track of the list of tasks associated with the currently selected Toggl # Project, again, these are associated like this: Toggl Project ---> Todoist Label of the same name self.tasks = [] self.task_names = [] # This is a big button that allows you to click anywhere outside the task selector window and associated # buttons to 'close' the Task Selection View (really just changes the value of self.task_selector) self.exit_task_selector = ui.Button(title='', action=self.task_selector_exit, bg_color='#818181', tint_color='#fff') self.add_subview(self.exit_task_selector) # The table that will display the list of tasks self.task_list = ui.TableView(action=self.select_task, data_source=ui.ListDataSource(items=self.task_names), corner_radius=10) self.add_subview(self.task_list) # The button to select a task, it will be red anf have a plus sign inside self.add = ui.Button(title='+', action=self.select_task, bg_color='#ea0000', tint_color='#fff', corner_radius=20) self.add_subview(self.add) # The buttons for page navigation, gray, with arrows in the direction they page self.next_page = ui.Button(title='>', change=1, action=self.change_page, bg_color='#5f5f5f', tint_color='#fff', corner_radius=20) self.last_page = ui.Button(title='<', change=-1, action=self.change_page, bg_color='#5f5f5f', tint_color='#fff', corner_radius=20) self.add_subview(self.next_page) self.add_subview(self.last_page) # The current page we're displaying self.page = 0 # Tasks per page, with is a function of how vertically tall the table view is. It is hardcoded because I'm lazy. self.tasks_per_page = int(self.height / 45)
def __init__(self, title, sections, done_button_title='Done'): self.was_canceled = True self.shield_view = None self.values = {} self.container_view = _FormContainerView() self.container_view.frame = (0, 0, 500, 500) self.container_view.delegate = self self.view = ui.TableView('grouped') self.view.flex = 'WH' self.container_view.add_subview(self.view) self.container_view.name = title self.view.frame = (0, 0, 500, 500) self.view.data_source = self self.view.delegate = self self.cells = [] self.sections = sections for section in self.sections: section_cells = [] self.cells.append(section_cells) items = section[1] for i, item in enumerate(items): cell = ui.TableViewCell('value1') icon = item.get('icon', None) tint_color = item.get('tint_color', None) if tint_color: cell.tint_color = tint_color if icon: if isinstance(icon, str) or isinstance(icon, unicode): icon = ui.Image.named(icon) if tint_color: cell.image_view.image = icon.with_rendering_mode( ui.RENDERING_MODE_TEMPLATE) else: cell.image_view.image = icon title_color = item.get('title_color', None) if title_color: cell.text_label.text_color = title_color t = item.get('type', None) key = item.get('key', item.get('title', str(i))) item['key'] = key title = item.get('title', '') if t == 'switch': value = item.get('value', False) self.values[key] = value cell.text_label.text = title cell.selectable = False switch = ui.Switch() w, h = cell.content_view.width, cell.content_view.height switch.center = (w - switch.width / 2 - 10, h / 2) switch.flex = 'TBL' switch.value = value switch.name = key switch.action = self.switch_action if tint_color: switch.tint_color = tint_color cell.content_view.add_subview(switch) elif t == 'text' or t == 'url' or t == 'email' or t == 'password' or t == 'number': value = item.get('value', '') self.values[key] = value placeholder = item.get('placeholder', '') cell.selectable = False cell.text_label.text = title label_width = ui.measure_string( title, font=cell.text_label.font)[0] if cell.image_view.image: label_width += min(64, cell.image_view.image.size[0] + 16) cell_width, cell_height = cell.content_view.width, cell.content_view.height tf = ui.TextField() tf_width = max(40, cell_width - label_width - 32) tf.frame = (cell_width - tf_width - 8, 1, tf_width, cell_height - 2) tf.bordered = False tf.placeholder = placeholder tf.flex = 'W' tf.text = value tf.text_color = '#337097' if t == 'text': tf.autocorrection_type = item.get( 'autocorrection', None) tf.autocapitalization_type = item.get( 'autocapitalization', ui.AUTOCAPITALIZE_SENTENCES) tf.spellchecking_type = item.get('spellchecking', None) if t == 'url': tf.keyboard_type = ui.KEYBOARD_URL tf.autocapitalization_type = ui.AUTOCAPITALIZE_NONE tf.autocorrection_type = False tf.spellchecking_type = False elif t == 'email': tf.keyboard_type = ui.KEYBOARD_EMAIL tf.autocapitalization_type = ui.AUTOCAPITALIZE_NONE tf.autocorrection_type = False tf.spellchecking_type = False elif t == 'number': tf.keyboard_type = ui.KEYBOARD_NUMBERS tf.autocapitalization_type = ui.AUTOCAPITALIZE_NONE tf.autocorrection_type = False tf.spellchecking_type = False elif t == 'password': tf.secure = True tf.clear_button_mode = 'while_editing' tf.name = key tf.delegate = self cell.content_view.add_subview(tf) elif t == 'check': value = item.get('value', False) group = item.get('group', None) if value: cell.accessory_type = 'checkmark' cell.text_label.text_color = cell.tint_color cell.text_label.text = title if group: if value: self.values[group] = key else: self.values[key] = value elif t == 'date' or t == 'datetime' or t == 'time': value = item.get('value', datetime.datetime.now()) if type(value) == datetime.date: value = datetime.datetime.combine( value, datetime.time()) if type(value) == datetime.time: value = datetime.datetime.combine( value, datetime.date.today()) date_format = item.get('format', None) if not date_format: if t == 'date': date_format = '%Y-%m-%d' elif t == 'time': date_format = '%H:%M' else: date_format = '%Y-%m-%d %H:%M' item['format'] = date_format cell.detail_text_label.text = value.strftime(date_format) self.values[key] = value cell.text_label.text = title else: cell.selectable = False cell.text_label.text = item.get('title', '') section_cells.append(cell) done_button = ui.ButtonItem(title=done_button_title) done_button.action = self.done_action self.container_view.right_button_items = [done_button]
def action(sender): set_view_text(tableview1.data_source.items[sender.selected_row]) textview1 = ui.TextView(name='textview1', frame=(w * .3, 0, w * .7, h * .9), flex='WH', text="Pista Tips", border_width=1, border_color=0, font=('<system>', 15)) tableview1 = ui.TableView(name='tableview1', frame=(0, 0, w * .3, h * .9), flex='HR', border_width=1, border_color=0, row_height=h / 20) tableview1_items = sorted(datadict) list_source = ui.ListDataSource(tableview1_items) list_source.font = ('<system>', 13) tableview1.data_source = tableview1.delegate = list_source tableview1.data_source.action = action root_view.add_subview(tableview1) root_view.add_subview(textview1) nav_view = ui.NavigationView(root_view) nav_view.present(hide_title_bar=True) # --------------------
def __init__(self, title, sections, done_button_title='Done', font=None): self.was_canceled = True #self.was_canceled = False self.shield_view = None self.values = {} self.container_view = _FormContainerView() self.container_view.frame = (0, 0, 500, 500) self.container_view.delegate = self self.view = ui.TableView('grouped') self.view.flex = 'WH' self.container_view.add_subview(self.view) self.container_view.name = title self.view.frame = (0, 0, 500, 500) self.view.data_source = self self.view.delegate = self self.cells = [] self.tf_ramq = 'xxxxxxxxxxxx' self.sections = sections for section in self.sections: section_cells = [] self.cells.append(section_cells) items = section[1] for i, item in enumerate(items): cell = ui.TableViewCell('value1') icon = item.get('icon', None) tint_color = item.get('tint_color', None) if font: cell.text_label.font = font if tint_color: cell.tint_color = tint_color if icon: if isinstance(icon, basestring): icon = ui.Image.named(icon) if tint_color: cell.image_view.image = icon.with_rendering_mode( ui.RENDERING_MODE_TEMPLATE) else: cell.image_view.image = icon title_color = item.get('title_color', None) if title_color: cell.text_label.text_color = title_color t = item.get('type', None) key = item.get('key', item.get('title', str(i))) item['key'] = key title = item.get('title', '') if t == 'segmented': value = item.get('value', '') self.values[key] = value #bgcolor = 0.9 #Set up cell cell.selectable = False cell.text_label.text = title label_width = ui.measure_string( title, font=cell.text_label.font)[0] cell_width, cell_height = cell.content_view.width, cell.content_view.height #cell.background_color= bgcolor #Set up scroll view scroll = ui.ScrollView() scroll_width = max(40, cell_width - label_width - 32) scroll.frame = (cell_width - scroll_width - 8, 1, scroll_width, cell_height - 2) scroll.flex = 'W' #scroll_width = max(40, cell_width - label_width ) #scroll.frame = (cell_width - scroll_width+40, 1, scroll_width, cell_height-2) scroll.shows_horizontal_scroll_indicator = False #scroll.background_color = bgcolor #Set up segment segment = ui.SegmentedControl() choices = item.get('choice', '').split("|") segment.segments = choices if value != '': segment.selected_index = choices.index(value) #segment.value = value segment.name = key segment.action = self.segment_action segment.frame = (0, 0, len(segment.segments) * 65, scroll.height) #Combining SUBVIEWS scroll.content_size = (len(segment.segments) * 65, scroll.height) scroll.add_subview(segment) cell.content_view.add_subview(scroll) elif t == 'photo': value = item.get('value', False) self.values[key] = value cell.text_label.text = title cell.selectable = False photo_button = ui.Button() photo_button.name = key show_photo = ui.Button() show_photo.name = key label_width = ui.measure_string( title, font=cell.text_label.font)[0] cell_width, cell_height = cell.content_view.width, cell.content_view.height ph_width = max(40, cell_width - label_width - 32) photo_button.frame = (cell_width - ph_width - 8, 1, ph_width / 3, cell_height - 2) show_photo.frame = (cell_width - ph_width / 2, 1, ph_width / 2, cell_height - 2) photo_button.flex = 'W' photo_button.background_color = 0.9 show_photo.background_color = 0.95 photo_button.title = 'Take picture' show_photo.title = 'Show picture' cell.content_view.add_subview(photo_button) cell.content_view.add_subview(show_photo) photo_button.action = self.take_photo #photo_button.action = self.photoBooth show_photo.action = self.photo_quicklook elif t == 'switch': value = item.get('value', False) self.values[key] = value cell.text_label.text = title cell.selectable = False switch = ui.Switch() w, h = cell.content_view.width, cell.content_view.height switch.center = (w - switch.width / 2 - 10, h / 2) switch.flex = 'TBL' switch.value = value switch.name = key switch.action = self.switch_action if tint_color: switch.tint_color = tint_color cell.content_view.add_subview(switch) elif t == 'text' or t == 'url' or t == 'email' or t == 'password' or t == 'number': value = item.get('value', '') self.values[key] = value placeholder = item.get('placeholder', '') cell.selectable = False cell.text_label.text = title label_width = ui.measure_string( title, font=cell.text_label.font)[0] if cell.image_view.image: label_width += min(64, cell.image_view.image.size[0] + 16) cell_width, cell_height = cell.content_view.width, cell.content_view.height tf = ui.TextField() tf.name = key if tf.name == 'fname': self.tf_fname = tf if tf.name == 'lname': self.tf_lname = tf if tf.name == 'ramq': self.tf_ramq = tf tf_width = max(40, cell_width - label_width - 32) tf.frame = (cell_width - tf_width - 8, 1, tf_width, cell_height - 2) tf.bordered = False tf.placeholder = placeholder tf.flex = 'W' tf.text = value tf.text_color = '#337097' if t == 'text': tf.autocorrection_type = item.get( 'autocorrection', None) tf.autocapitalization_type = item.get( 'autocapitalization', ui.AUTOCAPITALIZE_SENTENCES) tf.spellchecking_type = item.get('spellchecking', None) if t == 'url': tf.keyboard_type = ui.KEYBOARD_URL tf.autocapitalization_type = ui.AUTOCAPITALIZE_NONE tf.autocorrection_type = False tf.spellchecking_type = False elif t == 'email': tf.keyboard_type = ui.KEYBOARD_EMAIL tf.autocapitalization_type = ui.AUTOCAPITALIZE_NONE tf.autocorrection_type = False tf.spellchecking_type = False elif t == 'number': tf.keyboard_type = ui.KEYBOARD_NUMBERS tf.autocapitalization_type = ui.AUTOCAPITALIZE_NONE tf.autocorrection_type = False tf.spellchecking_type = False elif t == 'password': tf.secure = True tf.clear_button_mode = 'while_editing' tf.name = key tf.delegate = self cell.content_view.add_subview(tf) elif t == 'check': value = item.get('value', False) group = item.get('group', None) if value: cell.accessory_type = 'checkmark' cell.text_label.text_color = cell.tint_color cell.text_label.text = title if group: if value: self.values[group] = key else: self.values[key] = value elif t == 'date' or t == 'datetime' or t == 'time': value = item.get('value', datetime.datetime.now()) if type(value) == datetime.date: value = datetime.datetime.combine( value, datetime.time()) if type(value) == datetime.time: value = datetime.datetime.combine( value, datetime.date.today()) date_format = item.get('format', None) if not date_format: if t == 'date': date_format = '%Y-%m-%d' elif t == 'time': date_format = '%H:%M' else: date_format = '%Y-%m-%d %H:%M' item['format'] = date_format cell.detail_text_label.text = value.strftime(date_format) self.values[key] = value self.ramq_dob = '' cell.text_label.text = title else: cell.selectable = False cell.text_label.text = item.get('title', '') section_cells.append(cell) done_button = ui.ButtonItem(title=done_button_title) done_button.action = self.done_action self.container_view.right_button_items = [done_button]
def tableview_number_of_rows(self, tableview, section): return len(self.data) def tableview_cell_for_row(self, tableview, section, row): cell = ui.TableViewCell() label = ui.Label() label.text = self.data[row]['value'] label.number_of_lines = 0 label_objc = ObjCInstance(label) UIViewAutoresizingNone = 0 UIViewAutoresizingFlexibleLeftMargin = 1 << 0 UIViewAutoresizingFlexibleWidth = 1 << 1 UIViewAutoresizingFlexibleRightMargin = 1 << 2 UIViewAutoresizingFlexibleTopMargin = 1 << 3 UIViewAutoresizingFlexibleHeight = 1 << 4 UIViewAutoresizingFlexibleBottomMargin = 1 << 5 label_objc.autoresizeMask = UIViewAutoresizingFlexibleWidth + UIViewAutoresizingFlexibleTopMargin + UIViewAutoresizingFlexibleBottomMargin + UIViewAutoresizingFlexibleHeight label.height = self.data[row]['height'] cell.content_view.add_subview(label) return cell tv = ui.TableView() tv.data_source = TableData() tv_objc = ObjCInstance(tv) tv_objc.rowHeight = -1.0 #UITableViewAutomaticDimension tv_objc.estimatedRowHeight = 40.0 tv.present()
for item in collection: r = list(regex.finditer(accessor(item))) if r: best = min(r, key=lambda x: len(x.group(1))) suggestions.append( (len(best.group(1)), best.start(), accessor(item), item)) if sort_results: return (z[-1] for z in sorted(suggestions)) else: return (z[-1] for z in sorted(suggestions, key=lambda x: x[:2])) root = ui.View() symbol_table = ui.TableView( background_color='black', frame=root.bounds, flex='WH', ) data_source = symbol_table.data_source = SymbolSource(root, symbol_table) search_field = ui.TextField( frame=(8, 8, root.width - 16, 40), flex='W', clear_button_mode='always', delegate=data_source, ) symbol_table.y = search_field.height + 16 symbol_table.height -= (search_field.height + 16) root.add_subview(search_field) root.add_subview(symbol_table)
main = ui.View() main.frame = (0, 0, w, h * 0.9) main.name = 'Haiku' textview1 = ui.TextView() textview1.frame = (w * 0.25, 0, w * 0.75, h * 0.9) textview1.flex = 'WH' textview1.name = 'textview1' textview1.text = "Haiku For You" textview1.background_color = 'slateblue' textview1.text_color = 'white' textview1.font = ('Avenir-Light', 16) tableview1 = ui.TableView() tableview1.frame = (0, 0, w * 0.25, h * 0.9) tableview1.flex = 'HR' tableview1.name = 'tableview1' main.add_subview(tableview1) main.add_subview(textview1) table = main['tableview1'] table_items = dictsample list_source = ui.ListDataSource(table_items) list_source.font = ('Futura-CondensedMedium', 16) list_source.text_color = 'darkblue' table.data_source = table.delegate = list_source table.data_source.action = action
returns = [] input = dialogs.input_alert('Input Keyword') for i in items: if i['title'].lower().find(input.lower()) != -1: returns += [i] table.data_source.items = returns def refreshApp(Sender): table.data_source.items = items if __name__ == '__main__': apps = getAppsOfUserOnly() list = sorted(apps, key = lambda x: x.nameForSort, reverse = False) items = [] for i in list: items += [{'title': i.name, 'image': ui.Image.from_data(i.icon), 'app': i}] data = ui.ListDataSource(items) table = ui.TableView() table.name = 'All Apps' table.data_source = data table.right_button_items = [ui.ButtonItem(image=ui.Image.named('iob:ios7_refresh_empty_32'), action=refreshApp), ui.ButtonItem(image=ui.Image.named('iob:ios7_search_24'), action=findApp)] table.delegate = TableViewDelegate navigation = ui.NavigationView(table) navigation.name = 'URL Schemes Viewer' navigation.tint_color = 'black' navigation.present('fullscreen')
# https://forum.omz-software.com/topic/3716/action-on-cell-when-clicked-in-table/3 import ui import sys # Create a tableview, with data self.tv = ui.TableView() self.tv.row_height = 30 self.tv.data_source = MyTableViewDataSource(self.tv.row_height) self.tv.delegate = MyTableViewDelegate() # Update tableview data self.tv.data_source.items = sorted(self.c.read_vouchers(), key=itemgetter(0), reverse=True) # Do not allow selection on the TableView #self.tv.allows_selection = False self.tv.allows_selection = True # Add the table self.add_subview(self.tv) # Define the class for the Table Data class MyTableViewDataSource(object): def __init__(self, row_height): self.row_height = row_height self.width = None def tableview_number_of_rows(self, tableview, section):