Exemplo n.º 1
0
        def paintEvent(self, event):
            if self.text() != self._default_label.text():
                self._default_label.setText(self.text())
            if self.isTextVisible() != self._default_label.isVisible():
                self._default_label.setVisible(self.isTextVisible())

            percent = utils.get_percent(self.value(), self.minimum(),
                                        self.maximum())
            total_width = self._width
            pen_width = int(3 * total_width / 50.0)
            radius = total_width - pen_width - 1

            painter = QtGui.QPainter(self)
            painter.setRenderHints(QtGui.QPainter.Antialiasing)

            # draw background circle
            pen_background = QtGui.QPen()
            pen_background.setWidth(pen_width)
            pen_background.setColor(QtGui.QColor(80, 120, 110))
            pen_background.setCapStyle(QtCore.Qt.RoundCap)
            painter.setPen(pen_background)
            painter.drawArc(pen_width / 2.0 + 1, pen_width / 2.0 + 1, radius,
                            radius, self._start_angle, -self._max_delta_angle)

            # draw foreground circle
            pen_foreground = QtGui.QPen()
            pen_foreground.setWidth(pen_width)
            pen_foreground.setColor(self._color)
            pen_foreground.setCapStyle(QtCore.Qt.RoundCap)
            painter.setPen(pen_foreground)
            painter.drawArc(pen_width / 2.0 + 1, pen_width / 2.0 + 1, radius,
                            radius, self._start_angle,
                            -percent * 0.01 * self._max_delta_angle)
            painter.end()
Exemplo n.º 2
0
    def _fill_data(self):
        is_greater_version = self._is_greater_version()

        if is_greater_version:
            icon_pixmap = (resource.pixmap('success')
                           or QtGui.QPixmap()).scaled(
                               QtCore.QSize(30, 30),
                               QtCore.Qt.KeepAspectRatio,
                               transformMode=QtCore.Qt.SmoothTransformation)
            self._version_message_label.setText(
                'Artella {} Plugin is updated!'.format(dcc.nice_name()))
        else:
            icon_pixmap = (resource.pixmap('info') or QtGui.QPixmap()).scaled(
                QtCore.QSize(30, 30),
                QtCore.Qt.KeepAspectRatio,
                transformMode=QtCore.Qt.SmoothTransformation)
            self._version_icon.setPixmap(icon_pixmap)
            self._version_message_label.setText(
                'New Artella {} Plugin is available!'.format(dcc.nice_name()))

        self._version_icon.setPixmap(icon_pixmap)
        self._go_to_download_web_btn.setVisible(not is_greater_version)
        latest_version = self._latest_release_info.get('version', 'Undefined')
        self._current_version_label.setText(
            str(self._current_version or 'Undefined'))
        self._latest_version_label.setText(latest_version)
Exemplo n.º 3
0
def pixmap(pixmap_path, color=None):
    """
    Returns Qt pixmap instance

    :param pixmap_path: Path were pixmap resource is located
    :param color:
    :return: New instance of a Qt pixmap
    :rtype: QtGui.QPixmap
    """

    if color and isinstance(color, str):
        from artella.widgets import color as artella_color
        color = artella_color.from_string(color)

    new_pixmap = QtGui.QPixmap(pixmap_path)

    if not new_pixmap.isNull() and color:
        painter = QtGui.QPainter(new_pixmap)
        painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceIn)
        painter.setBrush(color)
        painter.setPen(color)
        painter.drawRect(new_pixmap.rect())
        painter.end()

    return new_pixmap
Exemplo n.º 4
0
        def __init__(self, parent=None, **kwargs):
            super(ProgressCricle, self).__init__(parent)

            self._infinite = False
            self._timer = QtCore.QTimer(self)
            self._timer.timeout.connect(self._on_increase_value)

            self._main_layout = QtWidgets.QHBoxLayout()
            self._default_label = QtWidgets.QLabel()
            self._default_label.setAlignment(QtCore.Qt.AlignCenter)
            self._main_layout.addWidget(self._default_label)
            self.setLayout(self._main_layout)
            self._color = QtGui.QColor(221, 235, 230)
            self._width = kwargs.get('width', 140)

            self.setTextDirection(self.Direction.BottomToTop)

            self._start_angle = 90 * 16
            self._max_delta_angle = 360 * 16
            self._height_factor = 1.0
            self._width_factor = 1.0

            self.setFixedSize(
                QtCore.QSize(self._width * self._width_factor,
                             self._width * self._height_factor))
Exemplo n.º 5
0
def generate_color(primary_color, index):
    """
    Generates a new color from the given one and with given index (between 1 and 10)
    https://github.com/phenom-films/dayu_widgets/blob/master/dayu_widgets/utils.py
    :param primary_color: base color (RRGGBB)
    :param index: color step from 1 (light) to 10 (dark)
    :return: out color Color
    """

    hue_step = 2
    saturation_step = 16
    saturation_step2 = 5
    brightness_step1 = 5
    brightness_step2 = 15
    light_color_count = 5
    dark_color_count = 4

    def _get_hue(color, i, is_light):
        h_comp = color.hue()
        if 60 <= h_comp <= 240:
            hue = h_comp - hue_step * i if is_light else h_comp + hue_step * i
        else:
            hue = h_comp + hue_step * i if is_light else h_comp - hue_step * i
        if hue < 0:
            hue += 359
        elif hue >= 359:
            hue -= 359
        return hue / 359.0

    def _get_saturation(color, i, is_light):
        s_comp = color.saturationF() * 100
        if is_light:
            saturation = s_comp - saturation_step * i
        elif i == dark_color_count:
            saturation = s_comp + saturation_step
        else:
            saturation = s_comp + saturation_step2 * i
        saturation = min(100.0, saturation)
        if is_light and i == light_color_count and saturation > 10:
            saturation = 10
        saturation = max(6.0, saturation)
        return round(saturation * 10) / 1000.0

    def _get_value(color, i, is_light):
        v_comp = color.valueF()
        if is_light:
            return min((v_comp * 100 + brightness_step1 * i) / 100, 1.0)
        return max((v_comp * 100 - brightness_step2 * i) / 100, 0.0)

    light = index <= 6
    hsv_color = QtGui.QColor(primary_color) if isinstance(primary_color, str) else primary_color
    index = light_color_count + 1 - index if light else index - light_color_count - 1
    return QtGui.QColor.fromHsvF(
        _get_hue(hsv_color, index, light),
        _get_saturation(hsv_color, index, light),
        _get_value(hsv_color, index, light)
    ).name()
Exemplo n.º 6
0
def fade_color(color, alpha):
    """
    Internal function that fades given color
    :param color: QColor
    :param alpha: float
    :return:
    """

    qt_color = QtGui.QColor(color)
    return 'rgba({}, {}, {}, {})'.format(qt_color.red(), qt_color.green(), qt_color.blue(), alpha)
Exemplo n.º 7
0
def icon(icon_path, color=None):
    """
    Returns Qt icon instance

    :param icon_path: Path were icon resource is located
    :param color:
    :return: New instance of a Qt icon
    :rtype: QtGui.QIcon
    """

    icon_pixmap = pixmap(icon_path, color=color)
    new_icon = QtGui.QIcon(icon_pixmap)

    return new_icon
Exemplo n.º 8
0
def icon(name, extension='png', color=None):
    """
    Returns Artella icon
    :param name:
    :param extension:
    :param color:
    :return: QIcon
    """

    new_icon = get(ResourceTypes.ICON,
                   name=name,
                   extension=extension,
                   color=color)
    if not new_icon:
        return None if not qtutils.QT_AVAILABLE else QtGui.QIcon()

    return new_icon
Exemplo n.º 9
0
def pixmap(name, extension='png', color=None):
    """
    Returns Artella pixmap resource
    :param name:
    :param extension:
    :param color:
    :return:
    """

    new_pixmap = get(ResourceTypes.PIXMAP,
                     name=name,
                     extension=extension,
                     color=color)
    if not new_pixmap:
        return None if not qtutils.QT_AVAILABLE else QtGui.QPixmap()

    return new_pixmap
Exemplo n.º 10
0
def from_string(text_color):
    """
    Returns a (int, int, int, int) format color from a string format color
    :param text_color: str, string format color to parse
    :param alpha: int, alpha of the color
    :return: (int, int, int, int)
    """

    a = 255
    if string_is_hex(text_color):
        r, g, b = rgb_from_hex(text_color)
    else:
        try:
            if text_color.startswith('rgba'):
                r, g, b, a = text_color.replace('rgba(', '').replace(')', '').split(',')
            else:
                r, g, b, a = text_color.replace('rgb(', '').replace(')', '').split(',')
        except ValueError:
            if text_color.startswith('rgba'):
                r, g, b = text_color.replace('rgba(', '').replace(')', '').split(',')
            else:
                r, g, b = text_color.replace('rgb(', '').replace(')', '').split(',')

    return QtGui.QColor(int(r), int(g), int(b), int(a))
Exemplo n.º 11
0
    def setup_ui(self):
        super(SplashDialog, self).setup_ui()

        self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint
                            | QtCore.Qt.WA_DeleteOnClose)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)

        splash_pixmap = resource.pixmap('artella_splash')
        splash = SplashScreen(splash_pixmap)
        splash.setMask(splash_pixmap.mask())
        self._splash_layout = QtWidgets.QVBoxLayout()
        self._splash_layout.setAlignment(QtCore.Qt.AlignBottom)
        splash.setLayout(self._splash_layout)
        self.main_layout.addWidget(splash)

        size_width = splash_pixmap.size().width() + 20
        size_height = splash_pixmap.size().height() + 20
        self.setFixedSize(QtCore.QSize(size_width, size_height))

        shadow_effect = QtWidgets.QGraphicsDropShadowEffect(self)
        shadow_effect.setBlurRadius(qtutils.dpi_scale(15))
        shadow_effect.setColor(QtGui.QColor(0, 0, 0, 150))
        shadow_effect.setOffset(qtutils.dpi_scale(0))
        self.setGraphicsEffect(shadow_effect)
Exemplo n.º 12
0
        def __init__(self,
                     id,
                     name,
                     package,
                     version,
                     author,
                     email,
                     summary,
                     latest_version,
                     upload_date,
                     size,
                     url,
                     icon_pixmap=None,
                     parent=None):
            super(PluginVersionWidget, self).__init__(parent)

            self._id = id
            self._name = name
            self._package = package
            self._version = version
            self._author = author
            self._email = email
            self._summary = summary
            self._latest_version = latest_version
            self._upload_date = upload_date
            self._size = size
            self._url = url

            icon_pixmap = (icon_pixmap or resource.pixmap('artella')
                           or QtGui.QPixmap()).scaled(
                               QtCore.QSize(30, 30),
                               QtCore.Qt.KeepAspectRatio,
                               transformMode=QtCore.Qt.SmoothTransformation)

            self.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self.setFrameShadow(QtWidgets.QFrame.Raised)
            self.setMinimumHeight(130)

            main_layout = QtWidgets.QHBoxLayout()
            main_layout.setContentsMargins(2, 2, 2, 2)
            main_layout.setSpacing(2)
            self.setLayout(main_layout)

            main_info_layout = QtWidgets.QVBoxLayout()
            main_info_layout.setContentsMargins(2, 2, 2, 2)
            main_info_layout.setSpacing(2)

            top_layout = QtWidgets.QHBoxLayout()
            top_layout.setContentsMargins(2, 2, 2, 2)
            top_layout.setSpacing(5)
            self._icon_label = QtWidgets.QLabel()
            self._icon_label.setPixmap(icon_pixmap)
            self._icon_label.setAlignment(QtCore.Qt.AlignTop)

            self._plugin_name_label = QtWidgets.QLabel(name)
            self._plugin_version_label = QtWidgets.QLabel(
                '({})'.format(version))

            plugin_name_info_layout = QtWidgets.QVBoxLayout()
            plugin_name_info_layout.setContentsMargins(2, 2, 2, 2)
            plugin_name_info_layout.setSpacing(5)
            plugin_name_layout = QtWidgets.QHBoxLayout()
            plugin_name_layout.setContentsMargins(2, 2, 2, 2)
            plugin_name_layout.setSpacing(2)
            plugin_info_layout = QtWidgets.QHBoxLayout()
            plugin_info_layout.setContentsMargins(2, 2, 2, 2)
            plugin_info_layout.setSpacing(5)
            plugin_name_layout.addWidget(self._plugin_name_label)
            plugin_name_layout.addWidget(self._plugin_version_label)
            plugin_name_layout.addStretch()
            plugin_name_info_layout.addLayout(plugin_name_layout)
            plugin_name_info_layout.addLayout(plugin_info_layout)
            plugin_name_info_layout.addStretch()
            self._plugin_date_label = QtWidgets.QLabel(upload_date)
            self._plugin_size_label = QtWidgets.QLabel(size)
            separator_widget = QtWidgets.QWidget()
            separator_layout = QtWidgets.QVBoxLayout()
            separator_layout.setAlignment(QtCore.Qt.AlignLeft)
            separator_layout.setContentsMargins(0, 0, 0, 0)
            separator_layout.setSpacing(0)
            separator_widget.setLayout(separator_layout)
            separator_frame = QtWidgets.QFrame()
            separator_frame.setMaximumHeight(15)
            separator_frame.setFrameShape(QtWidgets.QFrame.VLine)
            separator_frame.setFrameShadow(QtWidgets.QFrame.Sunken)
            separator_layout.addWidget(separator_frame)
            plugin_info_layout.addWidget(self._plugin_date_label)
            plugin_info_layout.addWidget(separator_widget)
            plugin_info_layout.addWidget(self._plugin_size_label)
            plugin_info_layout.addStretch()

            top_layout.addWidget(self._icon_label)
            top_layout.addLayout(plugin_name_info_layout)

            bottom_layout = QtWidgets.QHBoxLayout()
            bottom_layout.setContentsMargins(2, 2, 2, 2)
            bottom_layout.setSpacing(5)
            self._summary_text = QtWidgets.QPlainTextEdit(summary)
            self._summary_text.setReadOnly(True)
            self._summary_text.setMinimumHeight(60)
            self._summary_text.setFocusPolicy(QtCore.Qt.NoFocus)
            bottom_layout.addWidget(self._summary_text)

            download_layout = QtWidgets.QVBoxLayout()
            download_layout.setContentsMargins(2, 2, 2, 2)
            download_layout.setSpacing(2)
            self._progress = splash.ProgressCricle(width=80)
            self._progress_text = QtWidgets.QLabel('Wait please ...')
            self._ok_label = QtWidgets.QLabel()
            self._ok_label.setPixmap(resource.pixmap('success'))
            self._update_button = QtWidgets.QPushButton()
            self._progress.setVisible(False)
            self._progress_text.setVisible(False)
            self._ok_label.setVisible(False)
            progress_layout = QtWidgets.QHBoxLayout()
            progress_layout.addStretch()
            progress_layout.addWidget(self._progress)
            progress_layout.addStretch()
            progress_text_layout = QtWidgets.QHBoxLayout()
            progress_text_layout.addStretch()
            progress_text_layout.addWidget(self._progress_text)
            progress_text_layout.addStretch()
            ok_layout = QtWidgets.QHBoxLayout()
            ok_layout.addStretch()
            ok_layout.addWidget(self._ok_label)
            ok_layout.addStretch()
            download_layout.addStretch()
            download_layout.addLayout(progress_layout)
            download_layout.addLayout(progress_text_layout)
            download_layout.addLayout(ok_layout)
            download_layout.addWidget(self._update_button)
            download_layout.addStretch()

            main_info_layout.addLayout(top_layout)
            main_info_layout.addStretch()
            main_info_layout.addLayout(bottom_layout)
            main_info_layout.addStretch()

            main_info_layout.addStretch()
            main_layout.addLayout(main_info_layout)
            separator_widget = QtWidgets.QWidget()
            separator_layout = QtWidgets.QVBoxLayout()
            separator_layout.setAlignment(QtCore.Qt.AlignLeft)
            separator_layout.setContentsMargins(0, 0, 0, 0)
            separator_layout.setSpacing(0)
            separator_widget.setLayout(separator_layout)
            separator_frame = QtWidgets.QFrame()
            separator_frame.setFrameShape(QtWidgets.QFrame.VLine)
            separator_frame.setFrameShadow(QtWidgets.QFrame.Sunken)
            separator_layout.addWidget(separator_frame)
            main_layout.addWidget(separator_widget)
            main_layout.addLayout(download_layout)
            main_info_layout.addStretch()

            self._update_plugin_thread = QtCore.QThread(self)
            self._update_plugin_worker = utils.UpdatePluginWorker()
            self._update_plugin_worker.moveToThread(self._update_plugin_thread)
            self._update_plugin_worker.updateStart.connect(
                self._on_start_update)
            self._update_plugin_worker.updateFinish.connect(
                self._on_finish_update)
            self._update_plugin_thread.start()

            self._timer = QtCore.QTimer(self)

            self.updatePlugin.connect(self._update_plugin_worker.run)
            self._update_button.clicked.connect(self._on_update)
            self._timer.timeout.connect(self._on_advance_progress)

            self.refresh()
Exemplo n.º 13
0
        def _fill_data(self):

            install_path = r'D:\dev\artella\test_download'

            dcc_plugins = list()
            dcc_install_package = 'artella-installer-{}'.format(dcc.name())
            base_file_name = 'artella_installer_maya'
            file_name = '{}.tar.gz'.format(base_file_name)
            file_path = os.path.join(install_path, file_name)
            dcc_pypi_info = utils.get_pypi_info(dcc_install_package)
            if dcc_pypi_info:
                dcc_url = dcc_pypi_info.get('url', '')
                if dcc_url:
                    valid = utils.download_and_extract_package_from_pypi(dcc_url, file_path, install_path)
                    if valid:
                        config_file = None
                        print('Install Path: {}'.format(install_path))
                        for root, dirs, files in os.walk(install_path):
                            if config_file:
                                break
                            for file_path in files:
                                if file_path == 'artella-installer.json':
                                    config_file = os.path.join(root, file_path)
                                    break
                        if config_file and os.path.isfile(config_file):
                            config_data = core_utils.read_json(config_file)
                            config_plugins = config_data.get('plugins', list())
                            for config_plugin in config_plugins:
                                plugin_id = config_plugin.get('id', '')
                                if not plugin_id:
                                    plugin_repo = config_plugin.get('repo', '')
                                    if plugin_repo:
                                        plugin_id = plugin_repo.split('/')[-1]
                                if plugin_id:
                                    dcc_plugins.append(plugin_id)
            dcc_plugins = list(set(dcc_plugins))

            all_plugins = plugins.plugins()
            for plugin_id, plugin_data in all_plugins.items():

                plugin_name = plugin_data['name']
                plugin_icon_name = plugin_data.get('icon', None)
                plugin_package = plugin_data.get('package', None)
                plugin_version = plugin_data.get('version', None)
                plugin_resource_paths = plugin_data.get('resource_paths', list())

                if plugin_id in dcc_plugins:
                    dcc_plugins.remove(plugin_id)

                plugin_icon_pixmap = None
                if plugin_icon_name and plugin_resource_paths:
                    for plugin_resource_path in plugin_resource_paths:
                        plugin_icon_path = os.path.join(plugin_resource_path, plugin_icon_name)
                        if os.path.isfile(plugin_icon_path):
                            plugin_icon_pixmap = QtGui.QPixmap(plugin_icon_path)

                if plugin_package not in self._plugins:
                    package_layout = self._add_package_tab(plugin_package)
                    self._plugins[plugin_package] = {'layout': package_layout, 'plugins': []}
                else:
                    package_layout = self._plugins[plugin_package]['layout']

                pypi_info = utils.get_pypi_info(plugin_id)
                if not pypi_info:
                    continue

                plugin_author = pypi_info.get('author', '')
                plugin_author_email = pypi_info.get('author_email', '')
                plugin_summary = pypi_info.get('summary', '')
                plugin_latest_version = pypi_info.get('version', '')    # this is the latest version of the plugin in PyPI
                plugin_upload_date = pypi_info.get('upload_date', '')
                plugin_size = pypi_info.get('size', '')
                plugin_url = pypi_info.get('url', '')

                new_plugin_widget = plugin.PluginVersionWidget(
                    plugin_id, plugin_name, plugin_package, plugin_version, plugin_author, plugin_author_email,
                    plugin_summary, plugin_latest_version, plugin_upload_date, plugin_size, plugin_url, plugin_icon_pixmap)
                new_plugin_widget.updated.connect(self._on_updated_plugin)
                self._plugins[plugin_package]['plugins'].append(new_plugin_widget)
                package_layout.addWidget(new_plugin_widget)

            print(dcc_plugins)