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

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

项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def new_label(self):
        a_caption = 'Label' + '{:02d}'.format(self.count_objs)
        self.count_objs += 1
        mypage.unilabel((40, 240, 80, 20, a_caption))
        a_label = mypage.unilabels [-1]
        a_label.size_hint=(None,None)
        a_label.height = 20;
        if mypage.kivy:
            a_label.background_color = a_label.color
            a_label.bind(on_touch_down=self.touch_down)
            a_label.bind(on_touch_move=self.touch_move)
        else:
            a_label.touch_enabled = False
            a_label.pos = (a_label.x, a_label.y)
            a_label.color = a_label.background_color
        self.new_objs.append(a_label)
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def new_label(self):
        a_caption = 'Label' + '{:02d}'.format(self.count_objs)
        self.count_objs += 1
        mypage.unilabel((40, 240, 80, 20, a_caption))
        a_label = mypage.unilabels [-1]
        a_label.size_hint=(None,None)
        a_label.height = 20;
        if mypage.kivy:
            a_label.background_color = a_label.color
            a_label.bind(on_touch_down=self.touch_down)
            a_label.bind(on_touch_move=self.touch_move)
        else:
            a_label.touch_enabled = False
            a_label.pos = (a_label.x, a_label.y)
            a_label.color = a_label.background_color
        self.new_objs.append(a_label)
项目: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, default_user_name='Name'):
        self.name = 'Enter your username:'
        self.background_color = 0.40, 0.80, 1.00
        self.frame=(0, 0, 500, 500)
        self.label = ui.Label(frame=(12, 100, 2000, 55))
        self.label.text = 'What is your name?'
        self.label.text_color = 'black'
        self.label.font = ('Avenir-Black', 55)
        self.add_subview(self.label)
        self.text_field = ui.TextField(frame=(155, 175, 200, 32))
        self.text_field.text = default_user_name
        self.text_field.text_color = 'grey'
        self.text_field.clear_button_mode = 'while_editing'
        self.add_subview(self.text_field)
        button = ui.Button(background_color='white',
                   frame=(360, 175, 75, 36),
                   image=ui.Image.named('ionicons-arrow-right-a-32'))
        self.add_subview(button)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
            RootView.__init__(self)
            self.t1=ui.Label(frame=(0,60,400,20))
            self.t2=ui.Label(frame=(0,90,400,20))
            self.t3=ui.TextView( frame=(0,120,700,200),bg_color=(0.7,0.7,0.7,0.5))

            self.t3.text='textview for kb'
            # the first time the keyboard appears, get kbframe is wrong...
            #  so, show then hide keyboard.
            self.t3.begin_editing()
            ui.delay(self.t3.end_editing,0.5)
            # finally, show kbframe again
            ui.delay(self.t3.begin_editing,1.0)


            self.t1.text='touch to begin'
            [self.add_subview(s) for s in [self.t1,self.t2,self.t3]]
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
            RootView.__init__(self)
            self.t1=ui.Label(frame=(0,60,400,20))
            self.t2=ui.Label(frame=(0,90,400,20))
            self.t3=ui.TextView( frame=(0,120,700,200),bg_color=(0.7,0.7,0.7,0.5))

            self.t3.text='textview for kb'
            # the first time the keyboard appears, get kbframe is wrong...
            #  so, show then hide keyboard.
            self.t3.begin_editing()
            ui.delay(self.t3.end_editing,0.5)
            # finally, show kbframe again
            ui.delay(self.t3.begin_editing,1.0)


            self.t1.text='touch to begin'
            [self.add_subview(s) for s in [self.t1,self.t2,self.t3]]
项目: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()
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def add_waypoint(self):
    w = WayPointView(frame=(0,0,30,30))
    l = w['Label']
    self.waypoints.append(w)
    l.text=str(len(self.waypoints))
    l.text_color = 'black'
    l.font=('Arial Black', 16)
    w.background_color = '#a2c2ff' #
    self.add_subview(w)
    return w
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def remove_waypoint(self, wp_view):
    i = self.waypoints.index(wp_view)
    self.remove_subview(wp_view)
    del self.waypoints[i]
    for (i, wp) in enumerate(self.waypoints):
      wp['Label'].text=str(i+1)
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.corner_radius = self.height/2
    l = ui.Label()
    self.add_subview(l)
    l.frame = self.bounds
    l.flex = 'WH'
    l.name = 'Label'
    l.alignment = ui.ALIGN_CENTER
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def set_menu(self, menu_key, spec):
    menu_spec = spec[menu_key]
#    for v in self.menu.subviews:
#      self.menu.remove_subview(v)
    #top_y = 50
    x_increment = self.menu.width/(len(menu_spec)+1)
    dim = 0.55*x_increment
    for (i, (title, func)) in enumerate(menu_spec):
      btn = ui.Button()
      btn.title = title
      btn.action = func      
      btn.background_color = self.menu_color
      btn.tint_color = 'white'
      self.menu.add_subview(btn)
      btn.width = btn.height = dim
      btn.center = ((i+1)*x_increment, self.menu.height/4)
      btn.corner_radius = dim/2

#      label = list(section.keys())[0]
#      if isinstance(section[label], list):
#        l = ui.Label(text=label, text_color='black', background_color=(1,1,1,0.5), alignment=ui.ALIGN_CENTER, frame=(0, top_y, self.button_width, self.button_height))
#        #+self.button_gap)*(len(section[label])+1)))
#        self.menu.add_subview(l)
#        top_y += self.button_height + self.button_gap
#        for (title, action) in section[label]:
#          btn = self.menu_button(title, action, top_y)
#          self.menu.add_subview(btn)
#          btn.frame=(0, top_y, self.button_width, self.button_height)
#          top_y += self.button_height + self.button_gap
#      else:
#        btn = self.menu_button(label, section[label], top_y)
#        self.menu.add_subview(btn)
#        btn.frame=(0, top_y, self.button_width, self.button_height)
#        top_y += self.button_height + self.button_gap
项目:PhotoEditor    作者:philiplessner    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if self.name is not None:
            title_label = ui.Label(text=self.name,
                                   frame=(10, 0, 275, 25),
                                   alignment=ui.ALIGN_CENTER,
                                   font =('<system-bold>', 18))
            self.add_subview(title_label)
项目:PhotoEditor    作者:philiplessner    | 项目源码 | 文件源码
def __init__(self, slider_name, convert, action, valuefmt, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._m = convert['m']
        self._b = convert['b']
        self._valuefmt = valuefmt
        self.changed = action
        self.name = slider_name
        SLIDER_WIDTH = 200
        SLIDER_HEIGHT = 30
        SLIDER_TITLE_OFFSET = 25
        SLIDER_TITLE_WIDTH = 200
        SLIDER_TITLE_HEIGHT = 25
        SLIDER_VALUE_OFFSET = 10
        SLIDER_VALUE_HEIGHT = 25
        SLIDER_VALUE_WIDTH = 50
        self.border_width = 0
        self.border_color = 'black'
        self._slider = ui.Slider(frame=(0, SLIDER_TITLE_OFFSET, SLIDER_WIDTH, SLIDER_HEIGHT))
        self._slider.continuous = False
        self._slider.value = 0.5
        self._slider.action = self.update        
        slider_title = ui.Label(frame=(0, 0, SLIDER_TITLE_WIDTH, SLIDER_TITLE_HEIGHT))
        slider_title.text = slider_name
        slider_title.text_color = 'black'
        self._slider_valuelabel = ui.Label(frame=(SLIDER_WIDTH + SLIDER_VALUE_OFFSET, SLIDER_TITLE_OFFSET, SLIDER_VALUE_WIDTH, SLIDER_VALUE_HEIGHT))
        self._slider_valuelabel.text = str(0.5)
        self._slider_valuelabel.border_width = 1
        self._slider_valuelabel.border_color = 'black'
        self._slider_valuelabel.alignment = ui.ALIGN_CENTER
        self.add_subview(self._slider)
        self.add_subview(slider_title)
        self.add_subview(self._slider_valuelabel)
项目:PhotoEditor    作者:philiplessner    | 项目源码 | 文件源码
def __init__(self, initial_width, initial_height, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._initial_width = initial_width
        self._initial_height = initial_height
        self.frame = (10, 100, 275, 250)
        self.background_color = 'white'
        self.img_width = ui.TextField(frame=(10, 30, 100, 25),
                                      keyboard_type=ui.KEYBOARD_DECIMAL_PAD,
                                      text=str(initial_width),
                                      action=self.update_height)
        self.add_subview(self.img_width)
        width_label = ui.Label(frame=(10, 5, 150, 25), text='Image Width')
        self.add_subview(width_label)
        self.img_height = ui.TextField(frame=(150, 30, 100, 25),
                                       keyboard_type=ui.KEYBOARD_DECIMAL_PAD,
                                       text=str(initial_height),
                                       action=self.update_width)
        self.add_subview(self.img_height)
        height_label = ui.Label(frame=(150, 5, 150, 25), text='Image Height')
        self.add_subview(height_label)
        aspect_ratio = self._initial_width / self._initial_height
        self.aspect = ui.TextField(frame=(70, 100, 150, 25),
                                   text=str(aspect_ratio),
                                   keyboard_type=ui.KEYBOARD_DECIMAL_PAD,
                                   alignment=ui.ALIGN_CENTER,
                                   action=self.updatefrom_aspectratio)
        self.add_subview(self.aspect)
        aspect_label = ui.Label(frame=(70, 75, 150, 25), 
                                text='Aspect',
                                alignment=ui.ALIGN_CENTER)
        self.add_subview(aspect_label)
        self.save_button = ui.Button(frame=(175, 150, 50, 25), 
                                     title='Save',
                                     action=self.save)
        self.add_subview(self.save_button)
        self.cancel_button = ui.Button(frame=(30, 150, 50, 25), 
                                     title='Cancel',
                                     action=self.cancel)
        self.add_subview(self.cancel_button)
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
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])
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
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 = \
                ui.ALIGN_LEFT
            self.unilabels[len(self.unilabels) - 1].font = ('<system>', 18 * \
                self.yratio)
            self.root.add_subview(self.unilabels[len(self.unilabels) - 1])
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
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 = \
                ui.ALIGN_LEFT
            self.unilabels[len(self.unilabels) - 1].font = ('<system>', 18 * \
                self.yratio)
            self.root.add_subview(self.unilabels[len(self.unilabels) - 1])
项目:ccMVC    作者:polymerchm    | 项目源码 | 文件源码
def make_label(text, frame):
    label = ui.Label( )
    label.text = str(text)
    label.frame = frame
    label.text_color = 'black'
    label.border_color = 'black'
    label.alignment = ui.ALIGN_CENTER
    label.border_width = 1
    label.bring_to_front()
    return label
项目:pythonista-gestures    作者:mikaelho    | 项目源码 | 文件源码
def create_label(title):
    global label_count
    label_count += 1
    label_w = 175
    label_h = 75
    gap = 10
    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

    l = ui.Label(
      text=title, 
      background_color='grey',
      text_color='white',
      alignment=ui.ALIGN_CENTER,
      number_of_lines=0,
      frame=(
        left_margin+column * label_w_with_gap,
        gap+line * label_h_with_gap,
        label_w, label_h
    ))
    v.add_subview(l)
    return l
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def tableview_cell_for_row(self, tv, section, row):
        cell = ui.TableViewCell()
        entry = self.flat_entries[row]
        level = entry.level - 1
        image_view = ui.ImageView(frame=(44 + 20*level, 5, 34, 34))
        label_x = 44+34+8+20*level
        label_w = cell.content_view.bounds.w - label_x - 8
        if entry.subtitle:
            label_frame = (label_x, 0, label_w, 26)
            sub_label = ui.Label(frame=(label_x, 26, label_w, 14))
            sub_label.font = ('<System>', 12)
            sub_label.text = entry.subtitle
            sub_label.text_color = '#999'
            cell.content_view.add_subview(sub_label)
        else:
            label_frame = (label_x, 0, label_w, 44)
        label = ui.Label(frame=label_frame)
        if entry.subtitle:
            label.font = ('<System>', 15)
        else:
            label.font = ('<System>', 18)
        label.text = entry.title
        label.flex = 'W'
        cell.content_view.add_subview(label)
        if entry.leaf and not entry.enabled:
            label.text_color = '#999'
        cell.content_view.add_subview(image_view)
        if not entry.leaf:
            has_children = entry.expanded
            btn = ui.Button(image=ui.Image.named('CollapseFolder' if has_children else 'ExpandFolder'))
            btn.frame = (20*level, 0, 44, 44)
            btn.action = self.expand_dir_action
            cell.content_view.add_subview(btn)
        if entry.icon_name:
            image_view.image = ui.Image.named(entry.icon_name)
        else:
            image_view.image = None
        cell.selectable = entry.enabled
        return cell
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def make_header(cls):
        header = ui.Label(frame = (200, 19.5, 700, 116.5))
        header.text_color = 'white'
        header.text = 'Select A Character'
        header.font = ('AvenirNext-Heavy', 70)
        return header
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def remove(self, sender):
        label = self['Label']
        if label:
            self.remove_subview(label)
            self.labelcounter -= 1
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def add(self, sender, text='Labeltext'):
        self.labelcounter += 1
        label = ui.Label(name='Label')
        label.text = text
        label.x = label.y = self.labelcounter * 20
        self.add_subview(label)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
        self.view = ui.load_view('SpecialButton')
        self.view.present('fullscreen')
        self.label = ui.Label(frame=(120,100,100,100))
        self.btn = MyButtonClass(self.label)
        self.view.add_subview(self.btn)     #watch the order, first button and then the label
        self.view.add_subview(self.label)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
        w,h = ui.get_screen_size()
        self.ty = ui.Label()
        self.ty.text = 'Hello'
        self.ty.text_color = 'black'
        self.ty.font = ('<system>', 60)
        self.ty.frame = (0, 0, w, h*0.25)
        self.ty.bg_color = 'yellow'
        self.sv = ui.ScrollView()
        self.sv.width = w
        self.sv.height = h*0.25
        self.sv.content_size = (2*w, h*0.25)
        self.sv.add_subview(self.ty)
        self.add_subview(self.sv)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
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
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
        # Init
        self.views = []
        self.curview = None

        self.root = ui.View(name="Multipanel")

        self.close = ui.Button()
        self.close.name = "close"
        self.close.enabled = False
        self.close.image = ui.Image.named("ionicons-close-round-32")
        self.close.action = self.close_tapped
        self.root.add_subview(self.close)
        self.close.frame = self.root.width - 32, 0, 32, 32
        self.close.flex = "LB"

        self.tabs = ui.SegmentedControl()
        self.tabs.name = "tabs"
        self.tabs.enabled = False
        self.tabs.selected_index = -1
        self.tabs.segments = [PLACEHOLDER_TEXT]
        self.tabs.action = self.segment_changed
        self.root.add_subview(self.tabs)
        self.tabs.frame = 0, 0, self.root.width - self.close.width, self.tabs.height
        self.tabs.flex = "WB"

        self.placeholder = ui.View()
        self.placeholder.background_color = "lightgray"

        self.ph_label = ui.Label()
        self.ph_label.font = ("<system-bold>", 24)
        self.ph_label.text_color = "gray"
        self.ph_label.text = "No View Selected"
        self.placeholder.add_subview(self.ph_label)
        self.ph_label.size_to_fit()
        self.ph_label.center = self.placeholder.center
        self.ph_label.flex = "TBLR"

        self.update_view()
项目:Pythonista_scripts    作者:wizardofozzie    | 项目源码 | 文件源码
def main():
    global main_view
    delegate = MetadataDelegate.new()
    main_view = ui.View(frame=(0, 0, 400, 400))
    main_view.name = 'Barcode Scanner'
    session = AVCaptureSession.alloc().init()
    device = AVCaptureDevice.defaultDeviceWithMediaType_('vide')
    _input = AVCaptureDeviceInput.deviceInputWithDevice_error_(device, None)
    if _input:
        session.addInput_(_input)
    else:
        print('Failed to create input')
        return
    output = AVCaptureMetadataOutput.alloc().init()
    queue = ObjCInstance(dispatch_get_current_queue())
    output.setMetadataObjectsDelegate_queue_(delegate, queue)
    session.addOutput_(output)
    output.setMetadataObjectTypes_(output.availableMetadataObjectTypes())
    prev_layer = AVCaptureVideoPreviewLayer.layerWithSession_(session)
    prev_layer.frame = ObjCInstance(main_view).bounds()
    prev_layer.setVideoGravity_('AVLayerVideoGravityResizeAspectFill')
    ObjCInstance(main_view).layer().addSublayer_(prev_layer)
    label = ui.Label(frame=(0, 0, 400, 30), flex='W', name='label')
    label.background_color = (0, 0, 0, 0.5)
    label.text_color = 'white'
    label.text = 'Nothing scanned yet'
    label.alignment = ui.ALIGN_CENTER
    main_view.add_subview(label)
    session.startRunning()
    main_view.present('sheet')
    main_view.wait_modal()
    session.stopRunning()
    delegate.release()
    session.release()
    output.release()
    if found_codes:
        print 'All scanned codes:\n' + '\n'.join(found_codes)
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def __init__(self, container, state):
        self._container = container
        self._touch_began_location = None
        self._initial_container_frame = None
        self._container_superview = ObjCInstance(container).superview()

        label = LayoutProxy(ui.Label())
        label.font = ('<system>', 13.0)
        label.alignment = ui.ALIGN_CENTER
        label.text_color = get_theme_value('bar_title_color')
        label.touch_enabled = False
        self.add_subview(label)
        label.layout.align_left_with_superview.equal = 0
        label.layout.align_right_with_superview.equal = 0
        label.layout.align_center_y_with_superview.equal = 0
        self.title_label = label

        button = LayoutProxy(ui.Button(title='x', tint_color=get_theme_value('tint_color')))
        self.add_subview(button)
        button.layout.align_left_with_superview.equal = 0
        button.layout.align_top_with_superview.equal = 0
        button.layout.align_bottom_with_superview.equal = 0
        button.layout.width.equal = _OVERLAY_BAR_HEIGHT
        self.close_button = button

        button = LayoutProxy(ui.Button(title='-', tint_color=get_theme_value('tint_color')))
        self.add_subview(button)
        button.layout.align_right_with_superview.equal = 0
        button.layout.align_top_with_superview.equal = 0
        button.layout.align_bottom_with_superview.equal = 0
        button.layout.width.equal = _OVERLAY_BAR_HEIGHT
        self.collapse_button = button

        separator = LayoutProxy(ui.View(background_color=get_theme_value('separator_color')))
        self.add_subview(separator)
        separator.layout.height.equal = 1
        separator.layout.align_left_with_superview.equal = 0
        separator.layout.align_bottom_with_superview.equal = 0
        separator.layout.align_right_with_superview.equal = 0
        self.separator = separator

        self.update_appearance(state)
项目: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 tableview_cell_for_row(self, tv, section, row):
        if section == self._folder_section:
            item = self.items[row]
            node = item['node']
        else:
            item = self._files[row]
            node = None

        cell = ui.TableViewCell()

        cvb = cell.content_view.bounds

        x = 15 + cvb.x + item['level'] * 15

        if node and node.children_exists:
            image_view = ui.ImageView()
            image_view.frame = (x, 10, 24, 24)
            image_view.image = ui.Image.named(
                'iob:arrow_down_b_24' if node.path in self._expanded_node_paths else 'iob:arrow_right_b_24'
            )
            cell.content_view.add_subview(image_view)

        x += 24 + 8

        image_view = ui.ImageView()
        image_view.frame = (x, 10, 24, 24)
        image_view.image = ui.Image.named('iob:folder_24' if node else 'iob:document_24')
        cell.content_view.add_subview(image_view)

        x += 24 + 8

        title_label = ui.Label(flex='W')
        title_label.text = item['title']
        title_label.size_to_fit()
        title_label.frame = (
            x, cvb.y + (cvb.height - title_label.height) / 2.0,
            cvb.width - (x - cvb.x) - 8, title_label.height
        )
        cell.content_view.add_subview(title_label)

        separator = ui.View(flex='W')
        separator.background_color = (0, 0, 0, 0.05)
        x = title_label.frame.x - 12 - 8
        separator.frame = (
            x, cvb.y + cvb.height - 1,
            cvb.width - (x - cvb.x), 1
        )
        cell.content_view.add_subview(separator)

        cell_objc = ObjCInstance(cell)
        cell_objc.setSelectionStyle(0)

        return cell