def init_gui(self):
"""Builds GUI."""
self.root.title('Kindle to Anki')
self.grid(column=0, row=0, sticky='nsew')
# Load vocabulary file
ttk.Label(self, text='Vocabulary file').grid(column=0, row=0)
self.db_entry = ttk.Entry(self, width=30)
self.db_entry.grid(column=1, row = 0)
self.loaddb_button = ttk.Button(self, text='Load',
command=self.load_words)
self.loaddb_button.grid(column=2, row=0)
# Choose language
# ttk.Label(self, text='Language').grid(column=0, row=1)
# self.lang_entry = ttk.Combobox(self, width=15)
# self.lang_entry.grid(column=1, row = 1)
# self.lang_entry['values'] = ('en')
# self.lang_entry.state(['readonly'])
# Load from OED
ttk.Label(self, text='App id').grid(column=0, row=2)
self.appid_entry = ttk.Entry(self, width=30)
self.appid_entry.grid(column=1, row = 2)
ttk.Label(self, text='App key').grid(column=0, row=3)
self.keyid_entry = ttk.Entry(self, width=30)
self.keyid_entry.grid(column=1, row = 3)
self.loadOED_button = ttk.Button(self, text='Load definitions from OED',
command=self.load_OED)
self.loadOED_button.grid(column=2, row=2, columnspan = 2, rowspan = 2)
self.loadOED_button.state(['disabled'])
# Create vocabulary file
ttk.Label(self, text='Anki deck location:').grid(column=0, row=4)
self.deck_entry = ttk.Entry(self, width=30)
self.deck_entry.grid(column=1, row = 4)
self.create_button = ttk.Button(self, text='Create Anki Deck',
command=self.create_deck)
self.create_button.grid(column=2, row=4)
self.create_button.state(['disabled'])
for child in self.winfo_children():
child.grid_configure(padx=5, pady=5)
python类Combobox()的实例源码
def expand(self):
self.expFrame = f = tk.Frame(self)
f.columnconfigure(0, weight=1)
f.grid(sticky='we')
f1 = tk.Frame(f)
f1.columnconfigure(1, weight=1)
f1.grid(sticky='we')
labels = ['Path-fitting', 'Auto-rejoin', 'Offset x', 'Offset z', 'Repeat']
for row, text in enumerate(labels):
l = tk.Label(f1, text=text, font=self.labelFont, anchor='w')
l.grid(row=row, column = 0, sticky='we')
PF = ttk.Combobox(f1, takefocus=False, width=6, font=self.labelFont,
textvariable = self.pathfitting,
values=('None', 'Stretch', 'Scale'), state="readonly")
PF.grid(row=0, column = 1, sticky='we')
PF.bind("<<ComboboxSelected>>", self.draw)
JM = ttk.Combobox(f1, takefocus=False, width=6, font=self.labelFont,
textvariable = self.joint_mode,
values=('None', 'Lift', 'Bend'), state="readonly")
JM.grid(row=1, column = 1, sticky='we')
JM.bind("<<ComboboxSelected>>", self.draw)
OS_x = FloatEntry(f1, textvariable = self.x_offset, font=self.labelFont, width=5)
OS_x.grid(row=2, column = 1, sticky='we')
OS_x.bind('<Return>', self.draw)
OS_x.bind('<FocusOut>', self.draw)
OS_z = FloatEntry(f1, textvariable = self.z_offset, font=self.labelFont, width=5)
OS_z.grid(row=3, column = 1, sticky='we')
OS_z.bind('<Return>', self.draw)
OS_z.bind('<FocusOut>', self.draw)
RP = tk.Checkbutton(f1, variable=self._repeat, command=self.draw)
RP.grid(row=4, column = 1, sticky='w')
sep = ttk.Separator(f, orient=tk.HORIZONTAL)
sep.grid(padx=2, sticky='we')
f2 = tk.Frame(f)
for i in range(0, 3):
f2.columnconfigure(i, weight=1)
f2.grid(sticky='we')
DS = tk.Checkbutton(f2, text='Display', width=5, font=self.labelFont,
indicatoron=False, bd=1, variable=self._display,
command=self.draw)
DS.grid(row=0, column=0, sticky='wens', pady=2, padx=1)
self.SET = tk.Button(f2, text='Set', width=5, font=self.labelFont, bd=1, command=self.applyCommand)
self.SET.grid(row=0, column=1, sticky='we', pady=2, padx=1)
self.ADD = tk.Button(f2, text='Add', width=5, font=self.labelFont, bd=1, command = lambda: self.applyCommand(mode='add'))
self.ADD.grid(row=0, column=2, sticky='we', pady=2, padx=1)
def test_values(self):
def check_get_current(getval, currval):
self.assertEqual(self.combo.get(), getval)
self.assertEqual(self.combo.current(), currval)
self.assertEqual(self.combo['values'],
() if tcl_version < (8, 5) else '')
check_get_current('', -1)
self.checkParam(self.combo, 'values', 'mon tue wed thur',
expected=('mon', 'tue', 'wed', 'thur'))
self.checkParam(self.combo, 'values', ('mon', 'tue', 'wed', 'thur'))
self.checkParam(self.combo, 'values', (42, 3.14, '', 'any string'))
self.checkParam(self.combo, 'values', '',
expected='' if get_tk_patchlevel() < (8, 5, 10) else ())
self.combo['values'] = ['a', 1, 'c']
self.combo.set('c')
check_get_current('c', 2)
self.combo.current(0)
check_get_current('a', 0)
self.combo.set('d')
check_get_current('d', -1)
# testing values with empty string
self.combo.set('')
self.combo['values'] = (1, 2, '', 3)
check_get_current('', 2)
# testing values with empty string set through configure
self.combo.configure(values=[1, '', 2])
self.assertEqual(self.combo['values'],
('1', '', '2') if self.wantobjects else
'1 {} 2')
# testing values with spaces
self.combo['values'] = ['a b', 'a\tb', 'a\nb']
self.assertEqual(self.combo['values'],
('a b', 'a\tb', 'a\nb') if self.wantobjects else
'{a b} {a\tb} {a\nb}')
# testing values with special characters
self.combo['values'] = [r'a\tb', '"a"', '} {']
self.assertEqual(self.combo['values'],
(r'a\tb', '"a"', '} {') if self.wantobjects else
r'a\\tb {"a"} \}\ \{')
# out of range
self.assertRaises(tkinter.TclError, self.combo.current,
len(self.combo['values']))
# it expects an integer (or something that can be converted to int)
self.assertRaises(tkinter.TclError, self.combo.current, '')
# testing creating combobox with empty string in values
combo2 = ttk.Combobox(self.root, values=[1, 2, ''])
self.assertEqual(combo2['values'],
('1', '2', '') if self.wantobjects else '1 2 {}')
combo2.destroy()
def __init__(self, master=None, **kw):
"""
GUI tab that handles interface and region selection and starting the server.
:param master: root window
:param kw: args
"""
FrameTab.__init__(self, master, **kw)
self.wii_u_interface = None
self.normal_interface = None
self.drc_sim_c = None
self.wpa_supplicant = None
LoggerGui.extra("Initializing FrameRunServer")
# Create Widgets
self.label_wpa = Label(self, text="Wii U Connection:")
self.label_backend = Label(self, text="Server Status:")
self.label_wpa_status = Label(self)
self.label_backend_status = Label(self)
self.button_start = Button(self, text="Start")
self.button_stop = Button(self, text="Stop")
self.label_wiiu_interface = Label(self, text="Wii U Interface")
self.label_normal_interface = Label(self, text="Normal Interface")
self.dropdown_wiiu_interface = Combobox(self, state="readonly")
self.dropdown_normal_interface = Combobox(self, state="readonly")
self.label_interface_info = Label(self)
self.label_region = Label(self, text="Region")
self.dropdown_region = Combobox(self, state="readonly")
# Events
self.button_start.bind("<Button-1>", self.start_server)
self.button_stop.bind("<Button-1>", self.stop_server)
# Position widgets
self.label_wpa.grid(column=0, row=0, sticky="e")
self.label_backend.grid(column=0, row=1, sticky="e")
self.label_wpa_status.grid(column=1, row=0, sticky="w")
self.label_backend_status.grid(column=1, row=1, sticky="w")
self.label_wiiu_interface.grid(column=0, row=2)
self.label_normal_interface.grid(column=0, row=3)
self.dropdown_wiiu_interface.grid(column=1, row=2, columnspan=2)
self.dropdown_normal_interface.grid(column=1, row=3, columnspan=2)
self.label_region.grid(column=0, row=4)
self.dropdown_region.grid(column=1, row=4, columnspan=2)
self.button_start.grid(column=1, row=5)
self.button_stop.grid(column=2, row=5)
self.label_interface_info.grid(column=0, row=6, columnspan=3)
LoggerGui.extra("Initialized FrameRunServer")
def __init__(self, master=None, **kw):
FrameTab.__init__(self, master, **kw)
self.wpa_supplicant = None
self.getting_psk = False
# Widgets
button_size = 50
# Spade
self.button_spade = Button(self, width=button_size, height=button_size)
self.button_spade.image = self.get_image("image/spade.gif", button_size, button_size)
self.button_spade.config(image=self.button_spade.image)
self.button_spade.number = 0
# Heart
self.button_heart = Button(self, width=button_size, height=button_size)
self.button_heart.image = self.get_image("image/heart.gif", button_size, button_size)
self.button_heart.config(image=self.button_heart.image)
self.button_heart.number = 1
# Diamond
self.button_diamond = Button(self, width=button_size, height=button_size)
self.button_diamond.image = self.get_image("image/diamond.gif", button_size, button_size)
self.button_diamond.config(image=self.button_diamond.image)
self.button_diamond.number = 2
# Clover
self.button_clover = Button(self, width=button_size, height=button_size)
self.button_clover.image = self.get_image("image/clover.gif", button_size, button_size)
self.button_clover.config(image=self.button_clover.image)
self.button_clover.number = 3
# Delete
self.button_delete = Button(self, text="Delete")
# Code
self.entry_pair_code = Entry(self, state="readonly")
# Status Message
self.status_message = Label(self, state="readonly")
# interface dropdown
self.dropdown_wii_u = Combobox(self, state="readonly")
# Events
self.button_spade.bind("<Button-1>", self.button_clicked)
self.button_heart.bind("<Button-1>", self.button_clicked)
self.button_diamond.bind("<Button-1>", self.button_clicked)
self.button_clover.bind("<Button-1>", self.button_clicked)
self.button_delete.bind("<Button-1>", self.button_delete_clicked)
# Grid
self.button_spade.grid(column=0, row=0)
self.button_heart.grid(column=1, row=0)
self.button_diamond.grid(column=2, row=0)
self.button_clover.grid(column=3, row=0)
self.button_delete.grid(column=4, row=0)
self.entry_pair_code.grid(column=0, row=1, columnspan=5)
self.status_message.grid(column=0, row=3, columnspan=5)
self.dropdown_wii_u.grid(column=0, row=2, columnspan=5)
# noinspection PyUnusedLocal
def __init__(self, parent):
ttk.Frame.__init__(self, parent)
self.parent = parent
self['padding'] = '4'
self.TKvariables = {}
#Read in the defaults
for key in defaults:
if key[0:5] == 'graph' or key.find('ylims') >= 0:
self.TKvariables.update({key:[]})
for val in range(len(defaults[key])):
self.TKvariables[key].append(tk.StringVar(value=defaults[key][val]))
else:
self.TKvariables.update({key:tk.StringVar(value=defaults[key])})
num_vars = int(self.TKvariables['datalength'].get())
self.datalist = list(range(1,num_vars+1))
#Create a combobox containing the available COM ports
comlst = self.get_comlst()
self.COMbox = ttk.Labelframe(self, text='COM port to source data from')
self.COMcombo = ttk.Combobox(self.COMbox, width=60, values=comlst, \
state='readonly', textvariable=self.TKvariables['COMport'],\
postcommand=self.updateCOMbox )
self.COMbox.grid(row = 0, column = 0, columnspan = 5)
self.COMcombo.grid()
#Create an "about" text box
ABOUTframe = ttk.LabelFrame(self, text = 'What it does')
ABOUTlabel = ttk.Label(ABOUTframe, text= \
'Graphs data coming in over the serial port in a comma '
'seperated variable string. Hover over each option to get '
'a description of what the setting does', wraplength = 140)
ABOUTframe.grid(row=1, column = 0, rowspan = 2, columnspan = 2, \
sticky = 'nw, se', padx= 3, pady = 5)
CreateToolTip(ABOUTlabel,\
"The default values can be changed by opening defaults.py with a text "
"editor and changing the values")
ABOUTlabel.pack()
#Create a Graph! and About buttons
GObut = ttk.Button(self, text='Go!', command=self.goButton)
GObut.grid(row=6, column = 0, sticky = 'we')
ABOUTbut = ttk.Button(self, text='About', command=self.aboutButton)
ABOUTbut.grid(row = 6, column = 1, sticky = 'we')
#Create an instance of the class for the config panel
notebook = ConfigNotebook(self, self)
#Update the state of the graphs based on the defaults and grid
notebook.updateGraphs()
notebook.grid(row=1, column=3, columnspan=2, rowspan=6, sticky = 'nsew', \
padx = 5, pady = 5)
#Bind the enter key to start the program
self.parent.bind("<Return>", lambda event:self.goButton())
def test_values(self):
def check_get_current(getval, currval):
self.assertEqual(self.combo.get(), getval)
self.assertEqual(self.combo.current(), currval)
self.assertEqual(self.combo['values'],
() if tcl_version < (8, 5) else '')
check_get_current('', -1)
self.checkParam(self.combo, 'values', 'mon tue wed thur',
expected=('mon', 'tue', 'wed', 'thur'))
self.checkParam(self.combo, 'values', ('mon', 'tue', 'wed', 'thur'))
self.checkParam(self.combo, 'values', (42, 3.14, '', 'any string'))
self.checkParam(self.combo, 'values', '', expected=())
self.combo['values'] = ['a', 1, 'c']
self.combo.set('c')
check_get_current('c', 2)
self.combo.current(0)
check_get_current('a', 0)
self.combo.set('d')
check_get_current('d', -1)
# testing values with empty string
self.combo.set('')
self.combo['values'] = (1, 2, '', 3)
check_get_current('', 2)
# testing values with empty string set through configure
self.combo.configure(values=[1, '', 2])
self.assertEqual(self.combo['values'],
('1', '', '2') if self.wantobjects else
'1 {} 2')
# testing values with spaces
self.combo['values'] = ['a b', 'a\tb', 'a\nb']
self.assertEqual(self.combo['values'],
('a b', 'a\tb', 'a\nb') if self.wantobjects else
'{a b} {a\tb} {a\nb}')
# testing values with special characters
self.combo['values'] = [r'a\tb', '"a"', '} {']
self.assertEqual(self.combo['values'],
(r'a\tb', '"a"', '} {') if self.wantobjects else
r'a\\tb {"a"} \}\ \{')
# out of range
self.assertRaises(tkinter.TclError, self.combo.current,
len(self.combo['values']))
# it expects an integer (or something that can be converted to int)
self.assertRaises(tkinter.TclError, self.combo.current, '')
# testing creating combobox with empty string in values
combo2 = ttk.Combobox(self.root, values=[1, 2, ''])
self.assertEqual(combo2['values'],
('1', '2', '') if self.wantobjects else '1 2 {}')
combo2.destroy()
def __init__(self, controller):
super().__init__(controller)
self.configure(background='#A1DBCD')
lf_creation = ttk.Labelframe(
self,
text = 'Object management',
padding = (6, 6, 12, 12)
)
lf_creation.grid(row=0, column=0, padx=5, pady=5)
psf_object_label = tk.Label(
self,
image = controller.psf_button_image,
relief = 'flat',
bg = '#A1DBCD'
)
psf_object_label.bind('<Button-1>', controller.start_drag_and_drop)
psf_object_label.grid(row=0, column=0, pady=10, padx=55, in_=lf_creation)
import_nodes_button = ttk.Button(self, text='Import nodes',
command=controller.map.import_nodes, width=20)
import_nodes_button.grid(row=2, column=0, pady=5, in_=lf_creation)
lf_projection = ttk.Labelframe(
self,
text = 'Projection management',
padding = (6, 6, 12, 12)
)
lf_projection.grid(row=1, column=0, padx=5, pady=5)
self.projection_list = ttk.Combobox(self, width=18)
self.projection_list['values'] = tuple(controller.map.projections)
self.projection_list.current(0)
self.projection_list.grid(row=0, column=0, in_=lf_projection)
change_projection_button = ttk.Button(self, text='Change projection',
command=controller.map.change_projection, width=20)
change_projection_button.grid(row=1, column=0, pady=5, in_=lf_projection)
lf_map_management = ttk.Labelframe(
self,
text = 'Map management',
padding = (6, 6, 12, 12)
)
lf_map_management.grid(row=2, column=0, padx=5, pady=5)
delete_map = ttk.Button(self, text='Delete map',
command=controller.map.delete_map, width=20)
delete_map.grid(row=0, column=0, pady=5, in_=lf_map_management)
delete_selection = ttk.Button(self, text='Delete selected nodes',
command=controller.map.delete_selected_nodes, width=20)
delete_selection.grid(row=1, column=0, pady=5, in_=lf_map_management)
master_gui_main_window.py 文件源码
项目:BrickUsingMultipleModules
作者: hackffm
项目源码
文件源码
阅读 16
收藏 0
点赞 0
评论 0
def add_module_line(self, row, module_id, module_desc, expected_revisions):
self.module_controls[module_id] = {}
controls = self.module_controls[module_id]
module_id_widget = ttk.Label(self.table, text=module_id, **table_default_style)
module_id_widget.grid(row=row, column=COL_ID, sticky=tk.N+tk.S+tk.E+tk.W)
# revision
revision = module_desc["revision"]
if expected_revisions is None:
rev_text = "{}*".format(revision)
color = None
else:
try:
if revision == int(expected_revisions[module_id]):
rev_text = revision
color = None
else:
rev_text = "{} / {}".format(revision, expected_revisions[module_id])
color = "red"
except KeyError:
rev_text = "{} / ?".format(revision)
color = "red"
module_revision = ttk.Label(self.table, text=rev_text, background=color, **table_default_style)
module_revision.grid(row=row, column=COL_REVISION, sticky=tk.N+tk.S+tk.E+tk.W)
# nextstate
module_nextstate = ttk.Combobox(self.table, values=["on", "random", "off"], state="readonly")
module_nextstate.grid(row=row, column=COL_NEXTSTATE, sticky=tk.N+tk.S+tk.E+tk.W)
module_nextstate.current(1)
controls["nextstate"] = module_nextstate
# random value
random_value = tk.StringVar()
module_random = tk.Entry(self.table, textvariable=random_value, disabledforeground="black")
module_random.grid(row=row, column=COL_RANDOMNUMBER, sticky=tk.N+tk.S+tk.E+tk.W)
controls["random"] = module_random
controls["random_value"] = random_value
self.make_red_on_invalid_change(random_value, module_random, lambda module_id=module_id: self.parse_randomness_string(module_id))
random_value.trace("w", lambda *args: self.disable_widgets_if_necessary())
self.disable_while_running.append(module_random)
# state
module_state = ttk.Label(self.table, text="?", **table_default_style)
module_state.grid(row=row, column=COL_STATE, sticky=tk.N+tk.S+tk.E+tk.W)
controls["state"] = module_state
# failure counter
module_fail = ttk.Label(self.table, text="?", **table_default_style)
module_fail.grid(row=row, column=COL_FAILURES, sticky=tk.N+tk.S+tk.E+tk.W)
controls["fail"] = module_fail
# ui description
module_description = ttk.Label(self.table, text="?", relief=tk.RIDGE)
module_description.grid(row=row, column=COL_DESCRIPTION, sticky=tk.N+tk.S+tk.E+tk.W)
controls["desc"] = module_description
# solve button
module_solve = ttk.Button(self.table, text="solve", command=lambda module_id=module_id: self.solve(module_id), width=WIDTH_SHORT)
module_solve.grid(row=row, column=COL_SOLVE)