def __init__(self): # Create Ice thread and synch self.ice = ReplayCompIce() self.ice.start() self.paused = False icerunning = False self.finishing = False while icerunning == False: try: while self.ice.running == False: time.sleep(0.05) icerunning = True except: time.sleep(0.05) self.mode = self.ice.mode self.measures = 0 # GUI stuff QMainWindow.__init__(self) self.ui = Ui_ReplayMainWindow() self.ui.setupUi(self) self.ui.slider.setRange(0, len(self.ice.header.index) - 1) self.ui_ticks = 0 self.connect(self.ui.actionTile, SIGNAL('triggered(bool)'), self.tile) self.connect(self.ui.actionCascade, SIGNAL('triggered(bool)'), self.cascade) # Add plug-in windows to the MDI area global debug if debug: print 'Header list' for cfgId in self.ice.header.cfgDict: if debug: print cfgId cfg = self.ice.header.cfgDict[cfgId] cfg.gui_class = cfg.module.getGraphicalUserInterface() cfg.gui_class.setConfiguration(cfg.configuration) if cfg.gui_class == None: cfg.gui_class = DummyWidget(cfgId + ' didn\'t returned a GUI') cfg.gui_class.show() self.ice.header.cfgDict[cfgId] = cfg subwin = ReplayMDISubwindow() subwin.setWidget(cfg.gui_class) window = self.ui.mdiArea.addSubWindow(subwin) window.setWindowTitle(cfgId) try: window.resize(cfg.gui_class.getSize()) except: window.resize(400, 400) # Mode dependent UI config if self.mode == 'capture': self.ui.label.setEnabled(False) self.ui.PPButton.setEnabled(False) self.ui.forceButton.setEnabled(False) self.ui.spinBox.setEnabled(False) self.ui.slider.setEnabled(False) self.ui.statusbar.showMessage( 'Running in \'capture\' mode, controls are disabled.') else: self.ui.statusbar.showMessage('Running in \'replay\' mode.') self.tray = QSystemTrayIcon() self.connect( self.tray, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), self.trayClicked) self.iconGreen = QIcon("/opt/robocomp/icons/replay-green-icon.png") self.iconRed = QIcon("/opt/robocomp/icons/replay-red-icon.png") self.tray.setIcon(self.iconGreen) self.tray.show() self.menu = QMenu() self.ppaction = self.menu.addAction("Pause") self.connect(self.ppaction, SIGNAL('triggered(bool)'), self.playpause) self.connect(self.menu.addAction("Exit"), SIGNAL('triggered(bool)'), self.closeEvent) self.tray.setContextMenu(self.menu) # Signal handling self.timer = QTimer() if self.mode == 'capture': self.timer.start(200) else: self.changeSpeed(1.) self.connect(self.timer, SIGNAL('timeout()'), self.timeout) self.connect(self.ui.spinBox, SIGNAL('valueChanged(double)'), self.changeSpeed) self.connect(self.ui.PPButton, SIGNAL('clicked()'), self.playpause) self.connect(self.ui.forceButton, SIGNAL('clicked()'), self.force)
def __init__(self): # Create Ice thread and synch self.ice = ReplayCompIce() self.ice.start() self.paused = False icerunning = False self.finishing = False while icerunning == False: try: while self.ice.running == False: time.sleep(0.05) icerunning = True except: time.sleep(0.05) self.mode = self.ice.mode self.measures = 0 # GUI stuff QMainWindow.__init__(self) self.ui = Ui_ReplayMainWindow() self.ui.setupUi(self) self.ui.slider.setRange(0, len(self.ice.header.index)-1) self.ui_ticks = 0 self.connect(self.ui.actionTile, SIGNAL('triggered(bool)'), self.tile) self.connect(self.ui.actionCascade, SIGNAL('triggered(bool)'), self.cascade) # Add plug-in windows to the MDI area global debug if debug: print 'Header list' for cfgId in self.ice.header.cfgDict: if debug: print cfgId cfg = self.ice.header.cfgDict[cfgId] cfg.gui_class = cfg.module.getGraphicalUserInterface() cfg.gui_class.setConfiguration(cfg.configuration) if cfg.gui_class == None: cfg.gui_class = DummyWidget(cfgId+' didn\'t returned a GUI') cfg.gui_class.show() self.ice.header.cfgDict[cfgId] = cfg subwin = ReplayMDISubwindow() subwin.setWidget(cfg.gui_class) window = self.ui.mdiArea.addSubWindow(subwin) window.setWindowTitle(cfgId) try: window.resize(cfg.gui_class.getSize()) except: window.resize(400, 400) # Mode dependent UI config if self.mode == 'capture': self.ui.label.setEnabled(False) self.ui.PPButton.setEnabled(False) self.ui.forceButton.setEnabled(False) self.ui.spinBox.setEnabled(False) self.ui.slider.setEnabled(False) self.ui.statusbar.showMessage('Running in \'capture\' mode, controls are disabled.') else: self.ui.statusbar.showMessage('Running in \'replay\' mode.') self.tray = QSystemTrayIcon() self.connect(self.tray, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), self.trayClicked) self.iconGreen = QIcon("/opt/robocomp/icons/replay-green-icon.png") self.iconRed = QIcon("/opt/robocomp/icons/replay-red-icon.png") self.tray.setIcon(self.iconGreen) self.tray.show() self.menu = QMenu() self.ppaction = self.menu.addAction("Pause") self.connect(self.ppaction, SIGNAL('triggered(bool)'), self.playpause); self.connect(self.menu.addAction("Exit"), SIGNAL('triggered(bool)'), self.closeEvent); self.tray.setContextMenu(self.menu); # Signal handling self.timer = QTimer() if self.mode == 'capture': self.timer.start(200) else: self.changeSpeed(1.) self.connect(self.timer, SIGNAL('timeout()'), self.timeout) self.connect(self.ui.spinBox, SIGNAL('valueChanged(double)'), self.changeSpeed) self.connect(self.ui.PPButton, SIGNAL('clicked()'), self.playpause) self.connect(self.ui.forceButton, SIGNAL('clicked()'), self.force)
class ReplayCompUI(QMainWindow): # # Constructor def __init__(self): # Create Ice thread and synch self.ice = ReplayCompIce() self.ice.start() self.paused = False icerunning = False self.finishing = False while icerunning == False: try: while self.ice.running == False: time.sleep(0.05) icerunning = True except: time.sleep(0.05) self.mode = self.ice.mode self.measures = 0 # GUI stuff QMainWindow.__init__(self) self.ui = Ui_ReplayMainWindow() self.ui.setupUi(self) self.ui.slider.setRange(0, len(self.ice.header.index) - 1) self.ui_ticks = 0 self.connect(self.ui.actionTile, SIGNAL('triggered(bool)'), self.tile) self.connect(self.ui.actionCascade, SIGNAL('triggered(bool)'), self.cascade) # Add plug-in windows to the MDI area global debug if debug: print 'Header list' for cfgId in self.ice.header.cfgDict: if debug: print cfgId cfg = self.ice.header.cfgDict[cfgId] cfg.gui_class = cfg.module.getGraphicalUserInterface() cfg.gui_class.setConfiguration(cfg.configuration) if cfg.gui_class == None: cfg.gui_class = DummyWidget(cfgId + ' didn\'t returned a GUI') cfg.gui_class.show() self.ice.header.cfgDict[cfgId] = cfg subwin = ReplayMDISubwindow() subwin.setWidget(cfg.gui_class) window = self.ui.mdiArea.addSubWindow(subwin) window.setWindowTitle(cfgId) try: window.resize(cfg.gui_class.getSize()) except: window.resize(400, 400) # Mode dependent UI config if self.mode == 'capture': self.ui.label.setEnabled(False) self.ui.PPButton.setEnabled(False) self.ui.forceButton.setEnabled(False) self.ui.spinBox.setEnabled(False) self.ui.slider.setEnabled(False) self.ui.statusbar.showMessage( 'Running in \'capture\' mode, controls are disabled.') else: self.ui.statusbar.showMessage('Running in \'replay\' mode.') self.tray = QSystemTrayIcon() self.connect( self.tray, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), self.trayClicked) self.iconGreen = QIcon("/opt/robocomp/icons/replay-green-icon.png") self.iconRed = QIcon("/opt/robocomp/icons/replay-red-icon.png") self.tray.setIcon(self.iconGreen) self.tray.show() self.menu = QMenu() self.ppaction = self.menu.addAction("Pause") self.connect(self.ppaction, SIGNAL('triggered(bool)'), self.playpause) self.connect(self.menu.addAction("Exit"), SIGNAL('triggered(bool)'), self.closeEvent) self.tray.setContextMenu(self.menu) # Signal handling self.timer = QTimer() if self.mode == 'capture': self.timer.start(200) else: self.changeSpeed(1.) self.connect(self.timer, SIGNAL('timeout()'), self.timeout) self.connect(self.ui.spinBox, SIGNAL('valueChanged(double)'), self.changeSpeed) self.connect(self.ui.PPButton, SIGNAL('clicked()'), self.playpause) self.connect(self.ui.forceButton, SIGNAL('clicked()'), self.force) # # TrayClicked def trayClicked(self, reason): if reason == QSystemTrayIcon.Trigger or reason == QSystemTrayIcon.MiddleClick: if self.isHidden(): self.show() else: self.hide() # # Timeout def timeout(self, force=False): if self.finishing: self.finish() return do_gui_update = True # Timeout - CAPTURE if self.mode == 'capture': self.ice.writeMeasureSet() if do_gui_update: for cfg in self.ice.header.cfgDict.values(): cfg.gui_class.setMeasure(cfg.worker_class.getMeasure()) # Timeout - READ elif self.mode == 'replay' and ((not self.paused) or force): if self.ice.readMeasureSet(force) == True: self.disconnect(self.ui.slider, SIGNAL('sliderMoved(int)'), self.changeTime) self.ui.slider.setSliderPosition(self.ice.reader.measures) self.connect(self.ui.slider, SIGNAL('sliderMoved(int)'), self.changeTime) #if not self.ui_ticks % 30/self.period == 0: do_gui_update = False if do_gui_update: for cfg in self.ice.header.cfgDict.values(): cfg.gui_class.setMeasure(cfg.worker_class.getMeasure()) # UI update if do_gui_update: for cfg in self.ice.header.cfgDict.values(): cfg.gui_class.update() self.measures += 1 self.ui_ticks += 1 # # Handle quit def finish(self): self.disconnect(self.timer, SIGNAL('timeout()'), self.timeout) self.ice.done() self.close() if self.mode == 'capture': self.exitMessage.close() sys.exit(0) # # Handle speed-up value changes def changeSpeed(self, newSpeed): self.ice.setSpeedUp(newSpeed) self.period = int(round(30. / newSpeed)) self.timer.start(self.period) # # Handle jumps in time def changeTime(self, newIdx): self.ice.goto(newIdx) # # Play/Pause def playpause(self): if self.paused: self.paused = False self.ui.PPButton.setText('Pause') self.ppaction.setText('Pause') self.ui.forceButton.setEnabled(False) self.tray.setIcon(self.iconGreen) else: self.paused = True self.ui.PPButton.setText('Continue') self.ppaction.setText('Continue') self.ui.forceButton.setEnabled(True) self.tray.setIcon(self.iconRed) # # Force next measure def force(self): self.timeout(force=True) # # Close event def closeEvent(self, e): if self.mode == 'capture': self.exitMessage = ReplayExitMessage( 'Please wait while file header\nheader is written to file.', self) self.exitMessage.start() self.finishing = True e.ignore() def tile(self, b): self.ui.mdiArea.tileSubWindows() def cascade(self, b): self.ui.mdiArea.cascadeSubWindows()
class ReplayCompUI(QMainWindow): # # Constructor def __init__(self): # Create Ice thread and synch self.ice = ReplayCompIce() self.ice.start() self.paused = False icerunning = False self.finishing = False while icerunning == False: try: while self.ice.running == False: time.sleep(0.05) icerunning = True except: time.sleep(0.05) self.mode = self.ice.mode self.measures = 0 # GUI stuff QMainWindow.__init__(self) self.ui = Ui_ReplayMainWindow() self.ui.setupUi(self) self.ui.slider.setRange(0, len(self.ice.header.index)-1) self.ui_ticks = 0 self.connect(self.ui.actionTile, SIGNAL('triggered(bool)'), self.tile) self.connect(self.ui.actionCascade, SIGNAL('triggered(bool)'), self.cascade) # Add plug-in windows to the MDI area global debug if debug: print 'Header list' for cfgId in self.ice.header.cfgDict: if debug: print cfgId cfg = self.ice.header.cfgDict[cfgId] cfg.gui_class = cfg.module.getGraphicalUserInterface() cfg.gui_class.setConfiguration(cfg.configuration) if cfg.gui_class == None: cfg.gui_class = DummyWidget(cfgId+' didn\'t returned a GUI') cfg.gui_class.show() self.ice.header.cfgDict[cfgId] = cfg subwin = ReplayMDISubwindow() subwin.setWidget(cfg.gui_class) window = self.ui.mdiArea.addSubWindow(subwin) window.setWindowTitle(cfgId) try: window.resize(cfg.gui_class.getSize()) except: window.resize(400, 400) # Mode dependent UI config if self.mode == 'capture': self.ui.label.setEnabled(False) self.ui.PPButton.setEnabled(False) self.ui.forceButton.setEnabled(False) self.ui.spinBox.setEnabled(False) self.ui.slider.setEnabled(False) self.ui.statusbar.showMessage('Running in \'capture\' mode, controls are disabled.') else: self.ui.statusbar.showMessage('Running in \'replay\' mode.') self.tray = QSystemTrayIcon() self.connect(self.tray, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), self.trayClicked) self.iconGreen = QIcon("/opt/robocomp/icons/replay-green-icon.png") self.iconRed = QIcon("/opt/robocomp/icons/replay-red-icon.png") self.tray.setIcon(self.iconGreen) self.tray.show() self.menu = QMenu() self.ppaction = self.menu.addAction("Pause") self.connect(self.ppaction, SIGNAL('triggered(bool)'), self.playpause); self.connect(self.menu.addAction("Exit"), SIGNAL('triggered(bool)'), self.closeEvent); self.tray.setContextMenu(self.menu); # Signal handling self.timer = QTimer() if self.mode == 'capture': self.timer.start(200) else: self.changeSpeed(1.) self.connect(self.timer, SIGNAL('timeout()'), self.timeout) self.connect(self.ui.spinBox, SIGNAL('valueChanged(double)'), self.changeSpeed) self.connect(self.ui.PPButton, SIGNAL('clicked()'), self.playpause) self.connect(self.ui.forceButton, SIGNAL('clicked()'), self.force) # # TrayClicked def trayClicked(self, reason): if reason == QSystemTrayIcon.Trigger or reason == QSystemTrayIcon.MiddleClick: if self.isHidden(): self.show() else: self.hide() # # Timeout def timeout(self, force=False): if self.finishing: self.finish() return do_gui_update = True # Timeout - CAPTURE if self.mode == 'capture': self.ice.writeMeasureSet() if do_gui_update: for cfg in self.ice.header.cfgDict.values(): cfg.gui_class.setMeasure(cfg.worker_class.getMeasure()) # Timeout - READ elif self.mode == 'replay' and ((not self.paused) or force): if self.ice.readMeasureSet(force) == True: self.disconnect(self.ui.slider, SIGNAL('sliderMoved(int)'), self.changeTime) self.ui.slider.setSliderPosition(self.ice.reader.measures) self.connect(self.ui.slider, SIGNAL('sliderMoved(int)'), self.changeTime) #if not self.ui_ticks % 30/self.period == 0: do_gui_update = False if do_gui_update: for cfg in self.ice.header.cfgDict.values(): cfg.gui_class.setMeasure(cfg.worker_class.getMeasure()) # UI update if do_gui_update: for cfg in self.ice.header.cfgDict.values(): cfg.gui_class.update() self.measures += 1 self.ui_ticks += 1 # # Handle quit def finish(self): self.disconnect(self.timer, SIGNAL('timeout()'), self.timeout) self.ice.done() self.close() if self.mode == 'capture': self.exitMessage.close() sys.exit(0) # # Handle speed-up value changes def changeSpeed(self, newSpeed): self.ice.setSpeedUp(newSpeed) self.period = int(round(30./newSpeed)) self.timer.start(self.period) # # Handle jumps in time def changeTime(self, newIdx): self.ice.goto(newIdx) # # Play/Pause def playpause(self): if self.paused: self.paused = False self.ui.PPButton.setText('Pause') self.ppaction.setText('Pause') self.ui.forceButton.setEnabled(False) self.tray.setIcon(self.iconGreen) else: self.paused = True self.ui.PPButton.setText('Continue') self.ppaction.setText('Continue') self.ui.forceButton.setEnabled(True) self.tray.setIcon(self.iconRed) # # Force next measure def force(self): self.timeout(force=True) # # Close event def closeEvent(self, e): if self.mode == 'capture': self.exitMessage = ReplayExitMessage('Please wait while file header\nheader is written to file.', self) self.exitMessage.start() self.finishing = True e.ignore() def tile(self, b): self.ui.mdiArea.tileSubWindows() def cascade(self, b): self.ui.mdiArea.cascadeSubWindows()