123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- # -*- coding: utf-8 -*-
- from PyQt4 import QtGui, QtCore
- import kcgwidget as kcgw
- from callbacks import callbacks
- from plotWidget import PlotWidget
- from backend.board import available_boards
- from backend import io
- import storage
- from ..widgets import acquiresettings as acqs
- from groupedelements import Elements
- import backendinterface as bif
- import log
- tr = kcgw.tr
- from .. import config
- LIVE = 1
- FILE = 2
- class BoardSpecificInformation(kcgw.KCGWidgets):
- """
- Specific Part for each board
- """
- def __init__(self, board_id):
- """
- This creates the information part for board with id board_id.
- This is used to be able to create a variable number of board information areas.
- :param board_id: the id of the board
- """
- super(BoardSpecificInformation, self).__init__()
- self.temperature = self.createLabel(tr("Label", "Temp:"))
- def update_temp():
- '''update the temperature in the gui'''
- if bif.bk_get_board_status(board_id, 'board_connected'):
- self.temperature.setText("Temp: " + bif.bk_get_temperature(board_id) + u" °C")
- try:
- update_temp()
- except Exception: # TODO: Find correct exception to catch
- print "cannot get temperature"
- self.timer = QtCore.QTimer()
- self.timer.timeout.connect(update_temp)
- self.timer.start(30000)
- self.skipturns = self.createLabel(
- tr("Label", "O_skip:") + " " + str(bif.bk_get_config(board_id, 'orbits_skip')),
- tooltip=tr("Tooltip", "Skipped orbits\nKlick to open acquire settings"),
- click=True,
- connect=lambda: acqs.add_acquire_settings_widget(board_id=board_id)
- )
- bif.bk_get_board_config(board_id).observe(self.skipturns,
- lambda x: self.skipturns.setText(tr("Label", "O_skip:")+" "+str(x)),
- 'orbits_skip')
- self.orbitsobserved = self.createLabel(
- tr("Label", "O_obs:") + " " + str(bif.bk_get_config(board_id, 'orbits_observe')),
- tooltip=tr("Tooltip", "Number of observed Orbits\nKlick to open acquire settings"),
- click=True,
- connect=lambda: acqs.add_acquire_settings_widget(board_id=board_id)
- )
- bif.bk_get_board_config(board_id).observe(
- self.orbitsobserved,
- lambda x: self.orbitsobserved.setText(tr("Label", "O_obs:") + " " + str(x)), 'orbits_observe')
- self.orbitscount = self.createLabel(
- tr("Label", "Count:") + " " + str(bif.bk_get_config(board_id, 'acquisition_count')),
- tooltip=tr("Tooltip", "Number of acquisitions\nKlick to open acquire settings"),
- click=True,
- connect=lambda: acqs.add_acquire_settings_widget(board_id=board_id)
- )
- bif.bk_get_board_config(board_id).observe(
- self.orbitscount,
- lambda x: self.orbitscount.setText(tr("Label", "Count:") + " " + str(x)), 'acquisition_count')
- self.orbitswait = self.createLabel(
- tr("Label", "T_wait:") + " " + str(bif.bk_get_config(board_id, 'orbits_wait_time')),
- tooltip=tr("Tooltip", "Time in seconds to wait between acquisitions\nKlick to open acquire settings"),
- click=True,
- connect=lambda: acqs.add_acquire_settings_widget(board_id=board_id)
- )
- bif.bk_get_board_config(board_id).observe(
- self.orbitswait,
- lambda x: self.orbitswait.setText(tr("Label", "T_wait:") + " " + str(x)), 'orbits_wait_time')
- self.boardSpecificLayout = QtGui.QVBoxLayout()
- self.setLayout(self.boardSpecificLayout)
- self.layout = QtGui.QGridLayout()
- self.layout.addWidget(self.temperature, 0, 0)
- self.layout.addWidget(self.skipturns, 1, 1)
- self.layout.addWidget(self.orbitsobserved, 1, 0)
- self.layout.addWidget(self.orbitscount, 2, 0)
- self.layout.addWidget(self.orbitswait, 2, 1)
- self.boardSpecificLayout.addLayout(self.layout)
- class AcquisitionAndInfo(kcgw.KCGWidgets):
- """
- Widget to show below the plot list.
- Show certain information.
- Provide Start Acquisition button and settings.
- """
- # consistency_updated = QtCore.pyqtSignal(bool)
- # acquisition_started_signal = QtCore.pyqtSignal(int)
- def __init__(self):
- super(AcquisitionAndInfo, self).__init__()
- self.layout = QtGui.QVBoxLayout()
- self.layout.setContentsMargins(0, 0, 0, 0)
- self.setLayout(self.layout)
- if available_boards.multi_board:
- self.scroll_area = QtGui.QScrollArea()
- self.layout.addWidget(self.scroll_area)
- self.information_box = kcgw.AccordionWidget()
- for brd in available_boards.board_ids:
- self.information_box.addItem(BoardSpecificInformation(brd),
- available_boards.get_board_name_from_id(brd))
- self.scroll_area.setWidget(self.information_box)
- self.scroll_area.setWidgetResizable(True)
- self.information_box.hideAll()
- self.information_box.expandIndex(0)
- else:
- self.layout.addWidget(BoardSpecificInformation(available_boards.board_ids[0]))
- # -----[ Constistency ]-----------
- self.consistency = QtGui.QHBoxLayout()
- self.layout.addLayout(self.consistency)
- self.consistency_label = self.createLabel("Consistency:")
- self.consistency_content = self.createLabel(u"●")
- self.consistency_content.setStyleSheet("color: lightgrey;")
- self.consistency.addWidget(self.consistency_label)
- self.consistency.addWidget(self.consistency_content)
- # -------[ acquire ]--------------
- self.acquire = self.createButton(tr("Button", "Start Acquisition"),
- icon=QtGui.QIcon(config.install_path + config.startIcon),
- connect=self.toggle_acquisition)
- if not available_boards.multi_board:
- Elements.addItem('acquireTrigger_{}'.format(available_boards.board_ids[0]), self.acquire)
- if available_boards.multi_board:
- self.list_to_acquire = {
- i: self.createCheckbox(
- str(i),
- tooltip=str(tr("Tooltip",
- "Check this checkbox if you want to acquire with board {board}")
- ). format(board=i),
- connect=self.update_acq_tickboxes) for i in available_boards}
- self.list_of_active_boards = {i: False for i in available_boards}
- self.acq_list_layout = QtGui.QHBoxLayout()
- for b_id, cb in self.list_to_acquire.iteritems():
- self.acq_list_layout.addWidget(cb)
- Elements.addItem('acquireTrigger_{}'.format(b_id), cb)
- self.acquisition_stopped(b_id)
- # -----[ log ]-------
- self.log = self.createButton(tr("Button", "Log"),
- icon=QtGui.QIcon(config.install_path + config.logIcon),
- connect=lambda: log.log(additional="Manual Log"),
- tooltip="Rightclick to Configure")
- self.log_w_comment = self.createButton(tr("Button", "Log"),
- icon=QtGui.QIcon(config.install_path + config.logCommentIcon),
- connect=self.do_log_w_comment,
- tooltip="Log with Comment\nRightclick to Configure")
- self.log.contextMenuEvent = self.log_configure_context_menu
- self.log_w_comment.contextMenuEvent = self.log_configure_context_menu
- # self.layout.addLayout(self.consistency, 0, 0) # TODO: für welches board? zum board???
- if available_boards.multi_board:
- self.layout.addLayout(self.acq_list_layout)
- self.layout.addWidget(self.acquire)
- self.logLayout = QtGui.QHBoxLayout()
- self.logLayout.addWidget(self.log)
- self.logLayout.addWidget(self.log_w_comment)
- self.layout.addLayout(self.logLayout)
- callbacks.add_callback('update_consistency', self.update_consistency)
- callbacks.add_callback('acquisition_started', self.acquisition_started)
- callbacks.add_callback('acquisition_stopped', self.acquisition_stopped)
- def toggle_acquisition(self):
- """
- Turn acquisition on/off. This gets the information about which board to use by checking state of the checkboxes.
- :return:
- """
- if not available_boards.multi_board:
- bif.bk_acquire(available_boards.board_ids[0])
- return
- for b_id, cb in self.list_to_acquire.iteritems():
- if cb.isChecked():
- bif.bk_acquire(b_id)
- for cb in self.list_to_acquire.values():
- cb.setChecked(False)
- self.update_acq_tickboxes()
- def update_acq_tickboxes(self):
- """
- If at least one checkbox is checked, set all checkboxes with other state (acquiring or not)
- to disabled. This prevents the user to start with one board and stop with the other simultaneously.
- TODO: add option in settings to allow the now eliminated behaviour
- """
- active = False
- inactive = False
- for b_id, cb in self.list_to_acquire.iteritems():
- if cb.isChecked(): # search for first checked box
- if self.list_of_active_boards[b_id] is True: # if board is acquiring
- active = True
- break
- else:
- inactive = True
- break
- if active: # if checked box is for acquiring boards (meaning to stop them)
- for b_id, state in self.list_of_active_boards.iteritems():
- if Elements.isEnabled('acquireTrigger_{}'.format(b_id)):
- self.list_to_acquire[b_id].setEnabled(state) # set all active boards to enabled
- self.acquire.setIcon(QtGui.QIcon(config.install_path + config.stopIcon))
- self.acquire.setText(tr("Button", "Stop Acquisition"))
- elif inactive:
- for b_id, state in self.list_of_active_boards.iteritems():
- if Elements.isEnabled('acquireTrigger_{}'.format(b_id)) or bif.bk_get_board_status(b_id, 'acquisition'):
- self.list_to_acquire[b_id].setEnabled(not state) # set all active boards to not enabled
- self.acquire.setIcon(QtGui.QIcon(config.install_path + config.startIcon))
- self.acquire.setText(tr("Button", "Start Acquisition"))
- else: # if no board is selected
- for b_id, cb in self.list_to_acquire.items():
- if Elements.isEnabled('acquireTrigger_{}'.format(b_id)):
- cb.setEnabled(True)
- self.acquire.setIcon(QtGui.QIcon(config.install_path + config.startIcon))
- self.acquire.setText(tr("Button", "Start Acquisition"))
- def acquisition_stopped(self, board_id):
- """
- This is called when a acquisition is stopped.
- (has to be registered in Callbacks under 'acquisition_stopped'
- :param board_id: id of the board
- """
- if not available_boards.multi_board:
- for elem in Elements.getElements("acquireTrigger_{}".format(board_id)):
- if isinstance(elem, QtGui.QShortcut) or isinstance(elem, QtGui.QCheckBox):
- continue
- elem.setIcon(QtGui.QIcon(config.install_path + config.startIcon))
- elem.setText(tr("Button", "Start Acquisition"))
- return
- self.list_to_acquire[board_id].setStyleSheet('')
- self.list_of_active_boards[board_id] = False
- self.update_acq_tickboxes()
- def acquisition_started(self, board_id):
- """
- This is called when a acquisition is started.
- (has to be registered in Callbacks under 'acquisition_started'
- :param board_id: id of the board
- """
- if not available_boards.multi_board:
- for elem in Elements.getElements("acquireTrigger_{}".format(board_id)):
- if isinstance(elem, QtGui.QShortcut) or isinstance(elem, QtGui.QCheckBox):
- continue
- elem.setIcon(QtGui.QIcon(config.install_path + config.stopIcon))
- elem.setText(tr("Button", "Stop Acquisition"))
- return
- self.list_to_acquire[board_id].setStyleSheet("background-color: lightgreen;")
- self.list_of_active_boards[board_id] = True
- self.update_acq_tickboxes()
- def do_log_w_comment(self):
- """
- Function to handle logging with comments
- """
- # text, ok = QtGui.QInputDialog.getText(self, tr("Heading", 'Log Comment'), tr("Label", 'Log Comment:'))
- text, ok = kcgw.MultilineInputDialog().get_text(tr("Heading", "Log Comment"), tr("Label", "Log Comment:"))
- if ok:
- log.log(additional=text)
- def log_configure_context_menu(self, event):
- """
- Function that creates the context menu for the log buttons
- :param event: (QEvent) the event
- :return: -
- """
- pos = event.globalPos()
- def configure_log():
- '''Open the configuration window for logs'''
- c = log.ConfigureLog(self)
- c.exec_()
- del c
- if pos is not None:
- menu = QtGui.QMenu(self)
- configure = menu.addAction(tr("Button", "Configure Log"))
- configure.triggered.connect(configure_log)
- menu.popup(pos)
- event.accept()
- def update_consistency(self, status):
- """
- Set consistency indicator
- :param status: True if consistent, False if inconsistent, None is nothing
- :return: -
- """
- if status is True:
- self.consistency_content.setStyleSheet("color: green;")
- elif status is False:
- self.consistency_content.setStyleSheet("color: red;")
- else:
- self.consistency_content.setStyleSheet("color: lightgrey;")
- class LeftBar(kcgw.KCGWidgets):
- """
- Left bar in the main view of the gui.
- Shows plot list and acquisition and info panel
- """
- # general notes:
- # uid = unique_id
- # usid = unique_sub_id
- # upid = unique_parent_id
- possiblePlots = ["Heatmap", "FFT", "Trains", "Combined", "Compare"]
- def __init__(self, parent):
- super(LeftBar, self).__init__("LeftBar")
- self.parent = parent
- self.openData = {}
- self.openDataNames = {}
- self.openPlots = {}
- self.openPlotWindows = {}
- self.Data = {}
- self.initUI()
- def initUI(self):
- """
- Initialise the UI
- """
- self.layout = QtGui.QVBoxLayout()
- self.layout.setContentsMargins(0, 0, 5, 0)
- self.setMinimumWidth(230)
- self.treeWidget = QtGui.QTreeWidget()
- self.treeWidget.setObjectName("tree_view")
- self.treeWidget.setColumnCount(2)
- self.treeWidget.resizeColumnToContents(1)
- # self.treeWidget.header().resizeSection(0, 110)
- self.treeWidget.setHeaderHidden(True)
- self.treeWidget.itemClicked.connect(self.plot_clicked)
- self.treeWidget.contextMenuEvent = self.contextMenuEventListView
- self.rootItem = self.treeWidget.invisibleRootItem()
- self.infoAndAcquisitionWidget = AcquisitionAndInfo()
- self.layout.addWidget(self.treeWidget)
- self.layout.addWidget(self.infoAndAcquisitionWidget)
- self.setLayout(self.layout)
- def _generate_menu(self, menu, item):
- """
- Generate the right click menu
- :param menu: the menu to add the entries to
- :param item: the item that was clicked on
- """
- heatmap = menu.addAction(tr("Button", "Heatmap"))
- fft = menu.addAction(tr("Button", "FFT"))
- trains = menu.addAction(tr("Button", "Trains"))
- combined = menu.addAction(tr("Button", "Combined"))
- compare = menu.addAction(tr("Button", "Compare"))
- heatmap.triggered.connect(lambda: self.add_plot_node(
- text=tr("Label", 'Heatmap'), unique_id=item.uid, d_type=0, datatype=item.datatype))
- fft.triggered.connect(lambda: self.add_plot_node(
- text=tr("Label", 'FFT'), unique_id=item.uid, d_type=1, datatype=item.datatype))
- trains.triggered.connect(lambda: self.add_plot_node(
- text=tr("Label", 'Trains'), unique_id=item.uid, d_type=2, datatype=item.datatype))
- combined.triggered.connect(lambda: self.add_plot_node(
- text=tr("Label", 'Combined'), unique_id=item.uid, d_type=3, datatype=item.datatype))
- compare.triggered.connect(lambda: self.add_plot_node(
- text=tr("Label", 'Combined'), unique_id=item.uid, d_type=4, datatype=item.datatype))
- def contextMenuEventListView(self, event):
- """
- Gets called when right mouse button is clicked
- :param event: the event that causes the call of this function
- :return: -
- """
- pos = event.globalPos()
- try:
- item = self.treeWidget.selectedItems()[0]
- except IndexError:
- return
- if pos is not None:
- menu = QtGui.QMenu(self)
- close = menu.addAction(tr("Button", "Close"))
- if item.is_child:
- close.triggered.connect(lambda: self.remove_plot(item.usid, silent=False, close_plot_window=True))
- else:
- close.triggered.connect(lambda: self.remove_plot_tree(item.uid))
- self._generate_menu(menu, item)
- menu.popup(pos)
- event.accept()
- def plot_clicked(self, item, i):
- """
- Function to handle when a plot item is clicked.
- :param item: what item is clicked
- :param i: what column
- :return: -
- """
- if item.is_child:
- self.openPlotWindows[item.usid].setFocus()
- else:
- if not item.ready:
- return
- if i == 1:
- position = QtGui.QCursor.pos()
- menu = QtGui.QMenu(self)
- self._generate_menu(menu, item)
- menu.popup(position)
- def add_plot_tree(self, text=False, unique_id=None, datatype=None):
- """
- Add a top node to the plot list.
- :param text: (str) text to be displayed in the plot list
- :param unique_id: (int) unique id of this top node
- :param datatype: (int) live or data from file
- :return: -
- """
- if datatype == FILE:
- file_name = QtGui.QFileDialog.getOpenFileName()
- if file_name == "":
- return
- if file_name in self.openDataNames.itervalues(): # is this to prevent double opening?
- return
- self.openDataNames[unique_id] = file_name
- else:
- if text in self.openDataNames.itervalues():
- return
- self.openDataNames[unique_id] = QtCore.QString(text) # Add a qstring for comparison
- self.openData[unique_id] = QtGui.QTreeWidgetItem()
- self.openData[unique_id].uid = unique_id
- self.openData[unique_id].is_child = False
- self.openData[unique_id].datatype = datatype
- if datatype == FILE:
- self.openData[unique_id].file_name = file_name
- self.openData[unique_id].setText(0, "Live" if datatype == LIVE else file_name.split('/')[-1])
- self.openData[unique_id].setToolTip(0, "Live" if datatype == LIVE else file_name.split('/')[-1])
- self.openData[unique_id].setText(1, "Reading")
- if datatype == LIVE: # Insert LIVE on top
- self.treeWidget.insertTopLevelItem(0, self.openData[unique_id])
- else:
- self.treeWidget.addTopLevelItem(self.openData[unique_id])
- self.treeWidget.expandItem(self.openData[unique_id])
- self.treeWidget.resizeColumnToContents(0)
- self.openData[unique_id].ready = False # indicates whether data was completely read or not
- QtGui.qApp.processEvents()
- try:
- self.read_data(datatype, unique_id, file_name if datatype == FILE else None)
- except Exception:
- self.Data[unique_id] = None
- self.remove_plot_tree(unique_id, silent=True)
- QtGui.QMessageBox.critical(
- self,
- tr("Heading", "Error Reading Data"),
- tr("Dialog", "There was an error reading the datafile, make shure it is valid and try again."))
- self.openData[unique_id].ready = True # indicates whether data was completely read or not
- self.openData[unique_id].setText(1, "+")
- self.add_plot_node(d_type=0, unique_id=unique_id, datatype=datatype)
- def read_data(self, d_type, uid, file_name):
- """
- Reads datafile
- :param d_type: FILE or LIVE - type of datasource
- :param uid: unique id for the treeelement
- :param file_name: filename if type is FILE
- :return: -
- """
- if d_type == FILE:
- self.Data[uid] = io.read_from_file(file_name, header=storage.storage.header)
- else:
- self.Data[uid] = bif.livePlotData
- def add_plot_node(self, board_id=None, text=False, unique_id=None, d_type=None, datatype=None):
- """
- Actually open a new plot window.
- :param board_id: the id of the board to which the plot corresponds
- :param text: (str) text that is displayed in the plot list
- :param unique_id: (int) unique id of this plot window
- :param d_type: (int) type of this plot window
- :param datatype: (int) live or data from file
- :return: -
- """
- if datatype == LIVE and board_id is None: # get board_id for live plot from popup menu
- # board_id = 0
- if available_boards.multi_board:
- # raise NotImplementedError("Dialog to ask for board is not implemented yet.")
- position = QtGui.QCursor.pos()
- menu = QtGui.QMenu(self)
- for bid in available_boards:
- tmp = menu.addAction(available_boards.get_board_name_from_id(bid))
- tmp.triggered.connect(lambda _, b=bid: self.add_plot_node(board_id=b,
- text=text,
- unique_id=unique_id,
- d_type=d_type,
- datatype=datatype))
- # NOTE to the above: the lambda needs b=bid to capture the variable for the lambda
- # additionally the _ is needed because the call to the lambda includes an optional parameter
- # that is true or false, passed by pyqt
- menu.popup(position)
- return
- else:
- board_id = available_boards.board_ids[0]
- # if not board_id:
- # TODO: Activate this (No Board Id Given)
- # pass
- # raise NoBoardId("No Board Id was given.")
- unique_sub_id = kcgw.idg.genid()
- nr = self.openData[unique_id].childCount()
- if datatype == FILE:
- file_name = self.openData[unique_id].file_name
- else:
- file_name = None
- name = "Live" if not file_name else file_name.split('/')[-1]
- self.openPlotWindows[unique_sub_id] = PlotWidget(
- board_id=board_id,
- parent=self,
- name=name,
- unique_id=unique_sub_id,
- type=d_type,
- datatype=datatype,
- prefix=nr,
- fName=file_name,
- data=self.Data[unique_id]
- )
- self.openPlotWindows[unique_sub_id].change_type_signal.connect(self.update_plot)
- self.openPlotWindows[unique_sub_id].upid = unique_id
- self.parent.area.newWidget(
- self.openPlotWindows[unique_sub_id],
- name=text,
- unique_id=unique_sub_id,
- widget_type=d_type
- )
- self.openPlots[unique_sub_id] = QtGui.QTreeWidgetItem()
- if datatype == LIVE:
- brd = " B: "+available_boards.get_board_name_from_id(board_id)
- else:
- brd = ""
- if d_type == 4: # Compare Plot
- adc = "1+2"
- else:
- adc = "1"
- self.openPlots[unique_sub_id].is_child = True
- self.openPlots[unique_sub_id].usid = unique_sub_id
- self.openPlots[unique_sub_id].nr = nr
- self.update_plot(unique_sub_id, d_type, adc+brd)
- self.openData[unique_id].addChild(self.openPlots[unique_sub_id])
- self.treeWidget.resizeColumnToContents(0)
- @QtCore.pyqtSlot()
- def remove_plot(self, unique_id, silent=False, close_plot_window=False):
- """
- Removes a plot from the plot list.
- :param unique_id: (int) the unique id of the plot to remove
- :param silent: (bool) Ask to close the plot source node in the list if the last plot window is closed
- (if False the source node will not be closed)
- :param close_plot_window: (bool) close the corresponding plot window
- :return: -
- """
- parent = self.openData[self.openPlotWindows[unique_id].upid]
- if not silent:
- reply = QtGui.QMessageBox()
- reply.setIcon(QtGui.QMessageBox.Question)
- reply.setWindowTitle(tr("Heading", 'Close Plot'))
- reply.setText(tr("Dialog", "Close this plot?"))
- reply.addButton(QtGui.QMessageBox.Yes)
- reply.addButton(QtGui.QMessageBox.No)
- reply.setDefaultButton(QtGui.QMessageBox.No)
- if parent.childCount() == 1:
- reply.addButton("Close Plot Source", QtGui.QMessageBox.ResetRole)
- reply.exec_()
- if reply.buttonRole(reply.clickedButton()) == QtGui.QMessageBox.ResetRole:
- self.remove_plot_tree(parent.uid, silent=True)
- return True
- elif reply.buttonRole(reply.clickedButton()) == QtGui.QMessageBox.NoRole:
- return False
- if close_plot_window:
- self.openPlotWindows[unique_id].close_silent = True
- self.openPlotWindows[unique_id].close()
- parent.removeChild(self.openPlots[unique_id])
- self.openPlotWindows[unique_id] = None
- self.openPlots[unique_id] = None
- del self.openPlotWindows[unique_id]
- del self.openPlots[unique_id]
- return True
- def remove_plot_tree(self, unique_id, silent=False):
- """
- Remove the top node from the plot list
- :param unique_id: (int) the id of the top node
- :param silent: (bool) ask to close even if corresponding plot windows are open
- :return: -
- """
- if self.openData[unique_id].childCount() != 0 and not silent:
- reply = QtGui.QMessageBox.question(
- self, tr("Heading", 'Close Data Source'), tr(
- "Dialog", "There are open plot windows.\n"
- "Close this plot source and all corresponding plot windows?"),
- QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
- QtGui.QMessageBox.No)
- if reply == QtGui.QMessageBox.No:
- return
- for plot in self.openData[unique_id].takeChildren():
- self.openPlotWindows[plot.usid].close_silent = True
- self.openPlotWindows[plot.usid].close()
- self.openData[unique_id].removeChild(plot)
- self.rootItem.removeChild(self.openData[unique_id])
- del self.openData[unique_id]
- del self.openDataNames[unique_id]
- del self.Data[unique_id]
- @QtCore.pyqtSlot(int, int, str)
- def update_plot(self, uid, b_type, add):
- """
- Updates the plot list when the type of a plot window changes
- :param uid: (int) unique id of the plot window to update
- :param b_type: (int) type of that plot window
- :param str add: the add, board and additional text to update
- :return: -
- """
- text = str(self.openPlots[uid].nr) + "." + self.possiblePlots[b_type] + " - ADC " + str(add)
- self.openPlots[uid].setText(0, text)
- self.openPlots[uid].setToolTip(0, text)
- self.treeWidget.resizeColumnToContents(0)
- def handle_dialog(self, value, diag=None,):
- """
- Function that handles the return of the dialog that asks for live or data from file
- :param value: (int) the value of the pressed button in the dialog
- :param diag: (QDialog) the dialog that is to be closed (optional)
- :return: -
- """
- if diag:
- diag.close()
- s = kcgw.idg.genid()
- if value == 1:
- if tr("Label", "Live") in self.openDataNames.itervalues():
- x = [bid for bid, obj in self.openData.iteritems() if obj.datatype == LIVE][0]
- self.add_plot_node(unique_id=x, d_type=0, datatype=LIVE)
- else:
- self.add_plot_tree(text=tr("Label", "Live"), unique_id=s, datatype=LIVE)
- elif value == 2:
- self.add_plot_tree(text=tr("Label", "File"), unique_id=s, datatype=FILE)
- else:
- pass
- def add_plot(self, d_type=None):
- """
- Handles the creation of a plot.
- Also shows the dialog that asks for the data source.
- :param d_type: the type of the plot to add
- :return: -
- """
- if d_type == LIVE or d_type == FILE:
- self.handle_dialog(value=d_type)
- return
- ask = QtGui.QDialog()
- window = self.parent.geometry()
- ask_layout = QtGui.QVBoxLayout()
- ask_layout.addWidget(QtGui.QLabel(tr("Dialog", "Open file from disk or read live data?")))
- button_layout = QtGui.QHBoxLayout()
- ask_button_live = QtGui.QPushButton(tr("Button", "Live"))
- ask_button_file = QtGui.QPushButton(tr("Button", "Open File"))
- ask_button_cancel = QtGui.QPushButton(tr("Button", "Cancel"))
- ask_button_live.pressed.connect(lambda: self.handle_dialog(diag=ask, value=1))
- ask_button_file.pressed.connect(lambda: self.handle_dialog(diag=ask, value=2))
- ask_button_cancel.pressed.connect(lambda: self.handle_dialog(diag=ask, value=3))
- button_layout.addWidget(ask_button_live)
- button_layout.addWidget(ask_button_file)
- button_layout.addWidget(ask_button_cancel)
- ask_layout.addLayout(button_layout)
- ask.setGeometry(window.width()/2.-100, window.height()/2.-50, 200, 100)
- ask.setLayout(ask_layout)
- ask.exec_()
|