def test_model_build(self): setting = mqu.system_settings(testing=True) config_path = setting['config_path'].joinpath('test_custom_controller.json') new_config = mb.get_config(config_path) controller = mc.CustomController(new_config, setting) model_build = mqb.ModelBuild(controller) model_build.show() # TODO: add testing of build viewer for each component if 'IGNORE_EXEC' not in os.environ: app.exec() self.assertIsInstance(model_build, mqb.ModelBuild)
def test_indexed_sets_editor(self): setting = mqu.system_settings(testing=True) config_path = setting['config_path'].joinpath( 'Kondili_State_Task_Network.json') config = mb.get_config(config_path) spec = mb.create_specification(config['specification']) indexed_sets_editor = mw.IndexedSetsEditor(config['indexed_sets'], config['sets'], spec, lookup) indexed_sets_editor.show() if 'IGNORE_EXEC' not in os.environ: app.exec() self.assertIsInstance(indexed_sets_editor, mw.IndexedSetsEditor)
def test_model_solve(self): setting = mqu.system_settings(testing=True) config_path = setting['config_path'].joinpath('Lemon_Toy_Model.json') config = mb.get_config(config_path) instance = mb.build_instance(config) # get lookups from db conn = di.get_sqlite_connection() lookup = dv.LookupTables(conn) # setup a model run model_solve = ms.ModelSolve(lookup) model_solve.concrete_model = instance model_solve.resize(800, 600) model_solve.show() # run the model QTest.mouseClick(model_solve.run_button, Qt.LeftButton) if 'IGNORE_EXEC' not in os.environ: app.exec() self.assertIsInstance(model_solve, ms.ModelSolve)
from PyQt5.QtWidgets import QApplication from PyQt5.QtTest import QTest from PyQt5.Qt import Qt import pyomo.environ as pe import mola.dataimport as di import mola.dataview as dv import mola.build as mb import molaqt.view as mv import molaqt.utils as mqu app = QApplication(sys.argv) # load a model and solve it for viewing setting = mqu.system_settings(testing=True) config_path = setting['config_path'].joinpath('Lemon_Toy_Model.json') config = mb.get_config(config_path) spec = mb.create_specification(config['specification']) instance = mb.build_instance(config) for i, obj in enumerate(instance.component_objects(pe.Objective)): # activate first objective if i == 0: obj.activate() else: obj.deactivate() opt = pe.SolverFactory("glpk") opt.solve(instance) # get lookups from db conn = di.get_sqlite_connection()
def __init__(self, argv): super(MolaMainWindow, self).__init__() # process arguments opts, args = getopt.getopt(argv, 'd', ['development']) dev = False for opt, arg in opts: if opt in ('-d', '--development'): dev = True # general configuration self.development = False self.system = mu.system_settings(development=dev) self.qt_console = None self.setGeometry(50, 50, 800, 600) self.setWindowTitle(self.system['app_name']) self.setWindowIcon(QIcon(":python-logo.png")) self.statusBar() # model configuration self.new_model_action = QAction(QIcon(":New.svg"), "&New ...", self) self.new_model_action.setShortcut("Ctrl+N") self.new_model_action.triggered.connect(self.new_model) self.save_model_action = QAction(QIcon(":Save.svg"), "&Save", self) self.save_model_action.setShortcut("Ctrl+S") self.save_model_action.triggered.connect(self.save_model) self.build_model_action = QAction(QIcon(":Build.svg"), "&Build", self) self.build_model_action.setShortcut("Ctrl+B") self.build_model_action.triggered.connect(self.build_model) self.run_model_action = QAction(QIcon(":Run.svg"), "&Run", self) self.run_model_action.setShortcut("Ctrl+R") self.run_model_action.triggered.connect(self.run_model) close_model_action = QAction("&Close", self) close_model_action.triggered.connect(self.close_model) exit_action = QAction("&Exit", self) exit_action.setShortcut("Alt+E") exit_action.setStatusTip('Exit mola') exit_action.triggered.connect(self.close_application) # database import_sqlite_db_action = QAction("&Import sqlite ...", self) import_sqlite_db_action.setStatusTip('Import sqlite database') import_sqlite_db_action.triggered.connect(self.import_sqlite_database) self.open_db_action = QAction(QIcon(":Library.svg"), "&Open ...", self) self.open_db_action.setStatusTip('Open database') self.open_db_action.triggered.connect(self.open_database) # help general_specification_v5_action = QAction("&General Specification v5", self) general_specification_v5_action.triggered.connect( lambda: self.open_url(doc_file='General_Specification_v5.html')) github_home_action = QAction('&Github Home', self) github_home_action.triggered.connect( lambda: self.open_url(url='https://github.com/paulemms/LCA/wiki')) console_action = QAction("Qt Console", self) console_action.triggered.connect(self.console) self.about_action = QAction(QIcon(":Help.svg"), "&About", self) self.about_action.triggered.connect(self.about) # menus main_menu = self.menuBar() model_menu = main_menu.addMenu('&Model') model_menu.addAction(self.new_model_action) model_menu.addAction(self.save_model_action) model_menu.addAction(close_model_action) model_menu.addAction(exit_action) db_menu = main_menu.addMenu('&Database') db_menu.addAction(import_sqlite_db_action) db_menu.addAction(self.open_db_action) help_menu = main_menu.addMenu('&Help') help_menu.addAction(general_specification_v5_action) help_menu.addAction(github_home_action) help_menu.addAction(console_action) help_menu.addAction(self.about_action) self._create_toolbars() self.manager = mt.ModelManager(self.system) self.db_view = [] self.setCentralWidget(self.manager) self.show()