From 55318188cb893322be6ee9976ca04756e4dcb478 Mon Sep 17 00:00:00 2001 From: John Eslick Date: Wed, 26 Jul 2023 13:33:18 -0500 Subject: [PATCH 1/4] Fix model viewer --- pyomo/contrib/viewer/model_browser.py | 7 +++---- pyomo/contrib/viewer/model_select.py | 4 ++-- pyomo/contrib/viewer/pyomo_viewer.py | 6 +++--- pyomo/contrib/viewer/residual_table.py | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pyomo/contrib/viewer/model_browser.py b/pyomo/contrib/viewer/model_browser.py index 064e03c196f..8379518a4cf 100644 --- a/pyomo/contrib/viewer/model_browser.py +++ b/pyomo/contrib/viewer/model_browser.py @@ -102,17 +102,16 @@ def setModelData(self, editor, model, index): class ModelBrowser(_ModelBrowser, _ModelBrowserUI): - def __init__(self, ui_data, parent=None, standard="Var"): + def __init__(self, ui_data, standard="Var"): """ - Create a dock widdget with a QTreeView of a Pyomo model. + Create a dock widget with a QTreeView of a Pyomo model. Args: - parent: parent widget ui_data: Contains model and ui information standard: A standard setup for different types of model components {"Var", "Constraint", "Param", "Expression"} """ - super().__init__(parent=parent) + super().__init__() self.setupUi(self) # The default int and double spin boxes are not good for this # application. So just use regular line edits. diff --git a/pyomo/contrib/viewer/model_select.py b/pyomo/contrib/viewer/model_select.py index 2b81cda6665..db3c9b4deba 100644 --- a/pyomo/contrib/viewer/model_select.py +++ b/pyomo/contrib/viewer/model_select.py @@ -49,8 +49,8 @@ class _ModelSelect(object): class ModelSelect(_ModelSelect, _ModelSelectUI): - def __init__(self, ui_data, parent=None): - super().__init__(parent=parent) + def __init__(self, ui_data): + super().__init__() self.setupUi(self) self.ui_data = ui_data self.closeButton.clicked.connect(self.close) diff --git a/pyomo/contrib/viewer/pyomo_viewer.py b/pyomo/contrib/viewer/pyomo_viewer.py index f11f129cacd..8293ffa2546 100644 --- a/pyomo/contrib/viewer/pyomo_viewer.py +++ b/pyomo/contrib/viewer/pyomo_viewer.py @@ -97,11 +97,11 @@ def kernel_pyomo_init(self, kc): def init_qt_elements(self): super().init_qt_elements() self.kernel_pyomo_init(self.widget.kernel_client) - self.run_script_act = myqt.QtWidgets.QAction("&Run Script...", self.window) - self.show_ui_act = myqt.QtWidgets.QAction( + self.run_script_act = myqt.QAction("&Run Script...", self.window) + self.show_ui_act = myqt.QAction( "&Show Pyomo Model Viewer", self.window ) - self.hide_ui_act = myqt.QtWidgets.QAction( + self.hide_ui_act = myqt.QAction( "&Hide Pyomo Model Viewer", self.window ) self.window.file_menu.addSeparator() diff --git a/pyomo/contrib/viewer/residual_table.py b/pyomo/contrib/viewer/residual_table.py index 17eca6b3057..46a86adbce6 100644 --- a/pyomo/contrib/viewer/residual_table.py +++ b/pyomo/contrib/viewer/residual_table.py @@ -50,8 +50,8 @@ class _ResidualTable(object): class ResidualTable(_ResidualTable, _ResidualTableUI): - def __init__(self, ui_data, parent=None): - super().__init__(parent=parent) + def __init__(self, ui_data): + super().__init__() self.setupUi(self) self.ui_data = ui_data datmodel = ResidualDataModel(parent=self, ui_data=ui_data) From c126225ceba00e2e00307257842fd2f04339438e Mon Sep 17 00:00:00 2001 From: John Eslick Date: Wed, 26 Jul 2023 14:15:13 -0500 Subject: [PATCH 2/4] Fix model seletor --- pyomo/contrib/viewer/model_select.py | 4 ++-- pyomo/contrib/viewer/ui.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyomo/contrib/viewer/model_select.py b/pyomo/contrib/viewer/model_select.py index db3c9b4deba..3c6c4ccdf17 100644 --- a/pyomo/contrib/viewer/model_select.py +++ b/pyomo/contrib/viewer/model_select.py @@ -49,8 +49,8 @@ class _ModelSelect(object): class ModelSelect(_ModelSelect, _ModelSelectUI): - def __init__(self, ui_data): - super().__init__() + def __init__(self, parent, ui_data): + super().__init__(parent) self.setupUi(self) self.ui_data = ui_data self.closeButton.clicked.connect(self.close) diff --git a/pyomo/contrib/viewer/ui.py b/pyomo/contrib/viewer/ui.py index 8a621534b31..af69e445054 100644 --- a/pyomo/contrib/viewer/ui.py +++ b/pyomo/contrib/viewer/ui.py @@ -266,7 +266,8 @@ def show_model_select(self): model_select = ModelSelect(parent=self, ui_data=self.ui_data) model_select.update_models() model_select.show() - return model_select + print(model_select) + #return model_select def exit_action(self): """ From a43a06b0cc2bc3043941aaa624d54c3d0cb90f4d Mon Sep 17 00:00:00 2001 From: John Eslick Date: Thu, 27 Jul 2023 10:20:35 -0500 Subject: [PATCH 3/4] Run black --- pyomo/contrib/viewer/pyomo_viewer.py | 12 ++++-------- pyomo/contrib/viewer/ui.py | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pyomo/contrib/viewer/pyomo_viewer.py b/pyomo/contrib/viewer/pyomo_viewer.py index 8293ffa2546..a8fec745af4 100644 --- a/pyomo/contrib/viewer/pyomo_viewer.py +++ b/pyomo/contrib/viewer/pyomo_viewer.py @@ -26,7 +26,7 @@ from pyomo.scripting.pyomo_parser import add_subparser import pyomo.contrib.viewer.qt as myqt -qtconsole_app, qtconsole_available = attempt_import('qtconsole.qtconsoleapp') +qtconsole_app, qtconsole_available = attempt_import("qtconsole.qtconsoleapp") class QtApp( @@ -98,12 +98,8 @@ def init_qt_elements(self): super().init_qt_elements() self.kernel_pyomo_init(self.widget.kernel_client) self.run_script_act = myqt.QAction("&Run Script...", self.window) - self.show_ui_act = myqt.QAction( - "&Show Pyomo Model Viewer", self.window - ) - self.hide_ui_act = myqt.QAction( - "&Hide Pyomo Model Viewer", self.window - ) + self.show_ui_act = myqt.QAction("&Show Pyomo Model Viewer", self.window) + self.hide_ui_act = myqt.QAction("&Hide Pyomo Model Viewer", self.window) self.window.file_menu.addSeparator() self.window.file_menu.addAction(self.run_script_act) self.window.view_menu.addSeparator() @@ -125,7 +121,7 @@ def main(*args): errors = list(myqt.import_errors) if not qtconsole_available: errors.append(qtconsole_app._moduleunavailable_message()) - print("qt not available\n " + '\n '.join(errors)) + print("qt not available\n " + "\n ".join(errors)) return QtApp.launch_instance() diff --git a/pyomo/contrib/viewer/ui.py b/pyomo/contrib/viewer/ui.py index af69e445054..a12b4e4d989 100644 --- a/pyomo/contrib/viewer/ui.py +++ b/pyomo/contrib/viewer/ui.py @@ -267,7 +267,7 @@ def show_model_select(self): model_select.update_models() model_select.show() print(model_select) - #return model_select + # return model_select def exit_action(self): """ From d483aab4e90657f9b027da6eb02f3f93791403e4 Mon Sep 17 00:00:00 2001 From: John Eslick Date: Fri, 28 Jul 2023 08:14:09 -0500 Subject: [PATCH 4/4] Fix left over debug code --- pyomo/contrib/viewer/ui.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyomo/contrib/viewer/ui.py b/pyomo/contrib/viewer/ui.py index a12b4e4d989..8a621534b31 100644 --- a/pyomo/contrib/viewer/ui.py +++ b/pyomo/contrib/viewer/ui.py @@ -266,8 +266,7 @@ def show_model_select(self): model_select = ModelSelect(parent=self, ui_data=self.ui_data) model_select.update_models() model_select.show() - print(model_select) - # return model_select + return model_select def exit_action(self): """