Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open the bag directory instead of a single file #80

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions rqt_bag/src/rqt_bag/bag_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,14 @@ def _handle_record_clicked(self):
self.topic_selection.recordSettingsSelected.connect(self._on_record_settings_selected)

def _on_record_settings_selected(self, all_topics, selected_topics):
filename = \
QFileDialog.getSaveFileName(self, self.tr('Select prefix for new Bag File'), '.',
self.tr('Bag files {.bag} (*.bag)'))
if filename[0] != '':
prefix = filename[0].strip()
# Get bag name to record to, prepopulating the dialog input with the current time
proposed_filename = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
filename = QFileDialog.getSaveFileName(self, self.tr('Select name for new rosbag'), proposed_filename)

# Get filename to record to
record_filename = time.strftime('%Y-%m-%d-%H-%M-%S.bag', time.localtime(time.time()))
if prefix.endswith('.bag'):
prefix = prefix[:-len('.bag')]
if prefix:
record_filename = '%s_%s' % (prefix, record_filename)
if filename[0] != '':
record_filename = filename[0].strip()
if record_filename.endswith('.bag'):
record_filename = record_filename[:-len('.bag')]

self._logger.info('Recording to %s.' % record_filename)

Expand All @@ -277,10 +273,18 @@ def _on_record_settings_selected(self, all_topics, selected_topics):
self._timeline.record_bag(record_filename, all_topics, selected_topics)

def _handle_load_clicked(self):
filenames = QFileDialog.getOpenFileNames(
self, self.tr('Load from Files'), '.', self.tr('Rosbag2 Metadata File {.yaml} (*.yaml)'))
for filename in filenames[0]:
self.load_bag(filename)
# Create a dialog explicitly so that we can set options on it. We're currently using
# a native dialog which is not able to multi-select directories
dialog = QFileDialog(self)
dialog.setFileMode(QFileDialog.Directory)
dialog.setOption(QFileDialog.ShowDirsOnly, True)

if dialog.exec():
filenames = dialog.selectedFiles()
if filenames:
self.last_open_dir = filenames[0]
for filename in filenames:
self.load_bag(filename + "/metadata.yaml")

# After loading bag(s), force a resize event on the bag widget so that
# it can take the new height of the timeline into account (and show
Expand All @@ -289,21 +293,21 @@ def _handle_load_clicked(self):
self._resizeEvent(QResizeEvent(self.size(), self.size()))

def load_bag(self, filename):
qDebug("Loading '%s'..." % filename.encode(errors='replace'))
qDebug("Loading '%s' ..." % filename.encode(errors='replace'))

# QProgressBar can EITHER: show text or show a bouncing loading bar,
# but apparently the text is hidden when the bounding loading bar is
# shown
# self.progress_bar.setRange(0, 0)
self.set_status_text.emit("Loading '%s'..." % filename)
self.set_status_text.emit("Loading '%s' ..." % os.path.split(filename)[0])
# progress_format = self.progress_bar.format()
# progress_text_visible = self.progress_bar.isTextVisible()
# self.progress_bar.setFormat("Loading %s" % filename)
# self.progress_bar.setTextVisible(True)

try:
with open(filename) as f:
bag_info = yaml.load(f)
bag_info = yaml.safe_load(f)
bag = Rosbag2(bag_info['rosbag2_bagfile_information'], filename)
except Exception as e:
qWarning("Loading '%s' failed due to: %s" % (filename.encode(errors='replace'), e))
Expand Down Expand Up @@ -336,10 +340,10 @@ def load_bag(self, filename):
# self clear loading filename

def _handle_save_clicked(self):
filename = QFileDialog.getSaveFileName(
self, self.tr('Save selected region to file...'), '.',
self.tr('Bag files {.bag} (*.bag)'))

# Get the bag name to save to, prepopulating the dialog input with the current time
proposed_filename = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
filename = \
QFileDialog.getSaveFileName(self, self.tr('Save selected region...'), proposed_filename)
if filename[0] != '':
self._timeline.copy_region_to_bag(filename[0])

Expand Down
2 changes: 1 addition & 1 deletion rqt_bag/src/rqt_bag/plugins/raw_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _add_msg_object(self, parent, path, name, obj, obj_type):

elif type(obj) in [str, bool, int, long, float, complex, Time]:
# Ignore any binary data
obj_repr = codecs.utf_8_decode(str(obj).decode(), 'ignore')[0]
obj_repr = codecs.utf_8_decode(str(obj).encode(), 'ignore')[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks unrelated. Should it be included in this PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, doesn't have to be. I didn't know if it was worth a separate PR for a single line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I would try to keep changes focused on one thing for traceability (e.g. when reviewing commit history). I find it makes it easier to pinpoint where and why something was changed. It can also make porting/reverting specific changes easier when they are more focused.

In this case, we can leave it as-is since I see encode() was added in ROS 1 in #68, and I guess decode() was added accidentally during the port in #72 (independent of the ROS 1 change).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Yes, that's correct. Fixing an issue introduced accidentally.


# Truncate long representations
if len(obj_repr) >= 50:
Expand Down