def create_line_label(self, text): '''Create a label from a text, using line options ''' ntext = text.replace('\n', '').replace('\t', ' ' * self.tab_width) kw = self.get_line_options() cid = '%s\0%s' % (ntext, str(kw)) label = Cache.get('textarea.label', cid) if not label: label = Label(ntext, **kw) Cache.append('textarea.label', cid, label) return label
def _create_ui(self): # Title Text if self.titletext is not None: self.title = Label(font_size=18, bold=True, anchor_x='center', anchor_y='center', label=self.titletext) self.title.x = self.width / 2 + self.x self.title.y = self.height - 20 + self.y # Delete Button if self.deletable: self.db = MTToggleButton(label='X', pos=(self.x + self.width - 80, self.y + self.height - 40), size=(80, 40), cls='kineticlist-delete') self.db.push_handlers(on_press=self.toggle_delete) self.widgets.append(self.db) # Search Button and Input Text Area if self.searchable: self.sb = MTToggleButton( label='S', #Button pos=(self.x, self.y + self.width - 40), size=(80, 40), cls='kineticlist-search') self.sb.push_handlers(on_press=self.toggle_search) self.sb.parent = self self.widgets.append(self.sb) self.sinput = pymt.MTTextInput(pos=(self.x, self.y + self.height - 40), size=(80, 40), style={'font-size': 20}) self.sinput.parent = self self.sinput.push_handlers(on_text_change=self.apply_filter) self.widgets.insert(0, self.sinput) # Animations to hide and show the search text input box self._a_sinput_in = Animation(y=self.y + self.height - 40 - self.sinput.size[1], duration=0.5, f='ease_out_cubic') self._a_sinput_out = Animation(y=self.y + self.height - self.sinput.size[1], duration=0.5, f='ease_out_cubic')
def __init__(self, **kwargs): kwargs.setdefault('padding_x', 4) kwargs.setdefault('padding_y', 4) kwargs.setdefault('w_limit', 1) kwargs.setdefault('h_limit', 0) kwargs.setdefault('do_x', False) kwargs.setdefault('do_y', True) kwargs.setdefault('title', 'No title') kwargs.setdefault('deletable', True) kwargs.setdefault('searchable', True) kwargs.setdefault('align', 'center') super(MTKineticList, self).__init__(**kwargs) self.register_event_type('on_delete') self._a_sinput_out = None self._a_sinput_in = None self.title = Label('') self.sb = None self.sinput = None self.do_x = kwargs.get('do_x') self.do_y = kwargs.get('do_y') self.titletext = kwargs.get('title') self.deletable = kwargs.get('deletable') self.searchable = kwargs.get('searchable') self.padding_x = kwargs.get('padding_x') self.padding_y = kwargs.get('padding_y') self.w_limit = kwargs.get('w_limit') self.h_limit = kwargs.get('h_limit') self.align = kwargs.get('align') self.trigger_distance = kwargs.get( 'trigger_distance', pymt_config.getint('widgets', 'list_trigger_distance')) self.friction = kwargs.get( 'friction', pymt_config.getint('widgets', 'list_friction')) if self.w_limit and self.h_limit: raise Exception('You cannot limit both axes') elif not (self.w_limit or self.h_limit): raise Exception('You must limit at least one axis') # How far to offset tself.deletable and he axes(used for scrolling/panning) self.xoffset = 0 self.yoffset = 0 # X and Y translation vectors for the kinetic movement self.vx = 0 self.vy = 0 # List of all children, whatever will be the search self.pchildren = [] # For extra blob stats self.touch = {} # Holds widgets not a part of the scrolling(search button, etc) self.widgets = [] self._last_content_size = 0 self._scrollbar_index = 0 self._scrollbar_size = 0 # create the UI part. self._create_ui()