Python源码示例:ui.Button()

示例1
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() 
示例2
def makeButtons(self):
		buttonsize = int(self.height / CELLS_PER_ROW)
		self.startx = int(self.width / 2 - self.height / 2)
	
		rot=ui.Button(frame=(self.startx-2*buttonsize-10,10,2*buttonsize,2*buttonsize))
		rot.image = ui.Image.named('ionicons-ios7-refresh-empty-256')
		rot.action = self.rotate
		rot.tint_color = 'black'

		self.add_subview(rot)
		
		self.buttonView = ui.View(frame=(self.startx, 0, buttonsize*16,buttonsize*16))
		for x in range(CELLS_PER_ROW):
			for y in range(CELLS_PER_ROW):
				frame = (x*buttonsize, y*buttonsize, buttonsize, buttonsize)
				b = ui.Button(frame = frame)
				b.background_color = self.load[x,y]
				b.action = self.invert
				self.buttonView.add_subview(b)
		self.add_subview(self.buttonView) 
示例3
def __init__(self, lcd, phone, backfn, label = 'Weather'):  
        self.phone = phone
        super().__init__(lcd,backfn,label,ui.WHITE,ui.BLACK,ui.GREY)
        y = const(30)
        self.city = ui.Label(self,10,y-10,108,10,self.fg,self.bg,"City",1,1)
        self.weather = ui.Label(self,10,y,108,10,self.fg,self.bg,"Weather",1,0)
        self.icon = ui.Image(self,72,y+15,50,50,None)
        self.temperature = ui.Label(self,10,y+15,54,20,self.fg,self.bg,"Temp",3,1,False)
        self.humidity = ui.Label(self,10,y+35,54,10,self.fg,self.bg,"Humidity",1,0,False)
        self.pressure = ui.Label(self,10,y+45,54,10,self.fg,self.bg,"Pressure",1,0,False)
        self.wind = ui.Label(self,10,y+55,54,10,self.fg,self.bg,"Wind",1,0,False)
        self.sunrise = ui.Label(self,10,y+75,80,10,self.fg,self.bg,"Sunrise",1,0,False)
        self.sunset = ui.Label(self,10,y+85,80,10,self.fg,self.bg,"Sunset",1,0,False)
        self.location1  = ui.Button(self,0,135,30,20,self.fg,self.bb,'Lon')
        self.location1.callback(lambda x = 'GB/London': self.do_update(x))
        self.location2  = ui.Button(self,40,135,30,20,self.fg,self.bb,'Ros')
        self.location2.callback(lambda x = 'FR/Roscoff': self.do_update(x)) 
示例4
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 
示例5
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() 
示例6
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) 
示例7
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) 
示例8
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) 
示例9
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' 
示例10
def open_finder(self,sender):
        # expand out a view/dialog from sender
        root=self.find_root()
        overlay=ui.Button(frame=(0,0)+tuple(root.frame)[2:],bg_color=(0,0,0,0.25),name='overlay')
        dialog=ui.View(frame=sender.frame,bg_color='white',name='dialog')
        self.tbl=ui.TableView()
        self.tbl.width=dialog.width
        self.tbl.height=dialog.height
        self.listsource=ui.ListDataSource(items=[])
        self.tbl.data_source=self.listsource
        self.tbl.delegate=self.listsource
        self.listsource.action=self.stop_populating
        self.tbl.flex='wh'
        dialog.add_subview(self.tbl)
        overlay.add_subview(dialog)
        overlay.action=self.stop_populating
        root.add_subview(overlay)
        self.dialog=dialog
        def ani():
            dialog.x,dialog.y=ui.convert_point((self.textfield.x,self.textfield.y+self.textfield.height),self,root)
            dialog.width=self.textfield.width
            dialog.height=min(400,root.height-ui.convert_point((0,dialog.y),self,root)[1])
        ui.delay(self.start_populating,0.16)
        ui.animate(ani,0.15) 
示例11
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) 
示例12
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) 
示例13
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 
示例14
def open_finder(self,sender):
        # expand out a view/dialog from sender
        root=self.find_root()
        overlay=ui.Button(frame=(0,0)+tuple(root.frame)[2:],bg_color=(0,0,0,0.25),name='overlay')
        dialog=ui.View(frame=sender.frame,bg_color='white',name='dialog')
        self.tbl=ui.TableView()
        self.tbl.width=dialog.width
        self.tbl.height=dialog.height
        self.listsource=ui.ListDataSource(items=[])
        self.tbl.data_source=self.listsource
        self.tbl.delegate=self.listsource
        self.listsource.action=self.stop_populating
        self.tbl.flex='wh'
        dialog.add_subview(self.tbl)
        overlay.add_subview(dialog)
        overlay.action=self.stop_populating
        root.add_subview(overlay)
        self.dialog=dialog
        def ani():
            dialog.x,dialog.y=ui.convert_point((self.textfield.x,self.textfield.y+self.textfield.height),self,root)
            dialog.width=self.textfield.width
            dialog.height=min(400,root.height-ui.convert_point((0,dialog.y),self,root)[1])
        ui.delay(self.start_populating,0.16)
        ui.animate(ani,0.15) 
示例15
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) 
示例16
def make_button(title, action):
    button = ui.Button(title=title)
    button.action = action
    button.background_color ='lightgrey'
    button.border_color = 'black'
    button.border_width = 1
    button.flex = 'WB'
    return button 
示例17
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() 
示例18
def _vk_tapped(self, sender):
        """
        Called when a key was tapped
        :param sender: sender of the event
        :type sender: ui.Button
        """
        # resolve key
        mapping = [
            # we can not use a dict here because ui.Button is unhashable
            # instead, we use a pair of (key, value) and apply a liner search
            # a binary search may be more efficient, but come on, this is definetly not required here
            (self.k_tab, K_TAB),
            (self.k_hist, K_HIST),
            (self.k_hup, K_HUP),
            (self.k_hdn, K_HDN),
            (self.k_CC, K_CC),
            (self.k_CD, K_CD),
            (self.k_CU, K_CU),
            (self.k_CZ, K_CZ),
            (self.k_KB, K_KB),
        ]
        key = None
        for k, v in mapping:
            if sender is k:
                key = v
        if key is None:
            raise ValueError("Unknown sender: " + repr(sender))
        
        # call action
        self.stash.user_action_proxy.vk_tapped(key)

# ObjC related stuff 
示例19
def __init__(self, lcd, backfn, label, fg=ui.WHITE, bg=ui.BLACK, bb=ui.BLUE):
        super().__init__(lcd, fg, bg)
        self.bb = bb
        self.name =  ui.Label(self,0,0,128,20,self.fg,self.bg,label)
        self.back  = ui.Button(self,88,135,30,20,self.fg,self.bb,'Bk')
        self.back.callback(backfn) 
示例20
def install(self,  newapp, fn):
        self.apps.append(ui.Button(self,10,len(self.apps)*30+30,108,20,ui.FG,ui.GREEN, newapp.name.label))
        self.apps[-1].callback(fn) 
示例21
def __init__(self, lcd, phone, backfn, label = 'Currency'):  
        self.phone = phone
        super().__init__(lcd,backfn,label)
        self.euro = ui.Label(self,10,40,108,10,ui.FG,  ui.GREY,"Euro       :",1,0,False)
        self.dollar = ui.Label(self,10,55,108,10,ui.FG,ui.GREY,"US Dollar  :",1,0,False)
        self.swiss = ui.Label(self,10,70,108,10, ui.FG,ui.GREY,"Swiss Franc:",1,0,False)
        self.status = ui.Label(self,0,125,60,10, self.fg,self.bg,"",1,0)
        self.update  = ui.Button(self,0,135,60,20,ui.FG,ui.BLUE,'Update')
        self.update.callback(self.do_update) 
示例22
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 
示例23
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 
示例24
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 
示例25
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 
示例26
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") 
示例27
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() 
示例28
def add_new_button(self,name, new = False):
        b = ui.Button(title = str(name))
        b.height = self.tab_height
        b.width = self.tab_width
        b.border_width = 0.5
        b.corner_radius = 10
        if new == True:
            for r in range(len(self.sv.subviews)):
                self.sv.subviews[r].background_color = 'white'
            b.background_color = 'orange'
        else:
            b.background_color = 'white'
        b.border_color = 'grey'
        b.image = ui.Image.named('_blank')
        b.tint_color = 'black'
        b.action = self.open_url
        b.transform = ui.Transform.rotation(pi/2)
        count=self.count
        b.y = self.tab_width*count*1.05 + 120
        b.x = -10
        b.name = str(name)
        close_title = name + '_close'
        c = ui.Button()
        c.width = 15
        c.height = 15
        c.x = 3
        c.y = 3
        #c.corner_radius = c.height/2
        #c.border_width = 1
        c.image = ui.Image.named('ionicons-close-24')
        c.action = self.close_button
        b.add_subview(c)
        self.sv.add_subview(b)
        contentwidth,contentheight=self.sv.content_size
        self.sv.content_size=(contentwidth,(b.y+b.height)*1.6)
        self.count += 1 
示例29
def did_load(self):
        for s in self['scrollview1'].subviews:
            if isinstance(s,ui.Button):
                #pass
                s.action = self.handlebutton
        type(self)._lastinstance=self 
示例30
def set_actions(self):
        # method 2: traversing all subviews
        for subview in self.subviews:
            if isinstance(subview, ui.TextField):
                subview.delegate = self
            elif isinstance(subview, ui.Button):
                if subview.name == 'say hi':
        # method 3: button-specific action methods
                    subview.action = self.say_hi  
                else:
                    subview.action = self.button_pressed