示例#1
0
    def __init__(self):
        QTWindow.__init__(self, 'positioner', 'Positioner')
        self.connect("delete-event", self._delete_event_cb)

        self._moving = False

        self._controls = PositionControls(None)
        self._controls.connect('direction-clicked', self._direction_clicked_cb)
        self._controls.connect('direction-released', self._direction_released_cb)
        self._controls.connect('max-speed-changed', self._max_speed_changed_cb)
        self._controls.connect('min-speed-changed', self._min_speed_changed_cb)
        self._controls.connect('accel-changed', self._accel_changed_cb)
        self._controls.connect('decel-changed', self._decel_changed_cb)
        self._controls.connect('stop-request', self._stop_request_cb)
        self._max_speed = self._controls.get_max_speed()
        self._min_speed = self._controls.get_min_speed()
        self._accel_factor = self._controls.get_accel()
        self._decel_factor = self._controls.get_decel()

        self._bookmarks = PositionBookmarks(None)
        self._bookmarks.connect('go-request', self._go_request)

        self._ins_combo = InstrumentDropdown(types=['positioner'])
        self._ins_combo.connect('changed', self._instrument_changed_cb)
        self._instrument = None

        poslabel = gtk.Label()
        poslabel.set_markup('<big>%s</big>' % _L('Position'))
        self._position_label = gtk.Label()
        self._update_position()

        vbox = pack_vbox([
            self._ins_combo,
            pack_hbox([
                poslabel,
                self._position_label], True, True),
            self._controls,
            self._bookmarks], False, False)

        # Speed control variables
        self._direction_down = (0, 0, 0)
        self._step_done = False
        self._speed = [0, 0, 0]
        self._timer_hid = None
        self._counter = 0

        self.add(vbox)
        vbox.show_all()
示例#2
0
    def __init__(self):
        QTWindow.__init__(self, 'positioner', 'Positioner')
        self.connect("delete-event", self._delete_event_cb)

        self._moving = False

        self._controls = PositionControls(None)
        self._controls.connect('direction-clicked', self._direction_clicked_cb)
        self._controls.connect('direction-released', self._direction_released_cb)
        self._controls.connect('max-speed-changed', self._max_speed_changed_cb)
        self._controls.connect('min-speed-changed', self._min_speed_changed_cb)
        self._controls.connect('accel-changed', self._accel_changed_cb)
        self._controls.connect('decel-changed', self._decel_changed_cb)
        self._controls.connect('stop-request', self._stop_request_cb)
        self._max_speed = self._controls.get_max_speed()
        self._min_speed = self._controls.get_min_speed()
        self._accel_factor = self._controls.get_accel()
        self._decel_factor = self._controls.get_decel()

        self._bookmarks = PositionBookmarks(None)
        self._bookmarks.connect('go-request', self._go_request)

        self._ins_combo = InstrumentDropdown(types=['positioner'])
        self._ins_combo.connect('changed', self._instrument_changed_cb)
        self._instrument = None

        poslabel = gtk.Label()
        poslabel.set_markup('<big>%s</big>' % _L('Position'))
        self._position_label = gtk.Label()
        self._update_position()

        vbox = pack_vbox([
            self._ins_combo,
            pack_hbox([
                poslabel,
                self._position_label], True, True),
            self._controls,
            self._bookmarks], False, False)

        # Speed control variables
        self._direction_down = (0, 0, 0)
        self._step_done = False
        self._speed = [0, 0, 0]
        self._timer_hid = None
        self._counter = 0

        self.add(vbox)
        vbox.show_all()
示例#3
0
class PositionerWindow(QTWindow):

    def __init__(self):
        QTWindow.__init__(self, 'positioner', 'Positioner')
        self.connect("delete-event", self._delete_event_cb)

        self._moving = False

        self._controls = PositionControls(None)
        self._controls.connect('direction-clicked', self._direction_clicked_cb)
        self._controls.connect('direction-released', self._direction_released_cb)
        self._controls.connect('max-speed-changed', self._max_speed_changed_cb)
        self._controls.connect('min-speed-changed', self._min_speed_changed_cb)
        self._controls.connect('accel-changed', self._accel_changed_cb)
        self._controls.connect('decel-changed', self._decel_changed_cb)
        self._controls.connect('stop-request', self._stop_request_cb)
        self._max_speed = self._controls.get_max_speed()
        self._min_speed = self._controls.get_min_speed()
        self._accel_factor = self._controls.get_accel()
        self._decel_factor = self._controls.get_decel()

        self._bookmarks = PositionBookmarks(None)
        self._bookmarks.connect('go-request', self._go_request)

        self._ins_combo = InstrumentDropdown(types=['positioner'])
        self._ins_combo.connect('changed', self._instrument_changed_cb)
        self._instrument = None

        poslabel = gtk.Label()
        poslabel.set_markup('<big>%s</big>' % _L('Position'))
        self._position_label = gtk.Label()
        self._update_position()

        vbox = pack_vbox([
            self._ins_combo,
            pack_hbox([
                poslabel,
                self._position_label], True, True),
            self._controls,
            self._bookmarks], False, False)

        # Speed control variables
        self._direction_down = (0, 0, 0)
        self._step_done = False
        self._speed = [0, 0, 0]
        self._timer_hid = None
        self._counter = 0

        self.add(vbox)
        vbox.show_all()

    def _delete_event_cb(self, widget, event, data=None):
        self.hide()
        return True

    def _instrument_changed_cb(self, widget):
        ins = self._ins_combo.get_instrument()
        self._instrument = ins
        self._controls.set_instrument(ins)
        self._bookmarks.set_instrument(ins)
        self._update_position()

    def _go_request(self, sender, position):
        self._instrument.move_abs(position)

    def _direction_clicked_cb(self, sender, direction):
        self._direction_down = direction
        self._step_done = False
        if self._timer_hid is None:
            self._timer_hid = gobject.timeout_add(100, self._position_timer)

    def _direction_released_cb(self, sender, direction):
        if not self._step_done and self._speed == [0, 0, 0]:
            if self._timer_hid is not None:
                gobject.source_remove(self._timer_hid)
            self._timer_hid = None
            self._do_single_step()

        self._direction_down = (0, 0, 0)

    def _do_single_step(self):
        for i in range(len(self._direction_down)):
            if self._direction_down[i] != 0:
                self._instrument.step(i, sign(self._direction_down[i]))

    def _update_speed(self):
        for i in range(len(self._direction_down)):
            if self._direction_down[i] != 0:
                if self._speed[i] == 0:
                    self._speed[i] = self._direction_down[i] * self._min_speed
                else:
                    self._speed[i] = self._speed[i] * self._accel_factor
                    if abs(self._speed[i]) >= self._max_speed:
                        self._speed[i] = sign(self._speed[i]) * self._max_speed
            else:
                self._speed[i] = self._speed[i] / self._decel_factor
                if abs(self._speed[i]) < self._min_speed:
                    self._speed[i] = 0

        if self._speed != [0, 0, 0]:
            self._step_done = True
            self._instrument.set_speed(self._speed)
            if not self._moving:
                self._instrument.start()
                self._moving = True
            return True
        else:
            self._instrument.stop()
            self._moving = False
            return False

        return ret

    def _update_position(self):
        if self._instrument is not None and self._instrument.has_parameter('position'):
            pos = self._instrument.get_position()
            posstr = self._instrument.format_parameter_value('position', pos)
        else:
            posstr = 'None'
        self._position_label.set_markup('<big>%s</big>' % posstr)

    def _position_timer(self):
        self._counter += 1
        ret = self._update_speed()
        if not ret:
            self._timer_hid = None
        if (self._counter % 5) == 0 or not ret:
            self._update_position()
        return ret

    def _max_speed_changed_cb(self, sender, val):
        self._max_speed = val

    def _min_speed_changed_cb(self, sender, val):
        self._min_speed = val

    def _accel_changed_cb(self, sender, val):
        self._accel_factor = val

    def _decel_changed_cb(self, sender, val):
        self._decel_factor = val

    def _stop_request_cb(self, sender):
        self._instrument.stop()
示例#4
0
class PositionerWindow(QTWindow):

    def __init__(self):
        QTWindow.__init__(self, 'positioner', 'Positioner')
        self.connect("delete-event", self._delete_event_cb)

        self._moving = False

        self._controls = PositionControls(None)
        self._controls.connect('direction-clicked', self._direction_clicked_cb)
        self._controls.connect('direction-released', self._direction_released_cb)
        self._controls.connect('max-speed-changed', self._max_speed_changed_cb)
        self._controls.connect('min-speed-changed', self._min_speed_changed_cb)
        self._controls.connect('accel-changed', self._accel_changed_cb)
        self._controls.connect('decel-changed', self._decel_changed_cb)
        self._controls.connect('stop-request', self._stop_request_cb)
        self._max_speed = self._controls.get_max_speed()
        self._min_speed = self._controls.get_min_speed()
        self._accel_factor = self._controls.get_accel()
        self._decel_factor = self._controls.get_decel()

        self._bookmarks = PositionBookmarks(None)
        self._bookmarks.connect('go-request', self._go_request)

        self._ins_combo = InstrumentDropdown(types=['positioner'])
        self._ins_combo.connect('changed', self._instrument_changed_cb)
        self._instrument = None

        poslabel = gtk.Label()
        poslabel.set_markup('<big>%s</big>' % _L('Position'))
        self._position_label = gtk.Label()
        self._update_position()

        vbox = pack_vbox([
            self._ins_combo,
            pack_hbox([
                poslabel,
                self._position_label], True, True),
            self._controls,
            self._bookmarks], False, False)

        # Speed control variables
        self._direction_down = (0, 0, 0)
        self._step_done = False
        self._speed = [0, 0, 0]
        self._timer_hid = None
        self._counter = 0

        self.add(vbox)
        vbox.show_all()

    def _delete_event_cb(self, widget, event, data=None):
        self.hide()
        return True

    def _instrument_changed_cb(self, widget):
        ins = self._ins_combo.get_instrument()
        self._instrument = ins
        self._controls.set_instrument(ins)
        self._bookmarks.set_instrument(ins)
        self._update_position()

    def _go_request(self, sender, position):
        self._instrument.move_abs(position)

    def _direction_clicked_cb(self, sender, direction):
        self._direction_down = direction
        self._step_done = False
        if self._timer_hid is None:
            self._timer_hid = gobject.timeout_add(100, self._position_timer)

    def _direction_released_cb(self, sender, direction):
        if not self._step_done and self._speed == [0, 0, 0]:
            if self._timer_hid is not None:
                gobject.source_remove(self._timer_hid)
            self._timer_hid = None
            self._do_single_step()

        self._direction_down = (0, 0, 0)

    def _do_single_step(self):
        for i in range(len(self._direction_down)):
            if self._direction_down[i] != 0:
                self._instrument.step(i, sign(self._direction_down[i]))

    def _update_speed(self):
        for i in range(len(self._direction_down)):
            if self._direction_down[i] != 0:
                if self._speed[i] == 0:
                    self._speed[i] = self._direction_down[i] * self._min_speed
                else:
                    self._speed[i] = self._speed[i] * self._accel_factor
                    if abs(self._speed[i]) >= self._max_speed:
                        self._speed[i] = sign(self._speed[i]) * self._max_speed
            else:
                self._speed[i] = self._speed[i] / self._decel_factor
                if abs(self._speed[i]) < self._min_speed:
                    self._speed[i] = 0

        if self._speed != [0, 0, 0]:
            self._step_done = True
            self._instrument.set_speed(self._speed)
            if not self._moving:
                self._instrument.start()
                self._moving = True
            return True
        else:
            self._instrument.stop()
            self._moving = False
            return False

        return ret

    def _update_position(self):
        if self._instrument is not None and self._instrument.has_parameter('position'):
            pos = self._instrument.get_position()
            posstr = self._instrument.format_parameter_value('position', pos)
        else:
            posstr = 'None'
        self._position_label.set_markup('<big>%s</big>' % posstr)

    def _position_timer(self):
        self._counter += 1
        ret = self._update_speed()
        if not ret:
            self._timer_hid = None
        if (self._counter % 5) == 0 or not ret:
            self._update_position()
        return ret

    def _max_speed_changed_cb(self, sender, val):
        self._max_speed = val

    def _min_speed_changed_cb(self, sender, val):
        self._min_speed = val

    def _accel_changed_cb(self, sender, val):
        self._accel_factor = val

    def _decel_changed_cb(self, sender, val):
        self._decel_factor = val

    def _stop_request_cb(self, sender):
        self._instrument.stop()