def add_item_to_conversation_view(self, msg, type=0): label_msg = QLabel(msg) label_msg.setWordWrap(True) label_msg.setStyleSheet('font-size:10pt;') inner_text_layout = QHBoxLayout() horizonalSpacer1 = QSpacerItem(0, 0, QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) if type == 0: inner_text_layout.addWidget(label_msg) inner_text_layout.addItem(horizonalSpacer1) elif type == 1: inner_text_layout.addItem(horizonalSpacer1) inner_text_layout.addWidget(label_msg) inner_layout = QVBoxLayout() time_msg = QLabel(str(time.asctime(time.localtime(time.time())))) time_msg.setStyleSheet('font-size:8pt;') inner_layout.addItem(inner_text_layout) inner_layout.addWidget(time_msg) inner_layout.setSizeConstraint(QLayout.SetFixedSize) outer_layout = QHBoxLayout() horizonalSpacer2 = QSpacerItem(0, 0, QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) if type == 0: label_msg.setStyleSheet( 'background: #e5e5ea; padding: 6px; border-radius: 8px;') time_msg.setAlignment(Qt.AlignLeft) outer_layout.addItem(inner_layout) outer_layout.addItem(horizonalSpacer2) elif type == 1: label_msg.setStyleSheet( 'background: #1d86f4; padding: 6px; border-radius: 8px; color:#fff;' ) time_msg.setAlignment(Qt.AlignRight) outer_layout.addItem(horizonalSpacer2) outer_layout.addItem(inner_layout) outer_layout.setSizeConstraint(QLayout.SetMinimumSize) widget = QWidget() widget.setLayout(outer_layout) widget.resize(widget.sizeHint()) item = QListWidgetItem() item.setSizeHint(widget.sizeHint()) self._widget.listWidget.addItem(item) self._widget.listWidget.setItemWidget(item, widget) self._widget.listWidget.scrollToBottom()
def __init__(self, context): #Start client -rosbridge self.client = roslibpy.Ros(host='localhost', port=5803) self.client.run() super(Dashboard, self).__init__(context) # Give QObjects reasonable names self.setObjectName('Dashboard') # 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 should be in the "resource" folder of this package ui_file = os.path.join(rospkg.RosPack().get_path('rqt_dashboard'), 'resource', 'Dashboard.ui') # Extend the widget with all attributes and children from UI file loadUi(ui_file, self._widget) # Give QObjects reasonable names self._widget.setObjectName('DashboardUi') # Set up signal-slot connections self._widget.set_imu_angle_button.clicked.connect(self.setImuAngle) self._widget.imu_angle.valueChanged.connect(self.imuAngleChanged) self._widget.auto_wall_dist_button.clicked.connect(self.setAutoWallDist) self._widget.auto_wall_dist.valueChanged.connect(self.autoWallDistChanged) self._widget.ball_reset_button.clicked.connect(self.resetBallCount) self._widget.ball_reset_count.valueChanged.connect(self.resetBallChanged) # Add buttons for auto modes v_layout = self._widget.auto_mode_v_layout #vertical layout storing the buttons self.auto_mode_button_group = QButtonGroup(self._widget) # needs to be a member variable so the publisher can access it to see which auto mode was selected # Search for auto_mode config items for i in range(1,100): # loop will exit when can't find the next auto mode, so really only a while loop needed, but exiting at 100 will prevent infinite looping if rospy.has_param("/auto/auto_mode_" + str(i)): auto_sequence = rospy.get_param("/auto/auto_mode_" + str(i)) new_auto_mode = QWidget() new_h_layout = QHBoxLayout() new_h_layout.setContentsMargins(0,0,0,0) new_button = QRadioButton("Mode " + str(i)) new_button.setStyleSheet("font-weight: bold") self.auto_mode_button_group.addButton(new_button, i) #second arg is the button's id new_h_layout.addWidget( new_button ) new_h_layout.addWidget( QLabel(", ".join(auto_sequence)) ) hSpacer = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum) new_h_layout.addItem(hSpacer) new_auto_mode.setLayout( new_h_layout ) v_layout.addWidget(new_auto_mode) else: print(str(i-1) + " auto modes found.") # if no auto modes found, inform the user with a label if (i-1) == 0: v_layout.addWidget( QLabel("No auto modes found") ) break #break out of for loop searching for auto modes # auto state stuff self.autoState = 0 self.displayAutoState() #display initial auto state # publish thread publish_thread = Thread(target=self.publish_thread) #args=(self,)) publish_thread.start() # number balls display self.zero_balls = QPixmap(":/images/0_balls.png") self.one_ball = QPixmap(":/images/1_ball.png") self.two_balls = QPixmap(":/images/2_balls.png") self.three_balls = QPixmap(":/images/3_balls.png") self.four_balls = QPixmap(":/images/4_balls.png") self.five_balls = QPixmap(":/images/5_balls.png") self.more_than_five_balls = QPixmap(":/images/more_than_5_balls.png") self.n_balls = -1 #don't know n balls at first #in range stuff self.shooter_in_range = False self.turret_in_range = False self.in_range_pixmap = QPixmap(":/images/GreenTarget.png") self.not_in_range_pixmap = QPixmap(":/images/RedTarget.png") self._widget.in_range_display.setPixmap(self.not_in_range_pixmap) # 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) #initialize subscribers last, so that any callbacks they execute won't interfere with init auto_state_listener = roslibpy.Topic(self.client, '/auto/auto_state', 'behavior_actions/AutoState') self.auto_state_sub = auto_state_listener.subscribe(self.autoStateCallback) n_balls_listener = roslibpy.Topic(self.client,'/num_powercells','std_msgs/UInt8') self.n_balls_sub = n_balls_listener.subscribe(self.nBallsCallback) shooter_in_range_listener = roslibpy.Topic(self.client, '/shooter/shooter_in_range', std_msgs.msg.Bool) self.shooter_in_range_sub = shooter_in_range_listener.subscribe(self.shooterInRangeCallback) turret_in_range_listener = roslibpy.Topic(self.client, '/align_to_shoot/turret_in_range', std_msgs.msg.Bool) self.turret_in_range_sub = turret_in_range_listener.subscribe(self.turretInRangeCallback) self.autoStateSignal.connect(self.autoStateSlot) self.nBallsSignal.connect(self.nBallsSlot) self.shooterInRangeSignal.connect(self.shooterInRangeSlot) self.turretInRangeSignal.connect(self.turretInRangeSlot)