<commit_before># -*- coding: utf-8 -*-
"""Graphical user interface to Amtron CS400 laser controller."""

import sys
import sip
from functools import partial
from operator import mul
for cls in "QDate QDateTime QString QTextStream QTime QUrl QVariant".split():
    sip.setapi(cls, 2)

from PyQt4 import QtCore, QtGui
Qt = QtCore.Qt

import pyhard2.ctrlr as ctrlr
import pyhard2.driver as drv
Cmd = drv.Command
import pyhard2.driver.virtual as virtual
import pyhard2.driver.amtron as amtron
import pyhard2.driver.daq as daq


class _ButtonDelegate(QtGui.QAbstractItemDelegate):

    def __init__(self, parent=None):
        super(_ButtonDelegate, self).__init__(parent)

    def setEditorData(self, editor, index):
        if not index.isValid(): return
        editor.setChecked(index.data() is True)

    def setModelData(self, editor, model, index):
        if not index.isValid(): return
        model.setData(index, editor.isChecked())


class AmtronController(ctrlr.Controller):

    def __init__(self, driver, windowTitle="", uifile="", parent=None):
        super(AmtronController, self).__init__(driver, windowTitle,
                                               uifile, parent)

        self.ui.powerBtn = QtGui.QPushButton(u"Power", checkable=True)
        self.ui.gateBtn = QtGui.QPushButton(u"Gate", checkable=True)

        self.ui._layout = QtGui.QHBoxLayout()
        self.ui._layout.addWidget(self.ui.powerBtn)
        self.ui._layout.addWidget(self.ui.gateBtn)
        self.ui.instrumentPanel.layout().addLayout(self.ui._layout)

        self.programPool.default_factory = ctrlr.SetpointRampProgram

        self.powerBtnMapper = QtGui.QDataWidgetMapper(self.ui.powerBtn)
        self.powerBtnMapper.setModel(self._driverModel)
        self.powerBtnMapper.setItemDelegate(_ButtonDelegate(self.powerBtnMapper))
        self.ui.driverView.selectionModel().currentRowChanged.connect(
            self.powerBtnMapper.setCurrentModelIndex)
        self.populated.connect(self.powerBtnMapper.toFirst)
        self.ui.powerBtn.toggled.connect(self.powerBtnMapper.submit)

        self.gateBtnMapper = QtGui.QDataWidgetMapper(self.ui.gateBtn)
        self.gateBtnMapper.setModel(self._driverModel)
        self.gateBtnMapper.setItemDelegate(_ButtonDelegate(self.gateBtnMapper))
        self.ui.driverView.selectionModel().currentRowChanged.connect(
            self.gateBtnMapper.setCurrentModelIndex)
        self.populated.connect(self.gateBtnMapper.toFirst)
        self.ui.gateBtn.toggled.connect(self.gateBtnMapper.submit)

        self._specialColumnMapper.update(dict(
            laserpower=lambda column:
                       self.powerBtnMapper.addMapping(self.ui.powerBtn, column),
            lasergate=lambda column:
                      self.gateBtnMapper.addMapping(self.ui.gateBtn, column)))


class AmtronDaq(drv.Subsystem):

    """
    Instrument using the DAQ for input (temperature) and the CS400 for
    output (laser power).  Output is controller by a PID.

    """
    # connections:
    #    thermometer      pid           laser
    #    measure      ->  compute   ->  output
    def __init__(self, serial, daqline):
        super(AmtronDaq, self).__init__()
        self.pid = virtual.PidSubsystem(spmin=-100.0, spmax=1000.0)<commit_msg>Fix docstring Amtron<commit_after># -*- coding: utf-8 -*-
"""Graphical user interface to Amtron CS400 laser controller."""

import sys
import sip
from functools import partial
from operator import mul
for cls in "QDate QDateTime QString QTextStream QTime QUrl QVariant".split():
    sip.setapi(cls, 2)

from PyQt4 import QtCore, QtGui
Qt = QtCore.Qt

import pyhard2.ctrlr as ctrlr
import pyhard2.driver as drv
Cmd = drv.Command
import pyhard2.driver.virtual as virtual
import pyhard2.driver.amtron as amtron
import pyhard2.driver.daq as daq


class _ButtonDelegate(QtGui.QAbstractItemDelegate):

    def __init__(self, parent=None):
        super(_ButtonDelegate, self).__init__(parent)

    def setEditorData(self, editor, index):
        if not index.isValid(): return
        editor.setChecked(index.data() is True)

    def setModelData(self, editor, model, index):
        if not index.isValid(): return
        model.setData(index, editor.isChecked())


class AmtronController(ctrlr.Controller):

    def __init__(self, driver, windowTitle="", uifile="", parent=None):
        super(AmtronController, self).__init__(driver, windowTitle,
                                               uifile, parent)

        self.ui.powerBtn = QtGui.QPushButton(u"Power", checkable=True)
        self.ui.gateBtn = QtGui.QPushButton(u"Gate", checkable=True)

        self.ui._layout = QtGui.QHBoxLayout()
        self.ui._layout.addWidget(self.ui.powerBtn)
        self.ui._layout.addWidget(self.ui.gateBtn)
        self.ui.instrumentPanel.layout().addLayout(self.ui._layout)

        self.programPool.default_factory = ctrlr.SetpointRampProgram

        self.powerBtnMapper = QtGui.QDataWidgetMapper(self.ui.powerBtn)
        self.powerBtnMapper.setModel(self._driverModel)
        self.powerBtnMapper.setItemDelegate(_ButtonDelegate(self.powerBtnMapper))
        self.ui.driverView.selectionModel().currentRowChanged.connect(
            self.powerBtnMapper.setCurrentModelIndex)
        self.populated.connect(self.powerBtnMapper.toFirst)
        self.ui.powerBtn.toggled.connect(self.powerBtnMapper.submit)

        self.gateBtnMapper = QtGui.QDataWidgetMapper(self.ui.gateBtn)
        self.gateBtnMapper.setModel(self._driverModel)
        self.gateBtnMapper.setItemDelegate(_ButtonDelegate(self.gateBtnMapper))
        self.ui.driverView.selectionModel().currentRowChanged.connect(
            self.gateBtnMapper.setCurrentModelIndex)
        self.populated.connect(self.gateBtnMapper.toFirst)
        self.ui.gateBtn.toggled.connect(self.gateBtnMapper.submit)

        self._specialColumnMapper.update(dict(
            laserpower=lambda column:
                       self.powerBtnMapper.addMapping(self.ui.powerBtn, column),
            lasergate=lambda column:
                      self.gateBtnMapper.addMapping(self.ui.gateBtn, column)))


class AmtronDaq(drv.Subsystem):

    """Instrument using the DAQ for input (temperature) and the CS400
    for output (laser power).  Output is controller by a software PID.

    """
    # connections:
    #    thermometer      pid           laser
    #    measure      ->  compute   ->  output
    def __init__(self, serial, daqline):
        super(AmtronDaq, self).__init__()
        self.pid = virtual.PidSubsystem(spmin=-100.0, spmax=1000.0)
{'fraction_non_alphanumeric': 0.10028959000152415, 'fraction_numerical': 0.007011126352690139, 'mean_word_length': 3.1141065830721004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2063880', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1926, 'n_words': 366}