Example #1
0
    def __init__(self, listview, parent=None):
        super().__init__(parent)

        # Variables
        self.listview = listview

        # Actions
        self.act_add_pure = self.addAction(QtGui.QIcon.fromTheme("list-add"),
                                           "Pure")
        self.act_add_pure.setToolTip("Add pure material")

        self.act_add_formula = self.addAction(
            load_icon("material-add-formula.svg"), "Formula")
        self.act_add_formula.setToolTip("Add material from a formula")

        self.act_add_material = self.addAction(
            load_icon("material-add-advanced.svg"), "Advanced")
        self.act_add_material.setToolTip("Add material from composition")

        self.act_remove = QtWidgets.QAction()
        self.act_remove.setIcon(QtGui.QIcon.fromTheme("list-remove"))
        self.act_remove.setToolTip("Remove")
        self.act_remove.setEnabled(False)
        self.act_remove.setShortcutContext(QtCore.Qt.WindowShortcut)
        self.act_remove.setShortcut(QtGui.QKeySequence.Delete)

        self.act_clear = QtWidgets.QAction()
        self.act_clear.setIcon(QtGui.QIcon.fromTheme("edit-clear"))
        self.act_clear.setToolTip("Clear")
        self.act_clear.setEnabled(False)

        # Widgets
        tool_remove = QtWidgets.QToolButton()
        tool_remove.setDefaultAction(self.act_remove)
        self.addWidget(tool_remove)

        tool_clear = QtWidgets.QToolButton()
        tool_clear.setDefaultAction(self.act_clear)
        self.addWidget(tool_clear)

        # Signals
        self.listview.model().modelReset.connect(self._on_data_changed)
        self.listview.selectionModel().selectionChanged.connect(
            self._on_data_changed)

        self.act_add_pure.triggered.connect(
            functools.partial(self._on_add_material, MaterialPureWidget,
                              "Add pure material(s)"))
        self.act_add_formula.triggered.connect(
            functools.partial(
                self._on_add_material,
                MaterialFormulaWidget,
                "Add material from chemical formula",
            ))
        self.act_add_material.triggered.connect(
            functools.partial(self._on_add_material, MaterialAdvancedWidget,
                              "Add material(s)"))
        self.act_remove.triggered.connect(self._on_remove_material)
        self.act_clear.triggered.connect(self._on_clear_materials)
Example #2
0
 def icon(self):
     return load_icon("figure.svg")
Example #3
0
 def icon(self):
     return load_icon("table.svg")
Example #4
0
def test_load_icon():
    icon = load_icon("newsimulation.svg")
    assert icon is not None
Example #5
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("pyMonteCarlo")
        self.setWindowIcon(load_pixmap("logo_32x32.png"))

        # Variables
        self._should_save = False

        self._settings = Settings.read()

        max_workers = multiprocessing.cpu_count() - 1
        self._runner = LocalSimulationRunner(max_workers=max_workers)

        # Actions
        self.action_new_project = QtWidgets.QAction("New project")
        self.action_new_project.setIcon(QtGui.QIcon.fromTheme("document-new"))
        self.action_new_project.setShortcut(QtGui.QKeySequence.New)
        self.action_new_project.triggered.connect(self.newProject)

        self.action_open_project = QtWidgets.QAction("Open project")
        self.action_open_project.setIcon(
            QtGui.QIcon.fromTheme("document-open"))
        self.action_open_project.setShortcut(QtGui.QKeySequence.Open)
        self.action_open_project.triggered.connect(
            functools.partial(self.openProject, None))

        self.action_save_project = QtWidgets.QAction("Save project")
        self.action_save_project.setIcon(
            QtGui.QIcon.fromTheme("document-save"))
        self.action_save_project.setShortcut(QtGui.QKeySequence.Save)
        self.action_save_project.triggered.connect(
            functools.partial(self.saveProject, None))

        self.action_settings = QtWidgets.QAction("Settings")
        self.action_settings.setIcon(
            QtGui.QIcon.fromTheme("preferences-system"))
        self.action_settings.setShortcut(QtGui.QKeySequence.Preferences)
        self.action_settings.triggered.connect(self._on_settings)

        self.action_quit = QtWidgets.QAction("Quit")
        self.action_quit.setShortcut(QtGui.QKeySequence.Quit)
        self.action_quit.triggered.connect(self.close)

        self.action_create_simulations = QtWidgets.QAction(
            "Create new simulations")
        self.action_create_simulations.setIcon(load_icon("newsimulation.svg"))
        self.action_create_simulations.triggered.connect(
            self._on_create_new_simulations)

        self.action_stop_simulations = QtWidgets.QAction(
            "Stop all simulations")
        self.action_stop_simulations.setIcon(
            QtGui.QIcon.fromTheme("media-playback-stop"))
        self.action_stop_simulations.triggered.connect(self._on_stop)
        self.action_stop_simulations.setEnabled(False)

        # Timers
        self.timer_runner = QtCore.QTimer()
        self.timer_runner.setInterval(1000)
        self.timer_runner.setSingleShot(False)

        # Menus
        menu = self.menuBar()
        menu_file = menu.addMenu("File")
        menu_file.addAction(self.action_new_project)
        menu_file.addAction(self.action_open_project)
        menu_file.addAction(self.action_save_project)
        menu_file.addSeparator()
        menu_file.addAction(self.action_settings)
        menu_file.addSeparator()
        menu_file.addAction(self.action_quit)

        menu_simulation = menu.addMenu("Simulation")
        menu_simulation.addAction(self.action_create_simulations)
        menu_simulation.addAction(self.action_stop_simulations)

        # Tool bar
        toolbar_file = self.addToolBar("File")
        toolbar_file.addAction(self.action_new_project)
        toolbar_file.addAction(self.action_open_project)
        toolbar_file.addAction(self.action_save_project)

        toolbar_simulation = self.addToolBar("Simulation")
        toolbar_simulation.addAction(self.action_create_simulations)
        toolbar_simulation.addAction(self.action_stop_simulations)

        # Status bar
        self.statusbar_submitted = QtWidgets.QLabel()
        self.statusbar_submitted.setFrameStyle(QtWidgets.QFrame.Panel
                                               | QtWidgets.QFrame.Sunken)

        self.statusbar_done = QtWidgets.QLabel()
        self.statusbar_done.setFrameStyle(QtWidgets.QFrame.Panel
                                          | QtWidgets.QFrame.Sunken)

        self.statusbar_progressbar = QtWidgets.QProgressBar()
        self.statusbar_progressbar.setRange(0, 100)

        statusbar = self.statusBar()
        statusbar.addPermanentWidget(self.statusbar_submitted)
        statusbar.addPermanentWidget(self.statusbar_done)
        statusbar.addPermanentWidget(self.statusbar_progressbar)

        # Widgets
        self.tree = FieldTree()

        self.dock_project = QtWidgets.QDockWidget("Project")
        self.dock_project.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea
                                          | QtCore.Qt.RightDockWidgetArea)
        self.dock_project.setFeatures(
            QtWidgets.QDockWidget.NoDockWidgetFeatures
            | QtWidgets.QDockWidget.DockWidgetMovable)
        self.dock_project.setWidget(self.tree)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.dock_project)

        self.table_runner = TokenTableWidget(self._runner.token)

        self.dock_runner = QtWidgets.QDockWidget("Run")
        self.dock_runner.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea
                                         | QtCore.Qt.RightDockWidgetArea)
        self.dock_runner.setFeatures(QtWidgets.QDockWidget.NoDockWidgetFeatures
                                     | QtWidgets.QDockWidget.DockWidgetMovable)
        self.dock_runner.setWidget(self.table_runner)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.dock_runner)

        self.tabifyDockWidget(self.dock_project, self.dock_runner)
        self.dock_project.raise_()

        self.mdiarea = FieldMdiArea()

        self.setCentralWidget(self.mdiarea)

        # Dialogs
        self.wizard_simulation = NewSimulationWizard(self._settings)

        self.dialog_settings = SettingsDialog()

        # Signals
        self.tree.doubleClicked.connect(self._on_tree_double_clicked)

        self.mdiarea.windowOpened.connect(self._on_mdiarea_window_opened)
        self.mdiarea.windowClosed.connect(self._on_mdiarea_window_closed)

        self.timer_runner.timeout.connect(self._on_timer_runner_timeout)

        self.newSimulations.connect(self._on_new_simulations)

        # Start
        logger.debug("Before new project action")
        self.action_new_project.trigger()  # Required to setup project
        self.timer_runner.start()