I am not able to run my python ros file which is in the form of qtdesigner4 and also I am not getting any error and the problem is my widget is not getting launched

asked 2019-03-15 01:52:57 -0600

Samudrala Naveen gravatar image

updated 2019-03-15 04:14:23 -0600

#!/usr/bin/python import os import rospkg import rospy

from dof_pkg.msg import arm_msgs

from qt_gui.plugin import Plugin from python_qt_binding import loadUi from python_qt_binding.QtCore import Qt, QTimer, Slot from python_qt_binding.QtGui import QKeySequence from python_qt_binding.QtWidgets import QWidget

class dof(Plugin): slider_factor = 0.55 global var1 var1=None global var2 var2=None global var3 var3=None global var4 var4=None global var5 var5=None global dof6 var6=None global dofstrvalues

global dof_val


#global var1

#global var2

#global var3

#global var4

#global var5

#global var6

def __init__(self, context):
    super(dof, self).__init__(context)
    # Give QObjects reasonable names
    self.setObjectName('dof')
    rp = rospkg.RosPack()

    # Process standalone plugin command-line arguments
    from argparse import ArgumentParser
    parser = ArgumentParser()
    # Add argument(s) to the parser.
    parser.add_argument("-q", "--quiet", action="store_true",
                  dest="quiet",
                  help="Put plugin in silent mode")
    args, unknowns = parser.parse_known_args(context.argv())
    if not args.quiet:
        print ('arguments: ', args)
        print ('unknowns: ', unknowns)

    # Create QWidget
    self._widget = QWidget()
    # Get path to UI file which is a sibling of this file
    # in this example the .ui and .py file are in the same folder
    ui_file = os.path.join(rp.get_path('dof_pkg'), 'resource', 'dofgui.ui')
    # Extend the widget with all attributes and children from UI file
    loadUi(ui_file, self._widget)
    # Give QObjects reasonable names
    self._widget.setObjectName('MyPluginUi')
    # Show _widget.windowTitle on left-top of each plugin (when 
    # it's set in _widget). This is useful when you open multiple 
    # plugins at once. Also if you open multiple instances of your 
    # plugin at once, these lines add number to make it easy to 
    # tell from pane to pane.
    if context.serial_number() > 1:
        self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
    # Add widget to the user interface
    context.add_widget(self._widget)
    self._widget.pushButton.pressed.connect(self._on_button_clicked)
    self._widget.dof1_line.textChanged.connect(self._on_dof1_changed)
    self._widget.dof2_line.textChanged.connect(self._on_dof2_changed)
    self._widget.dof3_line.textChanged.connect(self._on_dof3_changed)
    self._widget.dof4_line.textChanged.connect(self._on_dof4_changed)
    self._widget.dof5_line.textChanged.connect(self._on_dof5_changed)
    self._widget.dof6_line.textChanged.connect(self._on_dof6_changed)
    #self._update_parameter_timer = QTimer(self)
    #self._update_parameter_timer.timeout.connect(self._on_dof1_changed)
    #self._update_parameter_timer.timeout.connect(self._on_dof2_changed)
    #self._update_parameter_timer.start(100)
    #self.zero_cmd_sent = False


@Slot(str)
def _on_dof1_changed(self,dof1val):
    global var1
    var1 = int(dof1val)


def _on_dof2_changed(self,dof2val):
    global var2
    var2= int(dof2val)


def _on_dof3_changed(self,dof3val):
    global var3
    var3= int(dof3val)

def _on_dof4_changed(self,dof4val):
    global var4
    var4= int(dof4val)

def _on_dof5_changed(self,dof5val):
    global var5
    var5= int(dof5val)

def _on_dof6_changed(self,dof6val):
    global var6
    var6= int(dof6val)




def _on_button_clicked(self):
    global dof_val
    global dofstrvalues
    dofstrvalues = arm_msgs()

    dofstrvalues.dofvalues = [var1,var2,var3,var4,var5,var6]

    dof_val=(dofstrvalues)
    try:
        self._publisher = rospy.Publisher("test1", arm_msgs, queue_size=10)
    except TypeError:
        self._publisher = rospy.Publisher("test1", arm_msgs)
    self._publisher.publish(dof_val)


def shutdown_plugin(self):
    # TODO unregister all publishers here
    pass

def save_settings(self, plugin_settings, instance_settings):
    # TODO save intrinsic configuration, usually using:
    # instance_settings.set_value(k, v)
    pass

def restore_settings(self, plugin_settings, instance_settings):
    # TODO restore intrinsic configuration, usually using:
    # v = instance_settings.value(k)
    pass

#def trigger_configuration(self):
    # Comment ...
(more)
edit retag flag offensive close merge delete