def test_integration(): t = Chronometer() t.start() a = t.elapsed time.sleep(0.002) b = t.elapsed assert b > a t.stop() c = t.elapsed time.sleep(0.002) d = t.elapsed assert (d - c) < 0.000001
class TabRover(QWidget): ''' Class TabRover is the sub widget that contains the rover launch, configuration and results for the rover Inherits from QWidget Divided into a Right Part, a Left Part, a Upper Part and a Lower Part Attributes: private path dirtrs : directory of the script private ConnectionToModel rover_model : connector to the Rover Model private QTimer rover_timer : timer of the widget private QPushButton start_b : button that launchs the acquisition private QPushButton config_b : button that opens the Config Window private QLabel icon : rover image private Chronometer chrono_rover : chronometer taht appears on the UI for the rover private QLabel lSol : indicates the mode of acquisition private QLabel lLong : shows the calculated Longitude private QLabel lLat : shows the calculated Latitude private QLabel lHeight : shows the calculated ellipsoidal Height private QLabel stream_status : shows the status of the stream ''' def __init__(self): # Inherits from the QWidget class super().__init__() #Setting font self.setFont(QFont('Helvetica',25)) # Get path to the script self.__dirtrs = os.path.dirname(os.path.abspath(__file__)) #Connection to the Rover model self.__rover_model = ConnectionToModel() #timer self.__rover_timer = QtCore.QTimer(self) self.__rover_timer.timeout.connect(self.updateRover) self.__satellites = None ###### RIGHT PART OF THE WIDGET ###### # Start Button self.__start_b = QPushButton('Start', self) self.__start_b.setCheckable(True) self.__start_b.setSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.MinimumExpanding) self.__start_b.toggled.connect(self.startRover) # Config Button self.__config_b = QPushButton('Config', self) self.__config_b.setSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.MinimumExpanding) self.__config_b.clicked.connect(self.openConfig) # Setting right part layout right_layout = QHBoxLayout() right_layout.addWidget(self.__start_b) right_layout.addWidget(self.__config_b) ###### LEFT PART OF THE WIDGET ###### # Rover image fig = QPixmap(self.__dirtrs +'/img/rover.png') self.__icon = QLabel(self) self.__icon.setPixmap(fig) # Chrono self.__chrono_rover = Chronometer() # Setting left part layout left_layout = QVBoxLayout() left_layout.addWidget(self.__icon) left_layout.addWidget(self.__chrono_rover) ###### LOWER PART OF THE WIDGET ###### # Position indicators Sol_=QLabel('Sol:') Sol_.setAlignment(QtCore.Qt.AlignRight) Lat_=QLabel('Lat:') Lat_.setAlignment(QtCore.Qt.AlignRight) Lon_=QLabel('Lon:') Lon_.setAlignment(QtCore.Qt.AlignRight) Alt_=QLabel('Height:') Alt_.setAlignment(QtCore.Qt.AlignRight) # Calculated Position to be modified by updateRover() self.__lSol=QLabel('') self.__lLat=QLabel('') self.__lLon=QLabel('') self.__lHeight=QLabel('') # Stream indicators status = QLabel('Stream Status:') status.setAlignment(QtCore.Qt.AlignLeft) self.__stream_status = QLabel('Not Started') self.__stream_status.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Minimum) # Setting lower part layout lower_layout = QHBoxLayout() lower_layout.addWidget(Sol_) lower_layout.addWidget(self.__lSol) lower_layout.addWidget(Lat_) lower_layout.addWidget(self.__lLat) lower_layout.addWidget(Lon_) lower_layout.addWidget(self.__lLon) lower_layout.addWidget(Alt_) lower_layout.addWidget(self.__lHeight) lower_layout2 = QHBoxLayout() lower_layout2.addWidget(status) lower_layout2.addWidget(self.__stream_status) ##### SETTING THE GLOBAL LAYOUT ###### rover_layout1 = QHBoxLayout() rover_layout1.addLayout(left_layout) rover_layout1.addLayout(right_layout) rover_layout = QVBoxLayout() rover_layout.addLayout(rover_layout1) rover_layout.addLayout(lower_layout) rover_layout.addLayout(lower_layout2) self.setLayout(rover_layout) ################# FUNCTIONS ######################### def getModel(self): ''' getter of the model return ConnectionToModel ''' return self.__rover_model def passSatellites(self, satellites): ''' passes the tabsatellites to connect to the rover timer ''' self.__satellites = satellites def openConfig(self): ''' Opens the RoverConfig subwindow ''' try: # disabling buttons to prevent multi opennings and launchings self.__config_b.setDisabled(True) self.__start_b.setDisabled(True) subWindow = RoverConfigWindow(self) subWindow.setModel(self.__rover_model) subWindow.show() except Exception as e: print(e) # enabling buttons back self.__config_b.setDisabled(False) self.__start_b.setDisabled(False) def startRover(self): ''' Launches the acquisition Notifies the Model Modifies the UI ''' if self.__start_b.isChecked(): # if the acquisition is started try: # Notifying the model real_rover_model = self.__rover_model.getInstanceRover() real_rover_model.startRover() # modifying the UI self.__start_b.setText('Stop') self.__config_b.setDisabled(True) self.__chrono_rover.start() self.__rover_timer.start(1000) except Exception as e: print(e) else: # if the acquisition is stopped try: self.__rover_timer.stop() # Notifying the model real_rover_model = self.__rover_model.getInstanceRover() real_rover_model.stopRover() # modifying the UI self.__start_b.setText('Start') self.__config_b.setDisabled(False) self.__chrono_rover.stop() self.__lSol.setText('') self.__lLat.setText('') self.__lLon.setText('') self.__lHeight.setText('') self.__stream_status.setText('Not Started') except Exception as e: print(e) def updateRover(self): ''' Access the Raws from the model and displays information on screen Displays the the calculus mode, the calculated position and the stream status ''' real_rover_model = self.__rover_model.getInstanceRover() rawsol, rawstream = real_rover_model.getRaw() # solutions if len(rawsol)>34: soltypes=re.findall(r'\(.*\)',rawsol) print(soltypes) try: soltype=soltypes[0][1:-1].strip() self.__lSol.setText(soltype) self.__lSol.setStyleSheet('font-family: Helvetica; font-size: 25pt') except Exception as e: print(e) sols=re.findall(r'\d*\.\d*',rawsol) print(sols) try: self.__lLat.setText(sols[1]) self.__lLon.setText(sols[2]) self.__lHeight.setText(sols[3]) except Exception as e: print(e) #stream rawstreams=rawstream.split('\n') statstr='' for stream in rawstreams: if stream.find('error')>0: streams=stream.split() statstr=streams[0]+' stream error' if stream.find(' C ')>0: streams=stream.split() if streams[0]=='input': statstr=streams[1]+':'+streams[6]+'bps ' else: statstr=streams[0]+':'+streams[8]+'bps ' self.__stream_status.setText(statstr)
import time from chronometer import Chronometer a = Chronometer() a.start() time.sleep(1) a.stop() a.start() time.sleep(2) a.stop() print(a) print("time should be around 3 seconds")
nameuserdef3 = "" userdef3 = [] if not config['Definition']['nameuserdef3'] == "None": nameuserdef3 = config['Definition']['nameuserdef3'] if not config['Definition']['userdef3'] == "None": userdef3 = config['Definition']['userdef3'].split(" ") root = tk.Tk() root.title("PosEdiOn") root.resizable(False, False) projectfile = config['Project']['file'] t = Chronometer() t.start() if os.path.isfile(projectfile): conn = sqlite3.connect(projectfile) cur = conn.cursor() else: print( "Project file does not exist. Check the information in the config.yaml file. Exiting" ) sys.exit() #CALCULEM EL TEMPS TOTAL PER AL CRONOMETRE cur.execute('SELECT tipus, datetime FROM actions') dts = cur.fetchall() tempsTotal = 0
class TabBase(QWidget): ''' Class TabBase is the sub widget that contains the base launch and configuration access button Inherits from QWidget Divided into a Right Part and a Left Part Attributes: private path dirtrs : directory of the script private ConnectionToModel base_model : connector to the Base Model private QTimer base_timer : timer of the widget private QPushButton start_b : button that launchs the acquisition private QPushButton config_b : button that opens the Config Window private QLabel icon : base image private Chronometer chrono_base : chronometer taht appears on the UI for the base private QLabel stream_status : shows the status of the stream ''' def __init__(self): # Inherits from the QWidget class super().__init__() #Setting font self.setFont(QFont('Helvetica', 25)) # Get path to the script self.__dirtrs = os.path.dirname(os.path.abspath(__file__)) #Connection to the Base model self.__base_model = ConnectionToModel() #timer self.__base_timer = QtCore.QTimer(self) self.__base_timer.timeout.connect(self.updateBase) ###### RIGHT PART OF THE WIDGET ###### # Start Button self.__start_b = QPushButton('Start', self) self.__start_b.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.__start_b.setCheckable(True) self.__start_b.toggled.connect(self.startBase) # Config Button self.__config_b = QPushButton('Config', self) self.__config_b.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.__config_b.clicked.connect(self.openConfig) # horizontal layout for the buttons right_layout = QHBoxLayout() right_layout.addWidget(self.__start_b) right_layout.addWidget(self.__config_b) ###### LEFT PART OF THE WIDGET ###### # Base image fig = QPixmap(self.__dirtrs + '/img/base.png') self.__icon = QLabel(self) self.__icon.setPixmap(fig) # Chrono self.__chrono_base = Chronometer() # Setting left part layout left_layout = QVBoxLayout() left_layout.addWidget(self.__icon) left_layout.addWidget(self.__chrono_base) ####### LOWER PART OF THE WIDGET ###### status = QLabel('Stream Status:') status.setAlignment(QtCore.Qt.AlignLeft) self.__status_base = QLabel('Not Started') self.__status_base.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) lower_layout = QHBoxLayout() lower_layout.addWidget(status) lower_layout.addWidget(self.__status_base) ##### SETTING THE GLOBAL LAYOUT ###### base_layout = QHBoxLayout() base_layout.addLayout(left_layout) base_layout.addLayout(right_layout) base_layout2 = QVBoxLayout() base_layout2.addLayout(base_layout) base_layout2.addLayout(lower_layout) self.setLayout(base_layout2) ########### FUNCTIONS ################## def openConfig(self): ''' Opens the BaseConfig subwindow ''' try: # disabling buttons to prevent multi opennings and launchings self.__config_b.setDisabled(True) self.__start_b.setDisabled(True) subWindow = BaseConfigWindow(self) subWindow.setModel(self.__base_model) subWindow.show() except Exception as e: print(e) # enabling buttons back self.__config_b.setDisabled(False) self.__start_b.setDisabled(False) def startBase(self): ''' Launches the acquisition Notifies the Model Modifies the UI ''' if self.__start_b.isChecked(): # if the acquisition is started try: # Notifying the model real_base_model = self.__base_model.getInstanceBase() real_base_model.startBase() # modifying the UI self.__start_b.setText('Stop') self.__config_b.setDisabled(True) self.__chrono_base.start() self.__base_timer.start(1000) except Exception as e: print(e) else: # if the acquisition is stopped try: self.__base_timer.stop() # Notifying the model real_base_model = self.__base_model.getInstanceBase() real_base_model.stopBase() # modifying the UI self.__start_b.setText('Start') self.__config_b.setDisabled(False) self.__chrono_base.stop() except Exception as e: print(e) def updateBase(self): ''' Access the Raws from the model and displays information on screen Displays the the calculus mode, the calculated position and the stream status ''' real_base_model = self.__base_model.getInstanceBase() rawstream = real_base_model.getRaw() if (rawstream == 'stream server start error'): self.__status_base.setText('stream server start error\n') streams = rawstream.split() print(streams) if len(streams) == 9: self.__status_base.setText(streams[0] + ' ' + streams[1] + ' ' + streams[5] + 'bps ' + streams[8]) if len(streams) >= 10: self.__status_base.setText(streams[0] + ' ' + streams[1] + ' ' + streams[5] + 'bps ' + streams[8] + ' ' + streams[10])