def setup_ui_core_command_area(self): # Create a label object to the Dialog window. # Set the alignment, the name, and the text of the label. # The label, Command Display_Label, labels the CommandDisplay_View_TextBrowser text edit object. self.grid_layout_row = self.grid_layout_row + 1 self.CommandDisplay_Label = QtWidgets.QLabel(self) self.CommandDisplay_Label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) self.CommandDisplay_Label.setObjectName(qt_util.from_utf8("CommandDisplay_Label")) self.CommandDisplay_Label.setText(qt_util.translate("Dialog", "Command: ", None)) self.grid_layout.addWidget(self.CommandDisplay_Label, self.grid_layout_row, 0, 2, 1) # Create a text edit object. Add the text edit object to the Dialog window. # Set the size, the name and the html of the text edit object. # The text edit object, CommandDisplay_View_TextBrowser, displays a dynamic view of the command string. self.CommandDisplay_View_TextBrowser = QtWidgets.QTextEdit(self) self.CommandDisplay_View_TextBrowser.setObjectName("CommandDisplay_View_TextBrowser") command_string = self.command.command_string if command_string == "Blank()": command_string = "" if command_string.endswith("()"): command_string = command_string[:-2] self.CommandDisplay_View_TextBrowser.setText(command_string) self.CommandDisplay_View_TextBrowser.setReadOnly(True) self.CommandDisplay_View_TextBrowser.setMaximumHeight(60) # self.CommandDisplay_View_TextBrowser.setMinimumSize(QtCore.QSize(0, 100)) # self.CommandDisplay_View_TextBrowser.setMaximumSize(QtCore.QSize(16777215, 100)) # #html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">" \ # # "\n<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\np, li { " \ # # "white-space: pre-wrap; }\n</style></head><body style=\" font-family:\'MS Shell Dlg 2\';" \ # # " font-size:8.25pt; font-weight:400; font-style:normal;\">\n<p style=\" margin-top:0px;" \ # # " margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" \ # # "<span style=\" font-size:8pt;\">ReadGeoLayerFromGeoJSON()</span></p></body></html>" # #self.CommandDisplay_View_TextBrowser.setHtml(qt_util.translate("Dialog", html, None)) self.grid_layout.addWidget(self.CommandDisplay_View_TextBrowser, self.grid_layout_row, 1, 1, -1)
def setup_ui_core_command_area(self): # Create a label object to the Dialog window. # Set the alignment, the name, and the text of the label. # The label, Command Display_Label, labels the CommandDisplay_View_TextBrowser text edit object. commandArea_Frame = QtWidgets.QFrame(self) commandArea_Frame.setFrameShape(QtWidgets.QFrame.StyledPanel) commandArea_Frame.setFrameShadow(QtWidgets.QFrame.Raised) commandArea_Frame.setObjectName("Command_Parameters") self.grid_layout_row = self.grid_layout_row + 1 # TODO smalers 2019-01-20 Need to understand why things work differently on each OS if os_util.is_linux_os() and not os_util.is_cygwin_os(): # Full Linux self.grid_layout.addWidget(commandArea_Frame, self.grid_layout_row, 0, 1, 1) else: # Cygwin and Windows self.grid_layout.addWidget(commandArea_Frame, self.grid_layout_row, 0, 1, -1) # Create a grid layout object. Apply to the Command_Parameters frame object. # Set the name of the grid layout object. commandArea_GridLayout = QtWidgets.QGridLayout(commandArea_Frame) commandArea_GridLayout.setObjectName("Command_Parameters_Layout") self.grid_layout_row = self.grid_layout_row + 1 self.CommandDisplay_Label = QtWidgets.QLabel(self) self.CommandDisplay_Label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.CommandDisplay_Label.setObjectName(qt_util.from_utf8("CommandDisplay_Label")) self.CommandDisplay_Label.setText(qt_util.translate("Dialog", "Command: ", None)) commandArea_GridLayout.addWidget(self.CommandDisplay_Label, self.grid_layout_row, 0, 1, 1) # Create a text edit object. Add the text edit object to the Dialog window. # Set the size, the name and the html of the text edit object. # The text edit object, CommandDisplay_View_TextBrowser, displays a dynamic view of the command string. self.CommandDisplay_View_TextBrowser = QtWidgets.QTextEdit(self) self.CommandDisplay_View_TextBrowser.setObjectName("CommandDisplay_View_TextBrowser") self.CommandDisplay_View_TextBrowser.setReadOnly(True) self.CommandDisplay_View_TextBrowser.setMaximumHeight(60) # self.CommandDisplay_View_TextBrowser.setMinimumSize(QtCore.QSize(0, 100)) # self.CommandDisplay_View_TextBrowser.setMaximumSize(QtCore.QSize(16777215, 100)) # #html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">" \ # # "\n<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\np, li { " \ # # "white-space: pre-wrap; }\n</style></head><body style=\" font-family:\'MS Shell Dlg 2\';" \ # # " font-size:8.25pt; font-weight:400; font-style:normal;\">\n<p style=\" margin-top:0px;" \ # # " margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" \ # # "<span style=\" font-size:8pt;\">ReadGeoLayerFromGeoJSON()</span></p></body></html>" # #self.CommandDisplay_View_TextBrowser.setHtml(_translate("Dialog", html, None)) # TODO smalers 2019-01-20 Need to understand why things work differently on each OS if os_util.is_linux_os() and not os_util.is_cygwin_os(): # Full Linux commandArea_GridLayout.addWidget(self.CommandDisplay_View_TextBrowser, self.grid_layout_row, 1, 1, 1) else: # Cygwin and Windows commandArea_GridLayout.addWidget(self.CommandDisplay_View_TextBrowser, self.grid_layout_row, 1, 1, -1)
def setup_ui_core_command_area(self): # Create a label object to the Dialog window. # Set the alignment, the name, and the text of the label. # The label, Command Display_Label, labels the CommandDisplay_View_TextBrowser text edit object. self.grid_layout_row = self.grid_layout_row + 1 self.CommandDisplay_Label = QtWidgets.QLabel(self) self.CommandDisplay_Label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.CommandDisplay_Label.setObjectName( qt_util.from_utf8("CommandDisplay_Label")) self.CommandDisplay_Label.setText( qt_util.translate("Dialog", "Comments: ", None)) self.grid_layout.addWidget(self.CommandDisplay_Label, self.grid_layout_row, 0, 4, 1) # Create a text edit object. Add the text edit object to the Dialog window. # Set the size, the name and the html of the text edit object. # The text edit object, CommandDisplay_View_TextBrowser, displays a dynamic view of the command string. self.CommandDisplay_View_TextBrowser = QtWidgets.QTextEdit(self) self.CommandDisplay_View_TextBrowser.setObjectName( "CommandDisplay_View_TextBrowser") self.CommandDisplay_View_TextBrowser.setMaximumHeight(200) self.CommandDisplay_View_Font = QtGui.QFont("Monospace") self.CommandDisplay_View_Font.setStyleHint(QtGui.QFont.TypeWriter) self.CommandDisplay_View_Font.setPointSize(10) self.CommandDisplay_View_TextBrowser.setFont( self.CommandDisplay_View_Font) self.CommandDisplay_View_TextBrowser.setWordWrapMode( QtGui.QTextOption.NoWrap) # Do not display default command string when editing a new comment # If command_string is default reset to empty command_string = self.command.command_string # - existing comments should be shown as is without stripping the leading # if command_string == "#()": # Special case for new comment command_string = "" if command_string.endswith("()"): command_string = command_string[:-2] self.CommandDisplay_View_TextBrowser.setText(command_string) # self.CommandDisplay_View_TextBrowser.setMinimumSize(QtCore.QSize(0, 100)) # self.CommandDisplay_View_TextBrowser.setMaximumSize(QtCore.QSize(16777215, 100)) # #html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">" \ # # "\n<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\np, li { " \ # # "white-space: pre-wrap; }\n</style></head><body style=\" font-family:\'MS Shell Dlg 2\';" \ # # " font-size:8.25pt; font-weight:400; font-style:normal;\">\n<p style=\" margin-top:0px;" \ # # " margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" \ # # "<span style=\" font-size:8pt;\">ReadGeoLayerFromGeoJSON()</span></p></body></html>" # #self.CommandDisplay_View_TextBrowser.setHtml(qt_util.translate("Dialog", html, None)) self.grid_layout.addWidget(self.CommandDisplay_View_TextBrowser, self.grid_layout_row, 1, 4, -1)
def setup_ui_core_command_description(self): """ Setup the description component at the top of the dialog. """ # Create a frame object. Add the frame object to the Dialog window. # Set the shape, the shadow, and the name of the frame object. # The frame object, Command_Description, holds the command description and the view documentation button. description_Frame = QtWidgets.QFrame(self) description_Frame.setFrameShape(QtWidgets.QFrame.StyledPanel) description_Frame.setFrameShadow(QtWidgets.QFrame.Raised) description_Frame.setObjectName(qt_util.from_utf8("Command_Description")) self.grid_layout_row = self.grid_layout_row + 1 self.grid_layout.addWidget(description_Frame, self.grid_layout_row, 0, 1, 8) # Create a grid layout object. Apply to the Command_Description frame object. # Set the name of the grid layout object. self.gridLayout_2 = QtWidgets.QGridLayout(description_Frame) self.gridLayout_2.setObjectName(qt_util.from_utf8("gridLayout_2")) # Create a spacer. Add the spacer to the Command_Description frame object. spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem, 2, 0, 1, 1) # Create a push button. Add the button to the Command_Description frame object. # Set the name, the button text and the connection of the push button. # The push button, View_Documentation_Button, displays the command's online user documentation when clicked. self.View_Documentation_Button = QtWidgets.QPushButton(description_Frame) self.View_Documentation_Button.setObjectName(qt_util.from_utf8("View_Documentation_Button")) self.View_Documentation_Button.setText(qt_util.translate("Dialog", " View Documentation ", None)) self.View_Documentation_Button.setToolTip("View command documentation in web browser.") self.View_Documentation_Button.clicked.connect(self.view_documentation) self.gridLayout_2.addWidget(self.View_Documentation_Button, 2, 1, 1, 1) # Create a label. Add the label to the Command_Description frame object. # Set the name and the text of the label. # The label, Command_Description_Label, briefly describes the command. self.Command_Description_Label = QtWidgets.QLabel(description_Frame) self.Command_Description_Label.setObjectName(qt_util.from_utf8("Command_Description_Label")) self.Command_Description_Label.setText(self.command.command_metadata['Description']) self.gridLayout_2.addWidget(self.Command_Description_Label, 0, 0, 1, 2)
def setup_ui_parameter_file_selector(self, input_metadata, parameter_name, parameter_Tooltip): """ Add file selector UI components for a command parameter. Args: input_metadata (dict): input metadata, to retrieve additional properties parameter_name (str): Parameter name. parameter_Tooltip (str): Tooltip to be used for the main text field. Returns: None """ debug = True if self.debug: logger = logging.getLogger(__name__) logger.info("For parameter '" + parameter_name + "', adding file selector") # Create the text field that will receive the file path parameter_QLineEdit = QtWidgets.QLineEdit(self.parameter_QFrame) parameter_QLineEdit.setObjectName(parameter_name) self.parameter_QGridLayout.addWidget(parameter_QLineEdit, self.y_parameter, 1, 1, 4) self.parameter_QGridLayout.setColumnStretch(1, 4) if parameter_Tooltip != "": parameter_QLineEdit.setToolTip(parameter_Tooltip) # Create a listener that reacts if the line edit field has been changed. If so, run the # refresh_ui function. # If this command is being updated add the command parameters to the text fields if self.update: parameter_value = self.command.get_parameter_value(parameter_name) parameter_QLineEdit.setText(parameter_value) parameter_QLineEdit.textChanged.connect(self.refresh_ui) # Save the UI component self.input_ui_components[parameter_name] = parameter_QLineEdit # ----------------- # Add a "..." button # ----------------- request_key = parameter_name + "." + "FileSelector.SelectFolder" select_folder = False try: # The following should match ParameterName.FileSelector.SelectFolder select_folder = self.command.parameter_input_metadata[request_key] except KeyError: # Default was specified above... pass request_key = parameter_name + "." + "FileSelector.Button.Tooltip" file_selector_button_tooltip = "" try: file_selector_button_tooltip = input_metadata[request_key] except KeyError: # Default... if select_folder: file_selector_button_tooltip = "Browse for folder" else: file_selector_button_tooltip = "Browse for file" parameter_select_file_QPushButton = QtWidgets.QPushButton(self.parameter_QFrame) # Object name has parameter at front, which can be parsed out in event-handling code # - IMPORTANT - don't change the object name without changing elsewhere parameter_select_file_QPushButton.setObjectName(qt_util.from_utf8(parameter_name + ".FileSelector.Button")) parameter_select_file_QPushButton.setText(qt_util.translate("Dialog", "...", None)) if file_selector_button_tooltip != "": parameter_select_file_QPushButton.setToolTip(file_selector_button_tooltip) parameter_select_file_QPushButton.setMaximumWidth(50) parameter_select_file_QPushButton.clicked.connect( lambda clicked, y_param=self.y_parameter: self.ui_action_select_file(parameter_select_file_QPushButton)) self.parameter_QGridLayout.addWidget(parameter_select_file_QPushButton, self.y_parameter, 6, 1, 1)
def setupUi_Abstract(self, Dialog): """ Sets up a Dialog object with the features that are common across all GeoProcessor command dialog windows. Arg: Dialog: a QDialog window instance (QtGui.QDialog()) Return: None """ # Set the name, the initial size and the window title (the name of the command) of the Dialog window object. # The Dialog window object, Dialog, represents the entire dialog window. Dialog.setObjectName(qt_util.from_utf8("Dialog")) Dialog.resize(684, 404) Dialog.setWindowTitle( qt_util.translate("Dialog", self.command_name, None)) # Create a grid layout object. Apply the grid layout to the Dialog window object. # Set the name of the grid layout object. self.gridLayout = QtWidgets.QGridLayout(Dialog) self.gridLayout.setObjectName(qt_util.from_utf8("gridLayout")) # Create a frame object. Add the frame object to the Dialog window. # Set the shape, the shadow, and the name of the frame object. # The frame object, Command_Description, holds the command description and the view documentation button. self.Command_Description = QtWidgets.QFrame(Dialog) self.Command_Description.setFrameShape(QtWidgets.QFrame.StyledPanel) self.Command_Description.setFrameShadow(QtWidgets.QFrame.Raised) self.Command_Description.setObjectName( qt_util.from_utf8("Command_Description")) self.gridLayout.addWidget(self.Command_Description, 0, 0, 1, 8) # Create a grid layout object. Apply to the Command_Description frame object. # Set the name of the grid layout object. self.gridLayout_2 = QtWidgets.QGridLayout(self.Command_Description) self.gridLayout_2.setObjectName(qt_util.from_utf8("gridLayout_2")) # Create a spacer. Add the spacer to the Command_Description frame object. spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem, 2, 0, 1, 1) # Create a push button. Add the button to the Command_Description frame object. # Set the name, the button text and the connection of the push button. # The push button, View_Documentation_Button, displays the command's online user documentation when clicked. self.View_Documentation_Button = QtWidgets.QPushButton( self.Command_Description) self.View_Documentation_Button.setObjectName( qt_util.from_utf8("View_Documentation_Button")) self.View_Documentation_Button.setText( qt_util.translate("Dialog", " View Documentation ", None)) self.View_Documentation_Button.clicked.connect(self.view_documentation) self.gridLayout_2.addWidget(self.View_Documentation_Button, 2, 1, 1, 1) # Create a label. Add the label to the Command_Description frame object. # Set the name and the text of the label. # The label, Command_Description_Label, briefly describes the command. self.Command_Description_Label = QtWidgets.QLabel( self.Command_Description) self.Command_Description_Label.setObjectName( qt_util.from_utf8("Command_Description_Label")) self.Command_Description_Label.setText( qt_util.translate("Dialog", self.command_description, None)) self.gridLayout_2.addWidget(self.Command_Description_Label, 0, 0, 1, 2) # Create a line (frame object with special specifications). Add the line to the Dialog window. # Set the size policy, the shape, the shadow, and the name of the frame object to create the line separator. # The frame object, Separator, separates the command description from the input form section of the Dialog box. self.Separator = QtWidgets.QFrame(Dialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.Separator.sizePolicy().hasHeightForWidth()) self.Separator.setSizePolicy(sizePolicy) self.Separator.setFrameShape(QtWidgets.QFrame.HLine) self.Separator.setFrameShadow(QtWidgets.QFrame.Sunken) self.Separator.setObjectName(qt_util.from_utf8("Separator")) self.gridLayout.addWidget(self.Separator, 1, 0, 1, 8) # Create a button box object. Add the button box object to the Dialog window. # Set the orientation, the standard buttons, the name and the connections of the button box object. # The button box object, OK_Cancel_Buttons, allow the user to accept or reject the changes made in the dialog. self.OK_Cancel_Buttons = QtWidgets.QDialogButtonBox(Dialog) self.OK_Cancel_Buttons.setOrientation(QtCore.Qt.Horizontal) self.OK_Cancel_Buttons.setStandardButtons( QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.OK_Cancel_Buttons.setObjectName( qt_util.from_utf8("OK_Cancel_Buttons")) self.OK_Cancel_Buttons.accepted.connect(Dialog.accept) self.OK_Cancel_Buttons.rejected.connect(Dialog.reject) self.gridLayout.addWidget(self.OK_Cancel_Buttons, self.parameter_count + 4, 6, 1, 2) # Create a text edit object. Add the text edit object to the Dialog window. # Set the size, the name and the html of the text edit object. # The text edit object, CommandDisplay_View_TextBrowser, displays a dynamic view of the command string. self.CommandDisplay_View_TextBrowser = QtWidgets.QTextEdit(Dialog) self.CommandDisplay_View_TextBrowser.setMinimumSize( QtCore.QSize(0, 100)) self.CommandDisplay_View_TextBrowser.setMaximumSize( QtCore.QSize(16777215, 100)) self.CommandDisplay_View_TextBrowser.setObjectName( qt_util.from_utf8("CommandDisplay_View_TextBrowser")) html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">" \ "\n<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\np, li { " \ "white-space: pre-wrap; }\n</style></head><body style=\" font-family:\'MS Shell Dlg 2\';" \ " font-size:8.25pt; font-weight:400; font-style:normal;\">\n<p style=\" margin-top:0px;" \ " margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" \ "<span style=\" font-size:8pt;\">ReadGeoLayerFromGeoJSON()</span></p></body></html>" self.CommandDisplay_View_TextBrowser.setHtml( qt_util.translate("Dialog", html, None)) self.gridLayout.addWidget(self.CommandDisplay_View_TextBrowser, self.parameter_count + 3, 1, 1, -1) # Create a label object to the Dialog window. # Set the alignment, the name, and the text of the label. # The label, Command Display_Label, labels the CommandDisplay_View_TextBrowser text edit object. self.CommandDisplay_Label = QtWidgets.QLabel(Dialog) self.CommandDisplay_Label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.CommandDisplay_Label.setObjectName( qt_util.from_utf8("CommandDisplay_Label")) self.CommandDisplay_Label.setText( qt_util.translate("Dialog", "Command: ", None)) self.gridLayout.addWidget(self.CommandDisplay_Label, self.parameter_count + 3, 0, 1, 1) # Create a spacer. Add the spacer to the Dialog window. # The spacer separates the input parameter value fields from the Command Display text browser. spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.gridLayout.addItem(spacerItem2, self.parameter_count + 2, 3, 1, -1) # This will wire up the signals and slots depending on names. # REF: http://joat-programmer.blogspot.com/2012/02/pyqt-signal-and-slots-to-capture-events.html QtCore.QMetaObject.connectSlotsByName(Dialog)