Example #1
0
    def perspective(self, parallel=None):
        """change the perspective of the vtk scene"""
        camera = self.vtkrenderer.GetActiveCamera()

        if parallel is None:
            parallel = not camera.GetParallelProjection()

        if parallel:
            camera.ParallelProjectionOn()
            self.toolbutton_perspective.setIcon(get_icon('parallel.svg'))
        else:
            camera.ParallelProjectionOff()
            self.toolbutton_perspective.setIcon(get_icon('perspective.svg'))

        self.render()
Example #2
0
    def __init__(self, solver, parent):
        super(RunPopup, self).__init__(parent)
        self.commandline_option_exe = solver if solver else None
        self.mfix_available = False
        self.mfix_exe_cache = {}
        self.solver_list = {}
        self.template_values = {}
        self.cmdline = []  # List of strings
        self.parent = parent
        self.project = parent.project
        self.settings = parent.settings
        self.project_dir = parent.get_project_dir()
        self.gui_comments = self.project.mfix_gui_comments
        self.flag_processes = {}
        self.title = 'Run Solver'

        # load ui
        ui = self.ui = get_ui('run_popup.ui', self)
        ui.layout.setSizeConstraint(ui.layout.SetFixedSize)

        ui.toolbutton_browse.clicked.connect(self.handle_browse_exe)
        ui.toolbutton_browse.setIcon(get_icon('add.svg'))
        ui.toolbutton_browse.setIconSize(sub_icon_size())

        ui.toolbutton_remove.clicked.connect(self.handle_remove_exe)
        ui.toolbutton_remove.setIcon(get_icon('remove.svg'))
        ui.toolbutton_remove.setIconSize(sub_icon_size())

        ui.toolbutton_view_error.clicked.connect(self.show_solver_error)

        ui.listwidget_solver_list.itemSelectionChanged.connect(
            self.update_dialog_options)
        ui.combobox_restart.addItems(RESTART_TYPES.keys())
        ui.combobox_restart.hide()

        ui.button_run.clicked.connect(self.handle_run)
        ui.button_cancel.clicked.connect(self.handle_abort)
        ui.pushbutton_browse_template.clicked.connect(
            self.handle_browse_template)

        n_cpus = multiprocessing.cpu_count()
        ui.groupbox_smp_options.setTitle("SMP Options (%s available locally)" %
                                         plural(n_cpus, "core"))
        ui.groupbox_queue.toggled.connect(self.toggle_run_btn_text)
        ui.widget_queue_options.hide()

        self.initialize_ui()
        self.init_templates()
Example #3
0
    def init_graphics_tabs(self, loadvtk=True):

        self.loadvtk = loadvtk
        self.plot_dict = OrderedDict()

        # configure tab widget
        tab_widget = self.ui.tabWidgetGraphics
        tab_widget.setTabsClosable(True)
        tab_widget.tabCloseRequested.connect(self.remove_tab)
        tab_bar = tab_widget.tabBar()
        tab_bar.setElideMode(QtCore.Qt.ElideRight)

        # create a tab at the end to act like "new" button
        tab_bar.setSelectionBehaviorOnRemove(QtWidgets.QTabBar.SelectLeftTab)
        new_tab = QtWidgets.QWidget()
        new_tab.unsaved_flag = False
        new_tab.name = None
        tab_widget.addTab(new_tab, '')
        idx = self.ui.tabWidgetGraphics.count() - 1
        tab_widget.setTabIcon(idx, get_icon('add.svg'))
        tab_widget.currentChanged.connect(self._tab_changed)

        # remove close btn
        right_btn = tab_widget.tabBar().tabButton(idx,
                                                  QtWidgets.QTabBar.RightSide)
        if right_btn:
            right_btn.resize(0, 0)
        left_btn = tab_widget.tabBar().tabButton(idx,
                                                 QtWidgets.QTabBar.LeftSide)
        if left_btn:
            left_btn.resize(0, 0)
Example #4
0
 def _make_back_button(self):
     btn = QToolButton(self.file_menu)
     btn.setIcon(get_icon('left.svg'))
     btn.setText('Back')
     btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
     btn.setAutoRaise(True)
     btn.clicked.connect(self.handle_file_menu_hide)
     return btn
Example #5
0
    def extend_context_menu(self):
        menu = self.context_menu()  # pylint: disable=not-callable
        first_default_action = menu.actions()

        if first_default_action:
            first_default_action = first_default_action[0]

        # clear
        clear_action = QtWidgets.QAction(get_icon('close.svg'), 'Clear', menu)
        clear_action.triggered.connect(self.clear)
        insert_append_action(menu, clear_action, first_default_action)

        # save
        clear_action = QtWidgets.QAction(get_icon('save.svg'), 'Save', menu)
        clear_action.triggered.connect(self.save_to_file)
        insert_append_action(menu, clear_action, first_default_action)

        return menu
Example #6
0
    def init_file_menu(self):
        """Build the file menu."""

        ui = self.ui

        self.file_menu = QWidget(self)
        self.file_menu.setObjectName('file_menu')
        self.file_menu.setStyleSheet(
            'QWidget#file_menu{background-color: #E0E0E0;}')
        self.file_menu.hide()

        layout = ui.file_menu_layout = QGridLayout(self.file_menu)
        layout.setContentsMargins(0, 0, 0, 0)

        # return
        ui.file_menu_return = self._make_back_button()
        layout.addWidget(ui.file_menu_return, 0, 0)

        # list widget
        lw = ui.file_menu_list = QListWidget()
        lw.setMaximumWidth(200)
        lw.setFrameStyle(lw.NoFrame)
        lw.setSizePolicy(QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Minimum))
        lw.setAttribute(Qt.WA_MacShowFocusRect, 0)
        lw.setStyleSheet('''QListView{background-color: #E0E0E0;}
                            QListView::item:selected{background: #64B5F6;
                                color: white;}
                            QListView::item:hover{background:#BBDEFB;}
                         ''')
        lw.selectionModel().selectionChanged.connect(
            self.handle_file_menu_selection_changed)

        for name, icon in MENU_ITEMS:
            if name == 'sep':
                li = QListWidgetItem()
                li.setFlags(Qt.NoItemFlags)
                li.setSizeHint(QSize(0, 10))
                lw.addItem(li)
                sep = get_separator(vertical=False)
                sep.setEnabled(False)
                lw.setItemWidget(li, sep)
            else:
                li = QListWidgetItem(get_icon(icon + '.svg'), name)
                lw.addItem(li)
        layout.addWidget(lw, 1, 0)

        layout.addWidget(_make_logo_label(), 2, 0)

        ui.file_menu_stackedwidget = QStackedWidget()
        layout.addWidget(ui.file_menu_stackedwidget, 0, 1, -1, 1)
        self._add_stacked_widgets(ui.file_menu_stackedwidget, ui)
Example #7
0
    def set_solver_icon(self, solver, status):
        items = self.ui.listwidget_solver_list.findItems(
            solver, Qt.MatchExactly)
        if not items:
            return
        item = items[0]

        icon = 'error_outline.svg'
        if status == LOOKING:
            icon = 'timelapse.svg'
        elif status == OK:
            icon = 'check_outline.svg'

        item.setIcon(get_icon(icon))
Example #8
0
    def __init__(self, parent):
        QtWidgets.QDialog.__init__(self, parent)
        self.gui = parent
        self.setWindowIcon(get_icon('mfix.png'))
        self.setWindowTitle('Help')

        self.grid_layout = QtWidgets.QGridLayout(self)
        self.grid_layout.setContentsMargins(5, 5, 5, 5)

        self.lineedit = LineEdit()
        self.lineedit.key = 'keyword'
        self.grid_layout.addWidget(QtWidgets.QLabel("Enter keyword:"), 0, 0)
        self.grid_layout.addWidget(self.lineedit, 1, 0)
        self.lineedit.value_updated.connect(self.do_help)
Example #9
0
    def extend_context_menu(self):
        if self.context_menu is None:
            return
        menu = self.context_menu()  # pylint: disable=not-callable
        first_default_action = menu.actions()

        if first_default_action:
            first_default_action = first_default_action[0]
        # help
        help_action = QtWidgets.QAction(get_icon('help.svg'), 'Help', menu)
        help_action.triggered.connect(self.show_help_message)
        insert_append_action(menu, help_action, first_default_action)

        # create parameter
        if self.allow_parameters:
            create_param_action = QtWidgets.QAction(get_icon('sliders.svg'),
                                                    'Create Parameter', menu)
            create_param_action.triggered.connect(self.create_parameter)
            insert_append_action(menu, create_param_action,
                                 first_default_action)

        insert_append_separator(menu, first_default_action)

        return menu
Example #10
0
    def __init__(self, parent):
        QtWidgets.QDialog.__init__(self, parent)

        self.vtk_widget = parent

        ui = self.ui = get_ui('new_project_popup.ui', self)

        self.setWindowTitle('Create a new project')

        ui.toolbutton_browse.clicked.connect(self.browse)
        ui.toolbutton_browse.setIcon(get_icon('folder.svg'))

        ui.lineedit_project_name.setValidator(
            QtGui.QRegExpValidator(QtCore.QRegExp(re_valid_run_name_qt)))
        ui.combobox_location.editTextChanged.connect(self.check_location)
Example #11
0
    def init_base_toolbar(self):
        """add base toolbar"""
        self.button_bar = QtWidgets.QWidget(self)
        self.button_bar_layout = QtWidgets.QHBoxLayout(self.button_bar)
        self.button_bar_layout.setContentsMargins(0, 0, 0, 0)
        self.button_bar_layout.setSpacing(0)
        self.button_bar.setLayout(self.button_bar_layout)
        self.button_bar.setGeometry(QtCore.QRect(0, 0, 300, 300))
        self.grid_layout.addWidget(self.button_bar, 0, 0)

        self.toolbutton_reset = QtWidgets.QToolButton()
        self.toolbutton_reset.clicked.connect(self.reset_view)
        self.toolbutton_reset.setIcon(get_icon('overscan.svg'))
        self.toolbutton_reset.setIconSize(sub_icon_size())
        self.toolbutton_reset.setToolTip('Reset View')

        self.toolbutton_perspective = QtWidgets.QToolButton()
        self.toolbutton_perspective.clicked.connect(lambda ignore: self.perspective())
        self.toolbutton_perspective.setIcon(get_icon('perspective.svg'))
        self.toolbutton_perspective.setIconSize(sub_icon_size())
        self.toolbutton_perspective.setToolTip('Perspective')

        self.toolbutton_view_xy = QtWidgets.QToolButton()
        self.toolbutton_view_xy.clicked.connect(lambda: self.set_view('xy'))
        self.toolbutton_view_xy.setIcon(get_icon('xy.svg'))
        self.toolbutton_view_xy.setIconSize(sub_icon_size())
        self.toolbutton_view_xy.setToolTip('XY View')

        self.toolbutton_view_yz = QtWidgets.QToolButton()
        self.toolbutton_view_yz.clicked.connect(lambda: self.set_view('yz'))
        self.toolbutton_view_yz.setIcon(get_icon('yz.svg'))
        self.toolbutton_view_yz.setIconSize(sub_icon_size())
        self.toolbutton_view_yz.setToolTip('YZ View')

        self.toolbutton_view_xz = QtWidgets.QToolButton()
        self.toolbutton_view_xz.clicked.connect(lambda: self.set_view('xz'))
        self.toolbutton_view_xz.setIcon(get_icon('xz.svg'))
        self.toolbutton_view_xz.setIconSize(sub_icon_size())
        self.toolbutton_view_xz.setToolTip('XZ View')

        self.toolbutton_screenshot = QtWidgets.QToolButton()
        self.toolbutton_screenshot.clicked.connect(self.screenshot)
        self.toolbutton_screenshot.setIcon(get_icon('camera.svg'))
        self.toolbutton_screenshot.setIconSize(sub_icon_size())
        self.toolbutton_screenshot.setToolTip('Save scene as image')

        for btn in [self.toolbutton_reset,
                    self.toolbutton_view_xy,
                    self.toolbutton_view_yz,
                    self.toolbutton_view_xz,
                    self.toolbutton_perspective,
                    self.toolbutton_screenshot,]:
            self.button_bar_layout.addWidget(btn)
            btn.setAutoRaise(True)
            btn.setFocusPolicy(QtCore.Qt.ClickFocus)
Example #12
0
    def init_dashboard(self):

        ui = self.ui.dashboard

        for plt, btn in [('Elapsed Time', ui.toolbutton_plot_time),
                         ('DT', ui.toolbutton_plot_dt),
                         ('NIT', ui.toolbutton_plot_nit)]:
            btn.setIcon(get_icon('timeline.svg'))
            btn.pressed.connect(lambda plt=plt:self.dashboard_create_plot(plt))
            btn.setEnabled(PYQTGRAPH_AVAILABLE)


        for pb in [ui.progressbar_dt, ui.progressbar_nit]:
            pb.setRange(0, 100)

        self.reset_dashboard()
    def __init__(self, parent):
        QtWidgets.QDialog.__init__(self, parent)

        self.data_old = {}

        self.setWindowIcon(get_icon('mfix.png'))
        self.setWindowTitle('Parameters')

        self.grid_layout = QtWidgets.QGridLayout(self)
        self.grid_layout.setContentsMargins(5, 5, 5, 5)

        # --- tool buttons ---
        self.button_bar = QtWidgets.QWidget(self)
        self.button_bar_layout = QtWidgets.QHBoxLayout(self.button_bar)
        self.button_bar_layout.setContentsMargins(0, 0, 0, 0)
        self.button_bar.setLayout(self.button_bar_layout)
        self.button_bar.setGeometry(QtCore.QRect(0, 0, 300, 300))
        self.grid_layout.addWidget(self.button_bar, 0, 0)

        self.toolbutton_add = QtWidgets.QToolButton()
        self.toolbutton_add.clicked.connect(self.new_parameter)
        self.toolbutton_add.setIcon(get_icon('add.svg'))
        self.toolbutton_add.setIconSize(sub_icon_size())

        self.toolbutton_remove = QtWidgets.QToolButton()
        self.toolbutton_remove.clicked.connect(self.remove_parameter)
        self.toolbutton_remove.setIcon(get_icon('remove.svg'))
        self.toolbutton_remove.setEnabled(False)
        self.toolbutton_remove.setIconSize(sub_icon_size())

        self.toolbutton_copy = QtWidgets.QToolButton()
        self.toolbutton_copy.clicked.connect(self.copy_parameter)
        self.toolbutton_copy.setIcon(get_icon('copy.svg'))
        self.toolbutton_copy.setEnabled(False)
        self.toolbutton_copy.setIconSize(sub_icon_size())

        for widget in [
                self.toolbutton_add, self.toolbutton_remove,
                self.toolbutton_copy
        ]:
            self.button_bar_layout.addWidget(widget)
            widget.setAutoRaise(True)

        self.button_bar_layout.addStretch()

        # --- tree ---
        delegate = CustomDelegate(
            column_dict={
                0: {
                    'widget': 'lineedit',
                },
                1: {
                    'widget': 'combobox',
                    'items': ['integer', 'float', 'string'],
                },
                2: {
                    'widget': 'lineedit',
                },
            })
        self.tree = QtWidgets.QTreeWidget()
        self.tree.setItemDelegate(delegate)
        self.tree.setColumnCount(3)
        self.tree.setHeaderLabels(['parameter', 'type', 'value'])
        self.tree.setMinimumWidth(400)
        self.tree.itemSelectionChanged.connect(self.tree_clicked)
        self.tree.itemChanged.connect(self.parameter_changed)

        # base items
        self.units_parent = QtWidgets.QTreeWidgetItem(['units'])
        self.model_parent = QtWidgets.QTreeWidgetItem(['model'])
        self.user_parent = QtWidgets.QTreeWidgetItem(['user'])

        for item in [self.units_parent, self.model_parent, self.user_parent]:
            self.tree.addTopLevelItem(item)

        self.grid_layout.addWidget(self.tree, 1, 0)

        # --- apply/close ---
        btn_widget = QtWidgets.QWidget()
        btn_widget_ly = QtWidgets.QHBoxLayout(btn_widget)
        btn_widget_ly.setContentsMargins(0, 0, 0, 0)
        self.grid_layout.addWidget(btn_widget, 2, 0)

        spacer = QtWidgets.QSpacerItem(100, 10,
                                       QtWidgets.QSizePolicy.Expanding,
                                       QtWidgets.QSizePolicy.Maximum)
        btn_widget_ly.addItem(spacer)

        self.pushbutton_close = QtWidgets.QPushButton('Close')
        self.pushbutton_close.clicked.connect(self.close)
        btn_widget_ly.addWidget(self.pushbutton_close)
Example #14
0
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.parent = parent
        self.parameter_key_map = {}

        get_ui('regions.ui', self)

        self.extent_lineedits = [
            self.lineedit_regions_from_x, self.lineedit_regions_to_x,
            self.lineedit_regions_from_y, self.lineedit_regions_to_y,
            self.lineedit_regions_from_z, self.lineedit_regions_to_z
        ]
        for ext in self.extent_lineedits:
            ext.allow_parameters = True
            ext.dtype = float
            ext.help_text = 'Physical coordinates describing the bounds of the region.'

        self.lineedit_regions_name.help_text = 'Name of the region. Used througout the gui to reference the region'
        self.combobox_stl_shape.help_text = 'Shape to be used to select facets.'
        self.checkbox_slice_facets.help_text = 'Slice facets if the facet is on the selection boundary.'
        for wid in [
                self.lineedit_filter_x, self.lineedit_filter_y,
                self.lineedit_filter_z
        ]:
            wid.allow_parameters = True
            wid.help_text = 'Vector to filter facets with. If the facet '\
                            'normal is the same as the vector, then the facet'\
                            ' will be added to the region, else discarded.'
        self.lineedit_deviation_angle.allow_parameters = True
        self.lineedit_deviation_angle.help_text = 'Angle to provide a'\
            'tolerence to the filtering of facets based on the facet normal.'

        self.toolbutton_region_add.clicked.connect(self.new_region)
        self.toolbutton_region_delete.clicked.connect(self.delete_region)
        self.toolbutton_region_delete.setEnabled(False)  #Need a selection
        self.toolbutton_region_copy.clicked.connect(self.copy_region)
        self.toolbutton_region_copy.setEnabled(False)  #Need a selection
        self.toolbutton_color.clicked.connect(self.change_color)

        tablewidget = self.tablewidget_regions
        tablewidget.dtype = OrderedDict
        tablewidget._setModel()
        tablewidget.set_selection_model()
        tablewidget.set_value(OrderedDict())
        tablewidget.set_columns(['visible', 'color', 'type', 'used by'])
        tablewidget.show_vertical_header(True)
        tablewidget.auto_update_rows(True)
        tablewidget.new_selection.connect(self.update_region_parameters)
        tablewidget.clicked.connect(self.cell_clicked)
        tablewidget.default_value = OrderedDict()
        self.inhibit_toggle = True

        self.widget_region_parameters.setEnabled(False)
        for widget in widget_iter(self.widget_region_parameters):
            if hasattr(widget, 'value_updated'):
                widget.value_updated.connect(self.region_value_changed)

                # example <name>: lineedit_regions_to_x
                name = str(widget.objectName())

                # set extent limits
                if '_to_' in name or '_from_' in name:
                    kinfo = name.split('_')
                    widget.key = '_'.join(kinfo[-2:])
                    widget.dtype = float
                    widget.setValInfo(max=Equation(kinfo[-1] + 'max'),
                                      min=Equation(kinfo[-1] + 'min'))
                elif 'name' in name:
                    widget.key = 'name'
                    widget.dtype = str
                elif 'stl_shape' in name:
                    widget.key = 'stl_shape'
                    widget.dtype = str
                elif 'slice' in name:
                    widget.key = 'slice'
                    widget.dtype = bool
                elif 'filter' in name:
                    widget.key = '_'.join(name.split('_')[-2:])
                    widget.dtype = float
                elif 'deviation_angle' in name:
                    widget.key = 'deviation_angle'
                    widget.dtype = float
                elif 'equilibrant' in name:
                    widget.key = 'equilibrant'
                    widget.dtype = bool
                elif 'invert' in name:
                    widget.key = 'invert'
                    widget.dtype = bool
        self.error = self.parent.error
        self.warning = self.warn = self.parent.warn

        self.checkbox_selectfacets.clicked.connect(self.stl_type_changed)
        self.checkbox_selectfacets.toggled.connect(
            lambda c: self.groupbox_stl.setEnabled(c))
        self.groupbox_filter_facets.clicked.connect(self.filter_facets_changed)

        # default region buttons
        for btn, region in [(self.toolbutton_region_a, 'all'),
                            (self.toolbutton_region_l, 'left'),
                            (self.toolbutton_region_r, 'right'),
                            (self.toolbutton_region_t, 'top'),
                            (self.toolbutton_region_b, 'bottom'),
                            (self.toolbutton_region_f, 'front'),
                            (self.toolbutton_region_back, 'back')]:
            btn.clicked.connect(
                lambda ignore, r=region: self.new_default_region(r))
            btn.setIcon(get_icon(region + '_region.svg'))
            btn.setToolTip(region)
            btn.setIconSize(sub_icon_size())
Example #15
0
    def __init__(self, project, parent=None):
        QtWidgets.QWidget.__init__(self, parent)

        self.project = project
        self.job_dict = {}
        self.update_timer = QtCore.QTimer()
        self.update_timer.timeout.connect(self.update_job_status)
        self.run_cmd = None
        self.submit_cmd = None
        self.queue = False
        self.file_timer = QtCore.QTimer()
        self.file_timer.timeout.connect(self.look_for_pid)
        self.watch_dir_paths = []
        self.mock_parents = []
        self.running_in_vnc = is_vnc()

        # --- initalize the node widget ---
        nc = self.nodeChart = NodeWidget(showtoolbar=False)
        if hasattr(self.nodeChart, 'needsSavedEvent'):
            self.nodeChart.needsSavedEvent.connect(self.set_save_btn)
        self.nodeChart.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                     QtWidgets.QSizePolicy.Preferred)
        self.nodeChart.setGeometry(0, 0, 100, 1000)

        # add btns to gui toolbar
        ly = parent.ui.horizontallayout_menu_bar
        i = ly.count() - 6

        nc.enable_disable_btns = []
        size = parent.ui.toolbutton_run_mfix.iconSize()

        btns = [
            nc.runToolButton, nc.stepToolButton, nc.autorunToolButton,
            nc.stopToolButton
        ]
        if hasattr(nc, 'debugToolButton'):
            btns.append(nc.debugToolButton)
        for btn in btns:
            btn.setIconSize(size)
            ly.insertWidget(i, btn)
            nc.enable_disable_btns.append(btn)
            i += 1

        # add the wizard on the end
        if WIZARD_AVAILABLE:
            w = self.wizard = Wizard()

            def wizard_menu_callback():
                w.current_nc = nc  # provide handle to current nodechart
                w.exec_()

            btn = nc.wizardToolButton = QtWidgets.QToolButton()
            btn.setIcon(get_icon('wand.svg'))
            btn.setIconSize(size)
            btn.setAutoRaise(True)
            btn.setCheckable(False)
            btn.setToolTip('Open node wizard')
            btn.clicked.connect(wizard_menu_callback)
            ly.insertWidget(ly.count() - 1, btn)
            nc.enable_disable_btns.append(btn)

        # add an attribute for the project manager
        self.nodeChart.project = project

        # add an attribute for the mfixgui
        self.mfixgui = parent
        self.nodeChart.nodeworks_widget = self
        self.nodeChart.mfixgui = parent

        # Build default node library
        self.nodeChart.nodeLibrary.buildDefaultLibrary()

        # Add custom Nodes
        # for node in []:
        #     self.nodeChart.nodeLibrary.addNode(node, ['MFIX', ])

        # --- initialize job status table ---
        self.job_frame = QtWidgets.QWidget()
        self.job_layout = QtWidgets.QVBoxLayout(self.job_frame)
        self.job_layout.setContentsMargins(0, 0, 0, 0)
        self.job_layout.setSpacing(0)
        self.job_frame.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                     QtWidgets.QSizePolicy.Preferred)
        self.job_frame.setLayout(self.job_layout)

        self.job_toolbar = QtWidgets.QWidget()
        self.job_toolbar.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                       QtWidgets.QSizePolicy.Fixed)
        self.job_toolbar_layout = QtWidgets.QHBoxLayout(self.job_toolbar)
        self.job_toolbar_layout.setContentsMargins(0, 0, 0, 0)
        self.job_toolbar_layout.setSpacing(0)
        self.job_toolbar.setLayout(self.job_toolbar_layout)
        self.job_layout.addWidget(self.job_toolbar)

        self.tool_btn_dict = OrderedDict()
        for tool, icon, callback in [
            ('play', 'play.svg', self.handle_play),
            ('stop', 'stop.svg', self.handle_stop),
            ('pause', 'pause.svg', self.handle_pause),
            ('delete', 'delete.svg', self.handle_delete),
            ('restart', 'restart.svg', self.handle_restart),
            ('auto restart', 'autorenew.svg', self.handle_renew),
            ('remove from queue', 'removefromqueue.svg',
             self.handle_remove_from_queue),
            ('submit to queue', 'addtoqueue.svg', self.handle_add_to_queue),
            ('open', 'folder.svg', self.handle_open),
            ('settings', 'settings.svg', self.handle_settings)
        ]:
            btn = QtWidgets.QToolButton()
            btn.setIcon(get_icon(icon))
            btn.pressed.connect(callback)
            btn.setAutoRaise(True)
            btn.setEnabled(tool == 'settings')
            btn.setToolTip(tool)
            self.tool_btn_dict[tool] = btn
            self.job_toolbar_layout.addWidget(btn)
        self.job_toolbar_layout.addStretch()

        self.job_status_table = Table(
            dtype=OrderedDict,
            columns=[
                'status', 'job id', 'progress', 'dt', 'time remaining', 'path'
            ],
            column_delegate={2: {
                'widget': 'progressbar'
            }},
            multi_selection=True)
        self.job_status_table.set_value(OrderedDict())
        self.job_status_table.show_vertical_header(True)
        self.job_status_table.auto_update_rows(True)
        self.job_status_table.default_value = OrderedDict()
        self.job_status_table.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Preferred)
        self.job_status_table.new_selection.connect(self.update_btns)
        self.job_layout.addWidget(self.job_status_table)

        # splitter
        self.splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        self.splitter.addWidget(self.nodeChart)
        self.splitter.addWidget(self.job_frame)

        # main layout
        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
        self.setLayout(self.layout)
        self.layout.addWidget(self.splitter)
Example #16
0
    def create_monitor_plot_widget(self, name='Monitors'):
        """ convert existing "New" tab to a monitor plot tab """
        layout = self.layout()

        clear_layout(layout)
        name = get_unique_string(name, self.graphic_tabs.plot_dict.keys())
        self._change_name(name)

        self.monitors = True
        self.curve = {}
        self.color_cycle = itertools.cycle(DEFAULT_PENS)

        mr = self.graphic_tabs.monitor_reader
        mr.connect(self.update_monitors)

        # splitter
        splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
        layout.addWidget(splitter, 0, 0)

        # plot widget
        plot = self.plot_widget = PlotWidget()
        plot.getPlotItem().showGrid(True, True, 0.5)
        plot.setDownsampling(ds=False, auto=True, mode='subsample')
        plot.setLabel('bottom', 'Time [s]')

        plot.addLegend()
        # monkey patch updateSize of the legend
        legend = plot.plotItem.legend
        legend.updateSize = lambda: legend_patch(legend)
        splitter.addWidget(plot)

        # table
        opt_widget = QtWidgets.QWidget(self)
        opt_layout = QtWidgets.QGridLayout(opt_widget)
        opt_layout.setContentsMargins(0, 0, 0, 0)

        # save
        tb_sv = QtWidgets.QToolButton()
        tb_sv.setToolTip('save plot')
        tb_sv.setIcon(get_icon('save.svg'))
        tb_sv.setAutoRaise(True)
        plot.sceneObj.contextMenuItem = plot.plotItem.vb  # fix missing attr
        tb_sv.clicked.connect(plot.sceneObj.showExportDialog)
        opt_layout.addWidget(tb_sv, 0, 0)

        # hide/show legend
        tb_lg = QtWidgets.QToolButton()
        tb_lg.setToolTip('hide/show legend')
        tb_lg.setCheckable(True)
        tb_lg.setChecked(True)
        tb_lg.setIcon(get_icon('bullet_list.svg'))
        tb_lg.setAutoRaise(True)
        tb_lg.clicked.connect(lambda: legend.setVisible(tb_lg.isChecked()))
        opt_layout.addWidget(tb_lg, 0, 1)

        mt = self.monitor_table = Table(
            dtype=dict,
            columns=['visible', 'color', 'variable', 'monitor'],
            selection_behavior='row',
            multi_selection=True)
        mt.set_value(dict())
        mt.show_vertical_header(False)
        mt.auto_update_rows(True)
        mt.clicked.connect(self.cell_clicked)
        mt.setEditTriggers(QtWidgets.QTableView.NoEditTriggers)

        # right click menu
        menu = QtWidgets.QMenu(mt)
        for text, method in [
            ('Select All', self.select_all),
            ('Clear Selection', self.clear_selection),
            ('Hide', self.hide_curves),
            ('Show', self.show_curves),
        ]:
            action = QtWidgets.QAction(text, mt)
            action.triggered.connect(method)
            menu.addAction(action)

        mt.menu = menu
        opt_layout.addWidget(mt, 1, 0, 1, 10)

        splitter.addWidget(opt_widget)
        splitter.setSizes([800, 200])

        # lb = QtWidgets.QLabel('X Axis')
        # layout.addWidget(lb, 2, 0)
        # cb = self.x_axis_cb = ComboBox()
        # cb.addItems(['Time'])
        # layout.addWidget(cb, 2, 1)

        for path in mr.data.keys():
            self.update_monitors(path, mr.data)