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.frame = (10, 20, 32, 32) end_button.background_image = ui.Image.named('iob:close_circled_256') 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.frame = (self.width-dat_button.width-10, end_button.y, 32, 32) dat_button.background_image = ui.Image.named('iob:calendar_256') dat_button.action = self.dat_action self.add_subview(dat_button) # Label: titre titlbl = ui.Label(name='titlbl') titlbl.width = titlbl.height = 32 titlbl.frame = (10, end_button.y, w - end_button.width - dat_button.width - 3*10, 32) 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.frame = (10, titlbl.y + titlbl.height + 10 self.width - 20, 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, **kwargs): self.background_color = 'black' super().__init__(**kwargs) self.data = None self.labels = {} self.translate_track = [] self.hint = ui.Label( text='Play with gestures or swipe from this edge', alignment=ui.ALIGN_CENTER, text_color=(1,1,1,0.5), flex='TLB' ) self.hint.size_to_fit() self.hint.center = ( self.width - self.hint.height, self.height/2) self.hint.transform = ui.Transform.rotation(math.radians(-90)) self.add_subview(self.hint) self.zpd = ZoomPanDemo( frame=self.bounds, flex='WH') self.add_subview(self.zpd)
def make_label(self): label = ui.Label(name='label') label.width = 234 label.text = 'Post contains Python code?' label.text_color = 'steelblue' label.center = self.width * .20, 50 return label
def unilabel(self, params): self.unilabels.append([]) if self.kivy: from kivy.uix.label import Label self.unilabels[len(self.unilabels) - 1] = Label(pos = \ (params[0] * self.xratio, params[1] * self.yratio), \ size_hint=(1.0,1.0), halign="left", \ valign="bottom", text = params[4]) self.unilabels[len(self.unilabels) - 1].font_size = 17.5 * \ self.yratio self.unilabels[len(self.unilabels) - 1].bind(size= \ self.unilabels[len(self.unilabels) - 1].setter('text_size')) self.root.add_widget(self.unilabels[len(self.unilabels) - 1]) else: import ui self.unilabels[len(self.unilabels) - 1] = ui.Label(frame= \ (params[0] * self.xratio, (600 - params[1] - params[3]) * \ self.yratio, params[2] * self.xratio, params[3] * self.yratio)) self.unilabels[len(self.unilabels) - 1].text = params[4] self.unilabels[len(self.unilabels) - 1].text_color = 'white' self.unilabels[len(self.unilabels) - 1].alignment = \ ALIGN_LEFT = True self.unilabels[len(self.unilabels) - 1].font = ('<system>', 18 * \ self.xratio) self.root.add_subview(self.unilabels[len(self.unilabels) - 1])
def create_label(title, instance=None): global label_count label_count += 1 label_w = 175 label_h = 75 gap = 5 label_w_with_gap = label_w + gap label_h_with_gap = label_h + gap labels_per_line = math.floor((v.width - 2 * gap) / (label_w + gap)) left_margin = (v.width - labels_per_line * label_w_with_gap + gap) / 2 line = math.floor(label_count / labels_per_line) column = label_count - line * labels_per_line if instance is None: instance = ui.Label(text=title, text_color='white', alignment=ui.ALIGN_CENTER, number_of_lines=0) instance.background_color = 'grey' instance.tint_color = 'white' instance.frame = (left_margin + column * label_w_with_gap, gap + line * label_h_with_gap, label_w, label_h) v.add_subview(instance) return instance
def add_title(self, l_txt): t = ui.Label() t.font = txt_fnt, 25 t.text = l_txt t.alignment = ui.ALIGN_CENTER t.frame = width / 4, height * 0.04, width * 0.50, height * 0.05 self.add_subview(t)
def enter(): global player, life, scoreLabel bg = Background() game_world.add_object(bg, game_world.layer_bg) player = Player() game_world.add_object(player, game_world.layer_player) life = Life() bg.target = player label = ui.Label("Score: 0", 35, get_canvas_height() - 55, 45, ui.FONT_2) label.color = (255, 127, 127) ui.labels.append(label) scoreLabel = label global highscore highscore = Highscore() global music_bg, wav_bomb, wav_item music_bg = load_music('background.mp3') wav_bomb = load_wav('explosion.wav') wav_item = load_wav('item.wav') game_world.isPaused = isPaused ready_game() global gameOverImage gameOverImage = load_image('game_over.png')
def handle_taglist(self, bilingual_taglist, translated=True, horizontal_inset=1, vertical_inset=11): y = 0 for k, v in bilingual_taglist.items(): tagsview = TagsView(v, tag_type=k, width=self.width-90, translated=translated) tagsview.x = 90 + horizontal_inset tagsview.y = y self.add_subview(tagsview) h = tagsview.height if translated: text = translate_tag_type(k) else: text = k titleview = ui.Label( alignment=ui.ALIGN_CENTER, text=text, height=h, width=90, background_color='white', font=('<system>', 14) ) titleview.x = 0 titleview.y = y self.add_subview(titleview) y = y + h + vertical_inset self.add_subview(ui.View(background_color='#c8c7cc', frame=(0, y-6, self.width, 1))) return y - vertical_inset
def draw(self): self.height = 40 self.y = 40 * len( self.superview.subviews[:self.superview.subviews. index(self)]) + self.ydent * 40 self.x = 0 self.width = self.superview.width indent = 32 * self.level for s in self.subviews: self.remove_subview(s) self.arrow = ui.ImageView(frame=(indent, 4, 32, 32)) self.arrow.image = self.arrowOpened if self.open else self.arrowClosed self.add_subview(self.arrow) self.folder = ui.ImageView(frame=(indent + 32, 4, 32, 32)) self.folder.image = self.folderIcon self.add_subview(self.folder) self.text = ui.Label(frame=(indent + 75, 4, 300, 32)) self.text.text = str(os.path.abspath(self.path)).split('/')[-1] self.text.font = ('AvenirNext-Light', 20) self.add_subview(self.text) maxscroll = max(x.y + 40 for x in self.superview.subviews) self.superview.content_size = (0, maxscroll)
def make_score_label(self): label = ui.Label(name='score') label.font = (font_name, 32) label.width = self.width * 0.2 label.x = 20 label.y = 100 - label.height / 2 return label
def __init__(self): self.frame = (0, 0, 768, 768) self.bg_color = 'white' fast = ui.Label(frame=(10, 10, 200, 50), name='fast') slow = ui.Label(frame=(10, 70, 200, 50), name='slow') stop = ui.Button(frame=(150, 150, 80, 80), bg_color='red', name='stop') go = ui.Button(frame=(250, 150, 80, 80), bg_color='green', name='go') go.title = 'go' stop.title = 'stop' go.action = self.go stop.action = self.stop self.add_subview(fast) self.add_subview(slow) self.add_subview(stop) self.add_subview(go) self._stopped = True
def main_menu(): global main_menu_item main_menu_item = menu = PrettyMenu() menu.add( ui.Label('version %s' % features.get('app.version'), color=(255, 0, 0, 150), font=ui.consolefont), (0, 0)) new_game_button = MenuButton('New\ngame', new_game_menu) menu.left.add(new_game_button) load_game_button = MenuButton('Load\ngame', save.load_dialog) menu.left.add(load_game_button) if features.get('app.multiplayer'): menu.left.add(MenuButton('Connect', save.connect_dialog)) menu.right.add(MenuButton('Feed\nback', feedback)) menu.right.add( MenuButton( '', options.show_options, image=ui.load_image('data/user/options.png').convert_alpha())) menu.right.add(MenuButton('Exit', ui.back)) menu.right.add(ui.Spacing(0, 0)) ui.replace(menu)
def set_labels(self): sets = [{ 'name': 'center', 'text': '–' * 10, 'flex': 'WTB', 'frame': (0, self.height / 2 - 25 / 2, self.width, 25) }, { 'name': 'left', 'text': '•', 'flex': 'RTB', 'frame': (0, self.height / 2 - 25 / 2, 25, 25) }, { 'name': 'right', 'text': '•', 'flex': 'LTB', 'frame': (self.width - 25, self.height / 2 - 25 / 2, 25, 25) }] for i in sets: l = ui.Label(text_color=(.9, .9, .9), bg_color=(0, 0, 0), alignment=1, **i) self.add_subview(l)
def makeLabel(name, frame): label = ui.Label() label.text = name label.frame = frame label.font = ("Courier", 18) return label
def presentResultsPage(hospIdx): v = ui.View() window = ui.get_screen_size() v.background_color = '#f0ede6' v.alpha = 0.95 v.name = 'Results' v.width, v.height = window.x, window.y * .9 hospName = HospNamesL[hospIdx] if '-' in hospName: name1, name2 = hospName.split('-') name1 = name1[:-1] name2 = name2[1:] hospName = name1 + '\n' + name2 hospTitle = ui.Label('Hospital Title') hospTitle.number_of_lines = 3 hospTitle.alignment = ui.ALIGN_CENTER hospTitle.text = (hospName) hospTitle.font = ('<system-bold>', 18) hospTitle.text_color = '#3d3da1' hospTitle.scales_font = True #hospTitle.center = (v.width/2, v.height/10) #hospTitle.width, hospTitle.height = 150, 50 hospTitle.frame = (v.width / 6, v.height / 20, 250, 50) v.add_subview(hospTitle) v.present('sheet', hide_title_bar=True)
def VersionInStatusBar(version=False): # called at begin of a script with version=text # end version=False root, ext = os.path.splitext(sys.argv[0]) # script path without .py script_name = os.path.basename(root) # script name without the path app = objc_util.UIApplication.sharedApplication() w = objc_util.ObjCClass('UIApplication').sharedApplication().keyWindow() main_view = w.rootViewController().view() bar = app.statusBar() b = bar.bounds() sv = bar.subviews() for v in sv: if v._get_objc_classname().startswith(b'SUILabel_PY3'): v.removeFromSuperview() del v if not version: # remove version label return lbl = ui.Label() lbl.frame = (200, 2, 23, 16) lbl.text_color = 'blue' lbl.border_width = 1 lbl.border_color = 'blue' lbl.font = ('Courier-Bold', 12) lbl.text = script_name + ': version=' + version lbl.width = ui.measure_string(lbl.text, font=lbl.font)[0] lbl = lbl bar.addSubview_(lbl)
def getResults(): global loadedHospitals global HospTimes global exResults window = ui.get_screen_size() #loadedHospitals = proximityHospitals() loadedHospitals = exResults hospNames = getHospNames() hospTimes = getHospTimes() hospStates = getHospStates() getHospAddresses() getHospPhones() getHospIDs() #print(loadedHospitals) #updatehospNames(getHospNames()) titleBox = ui.Label('Results Title') titleBox.text = 'Treatment Near You' titleBox.scales_font = True titleBox.font = ('Avenir_Black', 24) titleBox.text_color = '#797c65' titleBox.frame = (window.x / 4, window.y / 18, 200, 50) titleBox.alignment = ui.ALIGN_CENTER resultsV.add_subview(titleBox) resultBoxes(hospNames, hospStates, hospTimes)
def _make_label(name, text, font, color): lb = ui.Label(name='head') lb.text = text lb.font = font lb.text_color = color lb.size_to_fit() return lb
def custom_label(self, l_txt, size, x, y, w, h): t = ui.Label() t.font = txt_fnt, size t.text = l_txt t.alignment = ui.ALIGN_CENTER t.frame = width * x, height * y, width * w, height * h self.add_subview(t)
def SaveInFiles(file, w, h, mode='sheet', popover_location=None, callback=None, title=None): # view needed for picker uiview = ui.View() uiview.frame = (0, 0, w, h) if mode == 'sheet': uiview.present('sheet', hide_title_bar=True) elif mode == 'popover': if popover_location: uiview.present('popover', hide_title_bar=True, popover_location=popover_location) else: return else: return url = nsurl(file) urls = [url] UIDocumentPickerMode = 2 # 2 = UIDocumentPickerModeExportToService (copy) # 3 = UIDocumentPickerModeMoveToService (move)⚠️ UIDocumentPickerViewController = ObjCClass( 'UIDocumentPickerViewController').alloc().initWithURLs_inMode_( urls, UIDocumentPickerMode) # Use new delegate class: delegate = MyUIDocumentPickerViewControllerDelegate.alloc().init() UIDocumentPickerViewController.delegate = delegate UIDocumentPickerViewController.setModalPresentationStyle_( 3) #currentContext UIDocumentPickerViewController.callback = callback # used by delegate UIDocumentPickerViewController.uiview = uiview # used by delegate # only to show it is possible to add controls on ViewController if title: l = ui.Label() wb = 100 # button width wl = uiview.width - 2 * wb # title width #l.border_width = 1 # for tests only l.text = title # find greatest font size allowing to display title between buttons fs = 32 while True: wt, ht = ui.measure_string(title, font=('Menlo', fs)) if wt <= wl: break fs = fs - 1 l.frame = (wb, 42, wl, 32) l.text_color = 'green' UIDocumentPickerViewController.view().addSubview_(ObjCInstance(l)) objc_uiview = ObjCInstance(uiview) SUIViewController = ObjCClass('SUIViewController') vc = SUIViewController.viewControllerForView_(objc_uiview) vc.presentViewController_animated_completion_( UIDocumentPickerViewController, True, None)
def __init__(self, fldname, dateval, action=None): calendar.setfirstweekday(calendar.SUNDAY) self.days = calendar.weekheader(3).split() self.width, self.height = ui.get_screen_size() cv = ui.View(name=fldname) cv.frame = (0, 95, self.width, 255) cv.background_color = 'yellow' cv.border_color = 'yellow' cv.border_width = 2 self.view = cv self.action = action prv_mth = ui.Button(title='<') prv_mth.frame = (5, 5, 50, 25) prv_mth.action = self.prev_pressed self.day_color = prv_mth.tint_color self.view.add_subview(prv_mth) nxt_mth = ui.Button(title='>') nxt_mth.frame = (56, 5, 50, 25) nxt_mth.action = self.next_pressed self.view.add_subview(nxt_mth) label = ui.Label(name='caltitle') self.caldate = dateval #dt.datetime.strptime(dateval,'%d/%m/%Y') self.curdate = curdate = dt.datetime.today() label.text = str(self.caldate.strftime('%B %Y')) label.frame = (107, 5, 200, 25) label.alignment = ui.ALIGN_CENTER self.view.add_subview(label) today_btn = ui.Button(title='Today') today_btn.frame = (self.width - 60, 5, 50, 25) today_btn.action = self.today_pressed self.view.add_subview(today_btn) self.firstdate = dt.date(self.caldate.year, self.caldate.month, 1) self.create_buttons() self.draw_calendar()
def makeCounterView(v, name, x, y, startValue, updateAction): lbl = ui.Label(frame=(x + 32, y, 64, 32)) lbl.border_width = 1 lbl.flex = '' lbl.name = 'labelCount' + name lbl.font = ('<System-Bold>', 18) lbl.alignment = ui.ALIGN_CENTER lbl.text = str(startValue) lbl.updateAction = updateAction v.add_subview(lbl) btn = ui.Button() btn.frame = (x, y, 33, 32) btn.border_width = 1 btn.flex = '' btn.name = "buttonMinus" + name btn.font = ('<System-Bold>', 18) btn.title = "-" btn.action = minusTapped btn.counter = lbl v.add_subview(btn) btn = ui.Button() btn.frame = (x + 95, y, 33, 32) btn.border_width = 1 btn.flex = '' btn.name = "buttonPlus" + name btn.font = ('<System-Bold>', 18) btn.title = "+" btn.action = plusTapped btn.counter = lbl v.add_subview(btn)
def inputbox(text, default='', finish=None, cancel=None): def _finish(): if text.label: graphics.stop_text_input() finish(text.label) ui.back(allow_override=False) else: _cancel() def reset(): text.set_text('') def _cancel(): graphics.stop_text_input() if cancel: cancel() ui.back(allow_override=False) graphics.start_text_input() container = ui.LinearLayoutWidget() container.back = _cancel container.add(ui.Label('%s' % text)) text = InputBox(default) container.add(text) container.focus = text panel = ui.HorizontalLayoutWidget(spacing=10) panel.add(ui.Button('OK', _finish)) panel.add(ui.Button('Reset', reset)) container.add(panel) ui.set(container)
def tableview_cell_for_row(self, tableview, section, row): style = style_list[row] cell = ui.TableViewCell() cell.bg_color = style_data[style] cell.border_width = 0.3 cell.border_color = 'white' cell_selected_icon = ui.ImageView() cell_selected_icon.image = ui.Image.named('iow:checkmark_round_24') cell_selected_icon.frame = (30,15,20,20) cell_bg = ui.View() cell_bg.frame = (0,0,200,50) cell_bg.bg_color = style_data[style] cell_bg.corner_radius = 6 cell_title = ui.Label() cell_title.frame = (0,0,200,50) cell_title.alignment = ui.ALIGN_CENTER cell_title.number_of_lines = 3 cell_title.font = ('<System-Bold>',20) cell_title.text_color = 'white' if style_mode == 'system_theme' else 'black' cell_title.text = style cell.content_view.add_subview(cell_bg) cell.content_view.add_subview(cell_title) if style_data[style] == SYSTEM_STYLE or style_data[style] == READER_STYLE: cell.content_view.add_subview(cell_selected_icon) return cell
def tableview_cell_for_row(self, tableview, section, row): source = sources_list[row] cell = ui.TableViewCell() cell.text_label.text = source cell.text_label.font = ('<System-Bold>',14) cell.text_label.text_color = '#006f82' cell_selected = ui.View() cell_selected.bg_color = '#f7ffc4' cell_selected.corner_radius = 15 cell_selected.border_width = 3 cell_selected.border_color = '#00c4a8' cell_logo = ui.View() cell_logo.frame = (5,8,5,cell.height-16) cell_logo.bg_color = 'red' cell_detail = ui.Label() cell_detail.frame = (100,0,140,50) cell_detail.number_of_lines = 3 cell_detail.bg_color = 'white' cell_detail.font = ('<System>',12) cell_detail.text_color = '#c400a7' cell_detail.text = sources_data[source]['lastChapter'] cell.selected_background_view = cell_selected cell.content_view.add_subview(cell_detail) if source == chapterview.source_name: cell.content_view.add_subview(cell_logo) return cell
def __init__(self, parent, title, text, stockimage, buttons=(), default=None): Dialog.__init__(self, parent, "", buttons, default) # hbox with image and contents hbox = ui.HBox() hbox.set_spacing(12) self.vbox.pack_start(hbox) self.vbox.set_spacing(24) # set up image if stockimage != None: image = ui.Image(stockimage, gtk.ICON_SIZE_DIALOG) image.set_alignment(0.5, 0) hbox.pack_start(image, False, False) # set up message self.contents = ui.VBox() self.contents.set_spacing(10) hbox.pack_start(self.contents) label = ui.Label( "<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s" % (util.escape_markup(title), text)) label.set_alignment(0, 0) label.set_selectable(True) self.contents.pack_start(label)
def __init__(self, subview_, table_, dt_table_, cwd_): self.subview = subview_ self.table = table_ self.table_items = ['Device1', 'Device2', 'Device3'] self.list_source = ui.ListDataSource(self.table_items) self.table.data_source = self.list_source self.table.delegate.action = self.select_device self.dt_table = dt_table_ self.dt_table_items = [ 'US/Eastern', 'US/Central', 'US/Mountain', 'US/Pacific', 'US/Alaska', 'US/Hawaii' ] self.dt_source = ui.ListDataSource(self.dt_table_items) self.dt_table.data_source = self.dt_source self.dt_table.delegate.action = self.select_time self.cwd_ = cwd_ self.selector = ui.Button(title='Choose a device to pair', action=self.save_device) self.selector.y = self.table.y - 30 self.selector.x = self.table.x - 10 self.selector.alignment = ui.ALIGN_LEFT self.selector.tint_color = 'white' self.subview.add_subview(self.selector) self.time_selector = ui.Button(title='Choose a timezone ', action=self.save_time) self.time_selector.y = self.dt_table.y - 30 self.time_selector.x = self.dt_table.x - 10 self.time_selector.tint_color = 'white' self.time_selector.alignment = ui.ALIGN_LEFT self.subview.add_subview(self.time_selector) self.current_device = ui.Label(text=self.fetch_value('dev'), font=('Arial-ItalicMT', 12)) self.current_device.x = self.table.x + 10 self.current_device.y = self.table.x + self.table.height - 10 self.current_device.width = self.table.width + 150 self.subview.add_subview(self.current_device) self.current_tz = ui.Label(text=self.fetch_value('tz'), font=('Arial-ItalicMT', 12)) self.current_tz.x = self.dt_table.x + 10 self.current_tz.y = self.dt_table.y + self.dt_table.height - 55 self.current_tz.width = self.dt_table.width + 150 self.subview.add_subview(self.current_tz)
def run_ui(): # import ui class MyView(ui.View): moves = [None for i in range(4)] # list containing function handles old = np.array((0, 0)) # old touch location def touch_began(self, touch): # Called when a touch begins. store old location self.old[:] = touch.location def touch_ended(self, touch): # Called when a touch ends. # compute vector from old to new touch u = np.array(touch.location) - self.old # first, determine whether x or y moved the most if abs(u[0]) > abs(u[1]): dir = 0 else: dir = 1 # then, determine sign if u[dir] > 0: dir += 2 if dir else 0 else: dir += 0 if dir else 2 # call the appropriate move function if u[0]**2 + u[1]**2 > 30**2: self.moves[dir](self) v = MyView(frame=(0, 0, 100, 140)) v.background_color = (0.98039215686, 0.9725490196, 0.93725490196) board = Board() board.add_tile() labels = np.empty_like(board.data, dtype=object) for i in range(board.data.shape[0]): for j in range(board.data.shape[1]): labels[i, j] = ui.Label() labels[i, j].flex = 'HWLRTB' labels[i, j].alignment = ui.ALIGN_CENTER labels[i, j].border_width = 1 labels[i, j].corner_radius = 2 labels[i, j].font = (GAME_FONT, 24) labels[i, j].text_color = 0.00, 0.00, 0.00 labels[i, j].frame = (100 / board.data.shape[1] * (j + .04), 100 / board.data.shape[0] * (i + .04), 100 / board.data.shape[1] * .92, 100 / board.data.shape[0] * .92) v.add_subview(labels[i, j]) _ui_setup(board, labels, v) for i in range(4): v.moves[i] = partial(_ui_move, board, labels, v, i) but = ui.ButtonItem() but.title = 'Auto Move' but.action = partial(_ui_move_auto, board, labels, v) v.right_button_items = [but] v.present()
def make_label(self, **kwargs): return ui.Label(**{ 'background_color': 1, 'border_color': 0.6, 'border_width': 0.7, 'frame': (0, 0, 100, 100), **kwargs })
def set_turn_button_enable(self, enabled): dialog_state = self.turn_loading_dialog.is_opened( ) if self.turn_loading_dialog else False if not enabled and not dialog_state: self.turn_loading_dialog = ui.set_dialog( ui.Label('ending turn...')) elif dialog_state and enabled: self.turn_loading_dialog.close()