예제 #1
0
    def __init__(self, app, debug=False, name=None):
        """
        create new HardwareComponent attached to *app*
        """
        if name is not None:
            self.name = name

        QtCore.QObject.__init__(self)
        self.log = get_logger_from_class(self)

        self.app = app

        #self.logged_quantities = OrderedDict()
        self.settings = LQCollection()
        self.operations = OrderedDict()

        self.connected = self.add_logged_quantity("connected", dtype=bool)
        self.connected.updated_value[bool].connect(self.enable_connection)

        self.connect_success = False

        self.debug_mode = self.add_logged_quantity("debug_mode",
                                                   dtype=bool,
                                                   initial=debug)

        self.setup()

        self.has_been_connected_once = False

        self.is_connected = False
예제 #2
0
    def __init__(self,
                 min_lq,
                 max_lq,
                 step_lq,
                 num_lq,
                 center_lq=None,
                 span_lq=None):
        QtCore.QObject.__init__(self)
        self.log = get_logger_from_class(self)

        self.min = min_lq
        self.max = max_lq
        self.num = num_lq
        self.step = step_lq
        self.center = center_lq
        self.span = span_lq

        assert self.num.dtype == int

        self._array_valid = False  # Internal _array invalid, must be computed on next request

        self._array = None  #np.linspace(self.min.val, self.max.val, self.num.val)

        #step = self._array[1]-self._array[0]
        step = self.compute_step(self.min.val, self.max.val, self.num.val)
        self.step.update_value(step)

        self.num.updated_value[int].connect(self.recalc_with_new_num)
        self.min.updated_value.connect(self.recalc_with_new_min_max)
        self.max.updated_value.connect(self.recalc_with_new_min_max)
        self.step.updated_value.connect(self.recalc_with_new_step)

        if self.center and self.span:
            self.center.updated_value.connect(self.recalc_with_new_center_span)
            self.span.updated_value.connect(self.recalc_with_new_center_span)
예제 #3
0
    def __init__(self, app, name=None):
        """
        :type app: BaseMicroscopeApp
                
        """

        QtCore.QObject.__init__(self)
        self.log = get_logger_from_class(self)

        if not hasattr(self, 'name'):
            self.name = self.__class__.__name__

        if name is not None:
            self.name = name

        self.app = app

        self.display_update_period = 0.1  # seconds
        self.display_update_timer = QtCore.QTimer(self)
        self.display_update_timer.timeout.connect(
            self._on_display_update_timer)
        self.acq_thread = None

        self.interrupt_measurement_called = False

        #self.logged_quantities = OrderedDict()
        self.settings = LQCollection()
        self.operations = OrderedDict()

        self.activation = self.settings.New(
            'activation', dtype=bool,
            ro=False)  # does the user want to the thread to be running
        #self.running    = self.settings.New('running', dtype=bool, ro=True) # is the thread actually running?
        self.run_state = self.settings.New('run_state',
                                           dtype=str,
                                           initial='stop_first')
        self.progress = self.settings.New('progress',
                                          dtype=float,
                                          unit="%",
                                          si=False,
                                          ro=True)
        self.settings.New(
            'profile', dtype=bool, initial=False
        )  # Run a profile on the run to find performance problems

        self.activation.updated_value[bool].connect(self.start_stop)

        self.add_operation("start", self.start)
        self.add_operation("interrupt", self.interrupt)
        #self.add_operation('terminate', self.terminate)
        #self.add_operation("setup", self.setup)
        #self.add_operation("setup_figure", self.setup_figure)
        self.add_operation("update_display", self.update_display)
        self.add_operation('show_ui', self.show_ui)

        if hasattr(self, 'ui_filename'):
            self.load_ui()

        self.setup()
예제 #4
0
 def __init__(self, name, dtype=float, 
              hardware_read_func=None, hardware_set_func=None, 
              initial=0, fmt="%g", si=False,
              ro = False, # read only flag
              unit = None,
              spinbox_decimals = 2,
              spinbox_step=0.1,
              vmin=-1e12, vmax=+1e12, choices=None,
              reread_from_hardware_after_write = False,
              description = None
              ):
     QtCore.QObject.__init__(self)
     
     self.name = name
     self.dtype = dtype
     self.val = dtype(initial)
     self.hardware_read_func = hardware_read_func
     self.hardware_set_func = hardware_set_func
     self.fmt = fmt # string formatting string. This is ignored if dtype==str
     if self.dtype == str:
         self.fmt = "%s"
     self.si   = si # will use pyqtgraph SI Spinbox if True
     self.unit = unit
     self.vmin = vmin
     self.vmax = vmax
     # choices should be tuple [ ('name', val) ... ] or simple list [val, val, ...]
     self.choices = self._expand_choices(choices) 
     self.ro = ro # Read-Only
     self.is_array = False
     self.description = description
     
     self.log = get_logger_from_class(self)
     
     if self.dtype == int:
         self.spinbox_decimals = 0
     else:
         self.spinbox_decimals = spinbox_decimals
     self.reread_from_hardware_after_write = reread_from_hardware_after_write
     
     if self.dtype == int:
         self.spinbox_step = 1
     else:
         self.spinbox_step = spinbox_step
     
     self.oldval = None
     
     self._in_reread_loop = False # flag to prevent reread from hardware loops
     
     self.widget_list = []
     self.listeners = []
     
     # threading lock
     #self.lock = threading.Lock()
     #self.lock = DummyLock()
     self.lock = QLock(mode=0) # mode 0 is non-reentrant lock
예제 #5
0
    def __init__(self,
                 name,
                 dtype=float,
                 hardware_read_func=None,
                 hardware_set_func=None,
                 initial=[],
                 fmt="%g",
                 si=True,
                 ro=False,
                 unit=None,
                 vmin=-1e12,
                 vmax=+1e12,
                 choices=None):
        QtCore.QObject.__init__(self)

        self.name = name
        self.dtype = dtype
        if self.dtype == str:
            self.val = np.array(initial, dtype=object)
        else:
            self.val = np.array(initial, dtype=dtype)
        self.hardware_read_func = hardware_read_func
        self.hardware_set_func = hardware_set_func
        self.fmt = fmt  # % string formatting string. This is ignored if dtype==str
        if self.dtype == str:
            self.fmt = "%s"
        self.unit = unit
        self.vmin = vmin
        self.vmax = vmax
        self.ro = ro  # Read-Only

        self.log = get_logger_from_class(self)

        if self.dtype == int:
            self.spinbox_decimals = 0
        else:
            self.spinbox_decimals = 2
        self.reread_from_hardware_after_write = False

        self.oldval = None

        self._in_reread_loop = False  # flag to prevent reread from hardware loops

        self.widget_list = []
        self.listeners = []

        # threading lock
        self.lock = QLock(mode=0)  # mode 0 is non-reentrant lock

        self.is_array = True

        self._tableView = None
예제 #6
0
    def __init__(self, app, debug=False, name=None):
        """
        create new HardwareComponent attached to *app*
        """
        QtCore.QObject.__init__(self)

        if not hasattr(self, 'name'):
            self.name = self.__class__.__name__

        if name is not None:
            self.name = name

        self.log = get_logger_from_class(self)

        # threading lock
        #self.lock = threading.Lock()
        #self.lock = DummyLock()
        self.lock = QLock(mode=1)  # mode 0 is non-reentrant lock

        self.app = app

        #self.logged_quantities = OrderedDict()
        self.settings = LQCollection()
        self.operations = OrderedDict()

        self.connected = self.add_logged_quantity("connected", dtype=bool)
        self.connected.updated_value[bool].connect(self.enable_connection)

        self.connect_success = False

        self.debug_mode = self.add_logged_quantity("debug_mode",
                                                   dtype=bool,
                                                   initial=debug)

        self.auto_thread_lock = True

        self.setup()

        if self.auto_thread_lock:
            self.thread_lock_all_lq()

        self.has_been_connected_once = False

        self.is_connected = False

        self.connection_failed.connect(self.on_connection_failed)
        self.connection_succeeded.connect(self.on_connection_succeeded)

        self.add_operation('Reload_Code', self.reload_code)
예제 #7
0
    def __init__(self, argv=[]):
        QtCore.QObject.__init__(self)
        self.log = get_logger_from_class(self)

        self.this_dir, self.this_filename = os.path.split(__file__)

        self.qtapp = QtWidgets.QApplication.instance()
        if not self.qtapp:
            self.qtapp = QtWidgets.QApplication(argv)

        self.settings = LQCollection()

        # auto creation of console widget
        self.setup_console_widget()

        # FIXME Breaks things for microscopes, but necessary for stand alone apps!
        #if hasattr(self, "setup"):
        #    self.setup()

        self.setup_logging()

        if not hasattr(self, 'name'):
            self.name = "ScopeFoundry"
        self.qtapp.setApplicationName(self.name)
예제 #8
0
    def __init__(self):
        self._logged_quantities = OrderedDict()
        self.ranges = OrderedDict()

        self.log = get_logger_from_class(self)