def _get_stamp_as_qdatetime(self, stamp): if None in self.__stamp: return None dt = QDateTime() dt.setTime_t(stamp[0]) dt.addMSecs(int(float(stamp[1]) / 10**6)) return dt
def time_as_qdatetime(self): """ :returns: time with msecs included, ''QDateTime'' """ time = QDateTime() time.setTime_t(int(self._time[0])) time = time.addMSecs(int(str(self._time[1]).zfill(9)[:3])) return time
def datestamp_to_qdatetime(self, secs, nsecs): """ :param secs: seconds from a datestamp ''int'' :param nsecs: nanoseconds from a datestamp ''int'' :returns: converted time ''QDateTime'' """ temp_time = QDateTime() temp_time.setTime_t(int(secs)) return temp_time.addMSecs(int(str(nsecs).zfill(9)[:3]))
def time_as_datestamp(self): """ :returns: seconds with decimal fractions of a second, ''str'' """ seconds = self._time.toTime_t() seconds_in_qdate = QDateTime() seconds_in_qdate.setTime_t(seconds) msecs = seconds_in_qdate.msecsTo(self._time) return str(seconds) + '.' + str(msecs)
def from_ros_msg(cls, log_msg): """Returns an Entry from a given ROS log message. :type log_msg: rosgraph_msgs.msg.Log :param log_msg: The message to convert """ date_time = (QDateTime.currentDateTime() if log_msg.header.stamp.is_zero() else QDateTime.fromSecsSinceEpoch(log_msg.header.stamp.secs)) return cls(log_msg.msg, date_time, log_msg.level >= Log.ERROR)
def __init__(self, parentfilter, rospack, time_range_provider): """ Widget for displaying interactive data related to time filtering. :param parentfilter: buddy filter were data is stored, ''TimeFilter'' :param display_list_args: single element list containing one tuple with the min and max time to be displayed, ''list of tuple'' """ super(TimeFilterWidget, self).__init__() ui_file = os.path.join( rospack.get_path('rqt_console'), 'resource/filters', 'time_filter_widget.ui') loadUi(ui_file, self) self.setObjectName('TimeFilterWidget') self._parentfilter = parentfilter # When data is changed it is stored in the parent filter self.start_datetime.dateTimeChanged[QDateTime].connect(self.handle_start_changed) self.stop_datetime.dateTimeChanged[QDateTime].connect(self.handle_stop_changed) self.stop_enabled_check_box.clicked[bool].connect(self.handle_stop_enabled_changed) # Times are passed in unixtimestamp '.' decimal fraction of a second mintime, maxtime = time_range_provider() if mintime != -1: mintime = str(mintime).split('.') maxtime = str(maxtime).split('.') time = QDateTime() time.setTime_t(int(mintime[0])) mintime = time.addMSecs(int(str(mintime[1]).zfill(9)[:3])) self.start_datetime.setDateTime(mintime) time.setTime_t(int(maxtime[0])) maxtime = time.addMSecs(int(str(maxtime[1]).zfill(9)[:3])) self.stop_datetime.setDateTime(maxtime) else: self.start_datetime.setDateTime(datetime.now()) self.stop_datetime.setDateTime(datetime.now())
def __init__(self, content, date_time=None, is_error=False): super(Entry, self).__init__() self.content = content self.date_time = QDateTime.currentDateTime( ) if date_time is None else date_time self.is_error = is_error
def test_entry_model_to_string(self): entry = Entry("test1", QDateTime.fromSecsSinceEpoch(5)) self.model.insert_row(entry) self.model.insert_row(entry) self.model.insert_row(entry) self.assertEqual(str(self.model), "{0}\n{0}\n{0}".format(entry))
def from_ros_msg(cls, log_msg: Log, use_current_time: Optional[bool] = True): """Returns an Entry from a given ROS log message. :param log_msg: The message to convert :param use_current_time: Whether the current time should be used, instead of the timestamp of the log """ if use_current_time or log_msg.stamp is None: date_time = QDateTime.currentDateTime() else: date_time = QDateTime.fromSecsSinceEpoch(log_msg.stamp.sec) return cls( log_msg.msg, date_time, log_msg.level >= int.from_bytes(Log.ERROR, sys.byteorder), )
def test_insert_single_row(self): entry = Entry("test", QDateTime.fromSecsSinceEpoch(5)) self.model.insert_row(entry) time_index = self.model.createIndex(0, 0) content_index = self.model.createIndex(0, 1) self.assertEqual(self.model.data(time_index), entry.time_string()) self.assertEqual(self.model.data(content_index), entry.content)
def __init__(self, parentfilter, rospack, time_range_provider): """ Widget for displaying interactive data related to time filtering. :param parentfilter: buddy filter were data is stored, ''TimeFilter'' :param display_list_args: single element list containing one tuple with the min and max time to be displayed, ''list of tuple'' """ super(TimeFilterWidget, self).__init__() ui_file = os.path.join(rospack.get_path('rqt_console'), 'resource/filters', 'time_filter_widget.ui') loadUi(ui_file, self) self.setObjectName('TimeFilterWidget') self._parentfilter = parentfilter # When data is changed it is stored in the parent filter self.start_datetime.dateTimeChanged[QDateTime].connect(self.handle_start_changed) self.stop_datetime.dateTimeChanged[QDateTime].connect(self.handle_stop_changed) self.stop_enabled_check_box.clicked[bool].connect(self.handle_stop_enabled_changed) # Times are passed in unixtimestamp '.' decimal fraction of a second mintime, maxtime = time_range_provider() if mintime != -1: mintime = str(mintime).split('.') maxtime = str(maxtime).split('.') time = QDateTime() time.setTime_t(int(mintime[0])) mintime = time.addMSecs(int(str(mintime[1]).zfill(9)[:3])) self.start_datetime.setDateTime(mintime) time.setTime_t(int(maxtime[0])) maxtime = time.addMSecs(int(str(maxtime[1]).zfill(9)[:3])) self.stop_datetime.setDateTime(maxtime) else: self.start_datetime.setDateTime(datetime.now()) self.stop_datetime.setDateTime(datetime.now())
def restore_settings(self, settings): """ Restores the settings for this filter from an ini file. :param settings: used to extract the settings from an ini file ''qt_gui.settings.Settings'' """ self.handle_stop_enabled_changed(settings.value('stop_time_enabled') in [True, 'true']) if settings.contains('start_time'): self.handle_start_changed(QDateTime.fromString(settings.value('start_time'), 'hh:mm:ss.zzz (yyyy-MM-dd)')) else: self.handle_start_changed(QDateTime(datetime.now())) if settings.contains('stop_time'): self.handle_stop_changed(QDateTime.fromString(settings.value('stop_time'), 'hh:mm:ss.zzz (yyyy-MM-dd)')) else: self.handle_stop_changed(QDateTime(datetime.now())) self.stop_datetime.setDateTime(self._parentfilter._stop_time) self.start_datetime.setDateTime(self._parentfilter._start_time) self.stop_enabled_check_box.setChecked(self._parentfilter._stop_time_enabled)
def test_create_from_info_log_msg(self): content = "test" msg = Log() msg.msg = content msg.level = int.from_bytes(Log.INFO, sys.byteorder) entry = Entry.from_ros_msg(msg) self.assertEqual(entry.content, content) self.assertFalse(entry.is_error) self.assertAlmostEqual(entry.date_time.toSecsSinceEpoch(), QDateTime.currentSecsSinceEpoch(), 10)
def timestring_to_timedata(self, timestring): """ Converts a time string in the format of _time_format into a string of format '(unix timestamp).(fraction of second)' :param timestring: formatted time string ''str'' :returns: seconds and fractions thereof ''str'' """ timeval = QDateTime.fromString(timestring, self._time_format).toTime_t() return str(timeval) + '.' + timestring[9:12] # append '.(msecs)'
def timedata_to_timestring(self, timedata): """ Converts a string in the format of '(unix timestamp).(fraction of second)' into a string of format _time_format :param timedata: seconds and fractions thereof ''str'' :returns: formatted time string''str'' """ sec, fraction = timedata.split('.') if len(fraction) < 3: raise RuntimeError( 'Malformed timestring in timedata_to_timestring()') micro = int(fraction[:3]) return QDateTime.fromTime_t(long(sec)).addMSecs(micro).toString( self._time_format)
def __init__( self, content: str, date_time: Optional[QDateTime] = None, is_error: Optional[bool] = False, ): """Construct an Entry. :param content Content of the message :param date_time Time the entry was created :param is_error Whether the entry corresponds to an error """ super(Entry, self).__init__() self.content = content self.date_time = QDateTime.currentDateTime() if date_time is None else date_time self.is_error = is_error
def _add_log(self, data): timestamp = QStandardItem( QDateTime.currentDateTime().toString('d.M.yyyy hh:mm:ss.zzz')) timestamp.setTextAlignment(Qt.AlignRight) timestamp.setEditable(False) message = QStandardItem(data) message.setEditable(False) row = [] row.append(timestamp) row.append(message) self._message_count = self._message_count + 1 self.model.insertRow(0, row) if self._message_count > self._message_limit: self.model.removeRow(self.model.rowCount() - 1) self._message_count = self._message_count - 1
def test_insert_single_row_count(self): entry = Entry("test", QDateTime.fromSecsSinceEpoch(5)) self.model.insert_row(entry) self.assertEqual(self.model.rowCount(), 1)
def __init__(self): super(TimeFilter, self).__init__() self._start_time = QDateTime() self._stop_time = QDateTime() self._stop_time_enabled = True
def test_to_string(self): date_time = QDateTime.fromSecsSinceEpoch(2) content = "test" entry = Entry(content, date_time) self.assertEqual(str(entry), "[{0}] {1}".format(date_time.toString(), content))
def test_to_time_string(self): date_time = QDateTime.fromSecsSinceEpoch(5, QTimeZone.utc()) entry = Entry("", date_time) self.assertEqual(entry.time_string(), "00:00:05")