def __init__(self, name, label, cmap, parent=None):
        super().__init__(parent)

        self.setObjectName(name)

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setAlignment(Qt.AlignLeft)
        self.label = QtWidgets.QLabel(label)
        self.label.setStyleSheet("QLabel { font-size: 10px; }")

        self.b = QtWidgets.QCheckBox("Add opacity point: ", self)
        self.b.stateChanged.connect(self.clickBox)
        self.b.setLayoutDirection(Qt.RightToLeft)

        nF = QtWidgets.QFrame()
        layout1 = QtWidgets.QHBoxLayout(nF)
        layout1.setContentsMargins(0, 0, 0, 0)
        layout1.setAlignment(Qt.AlignLeft)
        layout1.addWidget(self.b)
        layout1.addWidget(self.setup_cmap_frame(cmap))

        self.layout.addWidget(self.label)
        self.layout.addWidget(nF)

        # Set shape of this QWidget
        self.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.setFrameShadow(QtWidgets.QFrame.Raised)
Esempio n. 2
0
    def __init__(self, canvas, num):
        """Ctor for the LeoFigureManagerQt class."""
        self.c = c = g.app.log.c
        super().__init__(canvas, num)
        self.canvas = canvas

        # New code for Leo: embed the canvas in the viewrendered area.
        self.vr_controller = vc = vr.controllers.get(c.hash())
        self.splitter = c.free_layout.get_top_splitter()
        self.frame = w = QtWidgets.QFrame()
        w.setLayout(QtWidgets.QVBoxLayout())
        w.layout().addWidget(self.canvas)
        if vc:
            vc.embed_widget(w)

        class DummyWindow:
            def __init__(self, c):
                self.c = c
                self._destroying = None

            def windowTitle(self):
                return self.c.p.h

            def show(self):
                pass

        self.window = None  #DummyWindow(c)

        # See comments in the base class ctor, in backend_qt5.py.
        self.canvas.setFocusPolicy(FocusPolicy.StrongFocus)
        self.canvas.setFocus()
        self.canvas._destroying = False

        self.toolbar = self._get_toolbar(self.canvas, self.frame)
        if self.toolbar is not None:
            # The toolbar is a matplotlib.backends.backend_qt.NavigationToolbar2QT.
            layout = self.frame.layout()
            layout.addWidget(self.toolbar)
            # add text label to status bar
            self.statusbar_label = QtWidgets.QLabel()
            layout.addWidget(self.statusbar_label)

        self.canvas.draw_idle()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)

        # Close the figure so that we don't create too many figure instances
        plt.close(canvas.figure)
    def setup_cmap_frame(self, cmap):
        nF = QtWidgets.QFrame()
        layout = QtWidgets.QHBoxLayout(nF)
        layout.setContentsMargins(5, 0, 5, 0)

        label = QtWidgets.QLabel('cmap: ')
        layout.addWidget(label)

        # Type dropdown list, training or test images
        self.type_combobox = QtWidgets.QComboBox()
        for colormap in sorted(Settings.colormaps):
            self.type_combobox.addItem(colormap)
        self.type_combobox.currentIndexChanged.connect(self.cmap_selectionchange)
        self.type_combobox.setCurrentText(cmap)
        layout.addWidget(self.type_combobox)

        return nF
    def __init__(self):
        super().__init__()
        # 1. Window settings
        self.setGeometry(300, 300, 800, 400)
        self.setWindowTitle("Matplotlib live plot in PyQt - example 1")
        self.frm = QtWidgets.QFrame(self)
        self.frm.setStyleSheet("QWidget { background-color: #eeeeec; }")
        self.lyt = QtWidgets.QVBoxLayout()
        self.frm.setLayout(self.lyt)
        self.setCentralWidget(self.frm)

        # 2. Place the matplotlib figure
        self.myFig = MyFigureCanvas(x_len=200, y_range=[0, 100], interval=20)
        self.lyt.addWidget(self.myFig)

        # 3. Show
        self.show()
        return
Esempio n. 5
0
    def _init_toolbar(self):

        for text, tooltip_text, image_file, callback in self.toolitems:

            if text is None:
                # bug fix to avoid duplicated separators in the task bar
                continue

            if text == 'Home':
                home_action = self.addAction(self._icon('home.png'),
                                             'Reset view', self.home)
                home_action.setToolTip('Reset view')
                self._actions['home'] = home_action
            elif text == 'Back':
                back_action = self.addAction(self._icon('back.png'), 'Back',
                                             self.back)
                back_action.setToolTip('Previous view')
                self._actions['back'] = back_action
            elif text == 'Forward':
                forward_action = self.addAction(self._icon('forward.png'),
                                                'Forward', self.forward)
                forward_action.setToolTip('Next view')
                self._actions['forward'] = forward_action
                self.addSeparator()
            elif text == 'Pan':
                pan_action = self.addAction(self._icon('pan.png'), 'Pan',
                                            self.pan)
                pan_action.setToolTip('Pan on plot')
                pan_action.setCheckable(True)
                self._actions['pan'] = pan_action
                scale_action = self.addAction(self._icon('scale.png'), 'Scale',
                                              self.scale)
                scale_action.setToolTip('Scale plot')
                scale_action.setCheckable(True)
                self._actions['scale'] = scale_action
            elif text == 'Zoom':
                zoom_in_action = self.addAction(self._icon('zoomin.png'),
                                                'Zoom in', self.zoom_in)
                zoom_in_action.setToolTip('Zoom in area')
                zoom_in_action.setCheckable(True)
                self._actions['zoom_in'] = zoom_in_action
                zoom_out_action = self.addAction(self._icon('zoomout.png'),
                                                 'Zoom out', self.zoom_out)
                zoom_out_action.setToolTip('Zoom out area')
                zoom_out_action.setCheckable(True)
                self._actions['zoom_out'] = zoom_out_action
                # flag/unflag actions
                self.flag_action = self.addAction(self._icon("flag.png"),
                                                  'Flag', self.flag)
                self.flag_action.setToolTip('Flag samples')
                self.flag_action.setCheckable(True)
                self._actions['flag'] = self.flag_action
                self.unflag_action = self.addAction(self._icon("unflag.png"),
                                                    'Unflag', self.unflag)
                self.unflag_action.setToolTip('Unflag samples')
                self.unflag_action.setCheckable(True)
                self._actions['unflag'] = self.unflag_action
                self.insert_action = self.addAction(self._icon("insert.png"),
                                                    'Insert', self.insert)
                self.insert_action.setToolTip('Insert samples')
                self.insert_action.setCheckable(True)
                self._actions['insert'] = self.insert_action
                self.addSeparator()
            elif text == 'Subplots':
                self.flagged_action = self.addAction(self._icon("flagged.png"),
                                                     'Flagged',
                                                     self.flagged_plot)
                self.flagged_action.setToolTip('Hide flagged')
                self.flagged_action.setCheckable(True)
                self.flagged_action.setChecked(True)
                self._actions['flagged'] = self.flagged_action
                self.grid_action = self.addAction(self._icon("plot_grid.png"),
                                                  'Grid', self.grid_plot)
                self.grid_action.setToolTip('Toggle grids')
                self.grid_action.setCheckable(True)
                self.grid_action.setChecked(True)
                self._actions['grid'] = self.grid_action
                self.legend_action = self.addAction(
                    self._icon("plot_legend.png"), 'Legend', self.legend_plot)
                self.legend_action.setToolTip('Toggle legends')
                self.legend_action.setCheckable(True)
                self.legend_action.setChecked(False)
                self._actions['legend'] = self.legend_action
                subplots_action = self.addAction(self._icon('subplots.png'),
                                                 'Subplots',
                                                 self.configure_subplots)
                subplots_action.setToolTip('Configure subplots')
                self._actions['subplots'] = subplots_action
                if figureoptions is not None:
                    a = self.addAction(self._icon("qt5_editor_options.png"),
                                       'Customize', self.edit_parameters)
                    a.setToolTip('Edit curves line and axes parameters')
            elif text == 'Save':
                self.addSeparator()
                save_action = self.addAction(self._icon('filesave.png'),
                                             'Save', self.save_figure)
                save_action.setToolTip('Save the figure')
                self._actions['save'] = save_action
            else:
                a = self.addAction(self._icon(image_file + '.png'), text,
                                   getattr(self, callback))
                self._actions[callback] = a
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)

        # Add the x,y location widget at the right side of the toolbar
        if self.coordinates:
            frame = QtWidgets.QFrame()
            # policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Ignored)
            # frame.setSizePolicy(policy)
            self.addWidget(frame)
            hbox = QtWidgets.QHBoxLayout()
            frame.setLayout(hbox)
            hbox.addStretch()
            vbox = QtWidgets.QVBoxLayout()
            hbox.addLayout(vbox)
            # - location label
            self.locLabel = QtWidgets.QLabel("", self)
            self.locLabel.setAlignment(QtCore.Qt.AlignRight
                                       | QtCore.Qt.AlignTop)
            vbox.addWidget(self.locLabel)
            # - insert label
            self.mon_label = QtWidgets.QLabel("", self)
            self.mon_label.setAlignment(QtCore.Qt.AlignRight
                                        | QtCore.Qt.AlignTop)
            self.mon_label.setStyleSheet("QLabel { color : red; }")
            vbox.addWidget(self.mon_label)
            # vbox.addStretch()
        # reference holder for subplots_adjust window
        self.adj_window = None
Esempio n. 6
0
 def __init__(self,gui,core,typ,res):
     self.gui,self.core= gui,core
     self.typ,self.res= typ,res
     QDialog.__init__(self,gui) 
     self.setModal(False)
     self.setWindowTitle('Plot of results')
     screenShape = QtWidgets.QDesktopWidget().screenGeometry()
     self.setGeometry(QRect(5, 5, screenShape.width()*.75, 
                            screenShape.height()*.7))
 ## main horizontal layout
     self.horizontalLayout = QHBoxLayout(self)
     self.horizontalLayout.setContentsMargins(10, 20, 10, 10)
 ## the left panel vertical layout  
     self.verticalLayout = QVBoxLayout()
     #self.verticalLayout.setGeometry(QRect(5, 5, 250, screenShape.height()*.68))
 ## title
     if self.typ == 'M' : title = 'Mass balance Graphs'
     if self.typ == 'Z' : title = 'Zone budget Graphs'
     label = str(title +' - '+self.res)
     self.label = QtWidgets.QLabel(self)
     self.label.setMaximumSize(250, 24)
     self.label.setText(label)
     font = QFont()
     font.setPointSize(9)
     font.setBold(True)
     self.label.setFont(font)
     self.verticalLayout.addWidget(self.label, alignment=Qt.AlignHCenter)
 ## model time list
     self.tlist = self.core.getTlist2()
 ## frame 1
     self.frame = QtWidgets.QFrame(self)
     self.frame.setMaximumSize(QtCore.QSize(250, 35)) 
     self.gl = QGridLayout(self.frame)
 ## Different type of graph
     self.label_1 = QtWidgets.QLabel(self.frame)
     self.label_1.setText("Type of graph")
     self.gl.addWidget(self.label_1,0,0,1,1)
     self.plgroup = QComboBox(self)
     self.plgroup.addItems(['Percent Discrepency','In-Out','Time Series',
                            'Time Step'])
     self.plgroup.setCurrentIndex(0)
     self.plgroup.activated['QString'].connect(self.onTstep)
     self.gl.addWidget(self.plgroup,0,1,1,1)
     self.verticalLayout.addWidget(self.frame)
 ## frame 2
     self.frame2 = QtWidgets.QFrame(self)
     self.frame2.setMaximumSize(QtCore.QSize(250,35)) 
     self.gl2 = QGridLayout(self.frame2)
 ## Time for time step graph
     self.label_2 = QtWidgets.QLabel(self.frame2)
     self.label_2.setText("Time")
     self.gl2.addWidget(self.label_2,0,0,1,1)
     self.Tstep = QComboBox(self.frame2)
     self.Tstep.addItems([str(n) for n in self.tlist])
     self.Tstep.setCurrentIndex(0)
     self.gl2.addWidget(self.Tstep,0,1,1,1)
     self.verticalLayout.addWidget(self.frame2) 
     self.frame2.hide()
 ## Choice of zone to perform budget
     if self.typ == 'Z':
 ## frame 3
         self.frame3 = QtWidgets.QFrame(self)
         self.frame3.setMaximumSize(QtCore.QSize(250, 35)) 
         self.gl3 = QGridLayout(self.frame3)
         self.lzname=self.core.diczone['Observation'].dic['obs.1']['name']
         self.label_3 = QtWidgets.QLabel(self.frame3)
         self.label_3.setText("Zone budget zone")
         self.gl3.addWidget(self.label_3,0,0,1,1)
         self.zgroup = QComboBox(self.frame3)
         self.zgroup.addItems([str(n) for n in self.lzname])
         self.zgroup.setCurrentIndex(0)
         self.gl3.addWidget(self.zgroup,0,1,1,1)
         self.zgroup.activated['QString'].connect(self.updateChoices)
         self.verticalLayout.addWidget(self.frame3) 
 ## the options :need to go in the interface to search for zones and others
     self.hlayout=QHBoxLayout()
     dic=self.getChoices() #self.res,self.typ
     self.nb = myNoteBookCheck(self.gui,"Options",dic)
     self.hlayout.addWidget(self.nb)
     self.nb.layout.removeWidget(self.nb.buttonBox) 
     self.nb.buttonBox.deleteLater()
     del self.nb.buttonBox
     self.verticalLayout.addLayout(self.hlayout)
     self.nb.apply()
 ## Apply button
     self.pushButton = QPushButton(self)
     self.pushButton.setText('Apply')
     self.verticalLayout.addWidget(self.pushButton, 
                                   alignment=Qt.AlignHCenter)
     self.pushButton.clicked.connect(self.buildGraph)
  ## add vertical layout   
     self.horizontalLayout.addLayout(self.verticalLayout)
  ## the right panel vertical layout
     self.verticalLayout2 = QVBoxLayout()
  ## the matplotlib figure 
     self.figure = Figure(tight_layout=True,figsize=(7.8, 3), dpi=100)  
     self.cnv = FigureCanvas(self.figure) 
     #self._ax = self.cnv.figure.subplots()#.add_axes([0.1, 0.15, 0.7, 0.8])
 ## add matplotlib figure
     #self.horizontalLayout.addWidget(self.cnv)
     self.verticalLayout2.addWidget(self.cnv)
     self.toolbar = NavigationToolbar(self.cnv, self) # EV 04/02/20 
     self.verticalLayout2.addWidget(self.toolbar, alignment=Qt.AlignHCenter) 
 ## Export button
     self.pushButton2 = QPushButton(self)
     self.pushButton2.setText('Export')
     self.verticalLayout2.addWidget(self.pushButton2, 
                                    alignment=Qt.AlignHCenter)
     #self.pushButton2.clicked.connect(self.onExport)
 ## add vertical layout 2
     self.horizontalLayout.addLayout(self.verticalLayout2)
     QMetaObject.connectSlotsByName(self)  #OA 1/6/19
Esempio n. 7
0
    def __init__(self, plot_callback=None):
        super(StyleBuilderMainWidget, self).__init__()
        self.setMinimumSize(600, 400)
        self.setLayout(QtWidgets.QVBoxLayout())

        self.top = QtWidgets.QWidget()
        self.top.setLayout( QtWidgets.QHBoxLayout() )
        self.layout().addWidget(self.top)

        self.top.layout().addWidget(QtWidgets.QLabel('Filter:'))
        self.filtration_field = QtWidgets.QLineEdit()
        self.top.layout().addWidget(self.filtration_field)
        self.filtration_field.textChanged.connect(self.filtration_changed)

        self.reset_all_button = QtWidgets.QPushButton('Reset all')
        self.top.layout().addWidget(self.reset_all_button)
        self.reset_all_button.clicked.connect(self.reset_all)

        self.show_changed_button = QtWidgets.QPushButton('Show changed')
        self.top.layout().addWidget(self.show_changed_button)
        self.show_changed_button.clicked.connect(
            lambda: self.display_list(sorted(self.changed))
        )

        self.mplstyle_combobox = QtWidgets.QComboBox()
        self.top.layout().addWidget(self.mplstyle_combobox)
        self.mplstyle_combobox.currentIndexChanged.connect(
            lambda _dummy: self.load_mplstyle(
                str(self.mplstyle_combobox.currentText())
            )
        )
        self.repopulate_stylelist()

        self.save_button = QtWidgets.QPushButton('Save new')
        self.top.layout().addWidget(self.save_button)
        self.save_button.clicked.connect(self.save_new_style)

        self.lower_frame = QtWidgets.QFrame()
        self.lower_frame.setLayout(QtWidgets.QHBoxLayout())
        self.layout().addWidget(self.lower_frame)

        self.tw = QtWidgets.QTreeWidget(self)
        self.tw.model().setHeaderData(0, QtCore.Qt.Horizontal, 'Category')
        self.tw.setMinimumWidth(100)
        self.lower_frame.layout().addWidget(self.tw, stretch=2)

        self.fig_widget = QtWidgets.QWidget()
        self.fig_widget.setMinimumSize(600, 400)
        self.fig_widget.setLayout(QtWidgets.QVBoxLayout())
        self.fig_widget.show()

        self.prop_frame = QtWidgets.QFrame()
        self.prop_frame.setLayout( QtWidgets.QVBoxLayout() )
        self.prop_frame.layout().addStretch()

        self.scroll_area = QtWidgets.QScrollArea()
        self.scroll_area.setWidget(self.prop_frame)
        self.scroll_area.setWidgetResizable(True)
        self.lower_frame.layout().addWidget(self.scroll_area, stretch=10)

        self.plot_callback = plot_callback
        self.prop_widgets = {}
        self.prevent_figure_update = False
        rc_yaml_path = os.path.join(os.path.dirname(__file__), 'rcParams.yaml')
        with open(rc_yaml_path) as fh:
            self.categorized_params = yaml.safe_load(fh)
        self.params = dict(chain.from_iterable(
            [subdict.items() for subdict in self.categorized_params.values()]
        ))
        self.currently_displayed = []
        self.changed = {}

        self.show()
Esempio n. 8
0
    def init_ui(self):
        self.win = QtWidgets.QWidget()
        self.win.setObjectName('window_widget')
        self.win.setStyleSheet("background-color:{};".format(BACKGROUND_COLOR))
        self.setGeometry(300, 300, 1224, 720)

        self.list_view = self.setup_list_view(self.model.item_model)
        logger.debug('Set up done: List view')

        self.marking_label = self.setup_marking_label()

        (
        self.fig,
        self.canvas,
        self.mpl_toolbar,
        ) = self.setup_figure()
        logger.debug('Set up done: Figure')
        (
        self.outline_view,
        self.detail_view,
        ) = self.setup_views(self.fig, self.model.items)
        logger.debug('Set up done: Views')
        self.setup_connections()
        logger.debug('Set up done: Connections')
        # Compose layout
        #
        # Left side
        self.frame_left = QtWidgets.QFrame()
        self.frame_left.setObjectName('frame_left')
        self.grid_left = QtWidgets.QGridLayout()
        self.grid_left.setSpacing(20)
        self.frame_left.setLayout(self.grid_left)
        self.grid_left.addWidget(self.marking_label, 0, 0, 2, 1)
        self.grid_left.addItem(
            QtWidgets.QSpacerItem(1,1),
            2, 0, 1, 1
        )
        self.help_item_model = QtGui.QStandardItemModel()
#         self.help_list = QListView()
        class CustListView(QtWidgets.QListView):
            def sizeHint(self, *args, **kwargs):
                return QtCore.QSize(100, 400)
        self.help_list = CustListView()
        self.help_list.setSizePolicy(
            QtWidgets.QSizePolicy.Preferred,
            QtWidgets.QSizePolicy.Preferred,
        )
        self.help_list.setModel(self.help_item_model)
        self.grid_left.addWidget(self.help_list, 2, 0, 1, 1)
        self.grid_left.addWidget(self.list_view, 4, 0, 4, 1)

        # Right side
        self.frame_right = QtWidgets.QFrame()
        self.frame_right.setObjectName('frame_right')
        self.frame_right.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.vbox_right = QtWidgets.QVBoxLayout()
        self.frame_right.setLayout(self.vbox_right)
        list(map(
            self.vbox_right.addWidget,
            [self.mpl_toolbar, self.canvas]
        ))

        # Vertical splitter
        self.vsplit = QtWidgets.QSplitter(self.win)
        self.vsplit.addWidget(self.frame_left)
        self.vsplit.addWidget(self.frame_right)
        self.vsplit.setStretchFactor(1, 2)

        self.hbox = QtWidgets.QHBoxLayout()
        self.hbox.addWidget(self.vsplit)
        self.win.setLayout(self.hbox)

#         self.grid = QGridLayout()
#         self.grid.setSpacing(10)
#         self.grid.addWidget(self.marking_label, 0, 0)
# #         self.grid.addWidget(self.list_view, 3, 0, 2, 1)
#         self.grid.addWidget(self.canvas, 1, 2, 4, 6)
#         self.grid.addWidget(self.mpl_toolbar, 0, 2, 1, 6)

#         self.win.setLayout(self.grid)
        self.setCentralWidget(self.win)
        self.setWindowTitle('Inspector')

        self.setup_menus_and_actions()

        self.setup_populate_help_list()

        self.statusBar().showMessage('Ready')
        self.show()
Esempio n. 9
0
    def __init__(self, gui, core, typ, res):
        self.gui, self.core = gui, core
        self.typ, self.res = typ, res
        QDialog.__init__(self, gui)  # OA 6/11/18 added gui (self,gui)
        self.setModal(False)
        self.setWindowTitle('Plot of results')
        screenShape = QtWidgets.QDesktopWidget().screenGeometry()
        self.setGeometry(
            QRect(5, 5,
                  screenShape.width() * .75,
                  screenShape.height() * .7))
        ## main horizontal layout
        self.horizontalLayout = QHBoxLayout(self)
        self.horizontalLayout.setContentsMargins(10, 20, 10, 10)
        ## the left panel vertical layout
        self.verticalLayout = QVBoxLayout()
        #self.verticalLayout.setGeometry(QRect(5,5,250,screenShape.height()*.68))
        ## title
        if self.typ == 'B': title = 'Time-series graph'
        if self.typ == 'P': title = 'Horizontal profile graph'
        if self.typ == 'V': title = 'Vertical profile graph'
        if self.typ == 'X': title = 'Calibration graph'
        label = str(title + ' - ' + self.res)
        self.label = QtWidgets.QLabel(self)
        self.label.setMaximumSize(250, 24)
        self.label.setText(label)
        font = QFont()
        font.setPointSize(9)
        font.setBold(True)
        self.label.setFont(font)
        self.verticalLayout.addWidget(self.label, alignment=Qt.AlignHCenter)
        ## model time list
        self.tlist = self.core.getTlist2()
        ## frame
        self.frame = QtWidgets.QFrame(self)
        self.frame.setMaximumSize(QtCore.QSize(250, 60))
        self.gl = QGridLayout(self.frame)
        ## type of result
        if self.res != 'W content':
            self.label_0 = QtWidgets.QLabel(self.frame)
            #self.label_0.setMaximumSize(QtCore.QSize(40, 20))
            self.label_0.setText("Type of result")
            self.gl.addWidget(self.label_0, 0, 0, 1, 1)
            self.rgroup = QComboBox(self)
            if self.res == 'Flow':  # EV 3/12/21
                mm, mval = self.core.dicaddin['usedM_Modflow']
                v1, v2 = mval[mm.index('UPW')], mval[mm.index('UZF')]
                mod = self.core.dicaddin['Model']['group']
                if (v1 == 2 or v2 == 2) and (mod == 'Modflow series'):
                    self.rgroup.addItems(['Head', 'W content'
                                          ])  #,'Flux']) #EV 02/03/20
                else:
                    self.rgroup.addItems(['Head'])
            if self.res in ['Transport', 'Chemistry']:
                self.rgroup.addItems([
                    'Concentration', 'Weighted concentration',
                    'Mass discharge', 'Mass Flux'
                ])
            self.rgroup.setCurrentIndex(0)
            self.gl.addWidget(self.rgroup, 0, 1, 1, 1)
    ## Plot order combo box for chemistry
        if self.res == 'Chemistry' and self.typ == 'B':
            self.label_1 = QtWidgets.QLabel(self.frame)
            #self.label_1.setMaximumSize(QtCore.QSize(40, 20))
            self.label_1.setText("Plot order")
            self.gl.addWidget(self.label_1, 1, 0, 1, 1)
            self.plgroup = QComboBox(self)
            self.plgroup.addItems(['By zone', 'By species'])
            self.plgroup.setCurrentIndex(0)
            self.gl.addWidget(self.plgroup, 1, 1, 1, 1)
            #!self.verticalLayout.addWidget(self.plgroup)
    ## Time combo box for profile and calibration graph
        if self.typ in ['P', 'V', 'X']:  #=='P' or self.typ=='X':
            #!self.frame = QtWidgets.QFrame(self)
            #!self.frame.setMaximumSize(QtCore.QSize(120, 38))
            #!self.horizontalLayout2 = QHBoxLayout(self.frame)
            #!self.horizontalLayout2.setContentsMargins(0, 0, 0, 0)
            #!self.horizontalLayout2.setSpacing(0)
            self.label_2 = QtWidgets.QLabel(self.frame)
            self.label_2.setMaximumSize(QtCore.QSize(40, 20))
            self.label_2.setText("Time")
            self.gl.addWidget(self.label_2, 1, 0, 1, 1)
            #!self.horizontalLayout2.addWidget(self.label_2)
            if self.typ == 'X':
                self.tlist = list(self.tlist)
                self.tlist.insert(0, 'All')
            self.Tstep = QComboBox(self.frame)
            self.Tstep.addItems([str(n) for n in self.tlist])
            self.Tstep.setCurrentIndex(0)
            self.gl.addWidget(self.Tstep, 1, 1, 1, 1)
            #!self.horizontalLayout2.addWidget(self.Tstep)
            #!self.verticalLayout.addWidget(self.frame)
        self.verticalLayout.addWidget(self.frame)
        ## choise plot obsData
        if self.typ == 'B':  # only for time series graphs for now (or typ=='P')
            self.checkBox = QCheckBox(self)
            self.checkBox.setText("Observed Data")
            self.verticalLayout.addWidget(self.checkBox)

    ## the options :need to go in the interface to search for zones and others
        dic = self.getChoices(self.res, self.typ)
        self.nb = myNoteBookCheck(self.gui, "Options", dic)
        self.nb.layout.removeWidget(self.nb.buttonBox)  #EV 06/12
        self.nb.buttonBox.deleteLater()
        del self.nb.buttonBox
        #self.nb.setGeometry(QRect(5, 5, 250,270))
        self.verticalLayout.addWidget(self.nb)
        self.nb.apply()
        ## Apply button
        self.pushButton = QPushButton(self)
        self.pushButton.setText('Apply')
        self.verticalLayout.addWidget(self.pushButton,
                                      alignment=Qt.AlignHCenter)
        self.pushButton.clicked.connect(self.buildPlot)
        ## add vertical layout
        self.horizontalLayout.addLayout(self.verticalLayout)
        ## the right panel vertical layout
        self.verticalLayout2 = QVBoxLayout()
        ## the matplotlib figure
        self.figure = Figure(tight_layout=True, figsize=(7.8, 3),
                             dpi=100)  # EV 04/02/20
        self.cnv = FigureCanvas(self.figure)
        #self._ax = self.cnv.figure.subplots()#.add_axes([0.1, 0.15, 0.7, 0.8])
        ## add matplotlib figure
        #self.horizontalLayout.addWidget(self.cnv)
        self.verticalLayout2.addWidget(self.cnv)
        self.toolbar = NavigationToolbar(self.cnv, self)  # EV 04/02/20
        self.verticalLayout2.addWidget(
            self.toolbar, alignment=Qt.AlignHCenter)  # EV 04/02/20
        ## Export button
        self.pushButton2 = QPushButton(self)
        self.pushButton2.setText('Export')
        self.verticalLayout2.addWidget(self.pushButton2,
                                       alignment=Qt.AlignHCenter)
        self.pushButton2.clicked.connect(self.onExport)
        ## add vertical layout 2
        self.horizontalLayout.addLayout(self.verticalLayout2)
        QMetaObject.connectSlotsByName(self)  #OA 1/6/19
Esempio n. 10
0
    def __init__(self):
        super().__init__()

        self.T = 60
        self.invertible_model = InvertibleModel(self.T)

        self._main = QtWidgets.QFrame(self)
        self.vertical_layout = QtWidgets.QVBoxLayout(self._main)
        self._main.setLayout(self.vertical_layout)
        self.setCentralWidget(self._main)

        self.toolbar = self.addToolBar('Toolbar')

        combo = QtWidgets.QComboBox(self)
        combo.addItem('Simple Example')
        combo.addItem('Complex Example 1')
        combo.addItem('Complex Example 2')
        combo.setCurrentIndex(0)
        combo.activated.connect(self.combo_activated)
        self.toolbar.addWidget(combo)

        compute_encode_action = QtWidgets.QAction('encode f(x) -> y,z', self)
        compute_encode_action.triggered.connect(self.compute_encode)
        self.toolbar.addAction(compute_encode_action)

        compute_decode_action = QtWidgets.QAction('decode f_inv(y,z) -> x',
                                                  self)
        compute_decode_action.triggered.connect(self.compute_decode)
        self.toolbar.addAction(compute_decode_action)

        denoise_action = QtWidgets.QAction('denoise [y, yz_pad, z]', self)
        denoise_action.triggered.connect(self.denoise)
        self.toolbar.addAction(denoise_action)

        # zero_yz_pad_action = QtWidgets.QAction('yz padding -> 0', self)
        # zero_yz_pad_action.triggered.connect(self.zero_yz_pad)
        # self.toolbar.addAction(zero_yz_pad_action)

        # confusing, leave out
        # label = 'yz padding -> N(0, {:>4.2g})'.format(self.invertible_model.model.zeros_noise_scale)
        # noise_yz_pad_action = QtWidgets.QAction(label, self)
        # noise_yz_pad_action.triggered.connect(self.noise_yz_pad)
        # self.toolbar.addAction(noise_yz_pad_action)

        gauss_z_action = QtWidgets.QAction('z -> N(0, 1)', self)
        gauss_z_action.triggered.connect(self.gauss_z)
        self.toolbar.addAction(gauss_z_action)

        self.ssim_label = QtWidgets.QLabel(
            'structural similarity(x, x_hat) = {:4.2g}'.format(0.9999), self)

        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                             QtWidgets.QSizePolicy.Expanding)
        self.toolbar.addWidget(spacer)
        self.toolbar.addWidget(self.ssim_label)

        # self.threshold_slider = QtWidgets.QSlider(Qt.Horizontal, self)
        # self.threshold_slider.setMinimum(0)
        # self.threshold_slider.setMaximum(500)
        # self.threshold_slider.setValue(50)
        # self.threshold_slider.valueChanged.connect(self.changeThreshold)
        # self.toolbar.addWidget(self.threshold_slider)

        # threshold_label = 'set all values < {:4.2g} to 0'.format(
        #     self.threshold_slider.value() / 100.
        # )
        # self.threshold_action = QtWidgets.QAction(threshold_label, self)
        # self.threshold_action.triggered.connect(self.threshold)
        # self.toolbar.addAction(self.threshold_action)

        # hide_editors_action = QtWidgets.QAction('Hide Editors', self)
        # hide_editors_action.triggered.connect(self.hide_editors)
        # self.toolbar.addAction(hide_editors_action)

        self.upper = QtWidgets.QFrame(self._main)
        self.lower_single = SingleEditorWidget(self._main)
        self.lower_single.setFixedHeight(170)
        self.lower_double = DoubleEditorWidget(self._main)
        self.lower_double.setFixedHeight(210)

        self.vertical_layout.addWidget(self.upper)
        self.vertical_layout.addWidget(self.lower_single)
        self.vertical_layout.addWidget(self.lower_double)

        upper_layout = QtWidgets.QHBoxLayout(self.upper)

        #####################################################
        # these calls need to stay in this order! otherwise
        # the event handlers registered in the figure
        # will be overwritten!

        # create a mpl figure
        self.figure = create_figure()

        # create the figurecanvas object
        self.canvas = FigureCanvas(self.figure)

        # plot into the figure
        # self.combo_activated(combo.currentIndex())
        filename, start = filenames_and_starts[combo.currentIndex()]

        x, x_frames, x_velocity = get_xy_from_file(
            filename + '.flac', filename + '.mid',
            self.invertible_model.audio_options)
        print('x.shape', x.shape)
        print('x_frames.shape', x_frames.shape)
        print('x_velocity.shape', x_velocity.shape)

        self.x_true = np.array(x[start:start + self.T])

        self.z_pred, self.yz_pad_pred, self.y_pred = self.invertible_model.encode(
            self.x_true)

        self.x_inv, self.x_inv_padding = self.invertible_model.decode(
            self.z_pred, self.yz_pad_pred, self.y_pred)

        #################################################################
        # test only

        # self.x_true = np.random.uniform(0, 1, (self.T, 256))

        # self.y_pred = np.random.uniform(0, 1, (self.T, 185))
        # self.z_pred = np.random.uniform(0, 1, (self.T, 9))
        # self.yz_pad_pred = np.random.uniform(0, 1, (self.T, 62))

        # self.x_inv = np.random.uniform(0, 1, (self.T, 256))
        #################################################################
        print('self.x_true.shape', self.x_true.shape)
        print('self.y_pred.shape', self.y_pred.shape)
        print('self.yz_pad_pred.shape', self.yz_pad_pred.shape)
        print('self.z_pred.shape', self.z_pred.shape)
        print('self.x_inv.shape', self.x_inv.shape)
        print('self.x_inv_padding.shape', self.x_inv_padding.shape)

        self.all_plots = AllPlots(fig=self.figure,
                                  x_true=self.x_true.view(),
                                  y_pred=self.y_pred.view(),
                                  z_pred=self.z_pred.view(),
                                  yz_pad_pred=self.yz_pad_pred.view(),
                                  x_inv=self.x_inv.view())

        upper_layout.addWidget(self.canvas)

        # connect the signals to slots
        self.all_plots.ipo_y_instrument.do_select.connect(self.select)
        self.all_plots.ipo_y_phase.do_select.connect(self.select_pv)
        self.all_plots.ipo_y_velocity.do_select.connect(self.select_pv)
        self.all_plots.ipo_z.do_select.connect(self.select)
        self.all_plots.ipo_yz_pad_pred.do_select.connect(self.select)
        ######################################################

        self.selected_y = 8
        self.selected_ipo = self.all_plots.ipo_y_instrument
        self.select(self.selected_ipo, self.selected_y)
        self.lower_single.show()
        self.lower_double.hide()
        self.upper.setFocus()