Пример #1
0
    def __init__(self, rel_item, obj_item, width, is_wip=False):
        """Initializes item.

        Args:
            rel_item (spinetoolbox.widgets.graph_view_graphics_items.RelationshipItem): relationship item
            obj_item (spinetoolbox.widgets.graph_view_graphics_items.ObjectItem): object item
            width (float): Preferred line width
        """
        super().__init__()
        self.rel_item = rel_item
        self.obj_item = obj_item
        self._width = float(width)
        self.is_wip = is_wip
        src_x = rel_item.x()
        src_y = rel_item.y()
        dst_x = obj_item.x()
        dst_y = obj_item.y()
        self.setLine(src_x, src_y, dst_x, dst_y)
        self._pen = QPen()
        self._pen.setWidth(self._width)
        color = QGuiApplication.palette().color(QPalette.Normal,
                                                QPalette.WindowText)
        color.setAlphaF(0.8)
        self._pen.setColor(color)
        self._pen.setStyle(Qt.SolidLine)
        self._pen.setCapStyle(Qt.RoundCap)
        self.setPen(self._pen)
        self.setZValue(-2)
        rel_item.add_arc_item(self)
        obj_item.add_arc_item(self)
        if self.is_wip:
            self.become_wip()
        self.setCursor(Qt.ArrowCursor)
Пример #2
0
def build_stylesheet(theme='', invert_secondary=False, resources=[], extra={}):
    """"""
    theme = get_theme(theme, invert_secondary)
    if theme is None:
        return None

    set_icons_theme(theme)

    loader = jinja2.FileSystemLoader(
        os.path.join(os.path.dirname(os.path.abspath(__file__))))
    env = jinja2.Environment(autoescape=True, loader=loader)

    theme['icon'] = None

    env.filters['opacity'] = opacity
    # env.filters['load'] = load

    stylesheet = env.get_template(template)

    theme.setdefault('font_family', 'Roboto')
    theme.setdefault('danger', '#dc3545')
    theme.setdefault('warning', '#ffc107')
    theme.setdefault('success', '#17a2b8')

    theme.update(extra)

    default_palette = QGuiApplication.palette()
    default_palette.setColor(
        QPalette.PlaceholderText,
        QColor(
            *[int(theme['primaryColor'][i:i + 2], 16)
              for i in range(1, 6, 2)] + [92]))
    QGuiApplication.setPalette(default_palette)

    return stylesheet.render(**theme)
Пример #3
0
 def data(self, index, role=Qt.DisplayRole):
     """Gets the id and database for the row, and reads data from the db manager
     using the item_type property.
     Paint the object class icon next to the name.
     Also paint background of fixed indexes gray and apply custom format to JSON fields."""
     field = self.header[index.column()]
     # Background role
     if role == Qt.BackgroundRole and field in self.fixed_fields:
         return QGuiApplication.palette().button()
     # Display, edit, tool tip role
     if role in (Qt.DisplayRole, Qt.EditRole, Qt.ToolTipRole):
         if field == "database":
             return self.db_map.codename
         id_ = self._main_data[index.row()]
         if field in self.json_fields:
             return self.db_mngr.get_value(self.db_map, self.item_type, id_,
                                           field, role)
         data = self.db_mngr.get_item(self.db_map, self.item_type,
                                      id_).get(field)
         if role == Qt.DisplayRole and data and field in self.group_fields:
             data = data.replace(",", self.db_mngr._GROUP_SEP)
         return data
     # Decoration role
     entity_class_name_field = {
         "object class": "object_class_name",
         "relationship class": "relationship_class_name",
     }[self.entity_class_type]
     if role == Qt.DecorationRole and field == entity_class_name_field:
         return self.db_mngr.entity_class_icon(self.db_map,
                                               self.entity_class_type,
                                               self.entity_class_id)
     return super().data(index, role)
Пример #4
0
	def data(self, role, column):
		if role == Qt.TextColorRole:
			return QGuiApplication.palette().text().color()
		elif role == Qt.FontRole:
			return QApplication.font()
		elif role == Qt.TextAlignmentRole:
			if column==0:
				return Qt.AlignLeft | Qt.AlignVCenter
			else:
				return Qt.AlignCenter | Qt.AlignVCenter
		elif role == Qt.SizeHintRole:
			return QSize(0, self.ITEM_ROW_HEIGHT)
		elif role == ITEM_ROLE_TYPE:
			return self.typeId()
		elif role == Qt.EditRole:
			return self.getAttributeByIndex(column)
		elif role == Qt.DisplayRole:
			return self.getAttributeByIndex(column)
		elif role == ITEM_ROLE_ENABLED:
			return self.getAttributeByLabel("Enable")
		elif role == ITEM_ROLE_ISOLATED:
			return self.getAttributeByLabel("Isolate")
		elif role == ITEM_ROLE_ATTR_TYPE:
			return self.attributeType(column)
		elif role == ITEM_ROLE_ATTR_HIDDEN:
			return self.attributeHidden(column)
		elif role == ITEM_ROLE_IS_LAYER_MEMBER:
			return self._isMemberOfVisibleLayer()
		return None
 def data(self, column, role=Qt.DisplayRole):
     if role == Qt.ForegroundRole and self.child_number() == self.parent_item.child_count() - 1:
         gray_color = QGuiApplication.palette().text().color()
         gray_color.setAlpha(128)
         gray_brush = QBrush(gray_color)
         return gray_brush
     return super().data(column, role)
Пример #6
0
 def _init_bg(self):
     extent = self._extent
     self._bg = QGraphicsEllipseItem(-0.5 * extent, -0.5 * extent, extent,
                                     extent, self)
     self._bg.setPen(Qt.NoPen)
     bg_color = QGuiApplication.palette().color(QPalette.Normal,
                                                QPalette.Window)
     bg_color.setAlphaF(0.8)
     self._bg_brush = QBrush(bg_color)
Пример #7
0
    def __init__(self, parent=None):
        super(GridWidget, self).__init__(parent)

        self.cells = [CellWidget(i, parent=self) for i in range(81)]
        pal = QGuiApplication.palette()
        pal.setColor(QPalette.Background, Qt.black)
        self.setPalette(pal)
        self.setAutoFillBackground(True)
        self.generate_layout()
Пример #8
0
 def _make_pen(self):
     pen = QPen()
     pen.setWidth(self._width)
     color = QGuiApplication.palette().color(QPalette.Normal,
                                             QPalette.WindowText)
     color.setAlphaF(0.8)
     pen.setColor(color)
     pen.setStyle(Qt.SolidLine)
     pen.setCapStyle(Qt.RoundCap)
     return pen
Пример #9
0
 def data(self, role):
     if role == Qt.DisplayRole:
         return self.name
     elif role == Qt.EditRole:
         return self.name
     elif role == Qt.TextAlignmentRole:
         return Qt.AlignLeft | Qt.AlignVCenter
     elif role == Qt.TextColorRole:
         return QGuiApplication.palette().text().color()
     elif role == Qt.FontRole:
         return QApplication.font()
     elif role == Qt.SizeHintRole:
         return QSize(0, utils.dpiScale(ROW_HEIGHT))
     elif role == NODE_ACCEPTS_DRAG:
         return False
     elif role == NODE_ACTIVE_FRAME:
         return QColor(150, 150, 150)
     else:
         return super(ModelProxyItem, self).data(role)
Пример #10
0
    def __init__(self, entity_item):
        """Initializes item.

        Args:
            entity_item (spinetoolbox.widgets.graph_view_graphics_items.EntityItem): The parent item.
        """
        super().__init__(entity_item)
        self.entity_item = entity_item
        self._font = QApplication.font()
        self._font.setPointSize(11)
        self.setFont(self._font)
        self.bg = QGraphicsRectItem(self)
        self.bg_color = QGuiApplication.palette().color(
            QPalette.Normal, QPalette.ToolTipBase)
        self.bg_color.setAlphaF(0.8)
        self.bg.setBrush(QBrush(self.bg_color))
        self.bg.setPen(Qt.NoPen)
        self.bg.setFlag(QGraphicsItem.ItemStacksBehindParent)
        self.setFlag(QGraphicsItem.ItemIsSelectable, enabled=False)
        self.setAcceptHoverEvents(False)
Пример #11
0
    def init_ui(self):

        self.setWindowTitle('Preferences')
        self.setGeometry(100, 100, 400, 200)

        grid = QVBoxLayout()
        grid.setSpacing(15)

        self.darkmode = QCheckBox('Dark Mode', self)

        self.app.setStyle("Fusion")

        if QGuiApplication.palette() != self.default:
            self.darkmode.setChecked(True)

        palette = QPalette()
        palette.setColor(QPalette.Window, QColor(25, 25, 25))  # 53 53 53
        palette.setColor(QPalette.WindowText, Qt.white)
        palette.setColor(QPalette.Base, QColor(53, 53, 53))  # 25 25 25
        palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
        palette.setColor(QPalette.ToolTipBase, Qt.white)
        palette.setColor(QPalette.ToolTipText, Qt.white)
        palette.setColor(QPalette.Text, Qt.white)
        palette.setColor(QPalette.Button, QColor(53, 53, 53))
        palette.setColor(QPalette.ButtonText, Qt.white)
        palette.setColor(QPalette.BrightText, Qt.red)
        palette.setColor(QPalette.Link, QColor(42, 130, 218))
        palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
        palette.setColor(QPalette.HighlightedText, Qt.black)

        self.darkmode.toggled.connect(lambda: self.app.setPalette(palette)
                                      if self.darkmode.isChecked() else self.
                                      app.setPalette(self.default))

        grid.addWidget(self.darkmode, 1)

        center = QWidget()
        center.setLayout(grid)
        self.setCentralWidget(center)

        self.show()
    def data(self, index, role=Qt.DisplayRole):
        """Gets the id and database for the row, and reads data from the db manager
        using the item_type property.
        Paint the object_class icon next to the name.
        Also paint background of fixed indexes gray and apply custom format to JSON fields."""
        field = self.header[index.column()]
        # Background role
        if role == Qt.BackgroundRole and field in self.fixed_fields:
            return QGuiApplication.palette().button()
        # Display, edit, tool tip, alignment role of 'json fields'
        if field in self.json_fields and role in (
                Qt.DisplayRole,
                Qt.EditRole,
                Qt.ToolTipRole,
                Qt.TextAlignmentRole,
                PARSED_ROLE,
        ):
            id_ = self._main_data[index.row()]
            return self.db_mngr.get_value(self.db_map, self.item_type, id_,
                                          role)
        if role in (Qt.DisplayRole, Qt.EditRole, Qt.ToolTipRole):
            if field == "database":
                return self.db_map.codename
            id_ = self._main_data[index.row()]
            item = self.db_mngr.get_item(self.db_map, self.item_type, id_)
            if role == Qt.ToolTipRole:
                description = self.get_field_item(field, item).get(
                    "description", None)
                if description not in (None, ""):
                    return description
            data = item.get(field)
            if role == Qt.DisplayRole and data and field in self.group_fields:
                data = data.replace(",", self.db_mngr._GROUP_SEP)
            return data
        # Decoration role

        if role == Qt.DecorationRole and field == self.entity_class_name_field:
            return self.db_mngr.entity_class_icon(self.db_map,
                                                  self.entity_class_type,
                                                  self.entity_class_id)
        return super().data(index, role)
Пример #13
0
    def __init__(self, app):

        self.app = app
 
        # self.qmp = QMP('localhost', 55555)
        self.qmp = QMP()

        self.qmp.stateChanged.connect(self.handle_pause_button)
        self.qmp.connectionChange.connect(self.handle_connect_button)

        self.paused = False

        super().__init__()
        self.init_ui()

        self.qmp.timeUpdate.connect(self.update_time)
        self.t = TimeThread(self.qmp)
        
        self.time_mult = TimeMultiplier(self.qmp, self.kill_thread)

        self.window = []

        self.default_theme = QGuiApplication.palette()
Пример #14
0
 def _paint_as_selected(self):
     self._bg.setBrush(QGuiApplication.palette().highlight())
Пример #15
0
def build_stylesheet(theme='', invert_secondary=False, extra={}, parent='theme', template=TEMPLATE_FILE):
    """"""
    try:
        add_fonts()
    except Exception as e:
        logging.warning(e)

    theme = get_theme(theme, invert_secondary)
    if theme is None:
        return None

    set_icons_theme(theme, parent=parent)

    # Render custom template
    if os.path.exists(template):
        parent, template = os.path.split(template)
        loader = jinja2.FileSystemLoader(parent)
        env = jinja2.Environment(autoescape=False, loader=loader)
        env.filters['opacity'] = opacity
        env.filters['density'] = density
        stylesheet = env.get_template(template)
    else:
        env = jinja2.Environment(autoescape=False, loader=jinja2.BaseLoader)
        env.filters['opacity'] = opacity
        env.filters['density'] = density
        stylesheet.from_string(template)

    theme.setdefault('icon', None)
    theme.setdefault('font_family', 'Roboto')
    theme.setdefault('danger', '#dc3545')
    theme.setdefault('warning', '#ffc107')
    theme.setdefault('success', '#17a2b8')
    theme.setdefault('density_scale', '0')
    theme.setdefault('button_shape', 'default')

    theme.update(extra)

    if GUI:
        default_palette = QGuiApplication.palette()
        color = QColor(*[int(theme['primaryColor'][i:i + 2], 16)
                         for i in range(1, 6, 2)] + [92])

        try:
            if hasattr(QPalette, 'PlaceholderText'):  # pyqt5, pyside2, pyside6
                default_palette.setColor(QPalette.PlaceholderText, color)
            else:  # pyqt6
                default_palette.setColor(QPalette.ColorRole.Text, color)
            QGuiApplication.setPalette(default_palette)

        except:  # pyside6  & snake_case, true_property
            default_palette.set_color(QPalette.ColorRole.Text, color)
            QGuiApplication.set_palette(default_palette)

    environ = {

        'linux': platform.system() == 'Linux',
        'windows': platform.system() == 'Windows',
        'darwin': platform.system() == 'Darwin',

        'pyqt5': 'PyQt5' in sys.modules,
        'pyqt6': 'PyQt6' in sys.modules,
        'pyside2': 'PySide2' in sys.modules,
        'pyside6': 'PySide6' in sys.modules,
    }

    environ.update(theme)
    return stylesheet.render(environ)