Merge pull request #876 from MikeTheWatchGuy/Dev-latest

Dev latest
This commit is contained in:
MikeTheWatchGuy 2018-12-08 13:28:52 -05:00 committed by GitHub
commit 2a64b170ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 41 deletions

View File

@ -1,29 +1,31 @@
import PySimpleGUI as sg
# import PySimpleGUIQt as sg # 100% portable to Qt by changing to this import
class keyboard():
def __init__(self, font=('Arial', 16)):
def __init__(self, location=(None, None), font=('Arial', 16)):
self.font = font
numberRow = '1234567890'
topRow = 'QWERTYUIOP'
midRow = 'ASDFGHJKL'
bottomRow = 'ZXCVBNM'
keyboard_layout = [[sg.Button(c, key=c, pad=(0, 0), size=(4, 2), font=self.font) for c in numberRow] + [
sg.Button('', key='back', pad=(0, 0), size=(4, 2), font=self.font),
sg.Button('Esc', key='close', pad=(0, 0), size=(4, 2), font=self.font)],
[sg.T(' ' * 4)] + [sg.Button(c, key=c, pad=(0, 0), size=(4, 2), font=self.font) for c in
topRow],
[sg.T(' ' * 11)] + [sg.Button(c, key=c, pad=(0, 0), size=(4, 2), font=self.font) for c in
midRow],
[sg.T(' ' * 18)] + [sg.Button(c, key=c, pad=(0, 0), size=(4, 2), font=self.font) for c in
bottomRow]]
keyboard_layout = [[sg.Button(c, key=c, size=(4, 2), font=self.font) for c in numberRow] + [
sg.Button('', key='back', size=(4, 2), font=self.font),
sg.Button('Esc', key='close', size=(4, 2), font=self.font)],
[sg.T(' ' * 4)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
topRow] + [sg.Stretch()],
[sg.T(' ' * 11)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
midRow] + [sg.Stretch()],
[sg.T(' ' * 18)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
bottomRow] + [sg.Stretch()]]
self.window = sg.Window('keyboard',
grab_anywhere=True,
keep_on_top=True,
alpha_channel=0,
location=(850,350),
no_titlebar=True,
element_padding=(0,0),
location=location
).Layout(keyboard_layout).Finalize()
self.hide()
@ -75,7 +77,9 @@ class GUI():
grab_anywhere=True,
no_titlebar=False,
).Layout(layout).Finalize()
self.keyboard = keyboard()
location = self.mainWindow.CurrentLocation()
location = location[0]-200, location[1]+200
self.keyboard = keyboard(location)
self.focus = None
def run(self):

View File

@ -342,7 +342,7 @@ class Element():
self.Size = size
self.Type = type
self.AutoSizeText = auto_size_text
self.Pad = DEFAULT_ELEMENT_PADDING if pad is None else pad
self.Pad = pad
self.Font = font
self.TKStringVar = None
@ -774,6 +774,15 @@ class Listbox(Element):
def GetListValues(self):
return self.Values
def SetFocus(self):
try:
self.TKListbox.focus_set()
except:
pass
def __del__(self):
try:
self.TKListBox.__del__()
@ -1862,7 +1871,6 @@ class Graph(Element):
print('Call Window.Finalize() prior to this operation')
return None
self.Images.append(image)
print(image, converted_point)
text_id = self._TKCanvas2.create_image(converted_point, image=image, anchor=tk.NW)
return text_id
@ -3015,7 +3023,7 @@ Stretch = ErrorElement
class Window:
def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None),
auto_size_text=None, auto_size_buttons=None, location=(None, None), size=(None, None), button_color=None, font=None,
auto_size_text=None, auto_size_buttons=None, location=(None, None), size=(None, None), element_padding=None, button_color=None, font=None,
progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False,
auto_close_duration=DEFAULT_AUTOCLOSE_TIME, icon=DEFAULT_WINDOW_ICON, force_toplevel=False,
alpha_channel=1, return_keyboard_events=False, use_default_focus=True, text_justification=None,
@ -3098,6 +3106,8 @@ class Window:
self._Hidden = False
self._Size = size
self.XFound = False
self.ElementPadding = element_padding or DEFAULT_ELEMENT_PADDING
# ------------------------- Add ONE Row to Form ------------------------- #
def AddRow(self, *args):
@ -3581,7 +3591,6 @@ class Window:
FlexForm = Window
# ################################################################################
# ################################################################################
# END OF ELEMENT DEFINITIONS
@ -4268,6 +4277,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element_type = element.Type
# Set foreground color
text_color = element.TextColor
elementpad = element.Pad if element.Pad is not None else toplevel_form.ElementPadding
# Determine Element size
element_size = element.Size
if (element_size == (None, None) and element_type != ELEM_TYPE_BUTTON): # user did not specify a size
@ -4296,7 +4306,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
else:
col_frame = tk.Frame(tk_row_frame)
PackFormIntoFrame(element, col_frame, toplevel_form)
col_frame.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], expand=True, fill='both')
col_frame.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1], expand=True, fill='both')
if element.Visible is False:
col_frame.pack_forget()
@ -4349,7 +4359,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
tktext_label.configure(background=element.BackgroundColor)
if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None:
tktext_label.configure(fg=element.TextColor)
tktext_label.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], expand=True)
tktext_label.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1], expand=True)
if element.Visible is False:
tktext_label.pack_forget()
element.TKText = tktext_label
@ -4419,7 +4429,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
tkbutton.image = photo
if width != 0:
tkbutton.configure(wraplength=wraplen + 10) # set wrap to width of widget
tkbutton.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
tkbutton.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
tkbutton.pack_forget()
if element.BindReturnKey:
@ -4455,7 +4465,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKEntry.configure(background=element.BackgroundColor)
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
element.TKEntry.configure(fg=text_color)
element.TKEntry.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], expand=True, fill='x')
element.TKEntry.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1], expand=True, fill='x')
if element.Visible is False:
element.TKEntry.pack_forget()
if element.Focus is True or (toplevel_form.UseDefaultFocus and not focus_set):
@ -4508,7 +4518,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
# element.TKCombo['state'] = 'disabled'
# if element.BackgroundColor is not None:
# element.TKCombo.configure(background=element.BackgroundColor)
element.TKCombo.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element.TKCombo.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element.TKCombo.pack_forget()
if element.DefaultValue:
@ -4543,7 +4553,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKOptionMenu.configure(background=element.BackgroundColor)
if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None:
element.TKOptionMenu.configure(fg=element.TextColor)
element.TKOptionMenu.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element.TKOptionMenu.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element.TKOptionMenu.pack_forget()
if element.Disabled == True:
@ -4576,7 +4586,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKListbox.configure(yscrollcommand=vsb.set)
element.TKListbox.pack(side=tk.LEFT)
vsb.pack(side=tk.LEFT, fill='y')
listbox_frame.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
listbox_frame.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
listbox_frame.pack_forget()
if element.BindReturnKey:
@ -4597,7 +4607,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
element.TKText.configure(background=element.BackgroundColor)
element.TKText.vbar.config(troughcolor=DEFAULT_SCROLLBAR_COLOR)
element.TKText.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], expand=True, fill='both')
element.TKText.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1], expand=True, fill='both')
if element.Visible is False:
element.TKText.pack_forget()
if element.ChangeSubmits:
@ -4634,7 +4644,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKCheckbutton.configure(activebackground=element.BackgroundColor)
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
element.TKCheckbutton.configure(fg=text_color)
element.TKCheckbutton.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element.TKCheckbutton.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element.TKCheckbutton.pack_forget()
if element.Tooltip is not None:
@ -4657,7 +4667,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
orientation=direction, BarColor=bar_color,
border_width=element.BorderWidth, relief=element.Relief,
style=element.BarStyle, key=element.Key)
element.TKProgressBar.TKProgressBarForReal.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element.TKProgressBar.TKProgressBarForReal.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element.TKProgressBar.TKProgressBarForReal.pack_forget()
# ------------------------- INPUT RADIO BUTTON element ------------------------- #
@ -4689,7 +4699,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKRadio.configure(fg=text_color)
if element.Disabled:
element.TKRadio['state'] = 'disabled'
element.TKRadio.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element.TKRadio.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element.TKRadio.pack_forget()
if element.Tooltip is not None:
@ -4705,7 +4715,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKSpinBox.configure(font=font) # set wrap to width of widget
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
element.TKSpinBox.configure(background=element.BackgroundColor)
element.TKSpinBox.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element.TKSpinBox.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element.TKSpinBox.pack_forget()
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
@ -4722,7 +4732,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
width, height = element_size
element._TKOut = TKOutput(tk_row_frame, width=width, height=height, bd=border_depth,
background_color=element.BackgroundColor, text_color=text_color, font=font,
pad=element.Pad)
pad=elementpad)
element._TKOut.pack(side=tk.LEFT, expand=True, fill='both')
if element.Visible is False:
element._TKOut.pack_forget()
@ -4754,7 +4764,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.tktext_label.image = photo
# tktext_label.configure(anchor=tk.NW, image=photo)
element.tktext_label.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element.tktext_label.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element.tktext_label.pack_forget()
if element.Tooltip is not None:
@ -4772,7 +4782,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element._TKCanvas.master = tk_row_frame
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
element._TKCanvas.configure(background=element.BackgroundColor, highlightthickness=0)
element._TKCanvas.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element._TKCanvas.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element._TKCanvas.pack_forget()
if element.Tooltip is not None:
@ -4792,7 +4802,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
element._TKCanvas2.configure(background=element.BackgroundColor, highlightthickness=0)
element._TKCanvas.configure(background=element.BackgroundColor, highlightthickness=0)
element._TKCanvas.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
element._TKCanvas.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element._TKCanvas.pack_forget()
element._TKCanvas2.pack_forget()
@ -4831,7 +4841,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
labeled_frame = tk.LabelFrame(tk_row_frame, text=element.Title, relief=element.Relief)
element.TKFrame = labeled_frame
PackFormIntoFrame(element, labeled_frame, toplevel_form)
labeled_frame.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
labeled_frame.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if not element.Visible:
labeled_frame.pack_forget()
if element.BackgroundColor != COLOR_SYSTEM_DEFAULT and element.BackgroundColor is not None:
@ -4856,7 +4866,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
form.TKNotebook.add(element.TKFrame, text=element.Title, state='disabled')
else:
form.TKNotebook.add(element.TKFrame, text=element.Title)
form.TKNotebook.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
form.TKNotebook.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
element.ParentNotebook = form.TKNotebook
element.TabID = form.TabCount
form.TabCount += 1
@ -4955,7 +4965,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
tkscale.config(showvalue=0)
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
tkscale.configure(fg=text_color)
tkscale.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
tkscale.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
tkscale.pack_forget()
element.TKScale = tkscale
@ -5026,7 +5036,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
ttk.Style().configure("Treeview", foreground=element.TextColor)
if element.RowHeight is not None:
ttk.Style().configure("Treeview", rowheight=element.RowHeight)
# scrollable_frame.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], expand=True, fill='both')
# scrollable_frame.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1], expand=True, fill='both')
treeview.bind("<<TreeviewSelect>>", element.treeview_selected)
if element.BindReturnKey:
treeview.bind('<Return>', element.treeview_double_click)
@ -5110,7 +5120,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
# ------------------------- Separator element ------------------------- #
elif element_type == ELEM_TYPE_SEPARATOR:
separator = ttk.Separator(tk_row_frame, orient=element.Orientation, )
separator.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], fill='both', expand=True)
separator.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1], fill='both', expand=True)
# ------------------------- StatusBar element ------------------------- #
elif element_type == ELEM_TYPE_STATUSBAR:
# auto_size_text = element.AutoSizeText
@ -5156,7 +5166,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
tktext_label.configure(background=element.BackgroundColor)
if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None:
tktext_label.configure(fg=element.TextColor)
tktext_label.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1],fill=tk.BOTH, expand=True)
tktext_label.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1],fill=tk.BOTH, expand=True)
if element.Visible is False:
tktext_label.pack_forget()
element.TKText = tktext_label

View File

@ -729,8 +729,7 @@ InputOptionMenu = OptionMenu
# Listbox #
# ---------------------------------------------------------------------- #
class Listbox(Element):
def __init__(self, values, default_values=None, select_mode=None, change_submits=False, enable_events=False, bind_return_key=False,
size=(None, None), disabled=False, auto_size_text=None, font=None, background_color=None,
def __init__(self, values, default_values=None, select_mode=None, change_submits=False, enable_events=False, bind_return_key=False, size=(None, None), disabled=False, auto_size_text=None, font=None, background_color=None,
text_color=None, key=None, pad=None, tooltip=None, visible=True, size_px=(None,None)):
'''
Listbox Element
@ -3068,12 +3067,14 @@ class Window:
self.DisableClose = disable_close
self._Hidden = False
self.QTApplication = None
self.QT_QMainWindow = None
self._Size=size
self.ElementPadding = element_padding or DEFAULT_ELEMENT_PADDING
self.FocusElement = None
self.BackgroundImage = background_image
self.XFound = False
# ------------------------- Add ONE Row to Form ------------------------- #
def AddRow(self, *args):
''' Parms are a variable number of Elements '''
@ -3499,7 +3500,8 @@ class Window:
pass
def CurrentLocation(self):
return int(self.TKroot.winfo_x()), int(self.TKroot.winfo_y())
location = self.QT_QMainWindow.geometry()
return location.left(), location.top()
class QTMainWindow(QWidget):
def __init__(self,enable_key_events, window):