Go to the documentation of this file.00001
00002
00003 import sys
00004 from PyQt4 import QtCore, QtGui, uic
00005
00006 import roslib
00007 roslib.load_manifest("rospy")
00008 roslib.load_manifest("std_msgs")
00009 import rospy
00010 from std_msgs.msg import String
00011
00012 from arm_cart_control_gui import Ui_Frame as QTArmControlGUIFrame
00013 from arm_cart_control_backend import MOVE_BUTTONS, MONITOR_RATE, MOVE_STATE_TOPIC, LOAD_ARM_TOPIC
00014
00015 ARM_STYLESHEET = """image: url(:/resources/arm_%s_%s.png);
00016 background-image: url(:/resources/empty.png);"""
00017
00018 class ArmCartControlGUIFrame(QtGui.QFrame):
00019 def __init__(self):
00020 super(ArmCartControlGUIFrame, self).__init__()
00021
00022 self.move_state_pub = rospy.Publisher(MOVE_STATE_TOPIC, String)
00023 self.arm_state_pub = rospy.Publisher(LOAD_ARM_TOPIC, String)
00024
00025 self.cur_arm = "l"
00026 self.init_ui()
00027 self.arm_left_clk()
00028
00029 def init_ui(self):
00030 self.ui = QTArmControlGUIFrame()
00031 self.ui.setupUi(self)
00032
00033 self.ui.arm_left.clicked.connect(self.arm_left_clk)
00034 self.ui.arm_right.clicked.connect(self.arm_right_clk)
00035 self.monitor_timer = QtCore.QTimer(self)
00036 QtCore.QObject.connect(self.monitor_timer, QtCore.SIGNAL("timeout()"), self.monitor_cb)
00037 self.monitor_timer.start(MONITOR_RATE)
00038
00039 def monitor_cb(self):
00040 move_button = ""
00041 for button in MOVE_BUTTONS:
00042 exec("is_down = self.ui.%s.isDown()" % button)
00043 if is_down:
00044 move_button = button
00045 self.move_state_pub.publish(String(move_button))
00046 self.arm_state_pub.publish(String(self.cur_arm))
00047
00048 def arm_left_clk(self):
00049 self.ui.arm_left.setDisabled(True)
00050 self.ui.arm_right.setEnabled(True)
00051 self.ui.arm_left.setStyleSheet(ARM_STYLESHEET % ("left", "on"))
00052 self.ui.arm_right.setStyleSheet(ARM_STYLESHEET % ("right", "off"))
00053 self.cur_arm = "l"
00054
00055 def arm_right_clk(self):
00056 self.arm_state_pub.publish(String("r"))
00057 self.ui.arm_right.setDisabled(True)
00058 self.ui.arm_left.setEnabled(True)
00059 self.ui.arm_left.setStyleSheet(ARM_STYLESHEET % ("left", "off"))
00060 self.ui.arm_right.setStyleSheet(ARM_STYLESHEET % ("right", "on"))
00061 self.cur_arm = "r"
00062
00063 def main():
00064 rospy.init_node("arm_cart_control_interface")
00065 app = QtGui.QApplication(sys.argv)
00066 frame = ArmCartControlGUIFrame()
00067 frame.show()
00068 sys.exit(app.exec_())
00069
00070 if __name__ == "__main__":
00071 main()