Ejemplo n.º 1
0
    def __init__(self, master=None, cnf={}, **kw):
        kw = _cnfmerge((cnf, kw))
        self._stop_state = False
        self.after_id = ' '
        cnf = dict(
            text=kw.pop('text', ''),
            font=kw.pop('font', 'TkDefaultFont'),
            fg=kw.pop('fg', 'black') if kw.get('fg') else kw.pop(
                'foreground', 'black'),
            fps=kw.pop('fps', 30),
            justify=kw.pop('justify', 'left'),
            left_margin=kw.pop('left_margin', 10),
            initial_delay=kw.pop('initial_delay', 1000),
            end_delay=kw.pop('end_delay', 1000),
            smoothness=kw.pop('smoothness', 1),  # 1 <= smooth < 1
            disabledforeground=kw.pop('disabledforeground', 'grey'))
        cnf['foreground'] = cnf['fg']
        cnf = {k: v for k, v in cnf.items() if v is not None}

        kw['height'] = kw.get('height', 24)
        kw['highlightthickness'] = kw.get('highlightthickness', 0)
        tkinter.Canvas.__init__(self, master=master, **kw)
        self.cnf = check_param(self, 'marquee', **cnf)
        self._set_text()
        _bind(self,
              className='configure',
              sequence='<Configure>',
              func=self._check)
Ejemplo n.º 2
0
 def _bind_handler(self, *ags, **kw):
     """Internet function.\n
     Don't call this function directly."""
     _bind(self, *ags, **kw)
     lb = getattr(self, '_indi_lb', False)
     if lb and lb.winfo_exists():
         _bind(lb, *ags, **kw)
Ejemplo n.º 3
0
 def set_widget(wid):
     """Internal function.\n
     Binds <Enter> and <Leave> to the widget 
     to enable/disable mousewheel scrolling."""
     binds = [{'className': 'mw_state_sframe', 'sequence':
               '<Leave>', 'func': lambda _: self._mouse_scrolling(True)}]
     if not isinstance(wid, SFrameBase):
         binds.append({'className': 'mw_state_sframe', 'sequence':
                       '<Enter>', 'func': lambda _: self._mouse_scrolling(False)})
     _bind(wid, *binds)
Ejemplo n.º 4
0
    def __init__(self, master=None, cnf={}, **kw):
        kw = {k: v for k, v in _cnfmerge((cnf, kw)).items() if v is not None}
        cnf = {
            k: kw.pop(k, None)
            for k in kw.copy() if k in COLORSCALE_FEATURES
        }

        cnf['command'] = cnf.get('command', '')
        cnf['gradient'] = cnf.get('gradient', 'default')
        cnf['mousewheel'] = cnf.get('mousewheel', False)
        cnf['orient'] = cnf.get('orient', 'vertical')
        cnf['showinfo'] = cnf.get('showinfo', True)
        cnf['showinfodelay'] = cnf.get('showinfodelay', 1500)
        cnf['value'] = cnf.get('value', 'hex')
        cnf['variable'] = cnf.get('variable', '')

        kw['width'] = kw.get("width", 250 if 'ver' in cnf['orient'] else 30)
        kw['height'] = kw.get("height", 30 if 'ver' in cnf['orient'] else 250)
        kw['highlightthickness'] = kw.get('highlightthickness', 0)
        _Canvas.__init__(self, master=master, cnf={}, **kw)

        self.cnf = self._check_param(**cnf)
        self._size = (0, 0)
        self._marker_color = 'black'
        self._xy = int((self.winfo_reqwidth() if 'ver' in self.cnf['orient']
                        else self.winfo_reqheight()) / 3)

        binds = [{
            'className': 'set_size',
            'sequence': '<Configure>',
            'func': self._set_size
        }, {
            'className': 'b1_on_motion',
            'sequence': '<B1-Motion>',
            'func': self._check_marker
        }, {
            'className': 'b1_press',
            'sequence': '<Button-1>',
            'func': self._check_marker
        }]
        _bind(self, *binds)
        self._set_mousewheel()
Ejemplo n.º 5
0
    def _mouse_scrolling(self, state):
        """Internal function."""
        def enable_mousewheel(evt=None):
            """Internal function."""
            self.bind_all('<MouseWheel>', self._on_mouse_scroll)

        def disable_mousewheel(evt=None):
            """Internal function."""
            self.unbind_all('<MouseWheel>')

        if state:
            _bind(self,
                  {'className': 'mousewheel_state', 'sequence':
                   '<Enter>', 'func': enable_mousewheel},
                  {'className': 'mousewheel_state', 'sequence':
                   '<Leave>', 'func': disable_mousewheel})
            enable_mousewheel()
        else:
            _bind(self,
                  {'className': 'mousewheel_state', 'sequence': '<Enter>'},
                  {'className': 'mousewheel_state', 'sequence': '<Leave>'})
            disable_mousewheel()
Ejemplo n.º 6
0
    def __init__(self, master=None, cnf={}, **kw):
        kw = _cnfmerge((cnf, kw))
        kw['class_'] = kw.get('class_', 'Sframe')
        self._after_ids = {}
        self._over_scrollbar = False
        cnf = {}
        cnf['scrollbarwidth'] = kw.pop('scrollbarwidth', 10)
        cnf['mousewheel'] = kw.pop('mousewheel', True)
        cnf['avoidmousewheel'] = kw.pop('avoidmousewheel', ())
        cnf['autohidescrollbar'] = kw.pop('autohidescrollbar', False)
        cnf['autohidescrollbardelay'] = kw.pop('autohidescrollbardelay', 1000)
        cnf['canvas'] = kw.pop(
            'canvas', tkinter.Canvas(master=master, highlightthickness=0,
                                     width=kw.pop('width', 250), height=kw.pop('height', 250)))
        cnf['scrollbar'] = kw.pop(
            'scrollbar', tkinter.Scrollbar(cnf['canvas'], orient='vertical',
                                           width=cnf.get('scrollbarwidth')))
        tkinter.Frame.__init__(self, cnf['canvas'], **kw)
        self.cnf = check_param(self, 'sframe', **cnf)
        self.cnf['canvas']['bg'] = self['bg']

        if not self.cnf['autohidescrollbar']:
            self.cnf['scrollbar'].place(
                relx=1, rely=0, anchor='ne', relheight=1)

        self.cnf['scrollbar'].configure(command=self.cnf['canvas'].yview)
        self.cnf['canvas'].configure(yscrollcommand=self.cnf['scrollbar'].set)
        self.cnf['canvas'].create_window(
            0, 0, anchor='nw', tags="window", window=self,
            width=self.cnf['canvas'].winfo_reqwidth()-self.cnf['scrollbar'].winfo_reqwidth())
        self.cnf['canvas'].bind("<Configure>", self._configure_height, add="+")

        _bind(self, className='configure',
              sequence='<Configure>', func=self._configure_window)
        _bind(self, className='auto_hide_motion',
              sequence='<Motion>', func=self._auto_hide_scrollbar)
        _bind(
            self['scrollbar'], className='auto_hide_motion', sequence='<Enter>',
            func=lambda _: self._auto_hide_scrollbar('show'))
        _bind(
            self['scrollbar'], className='auto_hide_motion', sequence='<Leave>',
            func=self._auto_hide_scrollbar)

        self._mouse_scrolling(self.cnf['mousewheel'])
        self._avoid_mousewheel(self.cnf.get('avoidmousewheel'))
        self._geometryManager()
Ejemplo n.º 7
0
    def _set_mousewheel(self, evt=None):
        """Internal function.\n
        Sets mousewheel scrolling."""
        def on_mousewheel(evt=None):
            "Internal function."
            ver_cond = self._xy < self.winfo_width() \
                and self['orient'] == 'vertical'
            hor_cond = self._xy < self.winfo_height() \
                and self['orient'] == 'horizontal'
            if delta(evt) <= -1 and (ver_cond or hor_cond):
                self._xy += 1
                if not self._check_marker(evt, mw=self._xy):
                    self._xy -= 1
            if delta(evt) >= 1 and self._xy > 1:
                self._xy -= 1
                if not self._check_marker(evt, mw=self._xy):
                    self._xy += 1

        if self.cnf.get('mousewheel'):
            _bind(self,
                  className='mousewheel',
                  sequence='<MouseWheel>',
                  func=on_mousewheel)
            _bind(self,
                  className='mousewheel_x11',
                  sequence='<Button-4>',
                  func=on_mousewheel)
            _bind(self,
                  className='mousewheel_x11',
                  sequence='<Button-5>',
                  func=on_mousewheel)
        else:
            _bind(self, className='mousewheel', sequence='<MouseWheel>')
            _bind(self, className='mousewheel_x11', sequence='<Button-4>')
            _bind(self, className='mousewheel_x11', sequence='<Button-5>')