Addd Image.Widget, return correct value when manual entry into ComboBox

This commit is contained in:
PySimpleGUI 2020-01-24 17:00:21 -05:00
parent 7a7513e00d
commit 4590dbc7ff
1 changed files with 40 additions and 36 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "0.31.0.1 Unreleased - fix for Listbox.update, Graph.change_coordinates" version = __version__ = "0.31.0.2 Unreleased - fix for Listbox.update, Graph.change_coordinates, Added Image.Widget, return correct value with ComboBox has manual data entry"
port = 'PySimpleGUIQt' port = 'PySimpleGUIQt'
@ -4325,11 +4325,11 @@ def BuildResultsForSubform(form, initialize_only, top_level_form):
value = None value = None
elif element.Type == ELEM_TYPE_INPUT_COMBO: elif element.Type == ELEM_TYPE_INPUT_COMBO:
element = element # type: Combo element = element # type: Combo
# value = element.QT_ComboBox.currentText() index = element.QT_ComboBox.currentIndex() # index into the list of values, but can be larger if manual entry
try: if index < len(element.Values):
value = element.Values[element.QT_ComboBox.currentIndex()] value = element.Values[index]
except: else: # if not a valid index, then get what was typed in
value = None value = element.QT_ComboBox.currentText()
elif element.Type == ELEM_TYPE_INPUT_OPTION_MENU: elif element.Type == ELEM_TYPE_INPUT_OPTION_MENU:
value = 0 value = 0
elif element.Type == ELEM_TYPE_INPUT_LISTBOX: elif element.Type == ELEM_TYPE_INPUT_LISTBOX:
@ -4765,7 +4765,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
except: except:
pass pass
# ------------------------- COLUMN element ------------------------- # # ------------------------- COLUMN placement element ------------------------- #
if element_type == ELEM_TYPE_COLUMN: if element_type == ELEM_TYPE_COLUMN:
# column_widget = QWidget() # column_widget = QWidget()
column_widget = QGroupBox() column_widget = QGroupBox()
@ -4780,9 +4780,13 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
style = style_generate('QGroupBox', style) style = style_generate('QGroupBox', style)
column_widget.setStyleSheet(style) column_widget.setStyleSheet(style)
# if element_size[0] is not None:
# column_widget.setFixedWidth(element_size[0])
# if element_size[1] is not None:
# column_widget.setFixedHeight(element_size[1])
column_layout = QFormLayout() column_layout = QFormLayout()
column_vbox = QVBoxLayout() column_vbox = QVBoxLayout()
PackFormIntoFrame(element, column_layout, toplevel_win) PackFormIntoFrame(element, column_layout, toplevel_win)
column_vbox.addLayout(column_layout) column_vbox.addLayout(column_layout)
@ -4793,7 +4797,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
column_widget.setVisible(False) column_widget.setVisible(False)
qt_row_layout.addWidget(column_widget) qt_row_layout.addWidget(column_widget)
# ------------------------- TEXT element ------------------------- # # ------------------------- TEXT placement element ------------------------- #
elif element_type == ELEM_TYPE_TEXT: elif element_type == ELEM_TYPE_TEXT:
element.Widget = element.QT_Label = qlabel = QLabel(element.DisplayText, toplevel_win.QTWindow) element.Widget = element.QT_Label = qlabel = QLabel(element.DisplayText, toplevel_win.QTWindow)
if element.Justification is not None: if element.Justification is not None:
@ -4837,7 +4841,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_Label.setVisible(False) element.QT_Label.setVisible(False)
qt_row_layout.addWidget(element.QT_Label) qt_row_layout.addWidget(element.QT_Label)
# ------------------------- BUTTON element ------------------------- # # ------------------------- BUTTON placement element ------------------------- #
elif element_type == ELEM_TYPE_BUTTON: elif element_type == ELEM_TYPE_BUTTON:
element = element #type: Button element = element #type: Button
btext = element.ButtonText btext = element.ButtonText
@ -4893,7 +4897,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
element.QT_QPushButton.setVisible(False) element.QT_QPushButton.setVisible(False)
qt_row_layout.addWidget(element.QT_QPushButton) qt_row_layout.addWidget(element.QT_QPushButton)
# ------------------------- INPUT element ------------------------- # # ------------------------- INPUT placement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_TEXT: elif element_type == ELEM_TYPE_INPUT_TEXT:
default_text = element.DefaultText default_text = element.DefaultText
element.Widget = element.QT_QLineEdit = qlineedit = QLineEdit() element.Widget = element.QT_QLineEdit = qlineedit = QLineEdit()
@ -4944,7 +4948,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_QLineEdit.setVisible(False) element.QT_QLineEdit.setVisible(False)
qt_row_layout.addWidget(element.QT_QLineEdit) qt_row_layout.addWidget(element.QT_QLineEdit)
# ------------------------- COMBO BOX (Drop Down) element ------------------------- # # ------------------------- COMBO placement BOX (Drop Down) element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_COMBO: elif element_type == ELEM_TYPE_INPUT_COMBO:
element.Widget = element.QT_ComboBox = QComboBox() element.Widget = element.QT_ComboBox = QComboBox()
max_line_len = max([len(str(l)) for l in element.Values]) max_line_len = max([len(str(l)) for l in element.Values])
@ -4997,7 +5001,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
# ------------------------- OPTION MENU (Like ComboBox but different) element ------------------------- # # ------------------------- OPTION MENU (Like ComboBox but different) element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_OPTION_MENU: elif element_type == ELEM_TYPE_INPUT_OPTION_MENU:
max_line_len = max([len(str(l)) for l in element.Values]) max_line_len = max([len(str(l)) for l in element.Values])
# ------------------------- LISTBOX element ------------------------- # # ------------------------- LISTBOX placement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_LISTBOX: elif element_type == ELEM_TYPE_INPUT_LISTBOX:
element = element # type: Listbox element = element # type: Listbox
max_line_len = max([len(str(l)) for l in element.Values]) if len(element.Values) != 0 else 0 max_line_len = max([len(str(l)) for l in element.Values]) if len(element.Values) != 0 else 0
@ -5054,7 +5058,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_ListWidget.setVisible(False) element.QT_ListWidget.setVisible(False)
qt_row_layout.addWidget(element.QT_ListWidget) qt_row_layout.addWidget(element.QT_ListWidget)
# ------------------------- INPUT MULTI LINE element ------------------------- # # ------------------------- INPUT MULTILINE placement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_MULTILINE: elif element_type == ELEM_TYPE_INPUT_MULTILINE:
element = element # type: Multiline element = element # type: Multiline
default_text = element.DefaultText default_text = element.DefaultText
@ -5103,7 +5107,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_TextEdit.setVisible(False) element.QT_TextEdit.setVisible(False)
qt_row_layout.addWidget(element.QT_TextEdit) qt_row_layout.addWidget(element.QT_TextEdit)
# ------------------------- OUTPUT MULTI LINE element ------------------------- # # ------------------------- OUTPUT MULTILINE placement element ------------------------- #
elif element_type == ELEM_TYPE_MULTILINE_OUTPUT: elif element_type == ELEM_TYPE_MULTILINE_OUTPUT:
element = element # type: MultilineOutput element = element # type: MultilineOutput
default_text = element.DefaultText default_text = element.DefaultText
@ -5135,7 +5139,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_TextBrowser.setVisible(False) element.QT_TextBrowser.setVisible(False)
qt_row_layout.addWidget(element.QT_TextBrowser) qt_row_layout.addWidget(element.QT_TextBrowser)
# ------------------------- INPUT CHECKBOX element ------------------------- # # ------------------------- INPUT CHECKBOX placement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_CHECKBOX: elif element_type == ELEM_TYPE_INPUT_CHECKBOX:
element = element # type: Checkbox element = element # type: Checkbox
element.QT_Checkbox = QCheckBox(element.Text) element.QT_Checkbox = QCheckBox(element.Text)
@ -5164,7 +5168,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_Checkbox.setVisible(False) element.QT_Checkbox.setVisible(False)
qt_row_layout.addWidget(element.QT_Checkbox) qt_row_layout.addWidget(element.QT_Checkbox)
# ------------------------- PROGRESS BAR element ------------------------- # # ------------------------- PROGRESSBAR placement element ------------------------- #
elif element_type == ELEM_TYPE_PROGRESS_BAR: elif element_type == ELEM_TYPE_PROGRESS_BAR:
element.Widget = element.QT_QProgressBar = QProgressBar() element.Widget = element.QT_QProgressBar = QProgressBar()
orientation = element.Orientation.lower()[0] orientation = element.Orientation.lower()[0]
@ -5198,7 +5202,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
element.QT_QProgressBar.setVisible(False) element.QT_QProgressBar.setVisible(False)
qt_row_layout.addWidget(element.QT_QProgressBar) qt_row_layout.addWidget(element.QT_QProgressBar)
# ------------------------- INPUT RADIO BUTTON element ------------------------- # # ------------------------- INPUT RADIO placement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_RADIO: elif element_type == ELEM_TYPE_INPUT_RADIO:
element = element # type: Radio element = element # type: Radio
default_value = element.InitialState default_value = element.InitialState
@ -5239,7 +5243,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_Radio_Button.setVisible(False) element.QT_Radio_Button.setVisible(False)
qt_row_layout.addWidget(element.QT_Radio_Button) qt_row_layout.addWidget(element.QT_Radio_Button)
# ------------------------- INPUT SPIN Box element ------------------------- # # ------------------------- INPUT SPIN placement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_SPIN: elif element_type == ELEM_TYPE_INPUT_SPIN:
# element.QT_Spinner = QSpinBox() # element.QT_Spinner = QSpinBox()
element = element # type: Spin element = element # type: Spin
@ -5275,7 +5279,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_Spinner.setVisible(False) element.QT_Spinner.setVisible(False)
qt_row_layout.addWidget(element.QT_Spinner) qt_row_layout.addWidget(element.QT_Spinner)
# ------------------------- OUTPUT element ------------------------- # # ------------------------- OUTPUT placement element ------------------------- #
elif element_type == ELEM_TYPE_OUTPUT: elif element_type == ELEM_TYPE_OUTPUT:
element.Widget = element.QT_TextBrowser = QTextBrowser() element.Widget = element.QT_TextBrowser = QTextBrowser()
element.QT_TextBrowser.setDisabled(False) element.QT_TextBrowser.setDisabled(False)
@ -5309,9 +5313,10 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_TextBrowser.setVisible(False) element.QT_TextBrowser.setVisible(False)
qt_row_layout.addWidget(element.QT_TextBrowser) qt_row_layout.addWidget(element.QT_TextBrowser)
# ------------------------- IMAGE element ------------------------- # # ------------------------- IMAGE placement element ------------------------- #
elif element_type == ELEM_TYPE_IMAGE: elif element_type == ELEM_TYPE_IMAGE:
qlabel = QLabel() element = element # type: Image
element.Widget = element.QT_QLabel = qlabel = QLabel()
if element.Filename is not None: if element.Filename is not None:
qlabel.setText('') qlabel.setText('')
w = QtGui.QPixmap(element.Filename).width() w = QtGui.QPixmap(element.Filename).width()
@ -5331,7 +5336,6 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
pixmap.loadFromData(ba) pixmap.loadFromData(ba)
qlabel.setPixmap(pixmap) qlabel.setPixmap(pixmap)
element.QT_QLabel = qlabel
style = '' style = ''
style += 'margin: {}px {}px {}px {}px;'.format(*full_element_pad) style += 'margin: {}px {}px {}px {}px;'.format(*full_element_pad)
element.QT_QLabel.setStyleSheet(style) element.QT_QLabel.setStyleSheet(style)
@ -5343,10 +5347,10 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_QLabel.setVisible(False) element.QT_QLabel.setVisible(False)
qt_row_layout.addWidget(element.QT_QLabel) qt_row_layout.addWidget(element.QT_QLabel)
# ------------------------- Canvas element ------------------------- # # ------------------------- Canvas placement element ------------------------- #
elif element_type == ELEM_TYPE_CANVAS: elif element_type == ELEM_TYPE_CANVAS:
width, height = element_size width, height = element_size
# ------------------------- Graph element ------------------------- # # ------------------------- Graph placement element ------------------------- #
elif element_type == ELEM_TYPE_GRAPH: elif element_type == ELEM_TYPE_GRAPH:
element = element # type: Graph element = element # type: Graph
width, height = element_size width, height = element_size
@ -5374,7 +5378,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_QGraphicsView.setVisible(False) element.QT_QGraphicsView.setVisible(False)
qt_row_layout.addWidget(element.QT_QGraphicsView) qt_row_layout.addWidget(element.QT_QGraphicsView)
# ------------------------- MENUBAR element ------------------------- # # ------------------------- MENUBAR placement element ------------------------- #
elif element_type == ELEM_TYPE_MENUBAR: elif element_type == ELEM_TYPE_MENUBAR:
element = element # type: Menu element = element # type: Menu
menu_def = element.MenuDefinition menu_def = element.MenuDefinition
@ -5397,7 +5401,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_QMenuBar.setVisible(False) element.QT_QMenuBar.setVisible(False)
toplevel_win.QT_QMainWindow.setMenuBar(element.QT_QMenuBar) toplevel_win.QT_QMainWindow.setMenuBar(element.QT_QMenuBar)
# ------------------------- BUTTONMENU element ------------------------- # # ------------------------- BUTTONMENU placement element ------------------------- #
elif element_type == ELEM_TYPE_BUTTONMENU: elif element_type == ELEM_TYPE_BUTTONMENU:
btext = element.ButtonText btext = element.ButtonText
element.Widget = element.QT_QPushButton = QPushButton(btext) element.Widget = element.QT_QPushButton = QPushButton(btext)
@ -5443,7 +5447,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_QPushButton.setVisible(False) element.QT_QPushButton.setVisible(False)
qt_row_layout.addWidget(element.QT_QPushButton) qt_row_layout.addWidget(element.QT_QPushButton)
# ------------------------- Frame element ------------------------- # # ------------------------- Frame placement element ------------------------- #
elif element_type == ELEM_TYPE_FRAME: elif element_type == ELEM_TYPE_FRAME:
element.Widget = column_widget = QGroupBox() element.Widget = column_widget = QGroupBox()
element.QT_QGroupBox = column_widget element.QT_QGroupBox = column_widget
@ -5468,7 +5472,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_QGroupBox.setVisible(False) element.QT_QGroupBox.setVisible(False)
qt_row_layout.addWidget(column_widget) qt_row_layout.addWidget(column_widget)
# ------------------------- Tab element ------------------------- # # ------------------------- Tab placement element ------------------------- #
elif element_type == ELEM_TYPE_TAB: elif element_type == ELEM_TYPE_TAB:
element.Widget = tab_widget = QWidget() element.Widget = tab_widget = QWidget()
element.QT_QWidget = tab_widget element.QT_QWidget = tab_widget
@ -5501,7 +5505,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_QWidget.setVisible(False) element.QT_QWidget.setVisible(False)
window.QT_QTabWidget.addTab(tab_widget, element.Title) window.QT_QTabWidget.addTab(tab_widget, element.Title)
# ------------------------- TabGroup element ------------------------- # # ------------------------- TabGroup placement element ------------------------- #
elif element_type == ELEM_TYPE_TAB_GROUP: elif element_type == ELEM_TYPE_TAB_GROUP:
element = element # type:TabGroup element = element # type:TabGroup
element.Widget = element.QT_QTabWidget = qtab =QTabWidget() element.Widget = element.QT_QTabWidget = qtab =QTabWidget()
@ -5531,7 +5535,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if element.ChangeSubmits: if element.ChangeSubmits:
element.QT_QTabWidget.currentChanged.connect(element.QtCallbackStateChanged) element.QT_QTabWidget.currentChanged.connect(element.QtCallbackStateChanged)
# ------------------------- SLIDER element ------------------------- # # ------------------------- SLIDER placement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_SLIDER: elif element_type == ELEM_TYPE_INPUT_SLIDER:
element.Widget = element.QT_Slider = QSlider() element.Widget = element.QT_Slider = QSlider()
if element.Orientation.startswith('h'): if element.Orientation.startswith('h'):
@ -5583,7 +5587,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_Slider.setVisible(False) element.QT_Slider.setVisible(False)
qt_row_layout.addWidget(element.QT_Slider) qt_row_layout.addWidget(element.QT_Slider)
# ------------------------- DIAL element ------------------------- # # ------------------------- DIAL placement element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_DIAL: elif element_type == ELEM_TYPE_INPUT_DIAL:
element.Widget = element.QT_Dial = qdial = QDial() element.Widget = element.QT_Dial = qdial = QDial()
@ -5619,11 +5623,11 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_Dial.setVisible(False) element.QT_Dial.setVisible(False)
qt_row_layout.addWidget(element.QT_Dial) qt_row_layout.addWidget(element.QT_Dial)
# ------------------------- Stretch element ------------------------- # # ------------------------- Stretch placement element ------------------------- #
elif element_type == ELEM_TYPE_STRETCH: elif element_type == ELEM_TYPE_STRETCH:
element = element # type: Stretch element = element # type: Stretch
element.Widget = qt_row_layout.addStretch(1) element.Widget = qt_row_layout.addStretch(1)
# ------------------------- TABLE element ------------------------- # # ------------------------- TABLE placement element ------------------------- #
elif element_type == ELEM_TYPE_TABLE: elif element_type == ELEM_TYPE_TABLE:
element = element # type: Table element = element # type: Table
element.Widget = element.QT_TableWidget = Table.QTTableWidget(toplevel_win.ReturnKeyboardEvents, toplevel_win) element.Widget = element.QT_TableWidget = Table.QTTableWidget(toplevel_win.ReturnKeyboardEvents, toplevel_win)
@ -5667,7 +5671,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
element.QT_TableWidget.setVisible(False) element.QT_TableWidget.setVisible(False)
qt_row_layout.addWidget(element.QT_TableWidget) qt_row_layout.addWidget(element.QT_TableWidget)
# ------------------------- Tree element ------------------------- # # ------------------------- Tree placement element ------------------------- #
elif element_type == ELEM_TYPE_TREE: elif element_type == ELEM_TYPE_TREE:
element = element # type: Tree element = element # type: Tree
element.Widget = element.QT_QTreeWidget = QTreeWidget() element.Widget = element.QT_QTreeWidget = QTreeWidget()
@ -5750,7 +5754,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
if not element.Visible: if not element.Visible:
element.QT_QTreeWidget.setVisible(False) element.QT_QTreeWidget.setVisible(False)
qt_row_layout.addWidget(element.QT_QTreeWidget) qt_row_layout.addWidget(element.QT_QTreeWidget)
# ------------------------- Separator element ------------------------- # # ------------------------- Separator placement element ------------------------- #
elif element_type == ELEM_TYPE_SEPARATOR: elif element_type == ELEM_TYPE_SEPARATOR:
element = element # type: HorizontalSeparator element = element # type: HorizontalSeparator
element.Widget = element.QT_Label = qlabel = QLabel('', toplevel_win.QTWindow) element.Widget = element.QT_Label = qlabel = QLabel('', toplevel_win.QTWindow)