rqt_plugin_meta.py
Go to the documentation of this file.
00001 '''
00002 Created on Sep 10, 2013
00003  \todo Add license information here
00004 @author: dnad
00005 '''
00006 import os
00007 
00008 from qt_gui.plugin import Plugin
00009 from python_qt_binding import loadUi, QtCore
00010 
00011 class RqtPluginMeta(Plugin):
00012     def __init__(self, 
00013                  context, 
00014                  name,
00015                  GuiT, 
00016                  RosT, 
00017                  resource = ""
00018                  ):
00019         super(RqtPluginMeta, self).__init__(context)
00020         # Give QObjects reasonable names
00021         self.setObjectName(name)
00022         
00023         if resource == "": resource=_resource(name, file)      
00024         # Process standalone plugin command-line arguments
00025         from argparse import ArgumentParser
00026         parser = ArgumentParser()
00027         # Add argument(s) to the parser.
00028         parser.add_argument("-q", "--quiet", action="store_true",
00029                       dest="quiet",
00030                       help="Put plugin in silent mode")
00031         args, unknowns = parser.parse_known_args(context.argv())
00032         if not args.quiet:
00033             print "arguments: ", args
00034             print "unknowns: ", unknowns
00035 
00036         # Create QWidget
00037         self._gui = GuiT()
00038         self._ros = RosT()
00039 
00040         # Extend the widget with all attributes and children from UI file
00041         loadUi(resource, self._gui)
00042         # Give QObjects reasonable names
00043         self._ros.setup(self._gui)
00044         self._gui.setup(name + "Rqt", self._ros)
00045         
00046         # Show _widget.windowTitle on left-top of each plugin (when 
00047         # it's set in _widget). This is useful when you open multiple 
00048         # plugins at once. Also if you open multiple instances of your 
00049         # plugin at once, these lines add number to make it easy to 
00050         # tell from pane to pane.
00051         if context.serial_number() > 1:
00052             self._widget.setWindowTitle(self._widget.windowTitle() + 
00053                                         (" (%d)" % context.serial_number()))
00054         # Add widget to the user interface
00055         context.add_widget(self._gui)      
00056 
00057     def shutdown_plugin(self):
00058         # TODO unregister all publishers here
00059         self._gui.unload();
00060         self._ros.unload()
00061         pass
00062 
00063     def save_settings(self, plugin_settings, instance_settings):
00064         # TODO save intrinsic configuration, usually using:
00065         # instance_settings.set_value(k, v)
00066         pass
00067 
00068     def restore_settings(self, plugin_settings, instance_settings):
00069         # TODO restore intrinsic configuration, usually using:
00070         # v = instance_settings.value(k)
00071         pass
00072 
00073     #def trigger_configuration(self):
00074         # Comment in to signal that the plugin has a way to configure
00075         # This will enable a setting button (gear icon) in each dock widget title bar
00076         # Usually used to open a modal configuration dialog
00077         
00078 def _resource(name):
00079     return os.path.join(os.path.dirname(
00080                         os.path.realpath(__file__)), 
00081                         "resource", name+".ui")    
00082     
00083 def resource_rpath(name, file):
00084     return os.path.join(os.path.dirname(
00085                         os.path.realpath(file)), 
00086                         "resource/" + name + ".ui")             
00087         
00088 def launch_standalone(name,
00089                       GuiT, 
00090                       RosT, 
00091                       resource = ""):
00092     import rospy, os, sys
00093     import python_qt_binding as pyqt
00094     from python_qt_binding import QtGui
00095     app = QtGui.QApplication(sys.argv)
00096     rospy.init_node(name, sys.argv)
00097     gui = GuiT()
00098     ros = RosT()
00099     
00100     if resource == "": 
00101         resource = _resource(name)
00102     #Load the UI
00103     pyqt.loadUi(resource, gui)   
00104     #Connect the user interface and ROS
00105     ros.setup(gui)
00106     gui.setup(name, ros)
00107     #Start GUI
00108     gui.show()
00109     
00110     sys.exit(app.exec_())  


labust_gui
Author(s): Gyula Nagy
autogenerated on Sun Mar 1 2015 12:12:46