time_filter_widget.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 from datetime import datetime
34 import os
35 import rospkg
36 
37 from python_qt_binding import loadUi
38 from python_qt_binding.QtCore import QDateTime
39 from python_qt_binding.QtWidgets import QWidget
40 
41 
42 class TimeFilterWidget(QWidget):
43 
44  def __init__(self, parentfilter, rospack, time_range_provider):
45  """
46  Widget for displaying interactive data related to time filtering.
47  :param parentfilter: buddy filter were data is stored, ''TimeFilter''
48  :param display_list_args: single element list containing one tuple with
49  the min and max time to be displayed, ''list of tuple''
50  """
51  super(TimeFilterWidget, self).__init__()
52  ui_file = os.path.join(
53  rospack.get_path('rqt_console'), 'resource/filters', 'time_filter_widget.ui')
54  loadUi(ui_file, self)
55  self.setObjectName('TimeFilterWidget')
56  self._parentfilter = parentfilter # When data is changed it is stored in the parent filter
57 
58  self.start_datetime.dateTimeChanged[QDateTime].connect(self.handle_start_changed)
59  self.stop_datetime.dateTimeChanged[QDateTime].connect(self.handle_stop_changed)
60  self.stop_enabled_check_box.clicked[bool].connect(self.handle_stop_enabled_changed)
61 
62  # Times are passed in unixtimestamp '.' decimal fraction of a second
63  mintime, maxtime = time_range_provider()
64  if mintime != -1:
65  mintime = str(mintime).split('.')
66  maxtime = str(maxtime).split('.')
67 
68  time = QDateTime()
69  time.setTime_t(int(mintime[0]))
70  mintime = time.addMSecs(int(str(mintime[1]).zfill(9)[:3]))
71  self.start_datetime.setDateTime(mintime)
72  time.setTime_t(int(maxtime[0]))
73  maxtime = time.addMSecs(int(str(maxtime[1]).zfill(9)[:3]))
74  self.stop_datetime.setDateTime(maxtime)
75  else:
76  self.start_datetime.setDateTime(datetime.now())
77  self.stop_datetime.setDateTime(datetime.now())
78 
79  def handle_start_changed(self, datetime_):
80  self._parentfilter.set_start_time(datetime_)
81 
82  def handle_stop_changed(self, datetime_):
83  self._parentfilter.set_stop_time(datetime_)
84 
85  def handle_stop_enabled_changed(self, checked):
86  self._parentfilter.set_stop_time_enabled(checked)
87  self.stop_datetime.setEnabled(checked)
88 
89  def repopulate(self):
90  """
91  Stub function.
92  If the widget had any dynamically adjustable data it would requery it
93  in this function.
94  """
95  pass
96 
97  def save_settings(self, settings):
98  """
99  Saves the settings for this filter to an ini file.
100  :param settings: used to write the settings to an ini file ''qt_gui.settings.Settings''
101  """
102  settings.set_value(
103  'start_time', self._parentfilter._start_time.toString('hh:mm:ss.zzz (yyyy-MM-dd)'))
104  settings.set_value(
105  'stop_time', self._parentfilter._stop_time.toString('hh:mm:ss.zzz (yyyy-MM-dd)'))
106  settings.set_value('stop_time_enabled', self._parentfilter._stop_time_enabled)
107 
108  def restore_settings(self, settings):
109  """
110  Restores the settings for this filter from an ini file.
111  :param settings: used to extract the settings from an ini file ''qt_gui.settings.Settings''
112  """
113  self.handle_stop_enabled_changed(settings.value('stop_time_enabled') in [True, 'true'])
114  if settings.contains('start_time'):
116  QDateTime.fromString(settings.value('start_time'), 'hh:mm:ss.zzz (yyyy-MM-dd)'))
117  else:
118  self.handle_start_changed(QDateTime(datetime.now()))
119  if settings.contains('stop_time'):
120  self.handle_stop_changed(
121  QDateTime.fromString(settings.value('stop_time'), 'hh:mm:ss.zzz (yyyy-MM-dd)'))
122  else:
123  self.handle_stop_changed(QDateTime(datetime.now()))
124 
125  self.stop_datetime.setDateTime(self._parentfilter._stop_time)
126  self.start_datetime.setDateTime(self._parentfilter._start_time)
127  self.stop_enabled_check_box.setChecked(self._parentfilter._stop_time_enabled)
def __init__(self, parentfilter, rospack, time_range_provider)


rqt_console
Author(s): Aaron Blasdel
autogenerated on Sun May 24 2020 03:23:49