time_filter_widget.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 from datetime import datetime
00034 import os
00035 
00036 from python_qt_binding import loadUi
00037 from python_qt_binding.QtCore import QDateTime
00038 from python_qt_binding.QtGui import QWidget
00039 
00040 
00041 class TimeFilterWidget(QWidget):
00042     def __init__(self, parentfilter, display_list_args):
00043         """
00044         Widget for displaying interactive data related to time filtering.
00045         :param parentfilter: buddy filter were data is stored, ''TimeFilter''
00046         :param display_list_args: single element list containing one tuple with
00047         the min and max time to be displayed, ''list of tuple''
00048         """
00049         super(TimeFilterWidget, self).__init__()
00050         ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'time_filter_widget.ui')
00051         loadUi(ui_file, self)
00052         self.setObjectName('TimeFilterWidget')
00053         self._parentfilter = parentfilter  # When data is changed it is stored in the parent filter
00054 
00055         self.start_datetime.dateTimeChanged[QDateTime].connect(self.handle_start_changed)
00056         self.stop_datetime.dateTimeChanged[QDateTime].connect(self.handle_stop_changed)
00057         self.stop_enabled_check_box.clicked[bool].connect(self.handle_stop_enabled_changed)
00058 
00059         # Times are passed in unixtimestamp '.' decimal fraction of a second
00060         mintime, maxtime = display_list_args[0]()
00061         if mintime != -1:
00062             mintime = str(mintime).split('.')
00063             maxtime = str(maxtime).split('.')
00064 
00065             time = QDateTime()
00066             time.setTime_t(int(mintime[0]))
00067             mintime = time.addMSecs(int(str(mintime[1]).zfill(9)[:3]))
00068             self.start_datetime.setDateTime(mintime)
00069             time.setTime_t(int(maxtime[0]))
00070             maxtime = time.addMSecs(int(str(maxtime[1]).zfill(9)[:3]))
00071             self.stop_datetime.setDateTime(maxtime)
00072         else:
00073             self.start_datetime.setDateTime(datetime.now())
00074             self.stop_datetime.setDateTime(datetime.now())
00075 
00076     def handle_start_changed(self, datetime_):
00077         self._parentfilter.set_start_time(datetime_)
00078 
00079     def handle_stop_changed(self, datetime_):
00080         self._parentfilter.set_stop_time(datetime_)
00081 
00082     def handle_stop_enabled_changed(self, checked):
00083         self._parentfilter.set_stop_time_enabled(checked)
00084         self.stop_datetime.setEnabled(checked)
00085 
00086     def repopulate(self):
00087         """
00088         Stub function.
00089         If the widget had any dynamically adjustable data it would requery it
00090         in this function.
00091         """
00092         pass
00093 
00094     def save_settings(self, settings):
00095         """
00096         Saves the settings for this filter to an ini file.
00097         :param settings: used to write the settings to an ini file ''qt_gui.settings.Settings''
00098         """
00099         settings.set_value('start_time', self._parentfilter._start_time.toString('hh:mm:ss.zzz (yyyy-MM-dd)'))
00100         settings.set_value('stop_time', self._parentfilter._stop_time.toString('hh:mm:ss.zzz (yyyy-MM-dd)'))
00101         settings.set_value('stop_time_enabled', self._parentfilter._stop_time_enabled)
00102 
00103     def restore_settings(self, settings):
00104         """
00105         Restores the settings for this filter from an ini file.
00106         :param settings: used to extract the settings from an ini file ''qt_gui.settings.Settings''
00107         """
00108         self.handle_stop_enabled_changed(settings.value('stop_time_enabled') in [True, 'true'])
00109         if settings.contains('start_time'):
00110             self.handle_start_changed(QDateTime.fromString(settings.value('start_time'), 'hh:mm:ss.zzz (yyyy-MM-dd)'))
00111         else:
00112             self.handle_start_changed(QDateTime(datetime.now()))
00113         if settings.contains('stop_time'):
00114             self.handle_stop_changed(QDateTime.fromString(settings.value('stop_time'), 'hh:mm:ss.zzz (yyyy-MM-dd)'))
00115         else:
00116             self.handle_stop_changed(QDateTime(datetime.now()))
00117 
00118         self.stop_datetime.setDateTime(self._parentfilter._stop_time)
00119         self.start_datetime.setDateTime(self._parentfilter._start_time)
00120         self.stop_enabled_check_box.setChecked(self._parentfilter._stop_time_enabled)


rqt_console
Author(s): Aaron Blasdel
autogenerated on Fri Jan 3 2014 11:54:30