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 process(self, action): """ :param action: action to execute, ''QAction'' :raises: when it doesn't recognice the action passed in, ''Exception'' """ if action == self._reset_timeline: self.timeline._timeline_frame.reset_timeline() elif action == self._play_all: self.timeline.toggle_play_all() elif action == self._publish_all: for topic in self.timeline._timeline_frame.topics: if not self.timeline.start_publishing(topic): break elif action == self._publish_none: for topic in self.timeline._timeline_frame.topics: if not self.timeline.stop_publishing(topic): break elif action == self._thumbnail_show_action: self.timeline._timeline_frame.set_renderers_active(True) elif action == self._thumbnail_hide_action: self.timeline._timeline_frame.set_renderers_active(False) elif action in self._thumbnail_actions: if self.timeline._timeline_frame.is_renderer_active(action.text()): self.timeline._timeline_frame.set_renderer_active( action.text(), False) else: self.timeline._timeline_frame.set_renderer_active( action.text(), True) elif action in self._topic_actions + self._type_actions: popup_name = action.parentWidget().title() + '__' + action.text() if popup_name not in self.timeline.popups: frame = QWidget() layout = QVBoxLayout() frame.setLayout(layout) frame.resize(640, 480) viewer_type = action.data() frame.setObjectName(popup_name) view = viewer_type(self.timeline, frame) self.timeline.popups.add(popup_name) self.timeline.get_context().add_widget(frame) self.timeline.add_view(action.parentWidget().title(), view, frame) frame.show() elif action in self._publish_actions: if self.timeline.is_publishing(action.text()): self.timeline.stop_publishing(action.text()) else: self.timeline.start_publishing(action.text()) else: raise Exception('Unknown action in TimelinePopupMenu.process')