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

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

项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def menu_button(self, title, action, diameter, center):
    btn = ui.Button(
      title=title,
      action=action,
      tint_color='white',
      background_color=self.menu_color
    )
    btn.width = btn.height = diameter
    btn.corner_radius = diameter/2
    btn.center = center
    self.menu.add_subview(btn)

#  def menu_player_field(self, action, name, text, corner, width):
#    (x,y) = corner
#    fld = ui.TextField(
#      action=action,
#      name=name,
#      text=text,
#      tint_color='white',
#      corner_radius=5,
#      background_color=self.menu_color,
#      frame=(x, y, width, 30)
#    )
#    self.menu.add_subview(fld)
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def __init__(self, spec):
    super().__init__()
    self.present('full_screen', hide_title_bar=True)

    spec.append(('Cancel', None))
    menu_content_height = len(spec) * (self.button_height + self.button_gap)
    self.menu_height = min(menu_content_height, self.menu_max_height)

    self.btns = []

    for (i, (action_title, action_func)) in enumerate(spec):
      action_wrapper = functools.partial(self.func_wrapper, action_func)

      bg_color = '#e9e1e1' if action_func else '#4e4b4b'
      tnt_color = 'black' if action_func else 'white'
      btn = ui.Button(
        title=action_title,
        action=action_wrapper,
        tint_color=tnt_color,
        background_color=bg_color,
        corner_radius=5
      )
      self.add_subview(btn)
      self.btns.append(btn)
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def new_button(self):

        a_caption = 'Button' + '{:02d}'.format(self.count_objs)
        self.count_objs += 1
        mypage.unibutton((40, 80, 80, 40, a_caption))
        a_button = mypage.unibuttons [-1]

        a_button.color = a_button.background_color
        if mypage.kivy:
            a_button.bind(on_touch_move=self.touch_move)
            a_button.bind(on_touch_down=self.touch_down)
        else:
            a_button.touch_enabled = False
            a_button.color = a_button.background_color
            a_button.pos = (a_button.x, a_button.y)
        self.new_objs.append(a_button)
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def new_button(self):

        a_caption = 'Button' + '{:02d}'.format(self.count_objs)
        self.count_objs += 1
        mypage.unibutton((40, 80, 80, 40, a_caption))
        a_button = mypage.unibuttons [-1]

        a_button.color = a_button.background_color
        if mypage.kivy:
            a_button.bind(on_touch_move=self.touch_move)
            a_button.bind(on_touch_down=self.touch_down)
        else:
            a_button.touch_enabled = False
            a_button.color = a_button.background_color
            a_button.pos = (a_button.x, a_button.y)
        self.new_objs.append(a_button)
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def demo_ChainedTransition():
    v1 = ui.View(frame=(0, 0, 500, 500), background_color="pink")
    v1.add_subview(ui.Button(frame=(100, 100, 300, 20)))
    v1.subviews[0].title = "Hello! I'm a button"
    v1.add_subview(ui.Slider(frame=(100, 300, 100, 20)))
    v2 = ui.View(background_color="lightblue")
    v2.add_subview(ui.ImageView(frame=(100, 100, 300, 300)))
    v2.subviews[0].image = ui.Image.named('test:Peppers')
    v3 = ui.View(background_color="lightgreen")
    v3.add_subview(ui.Switch(frame=(100, 100, 20, 10)))
    v3.subviews[0].value = True

    t1 = ui2.Transition(v1, v2, ui2.TRANSITION_CURL_UP, 1.5)
    t2 = ui2.Transition(v2, v3, ui2.TRANSITION_FLIP_FROM_LEFT, 1)
    t3 = ui2.Transition(v3, v1, ui2.TRANSITION_CROSS_DISSOLVE, 1)

    v1.present("sheet", hide_title_bar=True)

    ui2.delay(ui2.ChainedTransition(t1, t2, t3).play, 1)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, app, cell, category_name, tool_name, tool_url):
        self.app, self.cell = app, cell
        self.category_name, self.tool_name, self.tool_url = category_name, tool_name, tool_url

        self.btn = ui.Button()
        self.cell.content_view.add_subview(self.btn)
        self.btn.font = ('Helvetica', 12)
        self.btn.background_color = 'white'
        self.btn.border_width = 1
        self.btn.corner_radius = 5
        self.btn.size_to_fit()
        self.btn.width = 58
        self.btn.x = self.app.nav_view.width - self.btn.width - 8
        self.btn.y = (self.cell.height - self.btn.height) / 2

        if self.app.is_tool_installed(self.category_name, tool_name):
            self.set_state_uninstall()
        else:
            self.set_state_install()
项目: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 addbut(sender,toview):
        root=sender
        while root.superview:
            root=root.superview
        #add a button to parent view
        import random,string
        if root['switch'].value:
            w=random.randrange(30,110)
            h=random.randrange(20,75)
        else:
            w=40
            h=40
        title=string.ascii_letters[random.randint(0,26)]
        for v in toview:
            b=ui.Button(frame=(0,0,w,h),bg_color=(.8,.8,.8))
            b.border_width=1
            b.border_color=(0,0,0)
            b.corner_radius=10
            b.title=title
            b.action=lambda sender:addbut(sender,toview)
            v.add_subview(b)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def open_dialog(self,sender):
        # expand out a view/dialog from sender
        root=self.find_root(self.root)
        overlay=ui.Button(frame=(0,0)+tuple(root.frame)[2:],bg_color=(0,0,0,0.25),name='overlay')
        overlay.action=self.dispatch_cancel_action
        finalframe=self.frame
        self.width=5
        overlay.add_subview(self)

        root.add_subview(overlay)

        def ani():
            self.frame=finalframe
            self.center=overlay.center
            self.y=0
        ui.animate(ani,0.15)
        self.overlay=overlay
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def create_new_window(root,sender):
        v=ZoomView()
        v.bg_color=0.90, 0.90, 0.90
        v.border_color='grey'
        v.border_width=2
        v.x=random.randrange(75,300)
        v.y=random.randrange(75,300)
        v.width=v.height=300
        closebutton=ui.Button(frame=(250,0,50,50), bg_color='grey')
        closebutton.image=ui.Image.named('ionicons-close-round-32')
        closebutton.flex='bl'
        def closeview(sender):
            sender.superview.superview.remove_subview(sender.superview)
        closebutton.action=closeview
        tv=ui.TextView()
        tv.frame=(20,20,258,258)
        tv.flex='wh'
        v.add_subview(tv)
        v.add_subview(closebutton)
        root.add_subview(v)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self,frame=(0,0,300,32),name='dropdown', items=[]):
        '''Create a dropdown view, with items in list.
        items can be either an iterable, or a function returning an iterable.
        the function can be interrupted if it checks .abort(), which is set when user selects a row, for expensive ops like os.walk.
        pressing the dropdown button brings up the list, which can be aborted by selecting an item
        '''
        self.frame=frame
        self.textfield=ui.TextField(frame=frame,name='textfield')
        self.textfield.autocapitalization_type=ui.AUTOCAPITALIZE_NONE 
        self.textfield.autocorrection_type=False 
        self.button=ui.Button(name='button',bg_color=None)
        self.add_subview(self.textfield)
        self.add_subview(self.button)
        h=frame[3]
        self.button.frame=(self.width-32, h-32, 32,32)
        self.button.image=ui.Image.named('ionicons-arrow-down-b-32')
        self.button.action=self.open_finder

        self.base=os.path.expanduser('~/Documents')
        self._abort=False
        self.items=items
        self.button.flex='l'
        self.textfield.flex='w'
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def stop_populating(self,sender):
        console.hide_activity()
        root=self.find_root()
        self._abort=True
        if not isinstance(sender,ui.Button):
            #take no action
            self.textfield.text=sender.items[ sender.selected_row]
            def act():
                if self.textfield.action:
                    self.textfield.action(self.textfield)
            ui.delay(act,0.1)

        def ani():
            self.dialog.height=0
        def cleanup():
            root.remove_subview(root['overlay'])
        ui.delay(cleanup,0.2)
        ui.animate(ani,0.15)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def touch_ended(self,touch):
        # dispatch whatever is under the touch
        # for multitouch probably only want to execute when there are no active touches left.
        # this method would need to clean out touches, but still keep info on the active gesture.  when there are no active touches left, then kill the gesture
        # for now.... just look under the touch, and call something appropriate.
        # need to handle each ui type!
        #print self.name, 'touch ended'
        for s in self.subviews:
            #probably need to check whether another view is on top...
            if TouchDispatcher.hit(s,ui.convert_point(touch.location,self,s)):
                if isinstance(s,ui.TextField):
                    #print '..textfield begin editing'
                    s.begin_editing()
                    #think about setting cursor.... HARD! but possible i think?
                elif isinstance(s, ui.Button):
                    #print '..button launch'
                    s.action(s)
                elif isinstance(s, TouchDispatcher):
                    # adjust touch location to subviews coordinates, then dispatch
                   # print '..touch end: dispatch: ', s.name
                    t=Touch(touch)
                    t.location=ui.convert_point(touch.location,self,s)
                    s.touch_ended(t)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def create_new_window(root,sender):
        v=ZoomView()
        v.bg_color=0.90, 0.90, 0.90
        v.border_color='grey'
        v.border_width=2
        v.x=random.randrange(75,300)
        v.y=random.randrange(75,300)
        v.width=v.height=300
        closebutton=ui.Button(frame=(250,0,50,50), bg_color='grey')
        closebutton.image=ui.Image.named('ionicons-close-round-32')
        closebutton.flex='bl'
        def closeview(sender):
            sender.superview.superview.remove_subview(sender.superview)
        closebutton.action=closeview
        tv=ui.TextView()
        tv.frame=(20,20,258,258)
        tv.flex='wh'
        v.add_subview(tv)
        v.add_subview(closebutton)
        root.add_subview(v)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, elements, saveCallBack, addElementAction, saveFlowAction, runFlowAction, showElementRuntimeView, thememanager, flowType, flowTypeSelection):
        self.flowType = flowType
        self.elements = elements
        self.saveCallBack = saveCallBack
        self.flowTypeSelection = flowTypeSelection
        self.showElementRuntimeView = showElementRuntimeView
        self.extraRows = 2
        self.adminRow = 0
        self.typeRow = 1
        self.title = ''
        self.currentElementNumber = -1
        self.addElementButton = ui.ButtonItem(title = 'Add Element', action = addElementAction)
        self.saveFlowButton = ui.ButtonItem(title='Save', action=saveFlowAction)
        self.runFlowButton = ui.ButtonItem(title='Run', action=runFlowAction)
        self.titleButton = ui.Button(title='Change Title')
        self.editButtonsRight = [self.addElementButton]
        self.editButtonsLeft = [self.saveFlowButton]
        self.runButtonsRight = [self.runFlowButton]
        self.runButtonsLeft = []
        self.thememanager = thememanager
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def open_dialog(self,sender):
        # expand out a view/dialog from sender
        root=self.find_root(self.root)
        overlay=ui.Button(frame=(0,0)+tuple(root.frame)[2:],bg_color=(0,0,0,0.25),name='overlay')
        overlay.action=self.dispatch_cancel_action
        finalframe=self.frame
        self.width=5
        overlay.add_subview(self)

        root.add_subview(overlay)

        def ani():
            self.frame=finalframe
            self.center=overlay.center
            self.y=0
        ui.animate(ani,0.15)
        self.overlay=overlay
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self,frame=(0,0,300,32),name='dropdown', items=[]):
        '''Create a dropdown view, with items in list.
        items can be either an iterable, or a function returning an iterable.
        the function can be interrupted if it checks .abort(), which is set when user selects a row, for expensive ops like os.walk.
        pressing the dropdown button brings up the list, which can be aborted by selecting an item
        '''
        self.frame=frame
        self.textfield=ui.TextField(frame=frame,name='textfield')
        self.textfield.autocapitalization_type=ui.AUTOCAPITALIZE_NONE 
        self.textfield.autocorrection_type=False 
        self.button=ui.Button(name='button',bg_color=None)
        self.add_subview(self.textfield)
        self.add_subview(self.button)
        h=frame[3]
        self.button.frame=(self.width-32, h-32, 32,32)
        self.button.image=ui.Image.named('ionicons-arrow-down-b-32')
        self.button.action=self.open_finder

        self.base=os.path.expanduser('~/Documents')
        self._abort=False
        self.items=items
        self.button.flex='l'
        self.textfield.flex='w'
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def stop_populating(self,sender):
        console.hide_activity()
        root=self.find_root()
        self._abort=True
        if not isinstance(sender,ui.Button):
            #take no action
            self.textfield.text=sender.items[ sender.selected_row]
            def act():
                if self.textfield.action:
                    self.textfield.action(self.textfield)
            ui.delay(act,0.1)

        def ani():
            self.dialog.height=0
        def cleanup():
            root.remove_subview(root['overlay'])
        ui.delay(cleanup,0.2)
        ui.animate(ani,0.15)
项目:py-search    作者:vieira-rafael    | 项目源码 | 文件源码
def init_size(self): # initialize with correct size when landscape      orientation = ui.WebView(frame=(0,0,100,200)).eval_js('window.orientation') if orientation in (-90, 90): self.frame = (0, 0, self.height, self.width)
 def did_load(self): self.init_buttons() self.init_webbrowser() self.init_addressbar() self.init_size() self.flex = 'WH' self.bookmarks = self.load_bookmarks() self.history = self.load_history() self.addressbar_is_editing = False self.webpage_has_loaded = False self.favourite_images = {True :ui.Image.named('ionicons-ios7-star-32'), False:ui.Image.named('ionicons-ios7-star-outline-32')}
 def save_history(self, filename=filename_history): with open(filename, 'w') as f:          url = self.get_url() if url in self.history: self.history.remove(url) self.history.append(url)          f.seek(0)           pickle.dump(self.history, f)  def clear_history(self, sender, filename=filename_history): with open(filename, 'w') as f: self.history = []          f.seek(0)           pickle.dump(self.history, f)            sender.superview.superview['history'].data_source.items = self.history          sender.superview.superview['history'].reload()
 def save_bookmark(self, filename=filename_bookmarks): with open(filename, 'w') as f:           url = self.get_url()            title = self.get_title() or self.parse_url(url) self.bookmarks[title] = url         f.seek(0)           json.dump(self.bookmarks, f, indent=4) self['controlpanel']['favourite'].image = self.favourite_images[True]
 def remove_bookmark(self, title=None, filename=filename_bookmarks): with open(filename, 'w') as f:         title = title or self.get_title() del self.bookmarks[title]         f.seek(0)           json.dump(self.bookmarks, f, indent=4) self['controlpanel']['favourite'].image = self.favourite_images[False]
 def popup_menu(self):      popup = ui.View(name='menu', frame=(0, 0, 320, 500))        toolbar = ui.View(frame=(-5, 0, 330, 100), name='toolbar')      toolbar.border_width = 0.5      toolbar.border_color = '#B2B2B2'        label = ui.Label()      label.text = 'Bookmarks'        label.alignment = ui.ALIGN_CENTER       label.frame = (0, 0, 320, 50)       label.name = 'title'        segment_ctrl = ui.SegmentedControl(name='segctrl')      segment_ctrl.segments = ['Bookmarks', 'History']        segment_ctrl.width = 170        segment_ctrl.center = popup.center      segment_ctrl.y = label.height       segment_ctrl.selected_index = 0     segment_ctrl.action = self.bookmarks_or_history         button = ui.Button()        button.frame = (segment_ctrl.x*3.5, segment_ctrl.y, 60, 30)     button.font = ('<system>', 15)      button.title= 'Clear'       button.name = 'clear'       button.action = self.clear_history      button.hidden = True        toolbar.add_subview(label)      toolbar.add_subview(segment_ctrl)       toolbar.add_subview(button)         popup.add_subview(toolbar)      data_source = ui.ListDataSource(sorted(self.bookmarks.keys()))      popup.add_subview(self.list_bookmarks_and_history(data_source, width=320,height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='bookmarks'))       x, y = self['controlpanel']['bookmarks'].center     popup.present('popover', popover_location=(x, y), hide_title_bar=True)
 def bookmarks_or_history(self, sender):        toolbar = sender.superview if sender.selected_index == 0:           toolbar['clear'].hidden = True          toolbar['title'].text = 'Bookmarks'         data_source = ui.ListDataSource(sorted(self.bookmarks.keys()))          tv = self.list_bookmarks_and_history(data_source, width=320, height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='bookmarks')            toolbar.superview.remove_subview(toolbar.superview['history']) else:            toolbar['clear'].hidden = False             toolbar['title'].text = 'History'           data_source = ui.ListDataSource(self.history[::-1])         tv = self.list_bookmarks_and_history(data_source, width=320, height=toolbar.superview.height-toolbar.height, y=toolbar.height, name='history')          toolbar.superview['bookmarks'].hidden=True          toolbar.superview.remove_subview(toolbar.superview['bookmarks'])        sender.superview.superview.add_subview(tv)
 def list_bookmarks_and_history(self, data_source, **kwargs):       tv = ui.TableView()     tv.data_source = data_source        tv.delegate = self for k, v in kwargs.items(): setattr(tv, k, v) return tv
 def show_more_menu(self):      popup = ui.TableView()      popup.width = 250       popup.height = 500      popup.name = 'More'     popup.data_source = popup.delegate = self       button = self['controlpanel']['more']       popup.present('popover', popover_location=(button.x, button.y+button.height))
 def button_tapped(self, sender): if sender.name == 'favourite': if self.get_url() in self.bookmarks.values(): self.remove_bookmark() else: self.save_bookmark() elif sender.name == 'bookmarks': self.popup_menu() elif sender.name == 'more': self.show_more_menu() else: eval("self['webview'].{}()".format(sender.name))
 def tableview_number_of_rows(self, tableview, section): if tableview.name == 'Bookmarks': return len(self.bookmarks) elif tableview.name == 'More': return 1
 def tableview_cell_for_row(self, tableview, section, row): if tableview.name == 'Bookmarks':           cell = ui.TableViewCell()           cell.text_label.text = sorted(self.bookmarks.keys())[row]           cell.image_view.image = ui.Image.named('ionicons-ios7-bookmarks-outline-32')            cell.image_view.tint_color = '#66CCFF' return cell elif tableview.name == 'More':           cell = ui.TableViewCell()           cell.text_label.text = 'Settings'           cell.image_view.image = ui.Image.named('ionicons-wrench-32') return cell
 @ui.in_background def tableview_did_select(self, tableview, section, row): if tableview.name == 'bookmarks':           url = self.bookmarks[sorted(self.bookmarks.keys())[row]] self.load_url(url)         tableview.superview.close() elif tableview.name == 'history':           url = tableview.data_source.items[row]          tableview.superview.close() self.load_url(url) elif tableview.name == 'More':           tableview.close()           console.hud_alert('No settings yet...', 'error', 1)
 def tableview_can_delete(self, tableview, section, row): return True
 def tableview_delete(self, tableview, section, row):       item = sorted(self.bookmarks.keys())[row] self.remove_bookmark(item)        tableview.reload()
 def textfield_did_begin_editing(self, textfield): self.addressbar_is_editing = True self.set_url() self['controlpanel']['reload'].hidden = True
 def textfield_did_end_editing(self, textfield): self.addressbar_is_editing = False self['controlpanel']['reload'].hidden = False self.set_url()
 def textfield_should_return(self, textfield):      url = self['controlpanel']['addressbar'].text self.load_url(url)        textfield.end_editing() return True
 def webview_did_start_load(self, webview): self.webpage_has_loaded = False
 def webview_did_finish_load(self, webview): if not self.addressbar_is_editing: self.set_url() self.webpage_has_loaded = True       page_is_bookmarked = unicode(self.get_url()) in self.bookmarks.values() self['controlpanel']['favourite'].image = self.favourite_images[page_is_bookmarked] self.save_history()
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def next_turn(self, sender=None):
    self.turn += 1
    try:
      self.turn += self.active_players[self.turn:].index(True)
    except ValueError:
      winners = []
      for i, layer in enumerate(self.play_layers):
        if layer.waypoints_visited == len(layer.waypoints):
          winners.append(i)
      if len(winners) > 0:
        msg = ''
        for winner in winners:
          msg += ' ' + self.colors[winner].capitalize()
        console.alert('Winner', msg, button1='Ok', hide_cancel_button=True)
        self.hide_all()
        self.show_main_menu()
        return
      self.turn = self.active_players.index(True)

    self.hide_play_menu()
    if self.active_players.count(True) > 1:
      turn_button = ui.Button(frame=self.bg.bounds, background_color=(0, 0, 0, 0.9))
      turn_button.title = '  Tap to play'
      turn_button.tint_color = self.colors[self.turn]

      def turn_start_action(sender):
        self.bg.remove_subview(turn_button)
        self.play_layers[self.turn].start_turn()

      turn_button.action = turn_start_action
      self.bg.add_subview(turn_button)
      turn_button.image = self.main_menu.icons['player'+str(self.turn)]
    else:
      self.play_layers[self.turn].start_turn()
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def setup_bottom_menu(self, buttons):
    bottom_menu_height = 40
    (_, _, w, h) = self.bg.bounds
    bottom_menu = EvenView(margin = 20)
    bottom_menu.flex = 'WT'
    bottom_menu.frame = (0, h - bottom_menu_height, w, bottom_menu_height)
    bottom_menu.background_color = 'white'
    self.bg.add_subview(bottom_menu)
    for icon, func in buttons:
      button = ui.Button(image = ui.Image.named(icon))
      button.action = func
      button.name = func.__name__
      button.tint_color = self.menu_color
      bottom_menu.add_subview(button)
    return bottom_menu
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def menu_color_button(self, name, color, icon, corner):
    (x,y) = corner
    #img = self.button_image('plf:AlienBlue_stand', 45)
    #img =  ui.Image.named(icon_name).with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
    btn = ui.Button(
      name=name,
      action=self.toggle,
      background_color=color
    )
    btn.frame=(x, y, 50, 50)
    btn.corner_radius = 25
    btn.image=icon
    btn.background_color = tuple([btn.background_color[i] for i in range(3)]) + (0.8,)
    self.menu.add_subview(btn)
    return btn

#  def button_image(self, name, max_dim):
#    img = ui.Image.named(name)
#    with io.BytesIO(img.to_png()) as fp:
#      p_img = pilImage.open(fp)
#      scale = max_dim/max(p_img.size)
#      (w,h) = p_img.size
#      target = (int(w*scale), int(h*scale))
#      p_img = p_img.resize(target)
#    with io.BytesIO() as fp:
#      p_img.save(fp, 'PNG')
#      result_img = ui.Image.from_data(fp.getvalue())
#    return result_img.with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
项目: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)
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def __getDetailButtonForStatus(self, status, height, action, row):
        img = ui.Image.named(self.__getDetailImageForStatus(status))
        button = ui.Button()
        button.image = img
        size = img.size
        ratio = size.y / size.x
        button.height = height * 0.9
        button.width = button.height * ratio
        ca = CustomAction(button)
        ca.action = self.action
        ca.row = row
        button.action = ca
        return button
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def __getDetailButtonForStatus(self, status, height, action, row):
        img = ui.Image.named(self.__getDetailImageForStatus(status))
        button = ui.Button()
        button.image = img
        size = img.size
        ratio = size.y / size.x
        button.height = height * 0.9
        button.width = button.height * ratio
        ca = CustomAction(button)
        ca.action = self.action
        ca.row = row
        button.action = ca
        return button
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def __getDetailButtonForStatus(self, status, height, action, row):
        img = ui.Image.named(self.__getDetailImageForStatus(status))
        button = ui.Button()
        button.image = img
        size = img.size
        ratio = size.y / size.x
        button.height = height * 0.9
        button.width = button.height * ratio
        ca = CustomAction(button)
        ca.action = self.action
        ca.row = row
        button.action = ca
        return button
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def __getDetailButtonForStatus(self, status, height, action, row):
        img = ui.Image.named(self.__getDetailImageForStatus(status))
        button = ui.Button()
        button.image = img
        size = img.size
        ratio = size.y / size.x
        button.height = height * 0.9
        button.width = button.height * ratio
        ca = CustomAction(button)
        ca.action = self.action
        ca.row = row
        button.action = ca
        return button
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def __getDetailButtonForStatus(self, status, height, action, row):
        img = ui.Image.named(self.__getDetailImageForStatus(status))
        button = ui.Button()
        button.image = img
        size = img.size
        ratio = size.y / size.x
        button.height = height * 0.9
        button.width = button.height * ratio
        ca = CustomAction(button)
        ca.action = self.action
        ca.row = row
        button.action = ca
        return button
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def unibutton(self, params):
        self.unibuttons.append([])
        if len(params) == 6:
            function = params[5]
        else:
            function = nofunction
        if self.kivy:
            from kivy.uix.button import Button
            self.unibuttons[len(self.unibuttons) - 1] = Button(
            text = params[4],
            size_hint_y = None,
            size_hint_x = None,
            height = params[3] * self.yratio,
            width = params[2] * self.xratio,
            font_size = 17.5 * self.yratio,
            pos = (params[0] * self.xratio, params[1] * self.yratio),
            on_press = function )
            self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
        else:
            import ui
            self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
                (params[0] * self.xratio, (600 - params[1] - \
                params[3]) * self.yratio, \
                params[2] * self.xratio, params[3] * self.yratio), \
                title = params[4])
            self.unibuttons[len(self.unibuttons) - 1].background_color \
                = (0.4,0.4,0.4)
            self.unibuttons[len(self.unibuttons) - 1].action = function
            self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
                self.xratio
            self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
                self.yratio
            self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
            self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def unibutton(self, params):
        self.unibuttons.append([])
        if len(params) == 6:
            function = params[5]
        else:
            function = nofunction
        if self.kivy:
            from kivy.uix.button import Button
            self.unibuttons[len(self.unibuttons) - 1] = Button(
            text = params[4],
            size_hint_y = None,
            size_hint_x = None,
            height = params[3] * self.yratio,
            width = params[2] * self.xratio,
            font_size = 17.5 * self.yratio,
            pos = (params[0] * self.xratio, params[1] * self.yratio),
            on_press = function )
            self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
        else:
            import ui
            self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
                (params[0] * self.xratio, (600 - params[1] - \
                params[3]) * self.yratio, \
                params[2] * self.xratio, params[3] * self.yratio), \
                title = params[4])
            self.unibuttons[len(self.unibuttons) - 1].background_color \
                = (0.4,0.4,0.4)
            self.unibuttons[len(self.unibuttons) - 1].action = function
            self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
                self.xratio
            self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
                self.yratio
            self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
            self.unibuttons[len(self.unibuttons) - 1].font = ('<system>', \
                17.5 * self.yratio)
            self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def unibutton(self, params):
        self.unibuttons.append([])
        if len(params) == 6:
            function = params[5]
        else:
            function = nofunction
        if self.kivy:
            from kivy.uix.button import Button
            self.unibuttons[len(self.unibuttons) - 1] = Button(
            text = params[4],
            size_hint_y = None,
            size_hint_x = None,
            height = params[3] * self.yratio,
            width = params[2] * self.xratio,
            font_size = 17.5 * self.yratio,
            pos = (params[0] * self.xratio, params[1] * self.yratio),
            on_press = function )
            self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
        else:
            import ui
            self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
                (params[0] * self.xratio, (600 - params[1] - \
                params[3]) * self.yratio, \
                params[2] * self.xratio, params[3] * self.yratio), \
                title = params[4])
            self.unibuttons[len(self.unibuttons) - 1].background_color \
                = (0.4,0.4,0.4)
            self.unibuttons[len(self.unibuttons) - 1].action = function
            self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
                self.xratio
            self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
                self.yratio
            self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
            self.unibuttons[len(self.unibuttons) - 1].font = ('<system>', \
                17.5 * self.yratio)
            self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def test_Button(self):
        a = ui.Button()
        # Store attributes
        a.title = "Hey, it's a thing!"
        # Encode + decode
        b = ui._view_from_dict(ui2.ui_io._view_to_dict(a), globals(), locals())
        # Check that type and attributes were preserved
        self.assertIsInstance(b, type(a))
        self.assertEqual(a.title, b.title)
项目:ccMVC    作者:polymerchm    | 项目源码 | 文件源码
def make_button(name, bg_image_name, frame):
    button = ui.Button(name=name)
    button.frame = frame
    button.bg_color = 'ivory'
    button.border_color = 'black'
    button.border_width = 1
    button.background_image = ui.Image.named(bg_image_name)
    button.enabled = True
    return button
项目:pythonista-gestures    作者:mikaelho    | 项目源码 | 文件源码
def _get_recog(self, recog_name, view, internal_action, final_handler):
    view.touch_enabled = True
    button = ui.Button()
    key = str(uuid.uuid4())
    button.name = key
    button.action = internal_action
    self.buttons[key] = button
    self.views[key] = view
    recognizer = ObjCClass(recog_name).alloc().initWithTarget_action_(button, sel('invokeAction:')).autorelease()
    self.recognizers[key] = recognizer
    self.actions[key] = final_handler
    ObjCInstance(view).addGestureRecognizer_(recognizer)
    recognizer.delegate = self._delegate
    return recognizer
项目: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 __init__(self, *args, **kwargs):
      ui.View.__init__(self, *args, **kwargs)
      self.pinchgesture_recognizer_target = ui.Button()
      self.pinchgesture_recognizer_target.action = self.did_pinch

      self.pangesture_recognizer_target = ui.Button()
      self.pangesture_recognizer_target.action = self.did_pan

      self.gr_delegate=GRDelegate.alloc().init().autorelease()
      self.recognizers={}
      self_objc = ObjCInstance(self)     
      pinchobjctarget=ObjCInstance(self.pinchgesture_recognizer_target)
      panobjctarget=ObjCInstance(self.pangesture_recognizer_target)

      pinchrecognizer = ObjCClass('UIPinchGestureRecognizer').alloc()
      self.recognizers['pinch'] =         pinchrecognizer.initWithTarget_action_( pinchobjctarget, sel('invokeAction:')).autorelease()


      panrecognizer = ObjCClass('UIPanGestureRecognizer').alloc()
      self.recognizers['pan'] =            panrecognizer.initWithTarget_action_( panobjctarget, sel('invokeAction:')).autorelease()
      self.recognizers['pan'].setMinimumNumberOfTouches_(2)

      for r in self.recognizers.values():
         self_objc.addGestureRecognizer_(r)
         r.setDelegate_(self.gr_delegate)
      self.panx,self.pany,self.sx,self.sy=0,0,1,1
      self.panx0,self.pany0,self.sx0,self.sy0=0,0,1,1
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
      ui.View.__init__(self, *args, **kwargs)
      self.pinchgesture_recognizer_target = ui.Button()
      self.pinchgesture_recognizer_target.action = self.did_pinch

      self.pangesture_recognizer_target = ui.Button()
      self.pangesture_recognizer_target.action = self.did_pan

      self.gr_delegate=GRDelegate.alloc().init().autorelease()
      self.recognizers={}
      self_objc = ObjCInstance(self)     
      pinchobjctarget=ObjCInstance(self.pinchgesture_recognizer_target)
      panobjctarget=ObjCInstance(self.pangesture_recognizer_target)

      pinchrecognizer = ObjCClass('UIPinchGestureRecognizer').alloc()
      self.recognizers['pinch'] =         pinchrecognizer.initWithTarget_action_( pinchobjctarget, sel('invokeAction:')).autorelease()


      panrecognizer = ObjCClass('UIPanGestureRecognizer').alloc()
      self.recognizers['pan'] =            panrecognizer.initWithTarget_action_( panobjctarget, sel('invokeAction:')).autorelease()
      self.recognizers['pan'].setMinimumNumberOfTouches_(2)

      for r in self.recognizers.values():
         self_objc.addGestureRecognizer_(r)
         r.setDelegate_(self.gr_delegate)
      self.panx,self.pany,self.sx,self.sy=0,0,1,1
      self.panx0,self.pany0,self.sx0,self.sy0=0,0,1,1
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def create_toolbar_button(action,image,index=0,tag=''):
    '''create a button on main toolbar, with action,imagename, index location, and string tagname.  button and action are stored in __persistent_views[index].  tag allows finding view using tb.viewFromTag_(hash(tag)) (old idea)'''
    assert(callable(action))

    tb=get_toolbar(main_view)
    global __persistent_views
    try:
        __persistent_views
    except NameError:
        __persistent_views={}
    #check for existing button in this index and delete if needed
    remove_toolbar_button(index)

    #add new button to the left of the rightbuttons.  index 0 is next to left buttons, index 1 is further left, etc
    #store so it is not cleared.

    btn=ui.Button( frame=(tb.size().width -
    tb.rightItemsWidth()-(index+1)*40,22,40,40))
    btn.flex='L'
    btn.image=ui.Image.named(image)
    btn.action=action
    btn_obj=ObjCInstance(btn)
    btn_obj.tag=hash(tag)
    __persistent_views[index]=(btn,action,tag)
    tb.addSubview_(btn_obj)
    return btn
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def make_button(self, title, i):
        button = ui.Button(name=title, title=title.replace('_', ' '))
        # interesting that getattr(self, ...) != self.getattr(...)
        button.action = getattr(self, 'action_' + title.lower(), quit_action)
        #print(title, button.action)
        button.x = 30
        button.y = 105 * (i + 1)
        return button
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def close_button(self):
        the_button = ui.Button(title='X')
        the_button.x = self.width - the_button.width
        the_button.y = the_button.height / 2
        the_button.action = self.close_action
        the_button.font=('<system-bold>', 20)
        return the_button
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def make_buttons(self, name):
        button = ui.Button()
        button.name = name
        button.title = name
        button.border_color = 'blue'
        button.border_width = 1
        button.corner_radius = 3
        button.background_color = self.unselect_color
        button.action = self.btn_action
        self.add_subview(button)
        return button
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def _setup_cb(self):
        '''set up encapsulated button as checkbox'''
        tf=ui.Button()
        tf.action=self._button_action
        tf.width=self.width
        tf.height=self.height
        tf.flex='whtblr'
        tf.title=self._get_checkbox_char()
        self.add_subview(tf)
        return tf
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def setupkb(self):
         #define keys          
        redokey=key(title='redo',action=self.redoaction)
        undokey=key(title='undo',subkeys=[redokey], action=self.undoaction)
        hidekey=key(title='hide',action=self.hideaction)
        keymap=[key('\t',title='TAB'),key('_'),key('#',['@']),key('<',['<=']),key('>',['>=']),
                key('{'),key('}'),key('['),key(']'),key("'",['"']),key('('),key(')'),
                key(':',[';']), undokey]+[key(str(n)) for n in range(1,9)]+[key('0'),key('+',['%']),key('-'),key('/',['\\n','\\t','\\','/']),key('*'),key('=',['!=']), hidekey]


        #customkb component
        customkb=FlowContainer(frame=(0,self.height-100,self.width,100),flex='')
        customkb.name='customkb'
        self.add_subview(customkb)
        minimizedkb=ui.Button(frame=(0,self.height-15,self.width,15),flex='',bg_color=(.7, .7, .7))
        minimizedkb.action=self.showaction
        minimizedkb.title=u'\u2550'*10
        minimizedkb.name='minimizedkb'
        self.add_subview(minimizedkb)
        customkb.bring_to_front()
        customkb.hidden=True
        for k in keymap:
            customkb.add_subview(k.makeButton())
        customkb.flex='WT'
        customkb.y=self.height-customkb.height

        #contentframe
        content=ui.View(frame=(0,0,self.width,self.height-15))
        content.name='content'
        self.add_subview(content)
        content.send_to_back()
        content.border_color=(0,0,1)
        content.border_width=3
        self.content=content
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def did_load(self):
        for s in self['scrollview1'].subviews:
            if isinstance(s,ui.Button):
                #pass
                s.action = self.handlebutton
        type(self)._lastinstance=self
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
        self.schema_v = ui.TableView('grouped')
        self.data_v = ui.TableView()
        self.nbutton = ui.Button(title='Next')
        self.pbutton = ui.Button(title='Prev')
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __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()
项目:caves    作者:mikaelho    | 项目源码 | 文件源码
def __init__(self, control, spec, *args, **kwargs):
    super().__init__(*args, **kwargs)

    self.control = control
    img_view = ui.ImageView(frame=self.bounds)

    img_view.image = ui.Image.named("playfields/caves of soukka.png")
    self.add_subview(img_view)

    self.menu = ui.View(frame=(
      30, self.height/2.1, self.width - 60, self.height/2 - 30
    ), corner_radius=10)
    #self.menu.background_color=(0,0,0,0.7)
    self.add_subview(self.menu)

    (_,_,w,h) = self.menu.frame
    def pick_map(sender):
      self.control.load_map(next_func=self.control.set_map_for_play)
    self.map_btn = ui.Button(title='Pick map', tint_color='white', background_color=self.menu_color, corner_radius=5, action=pick_map)
    self.menu.add_subview(self.map_btn)
    self.map_btn.frame = (0.05*w, 0.05*h, 0.55*w, 50)

    (title, action) = spec[2]
    self.menu_button(title, action, 50, (0.7*w, 0.05*h+25))
    (title, action) = spec[1]
    self.menu_button(title, action, 50, (0.9*w, 0.05*h+25))

    self.icons = {}
    self.small_icons = {}
    for i in range(len(self.control.icon_names)):
      icon =   ui.Image.named(self.control.icon_names[i]).with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
      small_icon = ui.Image.named(self.control.small_icon_names[i]).with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
      name = 'player'+str(i)
      self.icons[name] = icon
      self.small_icons[name] = small_icon
      btn = self.menu_color_button(
        name, self.control.colors[i], icon,
        (0.05*w + i*51, 0.25*h))
      if i > 0:
        self.toggle(btn)

    (title, action) = spec[0]
    self.menu_button(title, action, 50, (0.9*w, 0.25*h+25))

    #btn = self.create_button
    #self.set_menu('main', spec)
项目:ccMVC    作者:polymerchm    | 项目源码 | 文件源码
def __init__(self,  frame=(0,0,150,32),
                                        buttonSize = (32,32),
                                        data = "this is a test".split(),
                                        font = None,
                                        initialItem = 0,
                                        offset_eps = 0,
                                        action = None,
                                        fullSize = 300,
                                        name = 'dropdown'):
        self.frame = frame  
        self._position = [ self.frame[x] for x in (0,1)]
        self.smallSize = frame[3]
        self.bg_color = None    
        self.border_width = 0
        self.border_color = 'black'
        self.buttonSize = buttonSize    
        self._data = data           
        self.delegate = _DropDownDelegate(self)
        if action:
            if inspect.isfunction(action) and len(inspect.getargspec(action).args) == 2:
                self.action = action
            else:
                raise TypeError('single argument function') 
        self.tvFrame = (0,0, self.frame[2] - self.buttonSize[0], self.buttonSize[1])
        self.tv = ui.TableView(frame=self.tvFrame)
        self.tv.row_height = self.smallSize
        self.tv.name = 'tableview'
        self.tv.allows_selection = True
        self.tv.delegate = self.tv.data_source = self.delegate
        self.tv.border_color = 'black'
        self.tv.border_width = 1
        self.button = ui.Button(frame = (self.frame[2]-self.buttonSize[0], 0) + self.buttonSize)
        self.button.bg_color = 'white'
        self.button.name = 'button'
        self.button.action = self.onArrow
        self.button.border_width = 1
        self.button.border_color = 'black'
        self.button.image=ui.Image.named('ionicons-arrow-down-b-24')
        self.expanded = False
        self.add_subview(self.tv)
        self.tv.frame = self.tvFrame
        self.add_subview(self.button)
        self.fullSize = fullSize
        self.smallSize = self.frame[3]
        self.offset_eps = offset_eps
        self.name = name
        self._hidden = False
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def create_accessory_toolbar(self):
        from objc_util import ObjCClass, ObjCInstance, sel

        def create_button(label, func):
            button_width = 25
            black = ObjCClass('UIColor').alloc().initWithWhite_alpha_(0.0, 1.0)
            action_button = ui.Button()
            action_button.action = func
            accessory_button = ObjCClass('UIBarButtonItem').alloc().initWithTitle_style_target_action_(label, 0, action_button, sel('invokeAction:'))
            accessory_button.width = button_width
            accessory_button.tintColor = black
            return (action_button, accessory_button)

        vobj = ObjCInstance(self.markup)

        keyboardToolbar = ObjCClass('UIToolbar').alloc().init()

        keyboardToolbar.sizeToFit()

        button_width = 25
        black = ObjCClass('UIColor').alloc().initWithWhite_alpha_(0.0, 1.0)

        # Create the buttons
        # Need to retain references to the buttons used
        # to handle clicks
        (self.indentButton, indentBarButton) = create_button(u'\u21E5', self.indent)

        (self.outdentButton, outdentBarButton) = create_button(u'\u21E4', self.outdent)

        (self.quoteButton, quoteBarButton) = create_button('>', self.block_quote)

        (self.linkButton, linkBarButton) = create_button('[]', self.link)

        #(self.anchorButton, anchorBarButton) = create_button('<>', self.anchor)

        (self.hashButton, hashBarButton) = create_button('#', self.heading)

        (self.numberedButton, numberedBarButton) = create_button('1.', self.numbered_list)

        (self.listButton, listBarButton) = create_button('•', self.unordered_list)

        (self.underscoreButton, underscoreBarButton) = create_button('_', self.insert_underscore)

        (self.backtickButton, backtickBarButton) = create_button('`', self.insert_backtick)

        # Flex between buttons
        f = ObjCClass('UIBarButtonItem').alloc().initWithBarButtonSystemItem_target_action_(5, None, None)

        doneBarButton = ObjCClass('UIBarButtonItem').alloc().initWithBarButtonSystemItem_target_action_(0, vobj, sel('endEditing:')) 

        keyboardToolbar.items = [indentBarButton, f, outdentBarButton, f, quoteBarButton, f, linkBarButton, f, hashBarButton, f, numberedBarButton, f, listBarButton, f, underscoreBarButton, f, backtickBarButton, f, doneBarButton]
        vobj.inputAccessoryView = keyboardToolbar
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def tableview_cell_for_row(self, tableview, section, row):
        if row >= self.extraRows:
            element = self.elements[row-self.extraRows]
            cell = ui.TableViewCell('subtitle')
            cell.selectable = False
            cell.text_label.text = element.get_title()
            cell.detail_text_label.text = element.get_description()
            cell.background_color=self.thememanager.main_background_colour
            cell.image_view.image = ui.Image.named(element.get_icon())
            params = element.get_params() or []
            selectable = False
            for p in params:
                if p.display:
                    selectable = True
                    cell.accessory_type = 'disclosure_indicator'
            cell.selectable = selectable
            if self.currentElementNumber >= self.extraRows:
                cell.selectable = False
            if self.currentElementNumber+1 == row:
                cell.background_color = self.thememanager.running_cell_background_colour
                cell.text_label.text_color = self.thememanager.running_cell_text_colour
                cell.detail_text_label.text_color = self.thememanager.running_cell_text_colour
            else:
                cell.background_color = self.thememanager.main_background_colour
                cell.text_label.text_color = self.thememanager.main_text_colour
                cell.detail_text_label.text_color = self.thememanager.main_text_colour
            return cell
        elif row == self.adminRow:
            cell = ui.TableViewCell()
            cell.background_color=self.thememanager.main_background_colour
            cell.selectable = False
            editButton = ui.Button(title='Done' if tableview.editing else 'Edit')
            editButton.width *= 1.4
            editButton.action = swap_edit
            editButton.y = cell.height/2 - editButton.height/2
            editButton.x = cell.width
            cell.add_subview(editButton)
            self.titleButton.y = cell.height/2 - editButton.height/2
            self.titleButton.x = self.titleButton.width/2
            self.titleButton.action = self.change_title
            cell.add_subview(self.titleButton)
            return cell
        elif row == self.typeRow:
            cell = ui.TableViewCell('value1')
            cell.background_color=self.thememanager.main_background_colour
            cell.selectable = True
            cell.text_label.text_color = self.thememanager.main_text_colour
            cell.detail_text_label.text_color = self.thememanager.main_text_colour
            cell.text_label.text = 'Type of Flow'
            cell.detail_text_label.text = self.flowType
            return cell