def _plot(self): """ Network performance graph """ setConfigOption('background', '#FF000000') _graph = PlotWidget() _graph.setMenuEnabled(enableMenu=False) _graph.setMouseEnabled(x=False, y=False) _graph.hideButtons() self._out_curve = _graph.getPlotItem().plot() self._inc_curve = _graph.getPlotItem().plot() self._legend = LegendItem(offset=(50, 10)) self._legend.setParentItem(_graph.getPlotItem()) self._legend.addItem(self._out_curve, self._lang.NetworkGraphOutgoing) self._legend.addItem(self._inc_curve, self._lang.NetworkGraphIncoming) self._base.net_perf_lyt.addWidget(_graph) self._menu_popup = QMenu() _action = QAction(QIcon('icon/reload.png'), self._lang.PopupReload, self._base.net_perf_box) _action.triggered.connect(self.reload) self._menu_popup.addAction(_action) self._base.net_perf_box.setContextMenuPolicy(Qt.CustomContextMenu) self._base.net_perf_box.customContextMenuRequested.connect( self._popup_show)
class Ui_plotWindow(object): def setupUi(self, plotWindow): plotWindow.setObjectName(_fromUtf8("plotWindow")) plotWindow.resize(540, 350) plotWindow.setMaximumSize(QtCore.QSize(16777215, 16777215)) self.gridLayout = QtGui.QGridLayout(plotWindow) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.graphicsView = PlotWidget(plotWindow) self.graphicsView.hideButtons() self.graphicsView.showGrid(True, True) self.graphicsView.setMenuEnabled(False) self.graphicsView.setMouseEnabled(False, False) self.graphicsView.setFrameShadow(QtGui.QFrame.Plain) self.graphicsView.setFrameShape(QtGui.QFrame.StyledPanel) self.graphicsView.setObjectName(_fromUtf8("graphicsView")) self.gridLayout.addWidget(self.graphicsView, 0, 1, 1, 1) self.treeWidget = QtGui.QTreeWidget(plotWindow) self.treeWidget.setMaximumSize(QtCore.QSize(200, 16777215)) self.treeWidget.setHorizontalScrollBarPolicy( QtCore.Qt.ScrollBarAlwaysOff) self.treeWidget.setRootIsDecorated(False) self.treeWidget.setItemsExpandable(False) self.treeWidget.setExpandsOnDoubleClick(False) self.treeWidget.setColumnCount(3) self.treeWidget.setObjectName(_fromUtf8("treeWidget")) self.treeWidget.header().setVisible(True) self.treeWidget.header().setDefaultSectionSize(80) self.gridLayout.addWidget(self.treeWidget, 0, 0, 1, 1) self.retranslateUi(plotWindow) QtCore.QMetaObject.connectSlotsByName(plotWindow) def retranslateUi(self, plotWindow): plotWindow.setWindowTitle( QtGui.QApplication.translate("plotWindow", "Form", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.headerItem().setText( 0, QtGui.QApplication.translate("plotWindow", "Legend", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.headerItem().setText( 1, QtGui.QApplication.translate("plotWindow", "Name", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.headerItem().setText( 2, QtGui.QApplication.translate("plotWindow", "Value", None, QtGui.QApplication.UnicodeUTF8))
class Ui_plotWindow(object): def setupUi(self, plotWindow): plotWindow.setObjectName(_fromUtf8("plotWindow")) plotWindow.resize(540, 350) plotWindow.setMaximumSize(QtCore.QSize(16777215, 16777215)) self.gridLayout = QtGui.QGridLayout(plotWindow) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.graphicsView = PlotWidget(plotWindow) self.graphicsView.hideButtons() self.graphicsView.showGrid(True, True) self.graphicsView.setMenuEnabled(False) self.graphicsView.setMouseEnabled(False, False) self.graphicsView.setFrameShadow(QtGui.QFrame.Plain) self.graphicsView.setFrameShape(QtGui.QFrame.StyledPanel) self.graphicsView.setObjectName(_fromUtf8("graphicsView")) self.gridLayout.addWidget(self.graphicsView, 0, 1, 1, 1) self.treeWidget = QtGui.QTreeWidget(plotWindow) self.treeWidget.setMaximumSize(QtCore.QSize(200, 16777215)) self.treeWidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.treeWidget.setRootIsDecorated(False) self.treeWidget.setItemsExpandable(False) self.treeWidget.setExpandsOnDoubleClick(False) self.treeWidget.setColumnCount(3) self.treeWidget.setObjectName(_fromUtf8("treeWidget")) self.treeWidget.header().setVisible(True) self.treeWidget.header().setDefaultSectionSize(80) self.gridLayout.addWidget(self.treeWidget, 0, 0, 1, 1) self.retranslateUi(plotWindow) QtCore.QMetaObject.connectSlotsByName(plotWindow) def retranslateUi(self, plotWindow): plotWindow.setWindowTitle(QtGui.QApplication.translate("plotWindow", "Form", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.headerItem().setText(0, QtGui.QApplication.translate("plotWindow", "Legend", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.headerItem().setText(1, QtGui.QApplication.translate("plotWindow", "Name", None, QtGui.QApplication.UnicodeUTF8)) self.treeWidget.headerItem().setText(2, QtGui.QApplication.translate("plotWindow", "Value", None, QtGui.QApplication.UnicodeUTF8))
def __init__(self, atri_plot: PlotWidget, vent_plot: PlotWidget, data_size: int): print("Graphs handler init") # noinspection PyArgumentList atri_plot.setRange(xRange=[-1, data_size], yRange=[-0.5, 5.5], padding=0) atri_plot.setLimits(xMin=-1, xMax=data_size, maxXRange=data_size + 1, yMin=-0.5, yMax=5.5) atri_plot.setMouseEnabled(x=True, y=False) atri_plot.enableAutoRange(x=False, y=True) atri_plot.setAutoVisible(x=False, y=True) atri_plot.showGrid(x=True, y=True) atri_plot.hideButtons() atri_plot.setMenuEnabled(False) atri_plot.setLabel('left', "Amplitude", units='V', **{'color': '#FFF', 'font-size': '10pt'}) atri_plot.setLabel('bottom', "Time", units='s', **{'color': '#FFF', 'font-size': '10pt'}) atri_plot.getAxis('bottom').setHeight(30) # noinspection PyArgumentList vent_plot.setRange(xRange=[-1, data_size], yRange=[-0.5, 5.5], padding=0) vent_plot.setLimits(xMin=-1, xMax=data_size, maxXRange=data_size + 1, yMin=-0.5, yMax=5.5) vent_plot.setMouseEnabled(x=True, y=False) vent_plot.enableAutoRange(x=False, y=True) vent_plot.setAutoVisible(x=False, y=True) vent_plot.showGrid(x=True, y=True) vent_plot.hideButtons() vent_plot.setMenuEnabled(False) vent_plot.setLabel('left', "Amplitude", units='V', **{'color': '#FFF', 'font-size': '10pt'}) vent_plot.setLabel('bottom', "Time", units='s', **{'color': '#FFF', 'font-size': '10pt'}) vent_plot.getAxis('bottom').setHeight(30) # Initialize graphs to 0 self._atri_data = np.zeros(data_size) self._vent_data = np.zeros(data_size) # Create new sense plots for the atrial and ventricular graphs, in blue self._atri_plot = atri_plot.plot(pen=(0, 229, 255)) self._vent_plot = vent_plot.plot(pen=(0, 229, 255)) self._plot_data()
class widget_mfi_lon_plot(QWidget): #----------------------------------------------------------------------- # DEFINE THE INITIALIZATION FUNCTION. #----------------------------------------------------------------------- def __init__(self, core): # Inherit all attributes of an instance of "QWidget". super(widget_mfi_lon_plot, self).__init__() # Store the Janus core. self.core = core # Prepare to respond to signals received from the core. self.connect(self.core, SIGNAL('janus_rset'), self.resp_rset) self.connect(self.core, SIGNAL('janus_chng_mfi'), self.resp_chng_mfi) # Initialize this widget's instance of "PlotWidget", which will # contain the plot of MFI magnetic field data. # Note. The "QGridLayout" object given to this widget as its # layout is essentially a dummy. I could have just had # this class inherit "PlotWidget", but I think that this # gives me a bit more control (and a similar structure # "janus_widget_fc_cup"). self.setLayout(QGridLayout()) self.plt = PlotWidget() self.layout().addWidget(self.plt) self.layout().setContentsMargins(0, 0, 0, 0) # Extract the individual elements of the "PlotWidget" object # (e.g., it's axes) for more convenient access later. self.vbx = self.plt.getViewBox() self.axs_x = self.plt.getAxis('bottom') self.axs_y = self.plt.getAxis('left') self.ptm = self.plt.getPlotItem() # Initialize and store the pens and fonts. self.pen_vbx = mkPen(color='k') self.pen_crv_lon = mkPen(color='#FFD700') self.fnt = self.core.app.font() # Configure the plot: disable automatic adjustments and # adjustments made by the user, change the background and # foreground colors, enable grid lines for both axes, label the # axes, adjust the tick font size, adjust the "AxisItem" sizes, # and add a margin around the entire plot. self.plt.disableAutoRange() self.plt.setMouseEnabled(False, False) self.plt.setMenuEnabled(False) self.plt.hideButtons() self.plt.setBackground('w') setConfigOption('foreground', 'k') #####self.plt.showGrid( True, True ) labelStyle = {'color': 'k'} self.axs_x.setLabel('Time [s]', **labelStyle) self.axs_y.setLabel('Azim. [deg]', **labelStyle) self.axs_x.label.setFont(self.fnt) self.axs_y.label.setFont(self.fnt) self.axs_x.setTickFont(self.fnt) self.axs_y.setTickFont(self.fnt) self.axs_x.setHeight(35) self.axs_y.setWidth(40) self.vbx.border = self.pen_vbx self.ptm.setContentsMargins(5, 5, 5, 5) # Initialize the curves that will be added to this plot. self.crv_lon = None # Populate this plot and adjust it's settings. self.make_plt() #----------------------------------------------------------------------- # DEFINE THE FUNCTION FOR POPULATING THE PLOT. #----------------------------------------------------------------------- def make_plt(self): # Reset the plot (i.e., remove all plot elements). self.rset_plt() # Establish the ranges of its time and magnetic field values. # If the core contains no data or only a single datum, # improvise (for the purpose of later establishing axis limits). if (self.core.n_mfi >= 1): # Establish the domain of the plot. t_min = min(amin(self.core.mfi_s), 0.) t_max = max(amax(self.core.mfi_s), self.core.fc_spec['dur']) # Establish the range of the plot. As part of this, # ensure that the range satisfies a minimum size and has # sufficient padding. ang_max = max(self.core.mfi_b_lon) ang_min = min(self.core.mfi_b_lon) ang_max = 5. + ang_max ang_min = -5. + ang_min d_t_0 = t_max - t_min d_t = max(1.5 + d_t_0, 3.) t_max = t_min + d_t else: t_min = 0.001 t_max = 3.500 ang_min = -360 ang_max = 360 # Set the range of the axis of each plot. self.plt.setXRange(t_min, t_max, padding=0.0) self.plt.setYRange(ang_min, ang_max, padding=0.0) # If the core contains no Wind/MFI magnetic field data, return. if (self.core.n_mfi <= 0): return # Generate and display each curve for the plot. self.crv_lon = PlotDataItem(self.core.mfi_s, self.core.mfi_b_lon, pen=self.pen_crv_lon) self.plt.addItem(self.crv_lon) #----------------------------------------------------------------------- # DEFINE THE FUNCTION FOR RESETTING THIS PLOT (CLEARING ALL ELEMENTS). #----------------------------------------------------------------------- def rset_plt(self): # Hide and remove each of this plot's elements. if (self.crv_lon is not None): self.plt.removeItem(self.crv_lon) # Permanently delete this plot's elements by setting each of the # variables that store them to "None". self.crv_lon = None #----------------------------------------------------------------------- # DEFINE THE FUNCTION FOR RESPONDING TO THE "rset" SIGNAL. #----------------------------------------------------------------------- def resp_rset(self): # Reset the plot. self.rset_plt() #----------------------------------------------------------------------- # DEFINE THE FUNCTION FOR RESPONDING TO THE "chng_mfi" SIGNAL. #----------------------------------------------------------------------- def resp_chng_mfi(self): # Regenerate the plot. self.make_plt()
class widget_mfi_lin_plot(QWidget): #----------------------------------------------------------------------- # DEFINE THE INITIALIZATION FUNCTION. #----------------------------------------------------------------------- def __init__(self, core): # Inherit all attributes of an instance of "QWidget". super(widget_mfi_lin_plot, self).__init__() # Store the Janus core. self.core = core # Prepare to respond to signals received from the core. self.connect(self.core, SIGNAL('janus_rset'), self.resp_rset) self.connect(self.core, SIGNAL('janus_chng_mfi'), self.resp_chng_mfi) # Initialize this widget's instance of "PlotWidget", which will # contain the plot of MFI magnetic field data. # Note. The "QGridLayout" object given to this widget as its # layout is essentially a dummy. I could have just had # this class inherit "PlotWidget", but I think that this # gives me a bit more control (and a similar structure # "janus_widget_fc_cup"). self.setLayout(QGridLayout()) self.plt = PlotWidget() self.layout().addWidget(self.plt) self.layout().setContentsMargins(0, 0, 0, 0) # Extract the individual elements of the "PlotWidget" object # (e.g., it's axes) for more convenient access later. self.vbx = self.plt.getViewBox() self.axs_x = self.plt.getAxis('bottom') self.axs_y = self.plt.getAxis('left') self.ptm = self.plt.getPlotItem() # Initialize and store the pens and fonts. self.pen_vbx = mkPen(color='k') self.pen_crv_m = mkPen(color='k') self.pen_crv_n = mkPen(color='k') self.pen_crv_x = mkPen(color='r') self.pen_crv_y = mkPen(color='g') self.pen_crv_z = mkPen(color='b') self.fnt = self.core.app.font() # Configure the plot: disable automatic adjustments and # adjustments made by the user, change the background and # foreground colors, enable grid lines for both axes, label the # axes, adjust the tick font size, adjust the "AxisItem" sizes, # and add a margin around the entire plot. self.plt.disableAutoRange() self.plt.setMouseEnabled(False, False) self.plt.setMenuEnabled(False) self.plt.hideButtons() self.plt.setBackground('w') setConfigOption('foreground', 'k') #####self.plt.showGrid( True, True ) labelStyle = {'color': 'k'} self.axs_x.setLabel('Time [s]', **labelStyle) self.axs_y.setLabel('Magnetic Field [nT]', **labelStyle) self.axs_x.label.setFont(self.fnt) self.axs_y.label.setFont(self.fnt) self.axs_x.setTickFont(self.fnt) self.axs_y.setTickFont(self.fnt) self.axs_x.setHeight(35) self.axs_y.setWidth(40) self.vbx.border = self.pen_vbx self.ptm.setContentsMargins(5, 5, 5, 5) # Initialize the curves that will be added to this plot. self.crv_m = None self.crv_n = None self.crv_x = None self.crv_y = None self.crv_z = None self.pl = [] # Populate this plot and adjust it's settings. self.make_plt() #----------------------------------------------------------------------- # DEFINE THE FUNCTION FOR POPULATING THE PLOT. #----------------------------------------------------------------------- def make_plt(self): # Reset the plot (i.e., remove all plot elements). self.rset_plt() # Establish the ranges of its time and magnetic field values. # If the core contains no data or only a single datum, # improvise (for the purpose of later establishing axis limits). if (self.core.n_mfi >= 1): # Establish the domain of the plot. t_min = min(amin(self.core.mfi_s), 0.) t_max = max(amax(self.core.mfi_s), self.core.fc_spec['dur']) # Establish the range of the plot. As part of this, # ensure that the range satisfies a minimum size and has # sufficient padding. b_max = amax(self.core.mfi_b) b_min = -b_max d_t_0 = t_max - t_min d_b_0 = b_max - b_min d_t = max(1.5 + d_t_0, 3.) d_b = max(1.2 * d_b_0, 5.) t_max = t_min + d_t b_min = b_min - (d_b - d_b_0) / 2. b_max = b_max + (d_b - d_b_0) / 2. else: t_min = 0.001 t_max = 3.500 b_min = -2.5 b_max = 2.5 # Set the range of the axis of each plot. self.plt.setXRange(t_min, t_max, padding=0.0) self.plt.setYRange(b_min, b_max, padding=0.0) # Set the PESA-L pen with a width corresponding to one rotation # Note: For some reason, the lines are not wide enough unless 5 # is added to the scaled width of the rotation time rot = 3.05 * self.axs_x.width() / (t_max - t_min) + 5 self.pen_pl = mkPen(color=(245, 245, 245), width=rot) # If the core contains no Wind/MFI magnetic field data, return. if (self.core.n_mfi <= 0): return # Generate and display each curve for the plot. self.crv_m = PlotDataItem(self.core.mfi_s, self.core.mfi_b, pen=self.pen_crv_m) self.crv_n = PlotDataItem(self.core.mfi_s, [-b for b in self.core.mfi_b], pen=self.pen_crv_n) self.crv_x = PlotDataItem(self.core.mfi_s, self.core.mfi_b_x, pen=self.pen_crv_x) self.crv_y = PlotDataItem(self.core.mfi_s, self.core.mfi_b_y, pen=self.pen_crv_y) self.crv_z = PlotDataItem(self.core.mfi_s, self.core.mfi_b_z, pen=self.pen_crv_z) # If PESA-L spectra were loaded, add the vertical indicators # showing their time relative to the start of the FC spectrum for n in range(len(self.core.pl_spec_arr)): time = self.core.pl_spec_arr[n]['time'][0] t_0 = self.core.fc_spec['time'] delta_t = (time - t_0).total_seconds() self.pl += [ InfiniteLine(delta_t + self.core.fc_spec['rot'] / 2., pen=self.pen_pl) ] for i in range(len(self.pl)): self.plt.addItem(self.pl[i]) self.plt.addItem(self.crv_m) self.plt.addItem(self.crv_n) self.plt.addItem(self.crv_x) self.plt.addItem(self.crv_y) self.plt.addItem(self.crv_z) #----------------------------------------------------------------------- # DEFINE THE FUNCTION FOR RESETTING THIS PLOT (CLEARING ALL ELEMENTS). #----------------------------------------------------------------------- def rset_plt(self): # Hide and remove each of this plot's elements. if (self.crv_m is not None): self.plt.removeItem(self.crv_m) if (self.crv_n is not None): self.plt.removeItem(self.crv_n) if (self.crv_x is not None): self.plt.removeItem(self.crv_x) if (self.crv_y is not None): self.plt.removeItem(self.crv_y) if (self.crv_z is not None): self.plt.removeItem(self.crv_z) if (self.pl != []): for i in range(len(self.pl)): self.plt.removeItem(self.pl[i]) # if ( self.crv_colat is not None ) : # self.plt.removeItem( self.crv_colat ) # if ( self.crv_lon is not None ) : # self.plt.removeItem( self.crv_lon ) # Permanently delete this plot's elements by setting each of the # variables that store them to "None". self.crv_m = None self.crv_n = None self.crv_x = None self.crv_y = None self.crv_z = None self.pl = [] #----------------------------------------------------------------------- # DEFINE THE FUNCTION FOR RESPONDING TO THE "rset" SIGNAL. #----------------------------------------------------------------------- def resp_rset(self): # Reset the plot. self.rset_plt() #----------------------------------------------------------------------- # DEFINE THE FUNCTION FOR RESPONDING TO THE "chng_mfi" SIGNAL. #----------------------------------------------------------------------- def resp_chng_mfi(self): # Regenerate the plot. self.make_plt()
def __init__(self, main_loop): # noinspection PyArgumentList super(ProgramUI, self).__init__() uic.loadUi("ui/USBIPManager.ui", self) self.show() # Setting application icon self.setWindowIcon(QIcon("icon/logo.png")) # Application main loop self.main_loop = main_loop # Getting the configuration from config.ini file self.config = config.get_config() self.cancel_process = CancelProcessButton( self.frameGeometry().width(), self.frameGeometry().height()) self.cancel_process.setParent(None) # Setting actions for main menu buttons self.auto_find_button.clicked.connect( partial(ApplicationMenu.auto_find, self)) self.add_server_button.clicked.connect( partial(ApplicationMenu.add_server, self)) self.search_all_button.clicked.connect( partial(ApplicationMenu.search_all, self)) self.connect_all_button.clicked.connect( partial(ApplicationMenu.connect_all, self)) self.disconnect_all_button.clicked.connect( partial(ApplicationMenu.disconnect_all, self, config.usbip_array)) self.settings_button.clicked.connect( partial(ApplicationMenu.settings, self)) # self.log.setContextMenuPolicy(Qt.CustomContextMenu) self.log.customContextMenuRequested.connect(self.log_context_menu) # Setting context menu for the server list box self.server_box.setContextMenuPolicy(Qt.CustomContextMenu) self.server_box.customContextMenuRequested.connect( partial(SRVArea.box_context_menu, self)) # Setting default context menu for the connected device tree box self.device_tree_menu = dict() self.device_tree_menu["menu"] = QMenu() self.device_tree_menu["action"] = dict() # Enabling data capture context action self.device_tree_menu["action"]["enable"] = \ QAction(QIcon("icon/enable.png"), _("Enable data capturing"), self) self.device_tree_menu["action"]["enable"].setEnabled(False) # Resetting data capture context action self.device_tree_menu["action"]["reset"] = \ QAction(QIcon("icon/reset.png"), _("Reset data capturing"), self) self.device_tree_menu["action"]["reset"].setEnabled(False) # Disabling data capture context action self.device_tree_menu["action"]["disable"] = \ QAction(QIcon("icon/disable.png"), _("Disable data capturing"), self) self.device_tree_menu["action"]["disable"].setEnabled(False) # self.device_box.setContextMenuPolicy(Qt.CustomContextMenu) self.device_box.customContextMenuRequested.connect( partial(DevTreeMenu.box_context_menu, self)) # Setting activity plot setConfigOption("background", "#FF000000") activity_graph = PlotWidget() activity_graph.setMenuEnabled(enableMenu=False) activity_graph.setMouseEnabled(x=False, y=False) activity_graph.showGrid(x=True, y=True) activity_graph.hideButtons() # Defining sent and received activity curves self.sent_curve = activity_graph.getPlotItem().plot() self.recv_curve = activity_graph.getPlotItem().plot() # Setting activity box layout and adding activity plot to the program window activity_layout = QGridLayout() self.activity_box.setLayout(activity_layout) activity_layout.addWidget(activity_graph) self.activity_box.setContextMenuPolicy(Qt.CustomContextMenu) self.activity_box.customContextMenuRequested.connect( partial(NetworkActivity.box_context_menu, self)) # Getting the configuration and filling the server list with the found servers SRVArea.srv_get(self) # Starting checking servers availability process self.srv_checking = self.main_loop.create_task( SRVArea.async_srv_check(self)) # Starting checking software cpu and memory usage process self.usage_checking = self.main_loop.create_task(async_sw_usage(self)) # Starting checking network activity process self.activity_checking = self.main_loop.create_task( NetworkActivity.async_get_activity(self)) if config.watchdog_enable: # Setting watchdog event handler as PyQt Object signal event_handler = ConfigWatchdog() event_handler.fileUpdated.connect(self.config_change_action) # Starting observer thread that schedules file watching and dispatches calls to event handler observer = Observer() observer.schedule(event_handler, path=path.dirname(path.abspath(__file__)), recursive=False) observer.start()