Skip to content

Commit

Permalink
Add task tags (#671)
Browse files Browse the repository at this point in the history
* Add task tags

* more tags

* Grid menu
  • Loading branch information
zkovari authored Sep 8, 2023
1 parent 0eb900f commit 2a9b145
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 28 deletions.
28 changes: 28 additions & 0 deletions src/main/python/plotlyst/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,33 @@ def __hash__(self):
return hash(str(id))


tag_characterization = SelectionItem('Characterization', icon='fa5s.user', icon_color='darkBlue')
tag_worldbuilding = SelectionItem('Worldbuilding', icon='mdi.globe-model', icon_color='#2d6a4f')
tag_brainstorming = SelectionItem('Brainstorming', icon='fa5s.brain', icon_color='#FF5733')
tag_research = SelectionItem('Research', icon='mdi.library', icon_color='#0066CC')
tag_writing = SelectionItem('Writing', icon='mdi.typewriter', icon_color='#9933CC')
tag_plotting = SelectionItem('Plotting', icon='fa5s.theater-masks', icon_color='#FF6666')
tag_theme = SelectionItem('Theme', icon='mdi.butterfly-outline', icon_color='#9d4edd')
tag_outlining = SelectionItem('Outlining', icon='fa5s.list', icon_color='#99CC00')
tag_revision = SelectionItem('Revision', icon='mdi.clipboard-edit-outline', icon_color='#FF9933')
tag_drafting = SelectionItem('Drafting', icon='fa5s.dog', icon_color='#66CC33')
tag_editing = SelectionItem('Editing', icon='fa5s.cat', icon_color='#ff758f')
tag_collect_feedback = SelectionItem('Collect feedback', icon='msc.feedback', icon_color='#5e60ce')
tag_publishing = SelectionItem('Publishing', icon='fa5s.cloud-upload-alt', icon_color='#FF9900')
tag_marketing = SelectionItem('Marketing', icon='fa5s.bullhorn', icon_color='#FF3366')
tag_book_cover_design = SelectionItem('Book cover design', icon='fa5s.book', icon_color='#FF66CC')
tag_formatting = SelectionItem('Formatting', icon='mdi.format-pilcrow', icon_color='#006600')

_tags = [
tag_characterization, tag_worldbuilding, tag_brainstorming, tag_research, tag_writing,
tag_plotting, tag_theme, tag_outlining, tag_revision, tag_drafting, tag_editing,
tag_collect_feedback, tag_publishing, tag_marketing, tag_book_cover_design, tag_formatting
]
task_tags: Dict[str, SelectionItem] = {}
for tag in _tags:
task_tags[tag.text] = tag


@dataclass
class Task(CharacterBased):
title: str
Expand All @@ -1041,6 +1068,7 @@ class Task(CharacterBased):
resolved_date: Optional[datetime] = None
summary: str = field(default='', metadata=config(exclude=exclude_if_empty))
character_id: Optional[uuid.UUID] = None
tags: List[str] = field(default_factory=list, metadata=config(exclude=exclude_if_empty))

def __post_init__(self):
if self.creation_date is None:
Expand Down
10 changes: 9 additions & 1 deletion src/main/python/plotlyst/view/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import math
import sys
from functools import partial
from typing import Optional, Tuple, List
from typing import Optional, Tuple, List, Union

import qtawesome
from PyQt6.QtCore import QRectF, QModelIndex, QRect, QPoint, QBuffer, QIODevice, QSize, QObject, QEvent, Qt, QTimer
Expand Down Expand Up @@ -469,3 +469,11 @@ def spawn(cls):
main_window.show()

sys.exit(app.exec())


def any_menu_visible(*buttons: Union[QPushButton, QToolButton]) -> bool:
for btn in buttons:
if btn.menu().isVisible():
return True

return False
2 changes: 1 addition & 1 deletion src/main/python/plotlyst/view/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def from_selection_item(item: SelectionItem) -> QIcon:
def from_name(name: str, color: str = 'black', color_on: str = '', mdi_scale: float = 1.2, hflip: bool = False,
vflip: bool = False) -> QIcon:
_color_on = color_on if color_on else color
if name.startswith('md') or name.startswith('ri') or name.startswith('ph'):
if name.startswith('md') or name.startswith('ri') or name.startswith('ph') or name.startswith('msc'):
return QIcon(qtawesome.icon(name, color=color, color_on=_color_on, hflip=hflip, vflip=vflip,
options=[{'scale_factor': mdi_scale}]))
return QIcon(qtawesome.icon(name, color=color, color_on=_color_on, hflip=hflip, vflip=vflip))
Expand Down
88 changes: 83 additions & 5 deletions src/main/python/plotlyst/view/widget/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@

import qtanim
from PyQt6.QtCore import pyqtSignal, Qt, pyqtProperty, QTimer, QEvent
from PyQt6.QtGui import QColor, QIcon, QMouseEvent
from PyQt6.QtGui import QColor, QIcon, QMouseEvent, QEnterEvent, QAction
from PyQt6.QtWidgets import QPushButton, QSizePolicy, QToolButton, QAbstractButton, QLabel, QButtonGroup, QMenu, QWidget
from overrides import overrides
from qtanim import fade_in
from qthandy import hbox, translucent, bold, incr_font, transparent, retain_when_hidden, underline, vbox, decr_icon
from qthandy import hbox, translucent, bold, incr_font, transparent, retain_when_hidden, underline, vbox, decr_icon, \
incr_icon, italic
from qthandy.filter import OpacityEventFilter, VisibilityToggleEventFilter
from qtmenu import MenuWidget
from qtmenu import MenuWidget, GridMenuWidget

from src.main.python.plotlyst.common import PLOTLYST_TERTIARY_COLOR
from src.main.python.plotlyst.core.domain import SelectionItem, Novel
from src.main.python.plotlyst.core.domain import SelectionItem, Novel, tag_characterization, tag_worldbuilding, \
tag_brainstorming, tag_research, tag_writing, tag_plotting, tag_theme, tag_outlining, tag_revision, tag_drafting, \
tag_editing, tag_collect_feedback, tag_publishing, tag_marketing, tag_book_cover_design, tag_formatting
from src.main.python.plotlyst.service.importer import SyncImporter
from src.main.python.plotlyst.view.common import pointy, ButtonPressResizeEventFilter, tool_btn, spin
from src.main.python.plotlyst.view.common import pointy, ButtonPressResizeEventFilter, tool_btn, spin, action
from src.main.python.plotlyst.view.icons import IconRegistry


Expand Down Expand Up @@ -494,3 +497,78 @@ def _toggled(self, toggled: bool):
else:
self.setIcon(IconRegistry.from_name('ei.eye-close'))
translucent(self)


class TaskTagSelector(QToolButton):
tagSelected = pyqtSignal(SelectionItem)

def __init__(self, parent=None):
super().__init__(parent)
self._selected = False
pointy(self)
self._reset()

tagsMenu = GridMenuWidget(self)

tagsMenu.addAction(self._action(tag_characterization), 0, 0)
tagsMenu.addAction(self._action(tag_worldbuilding), 0, 2)
tagsMenu.addAction(self._action(tag_brainstorming), 1, 0)
tagsMenu.addAction(self._action(tag_writing), 2, 0)
tagsMenu.addAction(self._action(tag_research), 1, 2)
tagsMenu.addAction(self._action(tag_plotting), 2, 2)
tagsMenu.addAction(self._action(tag_theme), 3, 0)
tagsMenu.addSeparator(4, 0, colSpan=3)

tagsMenu.addAction(self._action(tag_outlining), 5, 0)
tagsMenu.addAction(self._action(tag_revision), 6, 0)
tagsMenu.addAction(self._action(tag_drafting), 7, 0)
tagsMenu.addAction(self._action(tag_editing), 8, 0)
tagsMenu.addAction(self._action(tag_formatting), 9, 0)
tagsMenu.addSeparator(5, 1, rowSpan=5, vertical=True)

tagsMenu.addAction(self._action(tag_collect_feedback), 5, 2)
tagsMenu.addAction(self._action(tag_book_cover_design), 6, 2)
tagsMenu.addAction(self._action(tag_publishing), 7, 2)
tagsMenu.addAction(self._action(tag_marketing), 8, 2)

tagsMenu.addSeparator(10, 0, colSpan=3)
self._actionRemove = action('Remove', IconRegistry.trash_can_icon(), slot=self._reset)
italic(self._actionRemove)
tagsMenu.addAction(self._actionRemove, 12, 0)
transparent(self)
translucent(self, 0.9)
self.installEventFilter(ButtonPressResizeEventFilter(self))

@overrides
def enterEvent(self, event: QEnterEvent) -> None:
if not self._selected:
self.setIcon(IconRegistry.from_name('ei.tag', 'grey'))

@overrides
def leaveEvent(self, event: QEvent) -> None:
if not self._selected:
self.setIcon(IconRegistry.from_name('ei.tag', '#adb5bd'))

def select(self, tag: SelectionItem):
self.__updateTag(tag)

def _tagSelected(self, tag: SelectionItem):
self.__updateTag(tag)
self.tagSelected.emit(tag)

def _reset(self):
self.setIcon(IconRegistry.from_name('ei.tag', '#adb5bd'))
self.setToolTip('Ling a tag')
self._selected = False
decr_icon(self)

def _action(self, tag: SelectionItem) -> QAction:
return action(tag.text, IconRegistry.from_selection_item(tag),
slot=partial(self._tagSelected, tag))

def __updateTag(self, tag: SelectionItem):
if not self._selected:
incr_icon(self)
self.setIcon(IconRegistry.from_selection_item(tag))
self.setToolTip(tag.text)
self._selected = True
1 change: 1 addition & 0 deletions src/main/python/plotlyst/view/widget/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ def __init__(self, novel: Novel, parent=None, opacityEffectEnabled: bool = True,
self._opacityFilter = OpacityEventFilter(self)
else:
self._opacityFilter = None
self.installEventFilter(ButtonPressResizeEventFilter(self))
self._menu = CharacterSelectorMenu(self._novel, self)
self._menu.selected.connect(self._selected)
self.clear()
Expand Down
58 changes: 37 additions & 21 deletions src/main/python/plotlyst/view/widget/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,29 @@
import qtanim
from PyQt6.QtCore import Qt, pyqtSignal, QMimeData, QObject, QEvent
from PyQt6.QtGui import QFont
from PyQt6.QtWidgets import QWidget, QFrame, QSizePolicy, QLabel, QToolButton, QPushButton, \
QLineEdit
from PyQt6.QtWidgets import QWidget, QFrame, QSizePolicy, QLabel, QToolButton, QPushButton
from overrides import overrides
from qthandy import vbox, hbox, transparent, vspacer, margins, spacer, bold, retain_when_hidden, incr_font, \
gc
gc, decr_icon
from qthandy.filter import VisibilityToggleEventFilter, OpacityEventFilter, DragEventFilter, DropEventFilter
from qtmenu import MenuWidget

from src.main.python.plotlyst.common import RELAXED_WHITE_COLOR
from src.main.python.plotlyst.core.domain import TaskStatus, Task, Novel, Character
from src.main.python.plotlyst.core.domain import TaskStatus, Task, Novel, Character, task_tags
from src.main.python.plotlyst.core.template import SelectionItem
from src.main.python.plotlyst.env import app_env
from src.main.python.plotlyst.event.core import Event, emit_event
from src.main.python.plotlyst.event.handler import event_dispatchers
from src.main.python.plotlyst.events import CharacterDeletedEvent, TaskChanged, TaskDeleted, TaskChangedToWip, \
TaskChangedFromWip
from src.main.python.plotlyst.service.persistence import RepositoryPersistenceManager
from src.main.python.plotlyst.view.common import ButtonPressResizeEventFilter, pointy, shadow, action
from src.main.python.plotlyst.view.common import ButtonPressResizeEventFilter, pointy, shadow, action, tool_btn, \
any_menu_visible
from src.main.python.plotlyst.view.icons import IconRegistry
from src.main.python.plotlyst.view.layout import group
from src.main.python.plotlyst.view.widget.button import CollapseButton
from src.main.python.plotlyst.view.widget.button import CollapseButton, TaskTagSelector
from src.main.python.plotlyst.view.widget.characters import CharacterSelectorButton
from src.main.python.plotlyst.view.widget.input import AutoAdjustableLineEdit

TASK_WIDGET_MAX_WIDTH = 350

Expand All @@ -64,53 +66,60 @@ def __init__(self, task: Task, parent=None):
self.setMinimumHeight(75)
shadow(self, 3)

self._lineTitle = QLineEdit(self)
self._lineTitle = AutoAdjustableLineEdit(self, defaultWidth=100)
self._lineTitle.setPlaceholderText('New task')
self._lineTitle.setText(task.title)
self._lineTitle.setFrame(False)
font = QFont('Arial')
font = QFont('Helvetica')
font.setWeight(QFont.Weight.Medium)
self._lineTitle.setFont(font)
incr_font(self._lineTitle)

self._charSelector = CharacterSelectorButton(app_env.novel, self, opacityEffectEnabled=False, iconSize=24)
self._charSelector.setToolTip('Link character')
decr_icon(self._charSelector)
if self._task.character_id:
self._charSelector.setCharacter(self._task.character(app_env.novel))
else:
self._charSelector.setHidden(True)
retain_when_hidden(self._charSelector)
self._charSelector.characterSelected.connect(self._linkCharacter)
self._charSelector.menu().aboutToHide.connect(self._onLeave)
top_wdg = group(self._lineTitle, self._charSelector, margin=0, spacing=1)
top_wdg = group(self._lineTitle, spacer(), self._charSelector, margin=0, spacing=1)
self.layout().addWidget(top_wdg, alignment=Qt.AlignmentFlag.AlignTop)

self._wdgBottom = QWidget()
retain_when_hidden(self._wdgBottom)
hbox(self._wdgBottom)
self._btnResolve = QToolButton(self._wdgBottom)
self._btnResolve.setIcon(IconRegistry.from_name('fa5s.check', 'grey'))
self._btnResolve.setToolTip('Resolve task')
pointy(self._btnResolve)
self._btnResolve.setProperty('transparent-circle-bg-on-hover', True)
self._btnResolve.setProperty('positive', True)
self._btnResolve.installEventFilter(ButtonPressResizeEventFilter(self._btnResolve))

self._btnTags = TaskTagSelector(self._wdgBottom)
self._btnTags.tagSelected.connect(self._tagChanged)

self._btnResolve = tool_btn(IconRegistry.from_name('fa5s.check', 'grey'), 'Resolve task',
properties=['transparent-circle-bg-on-hover', 'positive'], parent=self._wdgBottom)
decr_icon(self._btnResolve)
self._btnResolve.clicked.connect(self.resolved.emit)

self._btnMenu = QToolButton(self._wdgBottom)
self._btnMenu.setIcon(IconRegistry.dots_icon('grey'))
self._btnMenu.setProperty('transparent-circle-bg-on-hover', True)
pointy(self._btnMenu)
self._btnMenu = tool_btn(IconRegistry.dots_icon('grey'), 'Menu', properties=['transparent-circle-bg-on-hover'],
parent=self._wdgBottom)
decr_icon(self._btnMenu)
menu = MenuWidget(self._btnMenu)
menu.addAction(action('Rename', IconRegistry.edit_icon(), self._lineTitle.setFocus))
menu.addSeparator()
menu.addAction(action('Delete', IconRegistry.trash_can_icon(), lambda: self.removalRequested.emit(self)))
menu.aboutToHide.connect(self._onLeave)
self._wdgBottom.layout().addWidget(self._btnTags)
self._wdgBottom.layout().addWidget(spacer())
self._wdgBottom.layout().addWidget(self._btnResolve, alignment=Qt.AlignmentFlag.AlignRight)
self._wdgBottom.layout().addWidget(self._btnMenu, alignment=Qt.AlignmentFlag.AlignRight)
self.layout().addWidget(self._wdgBottom, alignment=Qt.AlignmentFlag.AlignBottom)

if self._task.tags:
tag = task_tags.get(self._task.tags[0], None)
if tag:
self._btnTags.select(tag)
else:
self._btnTags.setHidden(True)
self._btnResolve.setHidden(True)
self._btnMenu.setHidden(True)

Expand All @@ -125,8 +134,9 @@ def eventFilter(self, watched: QObject, event: QEvent) -> bool:
self._charSelector.setVisible(True)
self._btnMenu.setVisible(True)
self._btnResolve.setVisible(True)
self._btnTags.setVisible(True)
elif event.type() == QEvent.Type.Leave:
if self._charSelector.menu().isVisible() or self._btnMenu.menu().isVisible():
if any_menu_visible(self._charSelector, self._btnMenu, self._btnTags):
return True
self._onLeave()
return super(TaskWidget, self).eventFilter(watched, event)
Expand All @@ -150,9 +160,15 @@ def _activated(self):
self._lineTitle.setFocus()
shadow(self, 3)

def _tagChanged(self, tag: SelectionItem):
self._task.tags.clear()
self._task.tags.append(tag.text)

def _onLeave(self):
if not self._task.character_id:
self._charSelector.setHidden(True)
if not self._task.tags:
self._btnTags.setHidden(True)
self._btnMenu.setVisible(False)
self._btnResolve.setVisible(False)

Expand Down

0 comments on commit 2a9b145

Please sign in to comment.