Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
support.root_deiconify()
xmldata = 'test_menu.ui'
self.builder = builder = pygubu.Builder()
filepath = os.path.dirname(os.path.realpath(__file__))
builder.add_resource_path(filepath)
builder.add_from_file(xmldata)
self.widget = builder.get_object('mainmenu')
ridge
-- A Label --
label_var
20
right
0
True
0
"""
self.builder = builder = pygubu.Builder()
builder.add_from_string(xmldata)
self.widget = builder.get_object('label')
def test_class(self):
self.assertIsInstance(self.widget,
pygubu.widgets.scrollbarhelper.ScrollbarHelper)
self.widget.destroy()
import argparse
try:
import tkinter as tk
except:
import Tkinter as tk
pygubu_basedir = os.path.abspath(os.path.dirname(
os.path.dirname(os.path.realpath(sys.argv[0]))))
if pygubu_basedir not in sys.path:
sys.path.insert(0, pygubu_basedir)
from pygubu import Builder, TkApplication
class UITester(TkApplication):
def __init__(self, uifile, rootwidget, rootmenu=None, master=None):
self.uifile = uifile
self.rootwidget = rootwidget
self.rootmenu = rootmenu
TkApplication.__init__(self, master)
def _create_ui(self):
self.builder = Builder()
self.builder.add_from_file(self.uifile)
self.builder.get_object(self.rootwidget, self.master)
if self.rootmenu:
menu = self.builder.get_object(self.rootmenu, top)
self.set_menu(menu)
#show callbacks defined
def __init__(self, uifile, rootwidget, rootmenu=None, master=None):
self.uifile = uifile
self.rootwidget = rootwidget
self.rootmenu = rootmenu
TkApplication.__init__(self, master)
#Start building widget tree selector
roots = {}
sections = {}
for key, wc in treelist:
root, section = key.split('>')
#insert root
if root not in roots:
roots[root] = widgetlisttv.insert('', 'end', text=root)
#insert section
if key not in sections:
sections[key] = widgetlisttv.insert(roots[root], 'end', text=section)
#insert widget
w_image = default_image
try:
w_image = StockImage.get('22x22-{0}'.format(wc.classname))
except StockImageException as e:
pass
widgetlisttv.insert(sections[key], 'end', text=wc.label,
image=w_image, tags='widget', values=(wc.classname,))
widgetlisttv.tag_bind('widget', '', self.on_widgetlist_dclick)
#Expand prefered widget set
hidews = 'tk'
prefws = get_option('widget_set')
if hidews == prefws:
hidews = 'ttk'
widgetlisttv.item(roots[hidews], open=False)
widgetlisttv.item(roots[prefws], open=True)
for child in widgetlisttv.get_children(roots[prefws]):
widgetlisttv.item(child, open=True)
if value in ('both', 'horizontally'):
target_widget.columnconfigure(0, weight=1)
if value in ('both', 'vertically'):
target_widget.rowconfigure(0, weight=1)
elif pname == 'maxsize':
if '|' in value:
w, h = value.split('|')
target_widget.maxsize(w, h)
elif pname == 'minsize':
if '|' in value:
w, h = value.split('|')
target_widget.minsize(w, h)
else:
super(TKToplevel, self)._set_property(target_widget, pname, value)
register_widget('tk.Toplevel', TKToplevel,
'Toplevel', ('Containers', 'tk', 'ttk'))
class TKFrame(BuilderObject):
OPTIONS_STANDARD = ('borderwidth', 'cursor', 'highlightbackground',
'highlightcolor', 'highlightthickness',
'padx', 'pady', 'relief', 'takefocus')
OPTIONS_SPECIFIC = ('background', 'class_', 'container',
'height', 'width')
class_ = tk.Frame
container = True
properties = OPTIONS_STANDARD + OPTIONS_SPECIFIC
register_widget('tk.Frame', TKFrame, 'Frame', ('Containers', 'tk'))
def _create_callback(self, cpname, command):
callback = command
if cpname in ('validatecommand', 'invalidcommand'):
args = self.properties.get(cpname + '_args', '')
if args:
args = args.split(' ')
callback = (self.widget.register(command),) + tuple(args)
else:
callback = self.widget.register(command)
return callback
register_widget('ttk.Combobox', TTKCombobox, 'Combobox',
('Control & Display', 'ttk'))
class TTKScrollbar(TTKWidgetBO):
OPTIONS_SPECIFIC = ('command', 'orient')
class_ = ttk.Scrollbar
container = False
properties = TTKWidgetBO.OPTIONS_STANDARD + OPTIONS_SPECIFIC
command_properties = ('command',)
register_widget('ttk.Scrollbar', TTKScrollbar,
'Scrollbar', ('Control & Display', 'ttk'))
class TTKSizegrip(TTKWidgetBO):
class_ = ttk.Sizegrip
container = False
properties = (TTKWidgetBO.OPTIONS_STANDARD +
TTKWidgetBO.OPTIONS_SPECIFIC)
# sbhelper widget
sbhelper = ScrollbarHelper(self.widgetlist, scrolltype='both')
# widgetlisttv widget
widgetlisttv = ttk.Treeview(sbhelper)
widgetlisttv.configure(selectmode='browse', show='tree')
widgetlisttv.grid(column='0', row='0', sticky='nsew')
sbhelper.add_child(widgetlisttv)
sbhelper.configure(usemousewheel='true')
sbhelper.grid(column='0', row='0', sticky='nsew')
#Default widget image:
default_image = ''
try:
default_image = StockImage.get('22x22-tk.default')
except StockImageException as e:
pass
#Start building widget tree selector
roots = {}
sections = {}
for key, wc in treelist:
root, section = key.split('>')
#insert root
if root not in roots:
roots[root] = widgetlisttv.insert('', 'end', text=root)
#insert section
if key not in sections:
sections[key] = widgetlisttv.insert(roots[root], 'end', text=section)
#insert widget
w_image = default_image
def create_accordion_widget_list(self, treelist):
acf = AccordionFrame(self.widgetlist)
acf.grid(sticky=tk.NSEW)
acf.bind('<>', self.on_widgetlist_group_toogle)
#Default widget image:
default_image = ''
try:
default_image = StockImage.get('22x22-tk.default')
except StockImageException as e:
pass
#Start building widget tree selector
roots = {}
sections = {}
for key, wc in treelist:
root, section = key.split('>')
#insert root