123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- # -*- coding: utf-8 -*-
- """
- This Module is the SingleRead window.
- """
- from PyQt4 import QtGui
- from ..base import kcgwidget as kcgw
- from ..base import backendinterface as bif
- from ..base.groupedelements import Elements
- from ..base.backend.board import available_boards
- from ..base.storage import storage
- from ..base.globals import glob as global_objects
- from .. import config
- tr = kcgw.tr
- __widget_id__ = None
- class SingleReadWidget(kcgw.KCGWidgets):
- """
- The actual single read window.
- """
- def __init__(self, unique_id, parent=None):
- """
- Initialise the single read widget
- :param unique_id: the id for this widget
- :param parent: parent object
- :return: -
- """
- super(SingleReadWidget, self).__init__()
- self.id = unique_id
- self.par = parent
- self.layout = QtGui.QGridLayout()
- self.outerLayout = QtGui.QVBoxLayout()
- self.setLayout(self.outerLayout)
- # ---------[ Create Labels and corresponding Fields ]---------
- self.single_read_button = self.createButton(tr("Button", "Single Read"), connect=self.on_single_read)
- self.interval_spinbox = self.createSpinbox(0, 100000, start_value=1000)
- self.interval_spinbox.valueChanged.connect(self.set_interval)
- self.board_ticks = {board_id: self.createCheckbox(str(board_id), checked=True if board_id==0 else False) for board_id in available_boards}
- self.board_ticks_continuous_read = {
- board_id: self.createCheckbox(str(board_id),
- connect=lambda state, b_id=board_id:
- self.on_continuous_read(state, board_id=b_id))
- for board_id in available_boards
- }
- for board_id, tick in self.board_ticks_continuous_read.items():
- Elements.addItem('acquireTrigger_{}'.format(board_id), tick)
- Elements.addItem(["acquire_{}".format(board_id), "no_board_{}".format(board_id)], tick)
- Elements.addItem('continuous_read_{}'.format(board_id), tick)
- for board_id, tick in self.board_ticks.iteritems():
- Elements.addItem('acquireTrigger_{}'.format(board_id), tick)
- Elements.addItem(["acquire_{}".format(board_id), "no_board_{}".format(board_id)], tick)
- # --------[ Fill Grid ]----------------
- self.layout.addWidget(self.single_read_button, 0, 1)
- # self.layout.addWidget(self.continuous_read_button, 0, 1)
- self.layout.addWidget(self.createLabel(tr("Label", "Interval:") + " (ms)"), 1, 0)
- self.layout.addWidget(self.interval_spinbox, 1, 1)
- self.setWindowTitle(tr("Heading", "Single and Continuous Read"))
- self.tickLayout = QtGui.QHBoxLayout()
- self.tickLayout.addWidget(self.createLabel(
- tr("Label", "Boards"), tooltip=tr("Tooltip", "Check the board you want to select for single read"))
- )
- self.tickLayout.addStretch(1)
- for tick in self.board_ticks.values():
- self.tickLayout.addWidget(tick)
- self.tickLayoutContinuousRead = QtGui.QHBoxLayout()
- self.tickLayoutContinuousRead.addWidget(self.createLabel(
- tr("Label", "Continuous Read"),
- tooltip=tr("Tooltip",
- "Tick the board you want to continuously read."
- "\nThe selected boards will continue reading until the checkbox is unticked.")
- )
- )
- self.tickLayoutContinuousRead.addStretch(1)
- for tick in self.board_ticks_continuous_read.values():
- self.tickLayoutContinuousRead.addWidget(tick)
- self.outerLayout.addLayout(self.tickLayoutContinuousRead)
- self.outerLayout.addLayout(self.tickLayout)
- self.outerLayout.addLayout(self.layout)
- self.outerLayout.addStretch(1)
- self.set_interval()
- def on_single_read(self):
- """
- Perform a single read on all boards which ticks are set
- :return:
- """
- for board_id, tick in self.board_ticks.iteritems():
- if tick.isChecked() and tick.isEnabled():
- bif.bk_single_read(board_id)
- def on_continuous_read(self, state, board_id):
- """
- Toggle function to toggle continuous read when the corresponding button is pressed.
- :param bool state: True to activate and False to deactivate continuous read for board_id
- :param int? board_id: the id of the board to take action with
- :return: -
- """
- # if self.board_ticks_continuous_read[id].isChecked():
- self.set_interval()
- if state:
- # self.continuous_read_button.setText(tr("Button", "Stop Continuous Read"))
- # self.continuous_read[id] = True
- self.board_ticks_continuous_read[board_id].setStyleSheet("border-color: green; border-width: 3px;")
- else:
- self.board_ticks_continuous_read[board_id].setStyleSheet("")
- bif.bk_continuous_read(board_id) # interval=self.interval_spinbox.value())
- def set_interval(self):
- """
- Set the interval between reads
- """
- storage.continuous_interval = self.interval_spinbox.value()
- def closeEvent(self, event):
- """
- Event handler to handle the event of closing this window and gracefully delete ids and such
- :param event: the event to process (gets passed by PyQt)
- """
- global __widget_id__
- __widget_id__ = None
- del self.par.widgets[self.id]
- Elements.removeItem(['no_board', 'acquire'],
- [
- self.single_read_button,
- # self.continuous_read_button
- ])
- for board_id, tick in self.board_ticks_continuous_read.items():
- Elements.removeItem(
- [
- "continuous_read_{}".format(board_id),
- "acquireTrigger_{}".format(board_id),
- "acquire_{}".format(board_id),
- "no_board_{}".format(board_id)
- ], tick)
- for board_id, tick in self.board_ticks.iteritems():
- Elements.removeItem(
- [
- "acquireTrigger_{}".format(board_id),
- "acquire_{}".format(board_id),
- "no_board_{}".format(board_id)
- ], tick)
- super(SingleReadWidget, self).closeEvent(event)
- def add_single_read_widget():
- """
- Add this widget to the gui.
- This function will actually open the subwindow.
- :return: -
- """
- global __widget_id__
- if __widget_id__:
- global_objects.get_global('area').widgets[__widget_id__].setFocus()
- else:
- nid = kcgw.idg.genid()
- __widget_id__ = nid
- w = SingleReadWidget(nid, global_objects.get_global('area'))
- global_objects.get_global('area').newWidget(w, "Single and Continuous Read", nid, widget_type=4, minSize=True) # TODO: proper type
- kcgw.register_widget(QtGui.QIcon(config.install_path + config.singleReadIcon),
- tr("Heading", "Single Read"),
- add_single_read_widget,
- "Ctrl+i"
- )
|