diff --git a/docs/overview/plot_section.md b/docs/overview/plot_section.md index a0277957..4c47f39a 100644 --- a/docs/overview/plot_section.md +++ b/docs/overview/plot_section.md @@ -28,6 +28,13 @@ For instance, toggling the 1h button will result in the last hour of data being +## Time Span LineEdit + +Next to the time span buttons is a LineEdit where the user can enter any timescale as an int or float, with the last character specified as +'m', 'h', 'd', 'w', or 'M' to specify minutes, hours, days, weeks, or months. Entering a timescale here and hitting the return key will +result in the specified timescale being displayed on the plot. For example, entering '1h' will display the last hour of data, '2w' will display the last two weeks. + + ## Plot Settings Users can change the settings of the plot using the settings button in the top left corner of the plot marked with a :octicons-gear-24: icon. diff --git a/trace/main.py b/trace/main.py index f5a414b0..94230892 100644 --- a/trace/main.py +++ b/trace/main.py @@ -14,6 +14,7 @@ QDialog, QWidget, QMenuBar, + QLineEdit, QSplitter, QFileDialog, QHBoxLayout, @@ -231,6 +232,12 @@ def build_toolbar(self, parent: QWidget) -> QWidget: timespan_buttons = self.build_timespan_buttons(toolbar_widget) tool_layout.addWidget(timespan_buttons) + self.timespan_lineEdit = QLineEdit() + self.timespan_lineEdit.returnPressed.connect(self.parse_time_input) + self.timespan_lineEdit.setFixedWidth(120) + self.timespan_lineEdit.setPlaceholderText("Enter timescale") + tool_layout.addWidget(self.timespan_lineEdit) + return toolbar_widget def build_timespan_buttons(self, parent: QWidget) -> QWidget: @@ -333,6 +340,38 @@ def build_footer(self, parent: QWidget) -> QWidget: return footer_widget + def parse_time_input(self) -> None: + """ + Parse user entered time input. Allows user to add 'm' 'h', 'd', 'w', or 'M' + to the end of a float timescale to select minutes, hours, days, weeks, or months. + Timescale multiplier is set accordingly, and if the remaining entry can be + converted to a float, the timescale is changed accordingly. + """ + + MULTIPLIERS = {"m": 60, "h": 3600, "d": 86400, "w": 604800, "M": 2628300} + + time_str = self.timespan_lineEdit.text() + + if time_str == "": + return + + if time_str[0] == "-": + time_str = time_str[1:] + + final_char = time_str[-1] + if final_char not in MULTIPLIERS: + return + + try: + time = float(time_str[:-1]) + except ValueError: + return + + multiplier = MULTIPLIERS.get(final_char) + + time_sec = time * multiplier + self.set_auto_scroll_span(time_sec) + @Slot(Path) def set_file_indicator(self, file_path: Path) -> None: """Set the file indicator label to the given file path.