Python ui 模块,ALIGN_CENTER 实例源码

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

项目:OCT_iOS    作者:MilkShakeYoung    | 项目源码 | 文件源码
def __init__(self, path='/'):
        tv = ui.TableView()
        tv.frame = self.bounds
        tv.flex = 'WH'
        ds = ui.ListDataSource([])
        ds.action = self.item_selected
        tv.data_source = ds
        tv.delegate = ds
        self.tableview = tv
        self.add_subview(self.tableview)
        self.name = 'Dropbox'
        label = ui.Label(frame=self.bounds)
        label.flex = 'WH'
        label.background_color = (1, 1, 1, 0.95)
        label.text = 'Loading...'
        label.touch_enabled = True
        label.alignment = ui.ALIGN_CENTER
        self.path = path
        self.add_subview(label)
        self.status_label = label
        self.canceled = False
项目:qdh_pythonista    作者:quadrohedron    | 项目源码 | 文件源码
def __init__(self, path='/'):
        tv = ui.TableView()
        tv.frame = self.bounds
        tv.flex = 'WH'
        ds = ui.ListDataSource([])
        ds.action = self.item_selected
        tv.data_source = ds
        tv.delegate = ds
        self.tableview = tv
        self.add_subview(self.tableview)
        self.name = 'Dropbox'
        label = ui.Label(frame=self.bounds)
        label.flex = 'WH'
        label.background_color = (1, 1, 1, 0.95)
        label.text = 'Loading...'
        label.touch_enabled = True
        label.alignment = ui.ALIGN_CENTER
        self.path = path
        self.add_subview(label)
        self.status_label = label
        self.canceled = False
项目: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 set_menu(self, menu_key, spec):
    menu_spec = spec[menu_key]
#    for v in self.menu.subviews:
#      self.menu.remove_subview(v)
    #top_y = 50
    x_increment = self.menu.width/(len(menu_spec)+1)
    dim = 0.55*x_increment
    for (i, (title, func)) in enumerate(menu_spec):
      btn = ui.Button()
      btn.title = title
      btn.action = func      
      btn.background_color = self.menu_color
      btn.tint_color = 'white'
      self.menu.add_subview(btn)
      btn.width = btn.height = dim
      btn.center = ((i+1)*x_increment, self.menu.height/4)
      btn.corner_radius = dim/2

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

    l = ui.Label(
      text=title, 
      background_color='grey',
      text_color='white',
      alignment=ui.ALIGN_CENTER,
      number_of_lines=0,
      frame=(
        left_margin+column * label_w_with_gap,
        gap+line * label_h_with_gap,
        label_w, label_h
    ))
    v.add_subview(l)
    return l
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def tableview_cell_for_row(self, tableview, section, row):
        cell = ui.TableViewCell()
        cell.text_label.text = str(self.items[row])
        cell.text_label.alignment = ui.ALIGN_CENTER
        return cell
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def make_right_side_view(cls, right_frame):
        text_view = ui.TextView(frame=right_frame)
        text_view.alpha = cls.views_alpha
        text_view.alignment = ui.ALIGN_CENTER
        text_view.editable = False
        text_view.text = '\n' + '1234567890 ' * 50
        return text_view
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def make_status_view(cls, status_frame):
        text_view = ui.TextView(frame=status_frame)
        text_view.alpha = cls.views_alpha
        text_view.alignment = ui.ALIGN_CENTER
        text_view.editable = False
        text_view.text = "Status: let the game begin...  It is white's turn to move"
        return text_view
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def to_css_alignment(self):
        mapping = { ui.ALIGN_LEFT: 'left', ui.ALIGN_CENTER: 'center', ui.ALIGN_RIGHT: 'right', ui.ALIGN_JUSTIFIED: 'justify', ui.ALIGN_NATURAL: 'start' }
        return mapping[self.markup.alignment]
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def make_labels(self, cell, text, pos):
        label = ui.Label()
        label.border_color = 'lightgrey'
        label.border_width = 0.5
        if pos == 2:
            label.text = str(datetime.datetime.fromtimestamp(text))
        else:
            label.text = str(text)
        label.frame = (pos*self.width/3,0,self.width/3,self.row_height)
        label.alignment = ui.ALIGN_CENTER
        cell.content_view.add_subview(label)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def parse_alignment(a):
    '''handle alignment attribute.  TODO: handle all valid types'''
    if a=='left':
        return ui.ALIGN_LEFT
    elif a=='right':
        return ui.ALIGN_RIGHT
    elif a=='center':
        return ui.ALIGN_CENTER
    else:        #fixme... handle all types. 
        print 'unhandled alignment',a
        return ui.ALIGN_LEFT
项目: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    作者:wizardofozzie    | 项目源码 | 文件源码
def main():
    global main_view
    delegate = MetadataDelegate.new()
    main_view = ui.View(frame=(0, 0, 400, 400))
    main_view.name = 'Barcode Scanner'
    session = AVCaptureSession.alloc().init()
    device = AVCaptureDevice.defaultDeviceWithMediaType_('vide')
    _input = AVCaptureDeviceInput.deviceInputWithDevice_error_(device, None)
    if _input:
        session.addInput_(_input)
    else:
        print('Failed to create input')
        return
    output = AVCaptureMetadataOutput.alloc().init()
    queue = ObjCInstance(dispatch_get_current_queue())
    output.setMetadataObjectsDelegate_queue_(delegate, queue)
    session.addOutput_(output)
    output.setMetadataObjectTypes_(output.availableMetadataObjectTypes())
    prev_layer = AVCaptureVideoPreviewLayer.layerWithSession_(session)
    prev_layer.frame = ObjCInstance(main_view).bounds()
    prev_layer.setVideoGravity_('AVLayerVideoGravityResizeAspectFill')
    ObjCInstance(main_view).layer().addSublayer_(prev_layer)
    label = ui.Label(frame=(0, 0, 400, 30), flex='W', name='label')
    label.background_color = (0, 0, 0, 0.5)
    label.text_color = 'white'
    label.text = 'Nothing scanned yet'
    label.alignment = ui.ALIGN_CENTER
    main_view.add_subview(label)
    session.startRunning()
    main_view.present('sheet')
    main_view.wait_modal()
    session.stopRunning()
    delegate.release()
    session.release()
    output.release()
    if found_codes:
        print 'All scanned codes:\n' + '\n'.join(found_codes)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def draw(self):
            square_size=min(self.width,self.height)
            N=self.N
            Nb=self.Nb
            dx=square_size*1.0/(N+2)
            dxb=N*dx/Nb
            h,s,v=self.current
            i0,j0,k0=(round(c*N) for c in self.current)

            k0=round(self.current[2]*Nb)
            #draw H/S grid
            for i in xrange(0,N):
                for j in xrange(0,N):           
                    ui.set_color(colorsys.hsv_to_rgb(i*1.0/N,j*1.0/N,v))
                    ui.set_blend_mode(ui.BLEND_NORMAL)
                    ui.fill_rect(round(i*dx),round(j*dx),round(dx),round(dx))

            #draw V slider
            for k in xrange(0,Nb):
                ui.set_color(colorsys.hsv_to_rgb(h,s,k*1./Nb))
                ui.set_blend_mode(ui.BLEND_NORMAL)
                ui.fill_rect(round((N+1)*dx),round(k*dxb),round(dx),round(dxb+0.5))

            #highlight selection
            if all([c>=0 for c in self.current]):
                ui.set_color(colorsys.hsv_to_rgb(h,s,1-0.5*(1-v)))
                p=ui.Path.rect(i0*dx,j0*dx,dx,dx)
                p.line_width=4
                p.stroke()

                ui.set_color(colorsys.hsv_to_rgb(h,s,1-0.5*(1-v)))
                p=ui.Path.rect((N+1)*dx,k0*dxb,dx,dxb)
                p.line_width=4
                p.stroke()
                #preview
                ui.set_color(colorsys.hsv_to_rgb(h,s,v))
                ui.fill_rect(0,(N+1)*dx,6*dx,dx)
                r,g,b=colorsys.hsv_to_rgb(h,s,v)

                clip=lambda x:min(max(x,0),1)
                rp,gp,bp=colorsys.hsv_to_rgb(1-h,1,clip((0.5-v)*100))
                ui.draw_string(         ('{:02x}'*3).format(int(r*255),int(g*255),int(b*255)), (0,(N+1)*dx,6*dx,dx),alignment=ui.ALIGN_CENTER,color=(rp,gp,bp))
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def draw(self):
        # redraw button
        def darken(color):
            return tuple([0.5*x for x in color])


        #set up button size to fit.
        padding=10
        textsize=ui.measure_string(string=self.title,max_width=0,font=self.font,alignment=ui.ALIGN_CENTER)

        #draw border
        ui.set_color(self.border_color)
        path = ui.Path.rounded_rect(0, 0, self.width, self.height,self.corner_radius)
        path.line_width=self.border_width
        path.stroke()

        #fill button, depending on touch state
        if self.touched:
            if self.doing_longtouch:
                ui.set_color('blue')
            else:
                ui.set_color('grey')
        else :
            ui.set_color(self.bg_color)
        path.fill()

        # fill corner darker, if has children
        if self.flow.subviews:
            corner = ui.Path()
            corner.move_to(self.width-1.5*self.corner_radius,0)
            corner.line_to(self.width,0)
            corner.line_to(self.width,1.5*self.corner_radius)
            corner.line_to(self.width-1.5*self.corner_radius,0)
            ui.set_color(darken(darken(self.bg_color)))
            corner.stroke()
            corner.fill()

        # draw title, center vertically, horiz
        rect=list(self.bounds)
        rect[1]=(rect[3]-textsize[1])/2 #vert center
        rect[2]=max(rect[2],textsize[0]+10)
        ui.draw_string(self.title, rect=tuple(rect), font=self.font, color=self.tint_color, alignment=ui.ALIGN_CENTER, line_break_mode=ui.LB_WORD_WRAP)

        if textsize[0]>self.bounds[2]:
            self.width=textsize[0]+10
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def __init__(self, container, state):
        self._container = container
        self._touch_began_location = None
        self._initial_container_frame = None
        self._container_superview = ObjCInstance(container).superview()

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

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

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

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

        self.update_appearance(state)
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def __init__(self, **kwargs):
        super().__init__(**kwargs)

        if 'background_color' not in kwargs:
            self.background_color = 'white'

        if 'frame' not in kwargs:
            self.width = min(ui.get_window_size()[0] * 0.8, 700)
            self.height = ui.get_window_size()[1] * 0.8

        self._tableview = ui.TableView()
        self._textfield = ui.TextField()
        self._help_label = ui.Label()
        self._datasource = None
        self._handlers = None
        self.shift_enter_enabled = True
        self.did_select_item_action = None

        tf = LayoutProxy(self._textfield)
        self.add_subview(tf)
        tf.layout.align_left_with_superview.equal = 8
        tf.layout.align_top_with_superview.equal = 8
        tf.layout.align_right_with_superview.equal = -8
        tf.layout.height.equal = 31
        tf.delegate = self

        tv = LayoutProxy(self._tableview)
        self.add_subview(tv)
        tv.layout.align_left_to(tf).equal = 0
        tv.layout.align_right_to(tf).equal = 0
        tv.layout.top_offset_to(tf).equal = 8
        tv.allows_selection = True
        tv.allows_multiple_selection = False

        hl = LayoutProxy(self._help_label)
        self.add_subview(hl)
        hl.layout.align_left_to(tv).equal = 0
        hl.layout.align_right_to(tv).equal = 0
        hl.layout.top_offset_to(tv).equal = 8
        hl.layout.align_bottom_with_superview.equal = -8
        hl.layout.height.max = 66
        hl.font = ('<system>', 13.0)
        hl.alignment = ui.ALIGN_CENTER
        hl.text_color = (0, 0, 0, 0.5)
        hl.number_of_lines = 2

        if is_in_hardware_keyboard_mode:
            tf.view.begin_editing()

        self._register_key_event_handlers()