def _options(self, cnf, kw=None): """Internal function.""" if kw: cnf = _TK._cnfmerge((cnf, kw)) else: cnf = _TK._cnfmerge(cnf) # ----------- Added the below block ------------- # Add the resources to the list to have ColorVar functionality. # It'll work as long as it's not an item of canvas or mark_tag of text. for i in ( 'fg', 'foreground', 'bg', 'background', 'activebackground', 'activeforeground', 'disabledforeground', 'highlightbackground', 'highlightcolor', 'selectforeground', 'readonlybackground', 'selectbackground', 'insertbackground', 'disabledbackground', ): if isinstance(cnf.get(i), _TK.Variable): var = cnf[i] cbname = var.trace_add( 'write', lambda *a, i=i, cls=self: cls.config({i: var.get()})) if (self, i) in _all_traces_colorvar: v, cb = _all_traces_colorvar.get((self, i)) v.trace_remove('write', cb) _all_traces_colorvar[(self, i)] = (var, cbname) else: _all_traces_colorvar[(self, i)] = (var, cbname) cnf[i] = var.get() # ----------------------------------------------- res = () for k, v in cnf.items(): if v is not None: if k[-1] == '_': k = k[:-1] if callable(v): v = self._register(v) elif isinstance(v, (tuple, list)): nv = [] for item in v: if isinstance(item, int): nv.append(str(item)) elif isinstance(item, str): nv.append(_TK._stringify(item)) else: break else: v = ' '.join(nv) res = res + ('-' + k, v) return res
def configure(self, cnf=None, **kw): if kw: cnf = tk._cnfmerge((cnf, kw)) elif cnf: cnf = tk._cnfmerge(cnf) key = 'width' if key in cnf: value = int(cnf[key]) minsize = self.tl_attrs.get('minsize', None) maxsize = self.tl_attrs.get('maxsize', None) # print(value, minsize, maxsize) remove = False # print('tl_attrs:', self.tl_attrs) if minsize and value < minsize[0]: remove = True if maxsize and value > maxsize[0]: remove = True if self._w_set: resizable = self.tl_attrs.get('resizable', None) if resizable and not TKToplevel.RESIZABLE[resizable][0]: remove = True if remove: # print('rm', key, value) cnf.pop(key) else: self._w_set = True key = 'height' if key in cnf: value = int(cnf[key]) minsize = self.tl_attrs.get('minsize', None) maxsize = self.tl_attrs.get('maxsize', None) # print(value, minsize, maxsize) remove = False if minsize and value < minsize[1]: remove = True if maxsize and value > maxsize[1]: remove = True if self._h_set: resizable = self.tl_attrs.get('resizable', None) if resizable and not TKToplevel.RESIZABLE[resizable][1]: remove = True if remove: # print('rm', key, value) cnf.pop(key) else: self._h_set = True key = 'menu' if key in cnf: # No menu preview available cnf.pop(key) return tk.Frame.configure(self, cnf)
def _options(self, cnf, kw=None): if kw: cnf = tkinter._cnfmerge((cnf, kw)) else: cnf = tkinter._cnfmerge(cnf) res = () for k,v in list(cnf.items()): if v is not None: if k[-1] == '_': k = k[:-1] #if callable(v): # v = self._register(v) res = res + ('-'+k, v) return res
def _options(self, cnf, kw=None): if kw: cnf = tkinter._cnfmerge((cnf, kw)) else: cnf = tkinter._cnfmerge(cnf) res = () for k, v in list(cnf.items()): if v is not None: if k[-1] == '_': k = k[:-1] #if callable(v): # v = self._register(v) res = res + ('-' + k, v) return res
def _configure(self, cnf=None, kw={}): if kw: cnf = tkinter._cnfmerge((cnf, kw)) elif cnf: cnf = tkinter._cnfmerge(cnf) if cnf is None: cnf = {} for x in self.tk.split(self.tk.call(self.name, 'configure')): cnf[x[0][1:]] = (x[0][1:], ) + x[1:] return cnf if type(cnf) is bytes: x = self.tk.split(self.tk.call(self.name, 'configure', '-' + cnf)) return (x[0][1:], ) + x[1:] self.tk.call((self.name, 'configure') + self._options(cnf))
def _options(self, cnf, kw=None): if kw: cnf = tkinter._cnfmerge((cnf, kw)) else: cnf = tkinter._cnfmerge(cnf) res = () for k, v in cnf.items(): if isinstance(v, collections.Callable): if k in self._tabsubst_commands: v = "%s %s" % (self._register(v, self._tabsubst), ' '.join(self._tabsubst_format)) else: v = self._register(v) res += ('-%s' % k, v) return res
def _configure(self, cnf=None, kw={}): if kw: cnf = tkinter._cnfmerge((cnf, kw)) elif cnf: cnf = tkinter._cnfmerge(cnf) if cnf is None: cnf = {} for x in self.tk.split( self.tk.call(self.name, 'configure')): cnf[x[0][1:]] = (x[0][1:],) + x[1:] return cnf if type(cnf) is bytes: x = self.tk.split(self.tk.call(self.name, 'configure', '-'+cnf)) return (x[0][1:],) + x[1:] self.tk.call((self.name, 'configure') + self._options(cnf))
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) color_change = False for key in ('calendarfg', 'calendarbg', 'headerfg', 'headerbg', 'selectbg', 'selectfg', 'markbg', 'markfg'): if key in args: self.__options[key] = args.pop(key) color_change = True calendar_change = False key = 'locale' if key in args: value = locale.normalize(args.pop(key)) self.__options[key] = value calendar_change = True key = 'firstweekday' if key in args: value = args.pop(key) self.__options[key] = int(value) calendar_change = True if calendar_change: self._reconfigure_calendar() date_change = False for key in ('year', 'month'): if key in args: self.__options[key] = int(args.pop(key)) date_change = True if date_change: self._reconfigure_date() if color_change or calendar_change or date_change: self._redraw_calendar() ttk.Frame.configure(self, args)
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) key = 'values' if key in args: self.choices = args[key] args[key] = self.__choices2tkvalues(self.choices) # clear variables: keyvar = self.__options['keyvariable'] if keyvar is not None: keyvar.set('') txtvar = self.cget('textvariable') if txtvar is not None: txtvar.set('') key = 'keyvariable' if key in args: value = args.pop(key) self.__config_keyvar(value) return key = 'textvariable' if key in args: value = args[key] self.__config_txtvar(value) # only readonly and disabled supported key = 'state' if key in args: if args[key] not in ('readonly', 'disabled'): args[key] = 'readonly' return ttk.Combobox.configure(self, args)
def __init__(self, master=None, cnf={}, **kw): kw = tk._cnfmerge((cnf, kw)) self.cnf = { 'value': kw.pop('value', 'rgb'), 'command': kw.pop("command", None), 'orient': kw.pop('orient', 'vertical'), 'mousewheel': kw.pop("mousewheel", True), 'variable': kw.pop('variable', None), 'showinfo': kw.pop('showinfo', True), 'showinfodelay': kw.pop('showinfodelay', 1500), } kw['width'] = kw.get("width", 250 if 'ver' in self.cnf['orient'] else 30) kw['height'] = kw.get("height", 30 if 'ver' in self.cnf['orient'] else 250) kw['highlightthickness'] = kw.get('highlightthickness', 0) tk.Canvas.__init__(self, master=master, **kw) self.xy_axis = int(self.winfo_width() / 3) self._size = (0, 0) self.np_im = np.load( os.path.dirname(os.path.abspath(__file__)) + "/images/colorscale.npy") self.image_id = self._image(0, 0, anchor='nw') # Binds self.bind_class(self, '<Button-1>', self.move_marker, '+') self.bind_class(self, "<B1-Motion>", self.move_marker, '+') self.set_mousewheel() self.bind_class(self, '<Configure>', self.on_resize, '+')
def __init__(self, master=None, cnf=None, **kw): if cnf is None: cnf = {} if kw: cnf = _cnfmerge((cnf, kw)) fcnf = {} for k in list(cnf.keys()): #if type(k) == ClassType or k == 'name': if k == 'name' or isinstance(k, type): fcnf[k] = cnf[k] del cnf[k] self.frame = Frame(master, **fcnf) self.vbar = AutoScrollbar(self.frame, name='vbar') self.vbar.grid(row=0, column=1, sticky=N + S) #self.vbar.pack(side=RIGHT, fill=Y) cnf['name'] = 'text' Text.__init__(self, self.frame, **cnf) self.grid(row=0, column=0, sticky=N + S + E + W) #self.pack(side=LEFT, fill=BOTH, expand=1) self['yscrollcommand'] = self.vbar.set self.vbar['command'] = self.yview self.master.grid_rowconfigure(0, weight=1) self.master.grid_columnconfigure(0, weight=1) # Copy geometry methods of self.frame -- hack! methods = list(Pack.__dict__.keys()) methods = methods + list(Grid.__dict__.keys()) methods = methods + list(Place.__dict__.keys()) for m in methods: if m[0] != '_' and m != 'config' and m != 'configure': setattr(self, m, getattr(self.frame, m))
def fade(widget, smoothness=3, cnf={}, **kw): """This function will show faded effect on widget's different color options. Args: widget (tk.Widget): Passed by the bind function. smoothness (int): Set the smoothness of the fading (1-10). background (str): Fade background color to. foreground (str): Fade foreground color to.""" kw = tk._cnfmerge((cnf, kw)) if not kw: raise ValueError("No option given, -bg, -fg, etc") if len(kw) > 1: return [fade(widget, smoothness, {k: v}) for k, v in kw.items()][0] if not getattr(widget, '_after_ids', None): widget._after_ids = {} widget.after_cancel(widget._after_ids.get(list(kw)[0], ' ')) c1 = tuple(map(lambda a: a / 65535, widget.winfo_rgb(widget[list(kw)[0]]))) c2 = tuple(map(lambda a: a / 65535, widget.winfo_rgb(list(kw.values())[0]))) colors = tuple( colour.rgb2hex(c, force_long=True) for c in colour.color_scale(c1, c2, max(1, smoothness * 15))) def worker(count=0): if len(colors) - 1 <= count: return widget.config({list(kw)[0]: colors[count]}) widget._after_ids.update({ list(kw)[0]: widget.after(max(1, int(smoothness / 10)), worker, count + 1) }) worker()
def __init__(self, master=None, cnf=None, **kw): if cnf is None: cnf = {} if kw: cnf = _cnfmerge((cnf, kw)) fcnf = {k:v for k,v in cnf.items() if isinstance(k,type) or k=='name'} for k in fcnf.keys(): del cnf[k] self.frame = Frame(master, **fcnf) self.vbar = Scrollbar(self.frame, name='vbar') self.vbar.pack(side=RIGHT, fill=Y) cnf['name'] = 'text' Text.__init__(self, self.frame, **cnf) self.pack(side=LEFT, fill=BOTH, expand=1) self['yscrollcommand'] = self.vbar.set self.vbar['command'] = self.yview # Copy geometry methods of self.frame -- hack! methods = Pack.__dict__.keys() methods = methods + Grid.__dict__.keys() methods = methods + Place.__dict__.keys() for m in methods: if m[0] != '_' and m != 'config' and m != 'configure': setattr(self, m, getattr(self.frame, m))
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) key = 'type' if key in args: self._choose = args[key] del args[key] key = 'image' if key in args: self.folder_button.configure(image=args[key]) del args[key] key = 'path' if key in args: self.entry.delete(0, 'end') self.entry.insert(0, args[key]) self._generate_changed_event() del args[key] key = 'textvariable' if key in args: self.entry.configure(textvariable=args[key]) self._generate_changed_event() del args[key] key = 'state' if key in args: value = args[key] self.entry.config(state=value) if value in ('disabled', 'readonly'): self.folder_button.config(state='disabled') else: self.folder_button.config(state=value) del args[key] ttk.Frame.configure(self, args)
def configure(self, cnf=None, **kw): if kw: cnf = tk._cnfmerge((cnf, kw)) elif cnf: cnf = tk._cnfmerge(cnf) key = 'width' if key in cnf: value = int(cnf[key]) minsize = self.tl_attrs.get('minsize', None) maxsize = self.tl_attrs.get('maxsize', None) # print(value, minsize, maxsize) remove = False # print('tl_attrs:', self.tl_attrs) if minsize and value < minsize[0]: remove = True if maxsize and value > maxsize[0]: remove = True if self._w_set: resizable = self.tl_attrs.get('resizable', None) if resizable and not TKToplevel.RESIZABLE[resizable][0]: remove = True if remove: # print('rm', key, value) cnf.pop(key) else: self._w_set = True key = 'height' if key in cnf: value = int(cnf[key]) minsize = self.tl_attrs.get('minsize', None) maxsize = self.tl_attrs.get('maxsize', None) # print(value, minsize, maxsize) remove = False if minsize and value < minsize[1]: remove = True if maxsize and value > maxsize[1]: remove = True if self._h_set: resizable = self.tl_attrs.get('resizable', None) if resizable and not TKToplevel.RESIZABLE[resizable][1]: remove = True if remove: # print('rm', key, value) cnf.pop(key) else: self._h_set = True return tk.Frame.configure(self, cnf)
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) key = 'usemousewheel' if key in args: self.usemousewheel = tk.getboolean(args[key]) del args[key] self._configure_mousewheel() frame_class.configure(self, args)
def configure(self, cnf=None, **kw): kw = _TK._cnfmerge((cnf, kw)) self._canvas['width'] = kw.pop('width', self._canvas['width']) self._canvas['height'] = kw.pop('height', self._canvas['height']) self.yScroll['width'] = kw.pop('scrollbarwidth', self.yScroll['width']) self.mousewheel = kw.pop('mousewheel', self.mousewheel) self._mouse_scrolling() return super().configure(**kw)
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) key = 'usemousewheel' if key in args: self.usemousewheel = tk.getboolean(args[key]) del args[key] self._configure_mousewheel() super(ScrollbarHelperBase, self).configure(args)
def __init__(self, master, cnf={}, **kw): kw = tk._cnfmerge((cnf, kw)) self.previous_ln = None self._text = kw.pop('textwidget', None) self._padx = kw.pop('padx', 1) kw['width'] = kw.get('width', 40) kw['highlightthickness'] = kw.get('highlightthickness', 0) tk.Canvas.__init__(self, master=master, **kw)
def _options(self, cnf, kw): if kw and cnf: cnf = _cnfmerge((cnf, kw)) elif kw: cnf = kw opts = () for k, v in cnf.items(): opts = opts + ('-'+k, v) return opts
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) key = 'usemousewheel' if key in args: self.usemousewheel = tk.getboolean(args[key]) del args[key] self._configure_mousewheel() #super(ScrolledFrameBase, self).configure(args) self._framecls.configure(self, args)
def __init__(self, master=None, cnf={}, **kw): cnf = _cnfmerge((cnf, kw)) self.widgetName = "__dialogue__" AsyncWidget._setup(self, master, cnf) self.num = self.tk.getint( self.tk.call("tk_dialog", self._w, cnf["title"], cnf["text"], cnf["bitmap"], cnf["default"], *cnf["strings"])) try: asyncio.ensure_future(AsyncWidget.destroy(self)) except TclError: pass
def _patch(self, cnf, kw=None): """Internal function.""" cnf = tkinter._cnfmerge(cnf) if kw: cnf = tkinter._cnfmerge((cnf, kw)) for i in _properties2: if isinstance(cnf.get(i), tkinter.Variable): var = cnf[i] cbname = var.trace_variable( 'w', lambda a, b, c, i=i, var=var, cls=self: cls.config({i: var.get()})) if (self, i) in _all_traces_colorvar: v, cb = _all_traces_colorvar.get((self, i)) v.trace_vdelete('w', cb) _all_traces_colorvar[(self, i)] = (var, cbname) else: _all_traces_colorvar[(self, i)] = (var, cbname) cnf[i] = var.get() return fn(self, cnf, None)
def __init__(self, master=None, cnf=None, **kwargs): self.kwargs = kwargs if cnf is None: cnf = {} cnf = tk._cnfmerge((cnf, kwargs)) super(HoverButton, self).__init__(master=master, cnf=cnf, **kwargs) self.DefaultBG = self.kwargs['bg'] self.HoverBG = self.kwargs['activeback'] self.bind_class(self, "<Enter>", self.Enter) self.bind_class(self, "<Leave>", self.Leave)
def __init__(self, master=None, cnf={}, **kw): kw = _TK._cnfmerge((cnf, kw)) kw = {k: v for k, v in kw.items() if v is not None} self.stopped = None self.cnf = {} for i in kw.copy().keys(): if i in self._features: self.cnf[i] = kw.pop(i, None) self.cnf['fg'] = self.cnf.get('fg') if self.cnf.get( 'fg', None) else self.cnf.get('foreground', 'black') self.cnf['bd'] = self.cnf.get('bd') if self.cnf.get( 'bd', None) else self.cnf.get('borderwidth', 6) self.cnf['borderless'] = self.cnf.get('borderless', False) self.cnf['disabledforeground'] = self.cnf.get('disabledforeground', 'grey') if self.cnf.get('textvariable') is not None: self.cnf['text'] = self.cnf['textvariable'].get() self.cnf['anchor'] = self.cnf.get('anchor', 'center') kw['takefocus'] = kw.get('takefocus', 1) kw['highlightthickness'] = kw.get('highlightthickness', 0) kw['width'] = kw.get('width', 87) kw['height'] = kw.get('height', 24) super(Widget, self).__init__(master=master, **kw) self._buttons.append(self) self._size = (self.winfo_width(), self.winfo_height()) if self.cnf.get('text'): self._text(0, 0, text=None, tag='_txt') if self.cnf.get('image'): self._image(0, 0, image=None, tag='_img') elif self.cnf.get('bitmap'): self._bitmap(0, 0, image=None, tag='_bit') self.bind_class('button_release', '<ButtonRelease-1>', self.on_release, '+') self.bind_class('button_press', '<Button-1>', self.on_press, '+') self.bind_class('set_size', '<Configure>', self._set_size, '+') self.original_bg = self['bg'] # Focus in and out effect main_win = self.winfo_toplevel() def _chngIn(evt): if self.focus_get() is None: color = get_shade(self['bg'], 0.04, 'auto-120') self.itemconfig('_border1', outline=color) self.itemconfig('_border2', fill=color) if self.focus_get() and get_shade(self['bg'], 0.04, 'auto-120') == self.itemcget( '_border2', 'fill'): color = get_shade(self['bg'], 0.1, 'auto-120') self.itemconfig('_border1', outline=color) self.itemconfig('_border2', fill=color) main_win.bind_class(main_win, '<FocusIn>', _chngIn, '+') main_win.bind_class(main_win, '<FocusOut>', _chngIn, '+') self._getconfigure2(self.cnf)
def __init__(self, master=None, cnf={}, **kw): cnf = _cnfmerge((cnf, kw)) self.widgetName = '__dialog__' Widget._setup(self, master, cnf) self.num = self.tk.getint( self.tk.call('tk_dialog', self._w, cnf['title'], cnf['text'], cnf['bitmap'], cnf['default'], *cnf['strings'])) try: Widget.destroy(self) except TclError: pass
def tix_configure(self, cnf=None, **kw): """Query or modify the configuration options of the Tix application context. If no option is specified, returns a dictionary all of the available options. If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given option(s) to have the given value(s); in this case the command returns an empty string. Option may be any of the configuration options. """ # Copied from Tkinter.py if kw: cnf = _cnfmerge((cnf, kw)) elif cnf: cnf = _cnfmerge(cnf) if cnf is None: return self._getconfigure('tix', 'configure') if isinstance(cnf, str): return self._getconfigure1('tix', 'configure', '-'+cnf) return self.tk.call(('tix', 'configure') + self._options(cnf))
def __init__(self, master=None, cnf={}, **kw): cnf = _cnfmerge((cnf, kw)) self.widgetName = '__dialog__' Widget._setup(self, master, cnf) self.num = self.tk.getint( self.tk.call( 'tk_dialog', self._w, cnf['title'], cnf['text'], cnf['bitmap'], cnf['default'], *cnf['strings'])) try: Widget.destroy(self) except TclError: pass
def __init__ (self, master=None, widgetName=None, static_options=None, cnf={}, kw={}): # Merge keywords and dictionary arguments if kw: cnf = _cnfmerge((cnf, kw)) else: cnf = _cnfmerge(cnf) # Move static options into extra. static_options must be # a list of keywords (or None). extra=() # 'options' is always a static option if static_options: static_options.append('options') else: static_options = ['options'] for k,v in list(cnf.items()): if k in static_options: extra = extra + ('-' + k, v) del cnf[k] self.widgetName = widgetName Widget._setup(self, master, cnf) # If widgetName is None, this is a dummy creation call where the # corresponding Tk widget has already been created by Tix if widgetName: self.tk.call(widgetName, self._w, *extra) # Non-static options - to be done via a 'config' command if cnf: Widget.config(self, cnf) # Dictionary to hold subwidget names for easier access. We can't # use the children list because the public Tix names may not be the # same as the pathname component self.subwidget_list = {}
def image_create(self, imgtype, cnf={}, master=None, **kw): if not master: master = tkinter._default_root if not master: raise RuntimeError('Too early to create image') if kw and cnf: cnf = _cnfmerge((cnf, kw)) elif kw: cnf = kw options = () for k, v in cnf.items(): if callable(v): v = self._register(v) options = options + ('-'+k, v) return master.tk.call(('image', 'create', imgtype,) + options)
def _configure(self, cmd, cnf, kw): """Internal function.""" if kw: cnf = _TK._cnfmerge((cnf, kw)) elif cnf: cnf = _TK._cnfmerge(cnf) if cnf is None: return self._getconfigure(_TK._flatten((self._w, cmd))) if isinstance(cnf, str): return self._getconfigure1(_TK._flatten((self._w, cmd, '-' + cnf))) # -------------------- Added the below block -------------------- # Add the resources to the list to have ColorVar functionality. if isinstance(cmd, tuple) and isinstance(self, _TK.Canvas): tags = self.find_withtag(cmd[1]) cnf_copy = cnf.copy() for tag in tags: for i in ('activefill', 'activeoutline', 'disabledfill', 'disabledoutline', 'fill', 'outline', 'background', 'activebackground', 'activeforeground', 'disabledbackground', 'disabledforeground', 'foreground'): if isinstance(cnf_copy.get(i), _TK.Variable): var = cnf_copy[i] cbname = var.trace_add( 'write', lambda *a, cls=self, opt=i, tagId=tag, var=var: cls. itemconfig(tagId, {opt: var.get()})) if (self, (i, tag)) in _all_traces_colorvar: v, cb = _all_traces_colorvar.get((self, (i, tag))) v.trace_remove('write', cb) _all_traces_colorvar[(self, (i, tag))] = (var, cbname) else: _all_traces_colorvar[(self, (i, tag))] = (var, cbname) cnf[i] = var.get() self.tk.call(_TK._flatten((self._w, cmd)) + self._options(cnf))
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) key = 'values' if key in args: self.choices = args[key] args[key] = self.__choices2tkvalues(self.choices) key = 'keyvariable' if key in args: value = args.pop(key) self.__config_keyvar(value) return key = 'textvariable' if key in args: value = args[key] self.__config_txtvar(value) return ttk.Combobox.configure(self, args)
def configure(self, cnf={}, **kw): """Configure resources of a widget. The values for resources are specified as keyword arguments. To get an overview about the allowed keyword arguments call the method keys. """ cnf = tk._cnfmerge((cnf, kw)) for k in cnf.copy(): if k in self.cnf.keys(): self.cnf[k] = cnf.pop(k) self.set_mousewheel() rv = super().configure(**cnf) if rv is not None: rv.update(self.cnf) return rv
def configure(cnf=None, **kw): """Configure resources of a widget. The values for resources are specified as keyword arguments. To get an overview about the allowed keyword arguments call the method keys. """ # Need a better fix .. kw = _TK._cnfmerge((cnf, kw)) r = self.master._configure('configure', None, kw) if kw.get('bg') or kw.get('background'): for i in self._buttons: if i['borderless']: i.cnf.update({'bordercolor': i.master['bg']}) i.itemconfig('_bd_color1', outline=i.master['bg']) i.itemconfig('_bd_color2', fill=i.master['bg']) return r
def configure(self, cnf={}, **kw): kw = _TK._cnfmerge((cnf, kw)) self.cnf = dict( text=kw.pop('text', self.cnf.get('text')), font=kw.pop('font', self.cnf.get('font')), fg=kw.pop('fg', self.cnf.get('fg')) if kw.get('fg') else kw.pop('foreground', self.cnf.get('foreground')), fps=kw.pop('fps', self.cnf.get('fps')), left_margin=kw.pop('left_margin', self.cnf.get('left_margin')), initial_delay=kw.pop( 'initial_delay', self.cnf.get('initial_delay')), end_delay=kw.pop('end_delay', self.cnf.get('end_delay')), smoothness=kw.pop('smoothness', self.cnf.get('smoothness')), ) self.itemconfig('text', text=self.cnf.get('text'), font=self.cnf.get('font'), fill=self.cnf.get('fg')) return super().configure(**kw)
def __init__(self, master=None, status=None, changed_cond=None, cnf={}, **kw): cnf_ = { 'background': self.DEFAULT_BACKGROUND, } cnf_.update(tkinter._cnfmerge((cnf, kw))) super().__init__(master=master, cnf=cnf_, **kw) self._worker_thread = None self.status = ({} if status is None else status) self.changed_cond = changed_cond or threading.Condition() self.head = InfoPanelHead(self) self.head.grid(row=0, column=0, sticky='news') self.table = InfoPanelTable(self, bg='white') self.table.grid(row=0, column=1, sticky='news') self.rowconfigure(0, weight=1) self.columnconfigure(1, weight=1) self.bind('<Configure>', self.on_configure)
def __init__(self, master=None, cnf={}, **kw): kw = _TK._cnfmerge((cnf, kw)) self.cnf = dict( text=kw.pop('text', ''), font=kw.pop('font', None), fg=kw.pop('fg', 'black') if kw.get( 'fg') else kw.pop('foreground', 'black'), fps=kw.pop('fps', 30), 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 ) kw['height'] = kw.get('height', 24) kw['highlightthickness'] = kw.get('highlightthickness', 0) super().__init__(master=master, **kw) self.create_text(3, 1, anchor='w', tag='text', text=self.cnf.get('text'), font=self.cnf.get('font'), fill=self.cnf.get('fg')) self.bind_class(self, '<Configure>', self.check, '+') self.after_id = ' '
def _create(self, itemType, args, kw): # Args: (val, val, ..., cnf={}) """Internal function.""" args = _TK._flatten(args) cnf = args[-1] if isinstance(cnf, (dict, tuple)): args = args[:-1] else: cnf = {} # -------------------- Added the below block -------------------- # Add the resources to the list to have ColorVar functionality. ckw = _TK._cnfmerge((cnf, kw)) var = None for i in ('activefill', 'activeoutline', 'disabledfill', 'disabledoutline', 'fill', 'outline', 'background', 'activebackground', 'activeforeground', 'disabledbackground', 'disabledforeground', 'foreground'): if isinstance(ckw.get(i), _TK.Variable): var = ckw[i] _all_traces_colorvar[(self, (i, None))] = (var, None) if i in cnf: cnf[i] = var.get() elif i in kw: kw[i] = var.get() # --------------------------------------------------------------- tagId = self.tk.getint( self.tk.call(self._w, 'create', itemType, *(args + self._options(cnf, kw)))) for key, value in _all_traces_colorvar.copy().items(): wid, (opt, tag_id) = key var, cbname = value if tag_id is None and cbname is None: cbname = var.trace_add( 'write', lambda *a, cls=self, opt=opt, tagId=tagId, var=var: cls. itemconfig(tagId, {opt: var.get()})) _all_traces_colorvar[(self, (opt, tagId))] = (var, cbname) _all_traces_colorvar.pop((self, (opt, None))) return tagId
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) key = 'type' if key in args: self._choose = args[key] del args[key] key = 'image' if key in args: self.folder_button.configure(image=args[key]) del args[key] key = 'path' if key in args: self.entry.delete(0, 'end') self.entry.insert(0, args[key]) self.event_generate('<<PathChooserPathChanged>>') del args[key] key = 'textvariable' if key in args: self.entry.configure(textvariable=args[key]) del args[key] ttk.Frame.configure(self, args)
def configure(self, cnf=None, **kw): """Configure resources of a widget. The values for resources are specified as keyword arguments. To get an overview about the allowed keyword arguments call the method keys. Returns tuple of 2 configuration settings info, if any """ kw = _TK._cnfmerge((cnf, kw)) cnf = {} for i in list(kw): if i in self._features: cnf[i] = kw.pop(i, None) r1 = super().configure(**kw) if kw.get('bg') or kw.get('background'): self.original_bg = self['bg'] self.after(10, self._getconfigure2, cnf) if r1 is not None: r1.update(self.cnf) return r1
def configure(self, cnf=None, **kw): args = tk._cnfmerge((cnf, kw)) key = 'type' if key in args: self._choose = args[key] del args[key] key = 'image' if key in args: self.folder_button.configure(image=args[key]) del args[key] key = 'path' if key in args: self.entry.delete(0, 'end') self.entry.insert(0, args[key]) self._generate_changed_event() del args[key] key = 'textvariable' if key in args: self.entry.configure(textvariable=args[key]) self._generate_changed_event() del args[key] ttk.Frame.configure(self, args)