def add_widget(self, widget, tab=None): if tab is None: if not hasattr(widget, 'tab'): raise Exception('Widget added without tab information') else: tab = widget.tab button = MTButton(label=tab, size=(120, 40)) button.tab_container = self button.connect('on_release', curry(self.select, tab)) self.topbar.add_widget(button) self.tabs[tab] = (button, widget)
def __init__(self, **kwargs): '''Kinetic object, the base object for every child in kineticlist. :Parameters: `deletable`: bool, default to True Indicate if object can be deleted or not ''' kwargs.setdefault('deletable', True) super(MTKineticObject, self).__init__(**kwargs) self.deletable = kwargs.get('deletable') self.register_event_type('on_animation_complete') self.push_handlers(on_animation_complete=self.on_animation_complete) # List of attributes that can be searched self.attr_search = ['label'] # In case the widget has to move itself # while still having kinetic movement applied self.xoffset = self.yoffset = 0 # The position values that the kinetic container edits. # We do this so we can break free and move ourself it necessary self.kx = self.ky = 0 self.db_alpha = 0.0 # Set to true if you want to break free from # the grasp of a kinetic widget self.free = False # Delete Button if self.deletable: self.db = MTButton(label='', size=(40, 40), pos=(self.x + self.width - 40, self.y + self.height - 40), style={'bg-color': (1, 0, 0, 0)}, visible=False) self.db.push_handlers(on_press=self._delete_callback) self.add_widget(self.db) self.a_delete = Animation(width=0, height=0, xoffset=self.kx + self.width / 2, yoffset=self.ky + self.height / 2, duration=0.5, f='ease_in_cubic') self.a_show = Animation(db_alpha=.5, duration=0.25) self.a_hide = Animation(db_alpha=0.0, duration=0.25)
def __init__(self, **kwargs): kwargs.setdefault('hide', True) super(MTSidePanel, self).__init__(**kwargs) self.side = kwargs.get('side', 'left') self.align = kwargs.get('align', 'center') self.corner_size = kwargs.get('corner_size', 30) self.duration = kwargs.get('duration', .5) layout = kwargs.get('layout', None) corner = kwargs.get('corner', None) assert (self.side in ('bottom', 'top', 'left', 'right')) assert (self.align in ('bottom', 'top', 'left', 'right', 'middle', 'center')) if layout is None: from pymt.ui.widgets.layout import MTBoxLayout layout = MTBoxLayout() self.layout = layout super(MTSidePanel, self).add_widget(layout) if corner is None: from pymt.ui.widgets.button import MTButton if self.side == 'right': label = '<' elif self.side == 'left': label = '>' elif self.side == 'top': label = 'v' elif self.side == 'bottom': label = '^' corner = MTButton(label=label) else: self.corner_size = None self.corner = corner # Don't add to front or widgets added as children of layout will be occluded super(MTSidePanel, self).add_widget(self.corner, front=False) self.corner.connect('on_press', self._corner_on_press) self.initial_pos = self.pos self.need_reposition = True if kwargs.get('hide'): self.layout.visible = False self.hide()
def fullscreen(self, *largs, **kwargs): root_win = self.parent.get_parent_window() # save state for restore self.old_children = root_win.children self.old_size = self.size # set new children root_win.children = SafeList() root_win.add_widget(self.container) btn_unfullscreen = MTButton(pos=(root_win.width - 50, root_win.height - 50), size=(50, 50), label='Back') btn_unfullscreen.push_handlers(on_release=self.unfullscreen) root_win.add_widget(btn_unfullscreen) self.size = root_win.size self.container.size = self.size
def new_tab(self, label): '''fucntion that returns a new tab. return value must be of type MTButton or derive from it (must have on_press handler) if you overwrite the method. A Screenlayuot subclasses can overwrite this to create tabs based with own look and feel or do other custom things when a new tab is created''' return MTButton(label=label, size_hint=(1, 1), height=30)
def __init__(self, **kwargs): kwargs.setdefault('anchor_x', 'left') kwargs.setdefault('anchor_y', 'center') kwargs.setdefault('halign', 'left') kwargs.setdefault('keyboard', None) kwargs.setdefault('keyboard_to_root', False) kwargs.setdefault('group', None) kwargs.setdefault('switch', True) kwargs.setdefault('keyboard_type', pymt_config.get('widgets', 'keyboard_type')) super(MTTextInput, self).__init__(**kwargs) self.register_event_type('on_text_change') self.register_event_type('on_text_validate') self._scroll_x = 0 self._can_deactive = True self._keyboard = kwargs.get('keyboard') self._is_active_input = False #: Boolean to activate the password mode on the textinput. #: If true, it will show star instead of real characters self.password = kwargs.get('password', False) #: Boolean to control the scrolling of the textinput content self.scroll = kwargs.get('scroll', True) #: If the scroll if more than scroll_trigger, no event will be #: dispatched, and no show/hide of keyboard. self.scroll_trigger = kwargs.get('scroll_trigger', 10) #: Keyboard type (virtual or real) self.keyboard_type = kwargs.get('keyboard_type') #: If True, the keyboard is added to root window, not to parent window. self.keyboard_to_root = kwargs.get('keyboard_to_root') # initialize group on random if nothing is set self._groupname = kwargs.get('group') if self._groupname is None: MTTextInput._group_id += 1 self._groupname = 'uniqgroup%d' % MTTextInput._group_id # first time ? create the group if not self._groupname in self._group: self.group['keyboard'] = None self.group['widgets'] = [] self.group['widgets'].append(self) # save original color for error self._notify_bg_color = self.style['bg-color'] self._notify_bg_color_active = self.style['bg-color-active'] self._notify_animation = None # switch button between vkeyboard or hardware self._switch = None if kwargs.get('switch'): self._switch = MTButton(label=kwargs.get('keyboard_type'), cls='switch-button', size=(60, 20), font_size=8, pos=(self.x + self.width - 60, self.y + self.height)) self.interesting_keys = { 8: 'backspace', 13: 'enter', 127: 'del', 271: 'enter', 273: 'cursor_up', 274: 'cursor_down', 275: 'cursor_right', 276: 'cursor_left', 278: 'cursor_home', 279: 'cursor_end', 280: 'cursor_pgup', 281: 'cursor_pgdown', 303: 'shift_L', 304: 'shift_R' }