Skip to content

Commit

Permalink
add arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslick authored and Eslick committed May 23, 2024
1 parent 35edf83 commit 01b5ef2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pyomo/contrib/viewer/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class _MainWindow(object):
_log.error(_err)


def get_mainwindow(model=None, show=True, ask_close=True, testing=False):
def get_mainwindow(
model=None, show=True, ask_close=True, model_var_name_in_main=None, testing=False
):
"""
Create a UI MainWindow.
Expand All @@ -79,18 +81,19 @@ def get_mainwindow(model=None, show=True, ask_close=True, testing=False):
(ui, model): ui is the MainWindow widget, and model is the linked Pyomo
model. If no model is provided a new ConcreteModel is created
"""
model_name = None
model_name = model_var_name_in_main
if model is None:
import __main__
if "model" in dir(__main__):
if isinstance(getattr(__main__, "model"), pyo.Block):
model = getattr(__main__, "model")
model_name = "model"
for s in dir(__main__):
if isinstance(getattr(__main__, s), pyo.Block):
model = getattr(__main__, s)
model_name = s
break

if model_name in dir(__main__):
if isinstance(getattr(__main__, model_name), pyo.Block):
model = getattr(__main__, model_name)
else:
for s in dir(__main__):
if isinstance(getattr(__main__, s), pyo.Block):
model = getattr(__main__, s)
model_name = s
break
ui = MainWindow(
model=model,
model_var_name_in_main=model_name,
Expand Down

0 comments on commit 01b5ef2

Please sign in to comment.