def paintEvent(self, event): """Custom paint event""" painter = QtGui.QPainter() painter.begin(self) painter.setRenderHint(QtGui.QPainter.Antialiasing) w = self._width + 0.01 h = self._height + 0.01 factor = float(min((self.width(), self.height())) - common.MARGIN()) / max(float(w), float(h)) w *= factor h *= factor painter.setBrush(common.SEPARATOR) painter.setPen(QtCore.Qt.NoPen) painter.setOpacity(0.3) painter.drawRect(self.rect()) painter.setOpacity(1.0) rect = QtCore.QRect(0, 0, w, h) rect.moveCenter(self.rect().center()) # Outline painter.setOpacity(0.2) pen = QtGui.QPen(common.ADD) pen.setWidthF(common.ROW_SEPARATOR() * 2.0) pen.setStyle(QtCore.Qt.SolidLine) pen.setJoinStyle(QtCore.Qt.RoundJoin) painter.setPen(pen) painter.setBrush(QtCore.Qt.NoBrush) painter.drawRect(rect) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(common.ADD) painter.drawRect(rect) painter.setOpacity(1.0) painter.setPen(common.TEXT) font, metrics = common.font_db.primary_font( font_size=common.SMALL_FONT_SIZE()) painter.setFont(font) _rect = self.rect() _rect.setLeft(rect.left() + common.SMALL_FONT_SIZE()) text = u'{w}{h}{fps}{pre}{start}{duration}'.format( w=u'{}px'.format(int(self._width)) if self._width else u'', h=u' * {}px'.format(int(self._height)) if self._height else u'', fps=u' | {}fps'.format(self._fps) if self._fps else u'', pre=u'\n{}'.format(self._prefix) if self._prefix else u'', start=u'\nIn: {}'.format(int(self._start)) if self._start else u'', duration=u'\nOut: {}\nDuration: {}'.format( int(self._start) + int(self._duration), int(self._duration) if self._duration else u'') if self._duration else u'') painter.drawText( _rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter | QtCore.Qt.TextWordWrap, text if text else u'Bookmark not yet configured') painter.end()
def __initdata__(self): self.beginResetModel() self.INTERNAL_USER_DATA = common.DataDict() channels = self.client.get_channels() profiles = self.client.get_user_profiles() # Channels try: for channel in sorted(channels, key=lambda x: x['name']): idx = len(self.INTERNAL_USER_DATA) self.INTERNAL_USER_DATA[idx] = common.DataDict({ QtCore.Qt.DisplayRole: u'Channel: ' + channel['name'], QtCore.Qt.DecorationRole: QtGui.QIcon(), QtCore.Qt.SizeHintRole: self.row_size, QtCore.Qt.FontRole: common.font_db.primary_font( font_size=common.SMALL_FONT_SIZE())[0], IdRole: channel[u'id'], ThumbnailHashRole: None, ThumbnailUrlRole: None, }) except Exception as e: log.error(u'Could not get channels.') try: for profile in sorted(profiles, key=self.get_pretty_name): idx = len(self.INTERNAL_USER_DATA) self.INTERNAL_USER_DATA[idx] = common.DataDict({ QtCore.Qt.DisplayRole: self.get_pretty_name(profile), QtCore.Qt.DecorationRole: QtGui.QIcon(), QtCore.Qt.SizeHintRole: self.row_size, QtCore.Qt.FontRole: common.font_db.primary_font( font_size=common.SMALL_FONT_SIZE())[0], IdRole: profile[u'id'], ThumbnailHashRole: profile[u'profile']['avatar_hash'], ThumbnailUrlRole: profile[u'profile']['image_32'], }) index = self.index(idx, 0) self.get_icon(index) except Exception as e: log.error('Could not get profiles') self.endResetModel()
def __init__(self, parent=None): super(ThreadMonitor, self).__init__(parent=parent) self.timer = QtCore.QTimer(parent=self) self.timer.setInterval(500) self.timer.setSingleShot(False) self.timer.timeout.connect(self.update) self.metrics = common.font_db.primary_font(common.SMALL_FONT_SIZE())[1]
def paintEvent(self, event): painter = QtGui.QPainter() painter.begin(self) common.draw_aliased_text( painter, common.font_db.primary_font(common.SMALL_FONT_SIZE())[0], self.rect(), self.text(), QtCore.Qt.AlignCenter, common.ADD) painter.end()
def paintEvent(self, event): painter = QtGui.QPainter() painter.begin(self) font, metrics = common.font_db.secondary_font(common.SMALL_FONT_SIZE()) common.draw_aliased_text( painter, font, self.rect().marginsRemoved( QtCore.QMargins(common.INDICATOR_WIDTH(), 0, common.INDICATOR_WIDTH(), 0)), u' {} '.format(self.currentMessage()), QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft, common.TEXT) painter.end()
def add_row(label, parent=None, padding=common.MARGIN(), height=common.ROW_HEIGHT(), cls=None, vertical=False): """Utility method for creating a row widget. Returns: QWidget: row widget. """ if cls: w = cls(parent=parent) else: w = QtWidgets.QWidget(parent=parent) if vertical: QtWidgets.QVBoxLayout(w) else: QtWidgets.QHBoxLayout(w) w.layout().setContentsMargins(0, 0, 0, 0) w.layout().setSpacing(common.INDICATOR_WIDTH()) w.layout().setAlignment(QtCore.Qt.AlignCenter) w.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding, ) if height: w.setFixedHeight(height) w.setAttribute(QtCore.Qt.WA_NoBackground) w.setAttribute(QtCore.Qt.WA_TranslucentBackground) if label: l = PaintedLabel(label, size=common.SMALL_FONT_SIZE(), color=common.SECONDARY_TEXT, parent=parent) l.setFixedWidth(common.MARGIN() * 6.6667) l.setDisabled(True) if padding: w.layout().addSpacing(padding) w.layout().addWidget(l, 0) if parent: parent.layout().addWidget(w, 1) return w
def add_description(text, label=u' ', padding=common.MARGIN(), parent=None): """Utility method for adding a description field. Returns: QLabel: the added QLabel. """ row = add_row(label, padding=padding, height=None, parent=parent) label = QtWidgets.QLabel(text, parent=parent) label.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft) label.setStyleSheet( u'color: rgba({}); font-size: {}px'.format( common.rgb(common.SECONDARY_TEXT), common.SMALL_FONT_SIZE() ) ) label.setWordWrap(True) row.layout().addWidget(label, 1) parent.layout().addWidget(row) return label
def _create_UI(self): def get_row(vertical=False, parent=None): row = QtWidgets.QWidget(parent=parent) if vertical: QtWidgets.QVBoxLayout(row) else: QtWidgets.QHBoxLayout(row) row.layout().setContentsMargins(0, 0, 0, 0) row.layout().setSpacing(0) row.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding, ) parent.layout().addWidget(row) return row QtWidgets.QHBoxLayout(self) o = 0 self.layout().setContentsMargins(o, o, o, o) self.layout().setSpacing(o) main_row = get_row(parent=self) main_row.layout().setContentsMargins(0, 0, 0, 0) main_row.layout().setSpacing(0) columns = get_row(vertical=True, parent=main_row) columns.layout().setContentsMargins(0, 0, 0, 0) columns.layout().setSpacing(0) short_text_row = get_row(parent=columns) columns.layout().addWidget(short_text_row, 1) long_text_row = get_row(parent=columns) pixmap = images.ImageCache.get_rsc_pixmap( self.icon, self.secondary_color.lighter(150), common.ROW_HEIGHT()) label = QtWidgets.QLabel(parent=self) label.setPixmap(pixmap) label.setSizePolicy( QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding, ) label.setStyleSheet( u'padding: {}px; background-color: rgba({});'.format( common.MEDIUM_FONT_SIZE(), common.rgb(self.primary_color) ) ) main_row.layout().insertWidget(0, label) short_text_row.layout().addWidget(self.short_text_label) self.short_text_label.setStyleSheet( u'padding:{m}px {s}px {m}px {s}px; background-color: rgba({c}); font-size: {s}px;'.format( m=common.MARGIN(), c=common.rgb(self.secondary_color.lighter(125)), s=common.MEDIUM_FONT_SIZE() )) self.short_text_label.setAlignment(QtCore.Qt.AlignLeft) long_text_row.layout().addWidget(self.long_text_label) self.long_text_label.setStyleSheet( u'padding:{m}px;background-color: rgba({c}); font-size:{s}px;'.format( m=common.MARGIN(), c=common.rgb(self.secondary_color), s=common.SMALL_FONT_SIZE() )) self.long_text_label.setAlignment(QtCore.Qt.AlignLeft) buttons_row = get_row(parent=columns) buttons_row.setStyleSheet( u'background-color: rgba({});'.format(common.rgb(self.secondary_color))) self.ok_button = QtWidgets.QPushButton(u'Ok', parent=self) buttons_row.layout().addWidget(self.ok_button) self.ok_button.setStyleSheet( """ QPushButton {{ font-size: {px}px; color: rgba(255,255,255,150); border-radius: {i}px; border: {s}px solid {c}; margin: {i}px; padding: {i}px; background-color: rgba({p}); }} QPushButton:hover {{ color: white; background-color: rgba({pl}); }} QPushButton:pressed {{ color: rgba(255,255,255,150); background-color: rgba({pd}); }} """.format( px=common.SMALL_FONT_SIZE(), i=common.INDICATOR_WIDTH(), s=common.ROW_SEPARATOR(), c=common.rgb(self.secondary_color.lighter(150)), p=common.rgb(self.primary_color), pl=common.rgb(self.primary_color.lighter(120)), pd=common.rgb(self.primary_color.darker(120)) ) )
def _create_UI(self): import bookmarks label = common_ui.PaintedLabel(u'General Preferences', size=common.LARGE_FONT_SIZE(), parent=self) self.layout().addWidget(label) grp = common_ui.get_group(parent=self) row = common_ui.add_row(u'Frameless window', parent=grp) self.frameless_window = QtWidgets.QCheckBox(u'Use frameless window', parent=self) row.layout().addStretch(1) row.layout().addWidget(self.frameless_window) label = common_ui.PaintedLabel(u'(Restart required)', size=common.SMALL_FONT_SIZE(), color=common.TEXT_DISABLED) row.layout().addWidget(label, 0) if common.STANDALONE: row = common_ui.add_row(u'Scale interface', parent=grp) self.ui_scale = QtWidgets.QComboBox(parent=self) self.ui_scale.setFixedHeight(common.ROW_HEIGHT() * 0.66) for s in (u'100%', u'125%', u'150%', u'175%', u'200%'): self.ui_scale.addItem(s) idx = self.ui_scale.count() - 1 data = int(s.strip(u'%')) * 0.01 self.ui_scale.setItemData(idx, data, role=QtCore.Qt.UserRole) data = QtCore.QSize(1, common.ROW_HEIGHT() * 0.66) self.ui_scale.setItemData(idx, data, role=QtCore.Qt.SizeHintRole) row.layout().addWidget(self.ui_scale, 1) label = common_ui.PaintedLabel(u'(Restart required)', size=common.SMALL_FONT_SIZE(), color=common.TEXT_DISABLED) row.layout().addWidget(label, 0) ############################## row = common_ui.add_row(u'Update', parent=grp) self.check_updates = common_ui.PaintedButton(u'Check for Updates', parent=row) self.show_help = common_ui.PaintedButton(u'Help', parent=row) row.layout().addWidget(self.check_updates) row.layout().addWidget(self.show_help) row.layout().addStretch(1.0) ####################################################### row = common_ui.add_row(None, parent=self) label = common_ui.PaintedLabel(u'Shotgun RV', size=common.LARGE_FONT_SIZE(), parent=row) row.layout().addWidget(label) row.layout().addStretch(1) grp = common_ui.get_group(parent=self) row = common_ui.add_row(u'Path to RV', parent=grp) self.rv_path = common_ui.add_line_edit(u'eg. c:/rv/bin/rv.exe', parent=row) row.layout().addWidget(self.rv_path, 1) button = common_ui.PaintedButton(u'Pick') button.clicked.connect(self.pick_rv) row.layout().addWidget(button) button = common_ui.PaintedButton(u'Reveal') button.clicked.connect(lambda: common.reveal(self.rv_path.text())) row.layout().addWidget(button) text = \ u'You can use {} to push footage to Shotgun RV \ (<span style="color:rgba({});">CTRL+P)</span>. Select the RV executable for this to work.' .format( common.PRODUCT, common.rgb(common.ADD)) common_ui.add_description(text, label=u'Hint', parent=grp) ####################################################### label = common_ui.PaintedLabel(u'Shortcuts', size=common.LARGE_FONT_SIZE(), parent=self) self.layout().addWidget(label) grp = common_ui.get_group(parent=self) label = QtWidgets.QLabel(parent=self) s = u'<table width="100%">' def r(): return unicode('<tr>\ <td align="center" style="background-color:rgba(0,0,0,80);padding:{pad}px;">\ <span style="color:rgba({ADD});">{shortcut}</span>\ </td>\ <td align="left" style="background-color:rgba(0,0,0,30);padding:{pad}px;">\ <span style="color:rgba({TEXT});">{description}</span>\ </td>\ </tr>') for shortcut, description in ( (u'Ctrl+N', u'Open new {} instance'.format(common.PRODUCT)), (u'Enter', u'Activate item'), (u'Space', u'Preview thumbnail'), (u'Arrow Up/Down', u'Navigate list'), (u'Ctrl+R', u'Reload'), (u'Ctrl+F', u'Edit filter'), (u'Ctrl+O', u'Reveal in file manager'), (u'Ctrl+C', u'Copy path'), (u'Ctrl+Shift+C', u'Copy path (alt)'), (u'Ctrl+S', u'Save/remove favourite'), (u'Ctrl+A', u'Archive/enable'), (u'Ctrl+T', u'Show Notes & Todos'), (u'Ctrl+H', u'Hide buttons'), (u'Ctrl+M', u'Toggle thumbnail loading'), (u'Ctrl+Shift+A', u'Show/Hide archived items'), (u'Ctrl+Shift+F', u'Show favourites only/Show all'), (u'Tab', u'Edit item description'), (u'Shift+Tab', u'Edit item description'), (u'Alt+Left', u'Show previous tab'), (u'Alt+Right', u'Show next tab'), (u'Ctrl+1', u'Show bookmarks'), (u'Ctrl+2', u'Show assets'), (u'Ctrl+3', u'Show files'), (u'Ctrl+4', u'Show favourites'), (u'Ctrl+Plus', u'Increase row height'), (u'Ctrl+Minus', u'Decrease row height'), (u'Ctrl+0', u'Reset row height'), ): s += r().format( shortcut=shortcut, description=description, pad=int(common.INDICATOR_WIDTH() * 1.5), ADD=common.rgb(common.ADD), TEXT=common.rgb(common.SECONDARY_TEXT), ) s += u'</table>' label.setText(s) label.setWordWrap(True) grp.layout().addWidget(label) label = common_ui.PaintedLabel(u'About {}'.format(common.PRODUCT), size=common.LARGE_FONT_SIZE(), parent=grp) self.layout().addWidget(label) grp = common_ui.get_group(parent=self) o = common.MARGIN() grp.layout().setContentsMargins(o, o, o, o) # row = common_ui.add_row(u'Version', parent=grp, height=None) s = u'\n'.join(bookmarks.get_info()) common_ui.add_description(s, label=None, parent=grp) self.layout().addStretch(1)
def paint_name(self, *args): """Paints the name and the number of files available for the given data-key.""" rectangles, painter, option, index, selected, focused, active, archived, favourite, hover, font, metrics, cursor_position = args if not index.data(QtCore.Qt.DisplayRole): return if index.data(common.TodoCountRole): color = common.TEXT_SELECTED if hover else common.TEXT else: color = common.TEXT if hover else common.BACKGROUND_SELECTED color = common.TEXT_SELECTED if selected else color font = common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0] o = common.MARGIN() rect = QtCore.QRect(option.rect) if selected: pixmap = images.ImageCache.get_rsc_pixmap(u'check', common.ADD, o) _rect = QtCore.QRect(option.rect) _rect.setSize(pixmap.size()) _rect.moveCenter(option.rect.center()) _rect.moveLeft(option.rect.left() + ((o + common.INDICATOR_WIDTH()) * 0.5)) painter.drawPixmap(_rect, pixmap, pixmap.rect()) rect = rect.marginsRemoved(QtCore.QMargins(o * 2, 0, o, 0)) else: rect = rect.marginsRemoved(QtCore.QMargins(o, 0, o, 0)) text = index.data(QtCore.Qt.DisplayRole).upper() width = 0 width = common.draw_aliased_text( painter, font, rect, text, QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft, color) rect.setLeft(rect.left() + width) items = [] # Adding an indicator for the number of items in the folder if index.data(common.TodoCountRole): if index.data(common.TodoCountRole) >= 999: text = u'999+ items' else: text = u'{} items'.format(index.data(common.TodoCountRole)) color = common.TEXT_SELECTED if selected else common.FAVOURITE color = common.TEXT_SELECTED if hover else color items.append((text, color)) else: color = common.TEXT if selected else common.BACKGROUND color = common.TEXT if hover else color items.append((u'n/a', color)) if index.data(QtCore.Qt.ToolTipRole): color = common.TEXT_SELECTED if selected else common.TEXT color = common.TEXT_SELECTED if hover else color items.append((index.data(QtCore.Qt.ToolTipRole), color)) for idx, val in enumerate(items): text, color = val if idx == 0: align = QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft else: align = QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight width = common.draw_aliased_text( painter, common.font_db.secondary_font(common.SMALL_FONT_SIZE())[0], rect, u' | ', align, common.SEPARATOR) rect.setLeft(rect.left() + width) width = common.draw_aliased_text( painter, common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0], rect, text, align, color) rect.setLeft(rect.left() + width)
def _create_UI(self): """Creates the ui layout.""" QtWidgets.QVBoxLayout(self) o = common.MARGIN() self.layout().setSpacing(common.INDICATOR_WIDTH()) self.layout().setContentsMargins(o, o, o, o) # Top row height = common.ROW_HEIGHT() * 0.6666 row = common_ui.add_row(None, height=height, parent=self) row.layout().addSpacing(height * 0.33) def paintEvent(event): painter = QtGui.QPainter() painter.begin(row) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(QtGui.QColor(0, 0, 0, 255)) rect = row.rect() rect.setTop(rect.bottom()) painter.drawRect(rect) painter.end() # row.paintEvent = paintEvent # Thumbnail self.add_button = common_ui.ClickableIconButton( u'add', (common.ADD, common.ADD), height, description=u'Click to add a new Todo item...', parent=self) # Name label text = u'Notes and Tasks' label = common_ui.PaintedLabel(text, color=common.SEPARATOR, size=common.LARGE_FONT_SIZE(), parent=self) row.layout().addWidget(label, 1) row.layout().addStretch(1) self.refresh_button = common_ui.ClickableIconButton( u'refresh', (QtGui.QColor(0, 0, 0, 255), QtGui.QColor(0, 0, 0, 255)), height, description=u'Refresh...', parent=self) self.refresh_button.clicked.connect(self.refresh) row.layout().addWidget(self.refresh_button, 0) self.remove_button = common_ui.ClickableIconButton( u'close', (QtGui.QColor(0, 0, 0, 255), QtGui.QColor(0, 0, 0, 255)), height, description=u'Refresh...', parent=self) self.remove_button.clicked.connect(self.close) row.layout().addWidget(self.remove_button, 0) row = common_ui.add_row(None, height=height, parent=self) text = u'Add new note' label = common_ui.PaintedLabel(text, color=common.SECONDARY_TEXT, size=common.SMALL_FONT_SIZE(), parent=self) row.layout().addWidget(self.add_button, 0) row.layout().addWidget(label, 0) row.layout().addStretch(1) self.add_button.clicked.connect(lambda: self.add_item(idx=0)) self.todoeditors_widget = TodoEditors(parent=self) self.setMinimumHeight(common.ROW_HEIGHT() * 3.0) self.scrollarea = QtWidgets.QScrollArea(parent=self) self.scrollarea.setWidgetResizable(True) self.scrollarea.setWidget(self.todoeditors_widget) self.scrollarea.setAttribute(QtCore.Qt.WA_NoSystemBackground) self.scrollarea.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.layout().addWidget(self.scrollarea)