本文整理汇总了Python中python_qt_binding.QtGui.QWidget.emit方法的典型用法代码示例。如果您正苦于以下问题:Python QWidget.emit方法的具体用法?Python QWidget.emit怎么用?Python QWidget.emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类python_qt_binding.QtGui.QWidget
的用法示例。
在下文中一共展示了QWidget.emit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QuestionDialogPlugin
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import emit [as 别名]
class QuestionDialogPlugin(Plugin):
def __init__(self, context):
super(QuestionDialogPlugin, self).__init__(context)
# Give QObjects reasonable names
self.setObjectName('QuestionDialogPlugin')
# Create QWidget
self._widget = QWidget()
self._widget.setFont(QFont("Times", 14, QFont.Bold))
self._layout = QVBoxLayout(self._widget)
self._text_browser = QTextBrowser(self._widget)
self._layout.addWidget(self._text_browser)
self._button_layout = QHBoxLayout()
self._layout.addLayout(self._button_layout)
# layout = QVBoxLayout(self._widget)
# layout.addWidget(self.button)
self._widget.setObjectName('QuestionDialogPluginUI')
if context.serial_number() > 1:
self._widget.setWindowTitle(self._widget.windowTitle() +
(' (%d)' % context.serial_number()))
context.add_widget(self._widget)
# Setup service provider
self.service = rospy.Service('question_dialog', QuestionDialog,
self.service_callback)
self.response_ready = False
self.response = None
self.buttons = []
self.text_label = None
self.text_input = None
self.connect(self._widget, SIGNAL("update"), self.update)
self.connect(self._widget, SIGNAL("timeout"), self.timeout)
def shutdown_plugin(self):
self.service.shutdown()
def service_callback(self, req):
self.response_ready = False
self.request = req
self._widget.emit(SIGNAL("update"))
# Start timer against wall clock here instead of the ros clock.
start_time = time.time()
while not self.response_ready:
if req.timeout != QuestionDialogRequest.NO_TIMEOUT:
current_time = time.time()
if current_time - start_time > req.timeout:
self._widget.emit(SIGNAL("timeout"))
return QuestionDialogResponse(
QuestionDialogRequest.TIMED_OUT, "")
time.sleep(0.2)
return self.response
def update(self):
self.clean()
req = self.request
self._text_browser.setText(req.message)
if req.type == QuestionDialogRequest.DISPLAY:
# All done, nothing more too see here.
self.response = QuestionDialogResponse(
QuestionDialogRequest.NO_RESPONSE, "")
self.response_ready = True
elif req.type == QuestionDialogRequest.CHOICE_QUESTION:
for index, options in enumerate(req.options):
button = QPushButton(options, self._widget)
button.clicked.connect(partial(self.handle_button, index))
self._button_layout.addWidget(button)
self.buttons.append(button)
elif req.type == QuestionDialogRequest.TEXT_QUESTION:
self.text_label = QLabel("Enter here: ", self._widget)
self._button_layout.addWidget(self.text_label)
self.text_input = QLineEdit(self._widget)
self.text_input.editingFinished.connect(self.handle_text)
self._button_layout.addWidget(self.text_input)
def timeout(self):
self._text_browser.setText("Oh no! The request timed out.")
self.clean()
def clean(self):
while self._button_layout.count():
item = self._button_layout.takeAt(0)
item.widget().deleteLater()
self.buttons = []
self.text_input = None
self.text_label = None
def handle_button(self, index):
self.response = QuestionDialogResponse(index, "")
self.clean()
self.response_ready = True
def handle_text(self):
self.response = QuestionDialogResponse(
QuestionDialogRequest.TEXT_RESPONSE,
self.text_input.text())
self.clean()
self.response_ready = True
#.........这里部分代码省略.........
示例2: MultiRobotPatrollerPlugin
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import emit [as 别名]
class MultiRobotPatrollerPlugin(Plugin):
def __init__(self, context):
super(MultiRobotPatrollerPlugin, self).__init__(context)
# Give QObjects reasonable names
self.setObjectName('MultiRobotPatrollerPlugin')
# Create QWidget
self.widget = QWidget()
self.master_layout = QVBoxLayout(self.widget)
self.buttons = []
self.button_layout = QHBoxLayout()
self.master_layout.addLayout(self.button_layout)
for button_text in ["Play", "Pause"]:
button = QPushButton(button_text, self.widget)
button.clicked[bool].connect(self.handle_button)
button.setCheckable(True)
self.button_layout.addWidget(button)
if button_text == "Pause":
button.setChecked(True)
self.buttons.append(button)
self.text_labels = {}
self.widget.setObjectName('MultiRobotPatrollerPluginUI')
if context.serial_number() > 1:
self.widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
context.add_widget(self.widget)
self.points = rospy.get_param("points")
self.flip_direction = rospy.get_param("flip_direction")
self.available_robots = []
self.global_start_counter = 0
self.global_forward = True
self.available_robot_subscriber = rospy.Subscriber("/available_robots", AvailableRobotArray,
self.available_robot_callback)
self.robot_goals = {}
self.paused = True
self.connect(self.widget, SIGNAL("update"), self.update)
def navigate_robot(self, robot_name, start_counter, forward):
client = actionlib.SimpleActionClient('/' + robot_name + '/move_base_interruptable', MoveBaseAction)
resolved_frame = '/' + robot_name + '/level_mux/map'
# Waits until the action server has started up and started
# listening for goals.
while not rospy.is_shutdown():
if client.wait_for_server(rospy.Duration(1)):
break
counter = start_counter
failures = 0
while not rospy.is_shutdown():
# Creates a goal to send to the action server.
if not self.paused:
goal = MoveBaseGoal()
goal.target_pose.header.frame_id = resolved_frame
goal.target_pose.header.stamp = rospy.get_rostime()
goal.target_pose.pose.position.x = self.points[counter][0]
goal.target_pose.pose.position.y = self.points[counter][1]
goal.target_pose.pose.position.z = 0.0
q = tf.transformations.quaternion_from_euler(0, 0, self.points[counter][2])
goal.target_pose.pose.orientation = Quaternion(*q)
# Sends the goal to the action server.
client.send_goal(goal)
self.robot_goals[robot_name] = counter
self.widget.emit(SIGNAL("update"))
# Waits for the server to finish performing the action.
while not rospy.is_shutdown():
if client.wait_for_result(rospy.Duration(1)):
break
elif self.paused:
client.cancel_goal()
break
if client.get_state() == GoalStatus.SUCCEEDED or failures >= 3:
failures = 0
if forward:
counter = (counter + 1) % len(self.points)
else:
counter = counter - 1
if counter < 0:
counter = len(self.points) - 1
else:
# Try the goal again after given seconds
time.sleep(3.0)
failures += 1
else:
time.sleep(1.0)
def available_robot_callback(self, msg):
#.........这里部分代码省略.........
示例3: RqtSrVisualServoing
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import emit [as 别名]
class RqtSrVisualServoing(Plugin):
def __init__(self, context):
super(RqtSrVisualServoing, self).__init__(context)
# Give QObjects reasonable names
self.setObjectName('RqtSrVisualServoing')
# # 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.ui = QWidget()
# Get path to UI file which is in our packages resource directory
rp = rospkg.RosPack()
self.ui_file = os.path.join(rp.get_path(PKG), 'resource', 'gui.ui')
# Extend the widget with all attributes and children from UI file
loadUi(self.ui_file, self.ui)
# Give QObjects reasonable names
self.ui.setObjectName('RqtSrVisualServoingUi')
# Show ui.windowTitle on left-top of each plugin (when it's set in ui).
# 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.ui.setWindowTitle(self.ui.windowTitle() + (' (%d)' % context.serial_number()))
# Wire up the buttons
self.ui.startBtn.clicked.connect( self.start_clicked )
self.ui.stopBtn.clicked.connect( self.stop_clicked )
# Annoyingly setting the icon theme in designer only works in designer,
# we have to set it again here for it to work at run time
self.ui.startBtn.setIcon(QIcon.fromTheme('media-playback-start'))
self.ui.stopBtn.setIcon(QIcon.fromTheme('media-playback-stop'))
# Add widget to the user interface
context.add_widget(self.ui)
# Setup a model for the feedback and link to the view.
self.feedback_model = QStandardItemModel(0,2)
self.feedback_model.setHorizontalHeaderLabels(['Name','Value'])
self.ui.feedbackView.setModel(self.feedback_model)
self.ui.connect( self.ui, SIGNAL('feedback(QString)'), self.update_feedback )
# ROS setup
self.last_feedback = None
self.client = actionlib.SimpleActionClient('visual_servo', VisualServoingAction)
msg = ""
if self.client.wait_for_server(rospy.Duration(2.0)):
msg = "Found action server, servoing appears to be running"
rospy.loginfo(msg)
else:
msg = "Can't find action server, servoing not running"
rospy.logerr(msg)
self.ui.statusValue.setText(msg)
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 in to signal that the plugin has a way to configure it
# Usually used to open a configuration dialog
def start_clicked(self):
goal = VisualServoingActionGoal()
self.client.send_goal(goal, feedback_cb = self._feedback_cb)
self.ui.statusValue.setText("Starting")
def stop_clicked(self):
self.client.cancel_all_goals()
self.ui.statusValue.setText("Stopped")
self.feedback_model.clear()
def _feedback_cb(self, feedback):
# We can't update the UI in this thread so stash the data and emit a
# signal that can be traped by the main thread and update the ui.
self.last_feedback = feedback
self.ui.emit( SIGNAL('feedback(QString)'), "" )
def update_feedback(self, data):
#.........这里部分代码省略.........
示例4: MultiRobotPasserGUIPlugin
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import emit [as 别名]
class MultiRobotPasserGUIPlugin(Plugin):
def __init__(self, context):
super(MultiRobotPasserGUIPlugin, self).__init__(context)
# Give QObjects reasonable names
self.setObjectName('MultiRobotPasserGUIPlugin')
# Create QWidget
self.widget = QWidget()
self.master_layout = QVBoxLayout(self.widget)
self.buttons = {}
self.button_layout = QHBoxLayout()
self.master_layout.addLayout(self.button_layout)
for button_text in ["Enable", "Disable"]:
button = QPushButton(button_text, self.widget)
button.clicked[bool].connect(self.handle_button)
button.setCheckable(True)
self.button_layout.addWidget(button)
self.buttons[button_text] = button
self.widget.setObjectName('MultiRobotPasserGUIPluginUI')
if context.serial_number() > 1:
self.widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
context.add_widget(self.widget)
self.status_subscriber = rospy.Subscriber("status", Bool, self.status_callback)
self.enable = rospy.ServiceProxy("enable", Empty)
self.disable = rospy.ServiceProxy("disable", Empty)
self.enabled = False
self.connect(self.widget, SIGNAL("update"), self.update)
def status_callback(self, msg):
self.enabled = msg.data
self.widget.emit(SIGNAL("update"))
def update(self):
if self.enabled:
self.buttons["Enable"].setChecked(True)
self.buttons["Disable"].setChecked(False)
else:
self.buttons["Enable"].setChecked(False)
self.buttons["Disable"].setChecked(True)
def handle_button(self):
source = self.sender()
if ((source.text() == "Enable" and self.enabled) or
(source.text() == "Disable" and not self.enabled)):
source.setChecked(True)
return
for _,button in self.buttons.iteritems():
if button != source:
button.setChecked(False)
# Call appropriate service here.
if source.text() == "Enable":
self.enable()
else:
self.disable()
def save_settings(self, plugin_settings, instance_settings):
pass
def restore_settings(self, plugin_settings, instance_settings):
pass
示例5: LevelSelectorPlugin
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import emit [as 别名]
class LevelSelectorPlugin(Plugin):
def __init__(self, context):
super(LevelSelectorPlugin, self).__init__(context)
# Give QObjects reasonable names
self.setObjectName('LevelSelectorPlugin')
# Create QWidget
self._widget = QWidget()
# self._widget.setFont(QFont("Times", 15, QFont.Bold))
self._button_layout = QVBoxLayout(self._widget)
self.buttons = []
self.text_label = QLabel("Waiting for MultiLevelMapData...", self._widget)
self._button_layout.addWidget(self.text_label)
self._widget.setObjectName('LevelSelectorPluginUI')
if context.serial_number() > 1:
self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
context.add_widget(self._widget)
self.connect(self._widget, SIGNAL("update_buttons"), self.update_buttons)
self.connect(self._widget, SIGNAL("update_button_status"), self.update_button_status)
# Subcribe to the multi level map data to get information about all the maps.
self.multimap_subscriber = rospy.Subscriber("map_metadata", MultiLevelMapData, self.process_multimap)
self.levels = []
self.current_level = None
# Subscribe to the current level we are on.
self.status_subscriber = None
# Create a service proxy to change the current level.
self.level_selector_proxy = rospy.ServiceProxy("level_mux/change_current_level", ChangeCurrentLevel)
self.level_selector_proxy.wait_for_service()
def process_multimap(self, msg):
self.levels = msg.levels
self._widget.emit(SIGNAL("update_buttons"))
def update_buttons(self):
self.clean()
for index, level in enumerate(self.levels):
self.text_label.setText("Choose Level: ")
button = QPushButton(level.level_id, self._widget)
button.clicked[bool].connect(self.handle_button)
button.setCheckable(True)
self._button_layout.addWidget(button)
self.buttons.append(button)
# Subscribe to the current level we are on.
if self.status_subscriber is None:
self.status_subscriber = rospy.Subscriber("level_mux/current_level", LevelMetaData, self.process_level_status)
def update_button_status(self):
for index, level in enumerate(self.levels):
if self.current_level == level.level_id:
self.buttons[index].setChecked(True)
else:
self.buttons[index].setChecked(False)
def process_level_status(self, msg):
level_found = False
for level in self.levels:
if msg.level_id == level.level_id:
self.current_level = level.level_id
level_found = True
break
if not level_found:
self.current_level = None
self._widget.emit(SIGNAL("update_button_status"))
def handle_button(self):
source = self.sender()
if source.text() == self.current_level:
source.setChecked(True)
return
# Construct a identity pose. The level selector cannot be used to choose the initialpose, as it does not have
# the interface for specifying the position. The position should be specified via rviz.
origin_pose = PoseWithCovarianceStamped()
origin_pose.header.frame_id = frameIdFromLevelId(source.text())
origin_pose.pose.pose.orientation.w = 1 # Makes the origin quaternion valid.
origin_pose.pose.covariance[0] = 1.0
origin_pose.pose.covariance[7] = 1.0
origin_pose.pose.covariance[14] = 1.0
origin_pose.pose.covariance[21] = 1.0
origin_pose.pose.covariance[28] = 1.0
origin_pose.pose.covariance[35] = 1.0
# Don't actually publish the initial pose via the level selector. It doesn't know any better.
self.level_selector_proxy(source.text(), False, origin_pose)
def clean(self):
while self._button_layout.count():
item = self._button_layout.takeAt(0)
item.widget().deleteLater()
def save_settings(self, plugin_settings, instance_settings):
#.........这里部分代码省略.........