Exemplo n.º 1
0
    def add_square(self, pos, size, col='black', thickness=None):
        """Draw a square.

        Args:
            pos (QPoint): square position
            size (QSize): square size
            col (str): square colour
            thickness (float): line thickness
        """
        from psyhive import qt

        _pos = qt.get_p(pos)
        _size = qt.get_size(size)
        _rect = QtCore.QRect(_pos, _size)

        _brush = QtGui.QBrush(qt.HColor(0, 0, 0, 0))
        _col = qt.get_col(col)
        _pen = QtGui.QPen(_col)
        if thickness:
            _pen.setWidthF(thickness)

        _pnt = qt.HPainter()
        _pnt.begin(self)
        _pnt.setPen(_pen)
        _pnt.setBrush(_brush)
        _pnt.drawRect(_rect)
        _pnt.end()

        return _rect
Exemplo n.º 2
0
def _get_flex_icon(arrow, arrow_size=80, bicep_size=110, verbose=0):
    """Build flex icon using the given arrow.

    Args:
        arrow (str): name of arrow emoji
        arrow_size (int): size of arrow icon
        bicep_size (int): size of bicep icon
        verbose (int): print process data
    """
    _path = '{}/psyhive/icons/ik_fk_{}.png'.format(pipe.TMP, arrow)

    _bicep = icons.EMOJI.find('Flexed Biceps: Light Skin Tone')
    _arrow = icons.EMOJI.find(arrow)

    _px = qt.HPixmap(144, 144)
    _px.fill(qt.HColor(0, 0, 0, 0))

    _bicep_px = qt.HPixmap(_bicep).resize(bicep_size, bicep_size)
    _px.add_overlay(_bicep_px, (0, 0))

    _arrow_px = qt.HPixmap(_arrow).resize(arrow_size, arrow_size)
    _px.add_overlay(_arrow_px, (_px.width(), _px.height()), anchor='BR')

    _px.save_as(_path, verbose=verbose, force=True)

    return _path
Exemplo n.º 3
0
    def _redraw__Task(self):

        _step = get_single(self.ui.Step.selected_data(), catch=True)

        self._work_files = []
        if _step:
            _work_area = _step.get_work_area(dcc=hb_utils.cur_dcc())
            self._work_files = _work_area.find_work()

        # Find mtimes of latest work versions
        _tasks = sorted(set([
            _work.task for _work in self._work_files]))
        _latest_works = [
            [_work for _work in self._work_files if _work.task == _task][-1]
            for _task in _tasks]
        _mtimes = [
            _work.get_mtime() for _work in _latest_works]

        # Clear task edit
        self.ui.TaskEdit.blockSignals(True)
        self.ui.TaskEdit.setText('')
        self.ui.TaskEdit.blockSignals(False)

        # Add to widget
        self.ui.Task.blockSignals(True)
        self.ui.Task.clear()
        for _task, _mtime in safe_zip(_tasks, _mtimes):
            _item = qt.HListWidgetItem(_task)
            if len(set(_mtimes)) == 1:
                _col = qt.HColor('white')
            else:
                _fr = val_map(
                    _mtime, in_min=min(_mtimes), in_max=max(_mtimes))
                _col = qt.HColor('Grey').whiten(_fr)
            _item.set_col(_col)
            self.ui.Task.addItem(_item)
        if _step in _tasks:
            self.ui.Task.select_text([_step])
        else:
            self.ui.Task.setCurrentRow(0)
        self.ui.Task.blockSignals(False)

        self._redraw__Work()
Exemplo n.º 4
0
    def darken(self, factor):
        """Darken this pixmap (1 makes the pixmap black).

        Args:
            factor (float): how much to darken

        Returns:
            (HPixmap): this pixmap
        """
        from psyhive import qt
        _tmp = HPixmap(self.size())
        _tmp.fill(qt.HColor(0, 0, 0, 255 * factor))
        self.add_overlay(_tmp, operation='over')
        return self
Exemplo n.º 5
0
    def whiten(self, factor):
        """Whiten this pixmap (1 makes the pixmap white).

        Args:
            factor (float): how much to whiten

        Returns:
            (HPixmap): this pixmap
        """
        from psyhive import qt
        _tmp = HPixmap(self.size())
        _fill = qt.HColor(255, 255, 255, 255 * factor)
        _tmp.fill(_fill)
        if self.hasAlpha():
            _tmp.setMask(self.mask())
        self.add_overlay(_tmp, operation='over')
        return self
Exemplo n.º 6
0
    def __init__(self,
                 path,
                 title=None,
                 all_defs=False,
                 base_col=None,
                 mod=None,
                 verbose=0):
        """Constructor.

        Args:
            path (str): path to build interface from
            title (str): override gui title
            all_defs (bool): force all defs into interface (by default
                only defs decorated with the py_gui.install decorator
                are added)
            base_col (QColor|str): override base colour for this interface
            mod (module): py file module (to avoid reimport/calculate)
            verbose (int): print process data
        """

        # Store kwargs for rebuild
        self._kwargs = copy.copy(locals())
        self._kwargs.pop('self')

        self.py_file = PyFile(path)
        self.label_width = 70
        self._height = 400
        self.all_defs = all_defs
        self.section = None

        _mod = mod or self.py_file.get_module()

        self.mod_name = _mod.__name__
        self.title = title or getattr(_mod, 'PYGUI_TITLE', self.mod_name)
        self.ui_name = self.mod_name.replace(".", "_") + "_ui"
        self.settings_file = abs_path('{}/Psyop/settings/py_gui/{}.yml'.format(
            os.environ.get('HOME') or os.environ.get('HOMEDRIVE'),
            self.mod_name.replace('.', '_')))

        # Read attrs from module
        self.icon_set = getattr(_mod, 'PYGUI_ICON_SET', icons.FRUIT)
        self._width = getattr(_mod, 'PYGUI_WIDTH', 300)
        self.base_col = base_col or getattr(
            _mod, 'PYGUI_COL',
            str_to_seed(self.mod_name).choice(NICE_COLS))
        self.section_col = qt.HColor(self.base_col).blacken(0.5)
        if self.icon_set:
            assert isinstance(self.icon_set, Collection)

        # Build defs into ui
        self.read_settings_fns = copy.deepcopy(_EMPTY_SETTINGS)
        self.set_settings_fns = copy.deepcopy(_EMPTY_SETTINGS)
        _defs_data = self._get_defs_data()
        self.init_ui()
        lprint('FOUND {:d} DEFS TO ADD'.format(len(_defs_data)),
               verbose=verbose)
        for _last, (_fn, _opts) in last(_defs_data):
            _def = self.py_file.find_def(_fn.__name__, catch=True)
            lprint(" - TESTING DEF", _fn, _opts, _def, verbose=verbose)
            if _def:
                lprint(" - ADDING DEF", _def, _opts, verbose=verbose)
                self.add_def(_def, opts=_opts, last_=_last)
        self.finalise_ui()
        if os.path.exists(self.settings_file):
            self.load_settings()
Exemplo n.º 7
0
def get_work_icon(work,
                  mode='full',
                  size=50,
                  overlay_size=25,
                  force=False,
                  verbose=0):
    """Get icon for the given work file.

    Args:
        work (CTTWork): work file
        mode (str): type of icon to build (full/basic)
        size (int): icon size
        overlay_size (int): overlay size
        force (bool): force redraw icon
        verbose (int): print process data

    Returns:
        (str|QPixmap): work file icon
    """

    # Get base icon
    _uid = work.task
    lprint('UID', _uid, verbose=verbose)
    if _uid == 'test':
        _icon = icons.EMOJI.find('Alembic')
    else:
        _random = str_to_seed(_uid)
        _icon = _random.choice(icons.FRUIT.get_paths())
    lprint('ICON', _icon, verbose=verbose)
    if mode == 'basic':
        return _icon

    _random = str_to_seed(work.path)
    _rotate = _random.random() * 360

    _pix = qt.HPixmap(size, size)
    _pix.fill(qt.HColor(0, 0, 0, 0))

    # Add rotated icon as overlay
    _size_fr = 1 / (2**0.5)
    _size = _pix.size() * _size_fr
    _over = qt.HPixmap(_icon).resize(_size)
    _tfm = QtGui.QTransform()
    _tfm.rotate(_rotate)
    _over = _over.transformed(_tfm)
    _offs = (_pix.size() - _over.size()) / 2
    _pix.add_overlay(_over, _offs)

    # Add overlays
    _overlays = []
    if work.find_seqs():
        _over = qt.HPixmap(
            icons.EMOJI.find('Play button')).resize(overlay_size)
        _overlays.append(_over)
    if work.find_publishes():
        _over = qt.HPixmap(
            icons.EMOJI.find('Funeral Urn')).resize(overlay_size)
        _overlays.append(_over)
    if work.find_caches():
        _over = qt.HPixmap(icons.EMOJI.find('Money bag')).resize(overlay_size)
        _overlays.append(_over)
    for _idx, _over in enumerate(_overlays):
        _offs = (13 * _idx, _pix.height() - 0 * _idx)
        lprint(' - ADD OVERLAY', _idx, _offs, verbose=verbose)
        _pix.add_overlay(_over, _offs, anchor='BL')

    return _pix