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

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

项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def tableview_cell_for_row(self, tableview, section, row):
        cell = ui.TableViewCell()
        cell.border_color = self.theme_manager.currentTheme.tintColour
        cell.background_color = self.theme_manager.currentTheme.backgroundColour
        cell.bar_tint_color = self.theme_manager.currentTheme.toolbarBackgroundColour
        cell.bg_color = self.theme_manager.currentTheme.backgroundColour
        cell.tint_color = self.theme_manager.currentTheme.tintColour
        cell.title_color = self.theme_manager.currentTheme.tintColour
        cell.text_label.text_color = self.theme_manager.currentTheme.textColour
        cell.text_label.text = self.data[row].plural
        cell.accessory_type = 'disclosure_indicator'
        selectedBackgroundView = ui.View()
        selectedBackgroundView.background_color = self.theme_manager.currentTheme.cellSelectionColour
        if not self.theme_manager.currentTheme.showCellSelection:
            selectedBackgroundView.alpha = 0
        cell.selected_background_view = selectedBackgroundView
        if not self.data[row].icon == None:
            cell.image_view.image = self.data[row].icon
        return cell
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def tableview_cell_for_row(self, tableview, section, row):
        cell = ui.TableViewCell()       
        cell.border_color = self.theme_manager.currentTheme.borderColour
        cell.background_color = self.theme_manager.currentTheme.backgroundColour
        cell.bg_color = self.theme_manager.currentTheme.backgroundColour
        cell.tint_color = self.theme_manager.currentTheme.tintColour
        cell.text_label.text_color = self.theme_manager.currentTheme.textColour
        selectedBackgroundView = ui.View()
        selectedBackgroundView.background_color = self.theme_manager.currentTheme.settingsCellSelectionColour
        if not self.theme_manager.currentTheme.showSettingsCellSelection:
            selectedBackgroundView.alpha = 0
        cell.selected_background_view = selectedBackgroundView
        if section == self.docset_section_number:
            cell.text_label.text = self.data[row]
            cell.accessory_type = 'disclosure_indicator'
        elif section == self.ack_section_number:
            cell.text_label.text = self.ack_data[row]['text']
        elif section == self.pydoc_updates_section_number:
            cell.text_label.text = self.updates_data[row]
        elif section == self.theme_section_number:
            cell.text_label.text = self.theme_data[row]
        elif section == self.websearch_section_number:
            cell.text_label.text = self.webSearch_data[row]
        return cell
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def tableview_cell_for_row(self, tableview, section, row):
        cell = ui.TableViewCell()
        cell.text_label.text = self.data[row]['name']
        cell.accessory_type = 'disclosure_indicator'
        cell.border_color = self.theme_manager.currentTheme.tintColour
        cell.background_color = self.theme_manager.currentTheme.backgroundColour
        cell.bar_tint_color = self.theme_manager.currentTheme.toolbarBackgroundColour
        cell.bg_color = self.theme_manager.currentTheme.backgroundColour
        cell.tint_color = self.theme_manager.currentTheme.tintColour
        cell.title_color = self.theme_manager.currentTheme.tintColour
        cell.text_label.text_color = self.theme_manager.currentTheme.textColour
        selectedBackgroundView = ui.View()
        selectedBackgroundView.background_color = self.theme_manager.currentTheme.cellSelectionColour
        if not self.theme_manager.currentTheme.showCellSelection:
            selectedBackgroundView.alpha = 0
        cell.selected_background_view = selectedBackgroundView      
        if not self.data[row]['type'].icon == None:
            cell.image_view.image = self.data[row]['type'].icon
        return cell
项目:PyDoc    作者:shaun-h    | 项目源码 | 文件源码
def __init__(self, tableView, filterData, *args, **kwargs):
        ui.View.__init__(self, *args, **kwargs)
        frame = CGRect(CGPoint(0, 0), CGSize(self.width, self.height))
        self.tv = tableView
        self.tableView = ObjCInstance(self.tv)
        flex_width, flex_height = (1<<1), (1<<4)
        self.tableView.setAutoresizingMask_(flex_width|flex_height)
        sd = createSearchDelegateClass()
        self.searchDelegate = sd.alloc().init().autorelease()
        self.searchDelegate.filt = filterData
        searchBar = UISearchBar.alloc().init()
        searchBar.setPlaceholder_(ns('Search'))
        searchBar.setDelegate_(self.searchDelegate)
        #searchBar.setShowsBookmarkButton_(ns(True))
        searchBar.setShowsCancelButton_(ns(True))
        #searchBar.setShowsSearchResultsButton_(ns(True))
        #searchBar.setScopeButtonTitles_(ns(['test1','hi']))
        #searchBar.setShowsScopeBar(ns(True))

        self.tableView.setTableHeaderView_(searchBar)
        searchBar.sizeToFit()

        self_objc = ObjCInstance(self)
        self_objc.addSubview_(self.tableView)
        self.tableView.release()
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def uniframe(self, params):
        if self.kivy:
            from kivy.graphics import Color
            from kivy.graphics import Rectangle
            self.root.canvas.add(Color (params[4][0],params[4][1], \
                params[4][2]))
            self.root.canvas.add(Rectangle(pos = (params[0] * self.xratio, \
                params[1] * self.yratio), size = (params[2] * self.xratio, \
                params[3] * self.yratio)))
        else:
            import ui
            self.uniframes.append([])
            self.uniframes[len(self.uniframes) - 1] = \
                ui.View(frame=(params[0] * self.xratio, \
                (600 - params[1] - params[3]) * self.yratio, \
                params[2] * self.xratio, params[3] * self.yratio))
            self.uniframes[len(self.uniframes) - 1].background_color = \
                (params[4][0],params[4][1], params[4][2],1.0)
            self.root.add_subview(self.uniframes[len(self.uniframes) - 1])
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def uniframe(self, params):
        if self.kivy:
            from kivy.graphics import Color
            from kivy.graphics import Rectangle
            self.root.canvas.add(Color (params[4][0],params[4][1], \
                params[4][2]))
            self.root.canvas.add(Rectangle(pos = (params[0] * self.xratio, \
                params[1] * self.yratio), size = (params[2] * self.xratio, \
                params[3] * self.yratio)))
        else:
            import ui
            self.uniframes.append([])
            self.uniframes[len(self.uniframes) - 1] = \
                ui.View(frame=(params[0] * self.xratio, \
                (600 - params[1] - params[3]) * self.yratio, \
                params[2] * self.xratio, params[3] * self.yratio))
            self.uniframes[len(self.uniframes) - 1].background_color = \
                (params[4][0],params[4][1], params[4][2],1.0)
            self.root.add_subview(self.uniframes[len(self.uniframes) - 1])
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def uniframe(self, params):
        if self.kivy:
            from kivy.graphics import Color
            from kivy.graphics import Rectangle
            self.root.canvas.add(Color (params[4][0],params[4][1], \
                params[4][2]))
            self.root.canvas.add(Rectangle(pos = (params[0] * self.xratio, \
                params[1] * self.yratio), size = (params[2] * self.xratio, \
                params[3] * self.yratio)))
        else:
            import ui
            self.uniframes.append([])
            self.uniframes[len(self.uniframes) - 1] = \
                ui.View(frame=(params[0] * self.xratio, \
                (600 - params[1] - params[3]) * self.yratio, \
                params[2] * self.xratio, params[3] * self.yratio))
            self.uniframes[len(self.uniframes) - 1].background_color = \
                (params[4][0],params[4][1], params[4][2],1.0)
            self.root.add_subview(self.uniframes[len(self.uniframes) - 1])
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def demo_ChainedAnimation():
    v = ui.View(frame=(0, 0, 500, 500), background_color="red")
    b = ui.View(frame=(100, 200, 100, 100), background_color="white")
    v.add_subview(b)

    def animation_a():
        b.x = 300

    def animation_b():
        b.x = 100

    a_anim = ui2.Animation(animation_a, 1, easing=ui2.ANIMATE_EASE_IN)
    b_anim = ui2.Animation(animation_b, 1, easing=ui2.ANIMATE_EASE_OUT)

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

    chain = ui2.ChainedAnimation(a_anim, b_anim, a_anim, b_anim, completion=_f)
    chain.play()
项目: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)
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def demo_BlurView():
    a = ui.View(frame=(0, 0, 500, 500))
    a.add_subview(ui.ImageView(frame=(0, 0, 500, 500)))
    a.subviews[0].image = ui.Image.named('test:Peppers')
    a.add_subview(ui2.BlurView())
    a.subviews[1].frame = (100, 100, 100, 100)
    a.present('sheet', hide_title_bar=True)

    toggle = ui2.Animation(a.subviews[1].toggle_brightness, 0.5)
    def movea():
        a.subviews[1].x = 300
    def moveb():
        a.subviews[1].y = 300
    def movec():
        a.subviews[1].x = 100
    def moved():
        a.subviews[1].y = 100
    movea = ui2.Animation(movea, 1)
    moveb = ui2.Animation(moveb, 1)
    movec = ui2.Animation(movec, 1)
    moved = ui2.Animation(moved, 1)
    ui2.ChainedAnimation(movea, moveb, movec, moved, toggle,
                         movea, moveb, movec, moved).play()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self,device=1, *args, **kwargs):
      ui.View.__init__(self,*args,**kwargs)
      self._session=ObjCClass('AVCaptureSession').alloc().init()
      self._session.setSessionPreset_('AVCaptureSessionPresetHigh');
      inputDevices=ObjCClass('AVCaptureDevice').devices()
      self._inputDevice=inputDevices[device]

      deviceInput=ObjCClass('AVCaptureDeviceInput').deviceInputWithDevice_error_(self._inputDevice, None);
      if self._session.canAddInput_(deviceInput):
         self._session.addInput_(deviceInput)
      self._previewLayer=ObjCClass('AVCaptureVideoPreviewLayer').alloc().initWithSession_(self._session)
      self._previewLayer.setVideoGravity_( 
         'AVLayerVideoGravityResizeAspectFill')
      rootLayer=ObjCInstance(self).layer()
      rootLayer.setMasksToBounds_(True)
      self._previewLayer.setFrame_(
         CGRect(CGPoint(-70, 0), CGSize(self.height,self.height)))
      rootLayer.insertSublayer_atIndex_(self._previewLayer,0)
      self._session.startRunning()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __new__(cls, ptr):
        # If there is already an instance that wraps this pointer, return the same object...
        # This makes it a little easier to put auxiliary data into the instance (e.g. to use in an ObjC callback)
        # Note however that a new instance may be created for the same underlying ObjC object if the last instance gets garbage-collected.
        if isinstance(ptr, ui.View):
            ptr = ptr._objc_ptr
        if isinstance(ptr, ObjCInstance):
            return ptr
        if isinstance(ptr, c_void_p):
            ptr = ptr.value
        cached_instance = _cached_instances.get(ptr)
        if cached_instance:
            return cached_instance
        objc_instance = super(ObjCInstance, cls).__new__(cls)
        _cached_instances[ptr] = objc_instance
        if isinstance(ptr, ui.View):
            ptr = ptr._objc_ptr
        objc_instance.ptr = ptr
        objc_instance._as_parameter_ = ptr
        objc_instance._cached_methods = weakref.WeakValueDictionary()
        objc_instance.weakrefs = weakref.WeakValueDictionary()
        if ptr:
            # Retain the ObjC object, so it doesn't get freed while a pointer to it exists:
            objc_instance.retain(restype=c_void_p, argtypes=[])
        return objc_instance
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self,detailwidth=320-22,style='slide',delegate=None,mainview= None,detailview=None, initial_state=0,**kwargs):
        ui.View.__init__(self,**kwargs)
        self._sv=ui.ScrollView()
        self._sv.flex='wh'
        self._sv.frame=self.bounds
        self._sv.content_size=(self.bounds[2]+1,self.bounds[3])
        self._mainviewcontainer=ui.View()
        self._mainviewcontainer.frame=self.bounds
        self._detailviewcontainer=ui.View()
        self._detailviewcontainer.frame=self.bounds
        self.detailwidth = detailwidth
        self._detailviewcontainer.width=detailwidth
        self._detailviewcontainer.x=-detailwidth
        self._mainviewcontainer.flex='WH'
        self._detailviewcontainer.flex='H'
        self._mainview=None
        self._detailview=None
        self.delegate=delegate
        self._sv.delegate=self
        self._sv.add_subview(self._mainviewcontainer)
        self._sv.add_subview(self._detailviewcontainer)
        self.add_subview(self._sv)
        self.style='slide'# 'slide','resize'
        self.state=0 #1 when detail shown
        self._modify_gesture()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
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)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def createView():
        main=ui.View(frame=(0,0,576,576))
        subpanel=ui.View(frame=(0,330,576,246))
        subpanel2=ui.View(frame=(0,0,576,246))
        slider=ui.Slider(frame=(10,10,150,44),name='slider1')
        slider.stored=True
        switch1=ui.Switch(frame=(10,66,70,44),name='switch1')
        switch1.stored=True
        switch2=ui.Switch(frame=(90,66,70,44)) #no name
        switch2.stored=True
        switch3=ui.Switch(frame=(10,120,70,44),name='switch3') #not stored
        tf1=ui.TextField(frame=(10,180,250,50),name='textfield')
        tf1.stored=True
        main.add_subview(subpanel)
        subpanel.add_subview(slider)
        subpanel.add_subview(switch1)
        subpanel.add_subview(switch2)
        subpanel.add_subview(switch3)
        subpanel.add_subview(tf1)
        slider2=ui.Slider(frame=(10,10,150,44),name='slider1')
        slider2.stored=True
        subpanel2.add_subview(slider2)
        main.add_subview(subpanel2)
        return main
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
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)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def init():
    # Monkey-patch the ui module to use Multipanel
    try:
        ui.view_real_present
    except AttributeError:
        ui.view_real_present = ui.View.present

    def present(self, mode, **kwargs):
        if mode == "panel":
            ui.multipanel.add_view(self)
        else:
            ui.view_real_present(self, mode, **kwargs)

    instancemethod = type(Multipanel.add_view)
    # ui.View is too builtin for us mere mortals to change its methods.
    ##ui.View.present = instancemethod(present, None, ui.View)

    ui.multipanel = Multipanel()
    ui.view_real_present(ui.multipanel.root, "panel")
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def __init__(self, view, attribute, other=None, other_attribute=LayoutAttribute.notAnAttribute):
        assert(isinstance(view, LayoutProxy))
        assert(isinstance(attribute, LayoutAttribute))

        self._view = view
        self._attribute = attribute
        self._constraints = {}

        if other:
            assert(isinstance(other, ui.View))
            assert(isinstance(other_attribute, LayoutAttribute))

            self._other = other
            self._other_attribute = other_attribute
        else:
            self._other = None
            self._other_attribute = LayoutAttribute.notAnAttribute
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def __init__(self, view):
        assert(isinstance(view, ui.View))

        self._view = view
        self.add_subview(self._view)

        self._view_objc = ObjCInstance(self._view)
        self._objc = ObjCInstance(self)

        self._view_objc.setTranslatesAutoresizingMaskIntoConstraints_(False)
        self._objc.setTranslatesAutoresizingMaskIntoConstraints_(False)

        attributes = [LayoutAttribute.left, LayoutAttribute.right, LayoutAttribute.top, LayoutAttribute.bottom]
        for attribute in attributes:
            constraint = _LayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self._view_objc, int(attribute), int(LayoutRelation.equal), self._objc, int(attribute), 1.0, 0
            )
            self._objc.addConstraint_(constraint)

        self._layout = None
项目: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 create_play_menu(self):
    play_menu = ui.View(frame=self.bg.bounds)
    self.bg.add_subview(play_menu)
    buttons = [
      [ 'iow:close_round_24', self.quit_game ],
      [ 'iow:arrow_right_b_32', self.next_turn ]
    ]
    return self.setup_bottom_menu(buttons)
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def close(self):
        ui.View.close(self)
项目:GAP    作者:Tileyon    | 项目源码 | 文件源码
def close(self):
        ui.View.close(self)
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def test_Generic(self):
        """ Test all generic attributes of any ui.View class """
        a = ui.View()
        # Store attributes
        a.background_color = "#ff00ff"
        # 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.background_color, b.background_color)
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def subclassable(view_type):
    """Return an inheritable version of an uninheritable ui.View class."""
    class ViewWrapper(ViewClassWrapper):
        def __init__(self, *args, **kwargs):
            super().__init__(view_type, *args, **kwargs)
    return ViewWrapper
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def demo_PathView():
    # SETUP
    p = ui2.get_regular_polygon_path(6, center=(50, 50), radius=50)
    pv = ui2.PathView(p)
    pv.x = 150
    pv.y = 150

    # ANIMATION FUNCTIONS
    def scaleWidth():
        pv.width = 200

    def scaleHeight():
        pv.height = 200

    def scaleBoth():
        pv.width = 300
        pv.height = 300

    def scaleBack():
        pv.x, pv.y = 0, 0
        pv.width, pv.height = 50, 50

    # BASIC USAGE
    v = ui.View(background_color="white")
    v.width = v.height = 500
    v.add_subview(pv)
    v.present("sheet", hide_title_bar=True)
    # PERFORM THE ANIMATIONS
    ui.animate(scaleWidth, 1)
    ui.delay(lambda: ui.animate(scaleHeight, 1), 1)
    ui.delay(lambda: ui.animate(scaleBoth, 1), 2)
    ui.delay(lambda: ui.animate(scaleBack, 1), 3)
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def demo_ProgressPathView():
    import math
    import random

    p = ui.Path()
    p.move_to(20, 20)
    p.line_to(480, 20)
    p.line_to(480, 250)
    p.add_arc(250, 250, 230, 0, math.radians(110))
    p.add_curve(50, 450, 20, 250, 480, 250)
    p.close()  # This makes the end look nicer

    ppv = ui2.ProgressPathView(p)

    view = ui.View(background_color="white")
    view.add_subview(ppv)
    view.width = view.height = ppv.width = ppv.height = 500
    view.present("sheet", hide_title_bar=True)

    def advance():
        """Advance by a random amount and repeat."""
        pg = ppv.progress + random.random() / 20
        if pg < 1:
            ppv.progress = pg
            ui.delay(advance, random.random() / 2)
        else:
            ppv.progress = 1

    advance()
项目:ui2    作者:controversial    | 项目源码 | 文件源码
def demo_Transition():
    v1 = ui.View(frame=(0, 0, 500, 500), background_color="red")
    v2 = ui.View(background_color="blue")
    v1.present('sheet', hide_title_bar=True)
    ui2.transition(v1, v2, ui2.TRANSITION_CURL_UP, 1.5, _f)
项目:Pythonista-C64-Painter    作者:superrune    | 项目源码 | 文件源码
def choose_color(self, sender):
        if sender.name in self.color:
            self.color[sender.name] = sender.value
            self.set_color()
        elif sender in self['palette'].subviews:
            self.set_color(sender.background_color)
        elif sender.name == 'color_input':
            try:
                c = sender.text if sender.text.startswith('#') else eval(sender.text)
                v = ui.View(background_color=c)
                self['color_input'].text = str(v.background_color)
                self.set_color(v.background_color)
            except Exception as e:
                console.hud_alert('Invalid Color', 'error')
项目:ccMVC    作者:polymerchm    | 项目源码 | 文件源码
def __init__(self,view,tint=(1.0, 1.0, 1.0),alpha=0.7,name=None,local=False): # view is view to cover
        self.view = view
        shieldName = name if name else 'shield'
        self.shield = ui.View(frame=view.frame,background_color=tint,flex='WH',name=shieldName)
        self.shield.alpha = alpha
        self._frame = self.shield.frame
        self._position = (tuple(self._frame)[:2])
        if local:
            self.view.add_subview(self.shield)
        else:
            self.view.superview.add_subview(self.shield)
        self.shield.send_to_back()
        self.shield.hidden = True
        self.status = False
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, root_node, allow_multi=False, async_mode=False):
        self.async_mode = async_mode
        self.allow_multi = allow_multi
        self.selected_entries = None
        self.table_view = ui.TableView()
        self.table_view.frame = (0, 0, 500, 500)
        self.table_view.data_source = self
        self.table_view.delegate = self
        self.table_view.flex = 'WH'
        self.table_view.allows_multiple_selection = True
        self.table_view.tint_color = 'gray'
        self.view = ui.View(frame=self.table_view.frame)
        self.view.add_subview(self.table_view)
        self.view.name = root_node.title
        self.busy_view = ui.View(frame=self.view.bounds, flex='WH', background_color=(0, 0, 0, 0.35))
        hud = ui.View(frame=(self.view.center.x - 50, self.view.center.y - 50, 100, 100))
        hud.background_color = (0, 0, 0, 0.7)
        hud.corner_radius = 8.0
        hud.flex = 'TLRB'
        spinner = ui.ActivityIndicator()
        spinner.style = ui.ACTIVITY_INDICATOR_STYLE_WHITE_LARGE
        spinner.center = (50, 50)
        spinner.start_animating()
        hud.add_subview(spinner)
        self.busy_view.add_subview(hud)
        self.busy_view.alpha = 0.0
        self.view.add_subview(self.busy_view)
        self.done_btn = ui.ButtonItem(title='Done', action=self.done_action)
        if self.allow_multi:
            self.view.right_button_items = [self.done_btn]
        self.done_btn.enabled = False
        self.root_node = root_node
        self.entries = []
        self.flat_entries = []
        if self.async_mode:
            self.set_busy(True)
            t = threading.Thread(target=self.expand_root)
            t.start()
        else:
            self.expand_root()
项目: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 ns(py_obj):
    '''Convert common Python objects to their ObjC equivalents, i.e. str => NSString, int/float => NSNumber, list => NSMutableArray, dict => NSMutableDictionary, bytearray => NSData, set => NSMutableSet. Nested structures (list/dict/set) are supported. If an object is already an instance of ObjCInstance, it is left untouched.
        '''
    if isinstance(py_obj, ObjCInstance):
        return py_obj
    if isinstance(py_obj, c_void_p):
        return ObjCInstance(py_obj)
    if isinstance(py_obj, ui.View):
        return ObjCInstance(py_obj)
    if isinstance(py_obj, str):
        return NSString.stringWithUTF8String_(py_obj)
    if isinstance(py_obj, unicode):
        return NSString.stringWithUTF8String_(py_obj.encode('utf-8'))
    elif isinstance(py_obj, bytearray):
        return NSData.dataWithBytes_length_(str(py_obj), len(py_obj))
    elif isinstance(py_obj, int):
        return NSNumber.numberWithInt_(py_obj)
    elif isinstance(py_obj, float):
        return NSNumber.numberWithDouble_(py_obj)
    elif isinstance(py_obj, bool):
        return NSNumber.numberWithBool_(py_obj)
    elif isinstance(py_obj, list):
        arr = NSMutableArray.array()
        for obj in py_obj:
            arr.addObject_(ns(obj))
        return arr
    elif isinstance(py_obj, set):
        s = NSMutableSet.set()
        for obj in py_obj:
            s.addObject_(ns(obj))
        return s
    elif isinstance(py_obj, dict):
        dct = NSMutableDictionary.dictionary()
        for key, value in py_obj.iteritems():
            dct.setObject_forKey_(ns(value), ns(key))
        return dct
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
    ui.View.__init__(self)
    self.tv = None
    self.difficulty = 1
    self.starting = True
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def make_board_scene(self, center_frame):
        board_scene = SkChessBoardScene(self.game, center_frame)
        scene_view = sk.View(board_scene)
        scene_view.frame = center_frame  # center_square()
        scene_view.shows_fps = True
        scene_view.shows_node_count = True
        scene_view.shows_physics = True
        return scene_view

    #@classmethod
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self):
        self.view = ui.View(background_color='lightyellow')
        self.view.name = 'MiniPhotoView'
        scrollview1 = ui.ScrollView()
        scrollview1.name = 'scrollview1'
        scrollview1.flex = 'WH'
        scrollview1.content_size = (2000,2000)
        self.view.add_subview(scrollview1)
        self.view.present('full_screen')
        self.sv1 = self.view['scrollview1']
        width, height = self.sv1.content_size
        self.sv1.add_subview(MyPictureView(width,height))
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def popover(self, msg):
        textview = ui.TextView()
        textview.editable = False
        textview.font = ('AmericanTypewriter', 24)
        textview.alignment = ui.ALIGN_CENTER
        textview.text = msg
        pov = ui.View()
        pov.width = textview.width = 222
        pov.add_subview(textview)
        pov.present('popover')

# in the .pyui file, the "Custom View Class" must be set to AreYouEnabledView
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, *args,**kwargs):
        ui.View.__init__(self,*args,**kwargs)
        self.history=[]  #future...keep track of recent colors
        self.current=(.3,0.2,0.5) 
        self.N=16
        self.Nb=32
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, 
                 frame=(0, 0, 600, 400),
                 **kwargs):
        self._undo = UndoStack()
        self._tv = ui.TextView(frame=(0,0,self.width,self.height),bg_color=(1.0,1.0,1.0))
        self._tv.flex='WH'
        self.add_subview(self._tv)
        ui.View.__init__(self,**kwargs)
        #ui props
        self.frame=frame
        self._tv.delegate = self
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def add_subview(self,subviews):
        if not hasattr(subviews,'__contains__'):
            subviews=[subviews]
        for s in subviews:
            self.originalSizes.append(s.frame[2:3])
            ui.View.add_subview(self,s)
        self.layout()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def add_subview(self,subviews):
        if not hasattr(subviews,'__contains__'):
            subviews=[subviews]
        _hidden=self.hidden
        self.hidden=True
        for s in subviews:
            self.originalSizes.append(s.frame[2:])
            print 'bf add'
            ui.View.add_subview(self,s)

        self.hidden=_hidden
            #self.originalSizes.append(s.frame[2:])
        print 'bf lay'
        self.layout()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, N_onscreen=700,*args, **kwargs):
      ui.View.__init__(self,*args,**kwargs)
      # ready lock is used to protect calls to matplotlib
      self.ready=threading.Lock()
      #set up zoomable sliders
      self.hslider=ZoomSlider(frame=(self.width*0.08,0,self.width*0.84,self.height*0.08),vert=0,flex='wt')
      self.vslider=ZoomSlider(frame=(0,self.height*0.08,self.width*0.08,self.height*0.84),vert=1,flex='hr')
      self.add_subview(self.hslider)
      self.add_subview(self.vslider)
      self.hslider.barvalue=0.125
      self.hslider.barwidth=0.25
      self.vslider.barvalue=0.5
      self.vslider.barwidth=1.0
      self.hslider.action=self.did_slide
      self.vslider.action=self.did_slide
      #matplotlib image output
      self.img_view = ui.ImageView(frame=[self.width*0.08,self.height*0.08,self.width*0.84,self.height*0.84],flex='WH',bg_color=(1,1,1))
      self.add_subview(self.img_view)
      # image buffer
      self.b = io.BytesIO()

      #store base xlim and ylim, only update when drag ends
      self.xlim=plt.xlim()
      self.ylim=plt.ylim()
      self.N_onscreen=N_onscreen # number of points onscreen

      # fast and slow dpi..  set low_dpi to lower number for snappier response
      self.high_dpi=92
      self.low_dpi=16.
      self.device_dpi=72
      # set output image size to match view size.  this probably should be modified to use actual device dpi and size.  fonts and line width are based on pts, not pixels
      plt.gcf().set_size_inches(self.img_view.width/self.device_dpi,self.img_view.height/self.device_dpi)
      #update plot, ensuring update really happens
      #self.update_plt(dpi=self.high_dpi, waitForLock=True)

      #ObjCInstance(self).becomeFirstResponder()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def add_subview(self,subview):
        #override add_subview to add to longtapbox
        ui.View.add_subview(self.flow,subview)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def layout(self):
        '''force internal slider to follow this Views width/height'''
        s=self.slider
        s.height,s.width=self.height,self.width
       # s.x=s.y=0 # i thought this might be needed, but it seems not to be.  

    # we want various View parameters to masquerade as the internal slider's.
    #   the importand ones seem to be 
    #        tint_color, bg_color, action, continuous, value
    #   though a few others like alpha, borderparameters, etc might be needed 
    #   if you plan on modifying from within the action
项目: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 __init__(self, *args, **kwargs):
        ui.View.__init__(self, *args, **kwargs)
        self.header = None
        self.border_color = 'black'
        self.border_width = 2
        self.corner_radius = 6
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        ui.View.__init__(self, *args, **kwargs)
        self.panels = []
        self.updates_running = False

        self.make_view()
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def display_toast(view, help_text, width = 220, height = 110, show_duration=2, fade_duration=0.5, background_colour=(.42, .42, .42), text_colour= (.96, .96, .96), corner_radius=10):

    w, h = ui.get_screen_size()

    help_view = ui.View(frame=((w/2)-(width/2),(h/2)-height, width, height))
    help_view.background_color = background_colour
    help_view.corner_radius = corner_radius

    label = ui.Label()
    label.text = help_text
    label.flex = 'H'
    label.width = help_view.width * 0.9
    label.alignment = ui.ALIGN_CENTER
    label.x = (help_view.width / 2) - (label.width / 2)
    label.y = (help_view.height / 2) - (label.height / 2)
    label.number_of_lines = 3

    label.text_color = text_colour

    help_view.add_subview(label)

    def animation_fade_in():
        help_view.alpha = 1.0
    def animation_fade_out():
        help_view.alpha = 0.0

    help_view.alpha = 0.0
    view.add_subview(help_view)
    ui.animate(animation_fade_in, duration=fade_duration)
    time.sleep(show_duration+fade_duration)
    ui.animate(animation_fade_out, duration=fade_duration)
    time.sleep(fade_duration)
    view.remove_subview(help_view)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        ui.View.__init__(self, *args, **kwargs)
        MKMapView = ObjCClass('MKMapView')
        frame = CGRect(CGPoint(0, 0), CGSize(self.width, self.height))
        self.mk_map_view = MKMapView.alloc().initWithFrame_(frame)
        flex_width, flex_height = (1<<1), (1<<4)
        self.mk_map_view.setAutoresizingMask_(flex_width|flex_height)
        self_objc = ObjCInstance(self)
        self_objc.addSubview_(self.mk_map_view)
        self.mk_map_view.release()
项目: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()