Skip to content

Commit

Permalink
Add diagram class
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Sep 5, 2023
1 parent 87c5cb1 commit 3d4a7a8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/main/python/plotlyst/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1728,12 +1728,12 @@ class CharacterNode(Node, CharacterBased):


@dataclass
class RelationsNetwork:
class Diagram:
title: str
id: uuid.UUID = field(default_factory=uuid.uuid4)
icon: str = field(default='', metadata=config(exclude=exclude_if_empty))
icon_color: str = field(default='black', metadata=config(exclude=exclude_if_black))
nodes: List[CharacterNode] = field(default_factory=list)
nodes: List[Node] = field(default_factory=list)


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/plotlyst/service/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from qthandy import ask_confirmation

from src.main.python.plotlyst.core.client import client, json_client
from src.main.python.plotlyst.core.domain import Novel, Character, Scene, NovelDescriptor, Document, Plot
from src.main.python.plotlyst.core.domain import Novel, Character, Scene, NovelDescriptor, Document, Plot, Diagram
from src.main.python.plotlyst.env import app_env


Expand All @@ -48,6 +48,7 @@ class Operation:
scene: Optional[Scene] = None
update_image: bool = False
doc: Optional[Document] = None
diagram: Optional[Diagram] = None


class RepositoryPersistenceManager(QObject):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from qthandy import vline, retain_when_hidden
from qtmenu import GridMenuWidget

from src.main.python.plotlyst.core.domain import RelationsNetwork, Relation
from src.main.python.plotlyst.core.domain import Diagram, Relation
from src.main.python.plotlyst.view.common import tool_btn, action
from src.main.python.plotlyst.view.dialog.utility import IconSelectorDialog
from src.main.python.plotlyst.view.icons import IconRegistry
Expand All @@ -37,7 +37,7 @@
class RelationSelector(GridMenuWidget):
relationSelected = pyqtSignal(Relation)

def __init__(self, network: RelationsNetwork = None, parent=None):
def __init__(self, network: Diagram = None, parent=None):
super().__init__(parent)
self._network = network
self._romance = Relation('Romance', icon='ei.heart', icon_color='#d1495b')
Expand Down Expand Up @@ -87,7 +87,7 @@ def _newAction(self, relation: Relation, row: int, col: int, colSpan: int = 1, s


class ConnectorEditor(BaseItemEditor):
def __init__(self, network: RelationsNetwork, parent=None):
def __init__(self, network: Diagram, parent=None):
super().__init__(parent)
self._connector: Optional[ConnectorItem] = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from overrides import overrides

from src.main.python.plotlyst.common import PLOTLYST_SECONDARY_COLOR, PLOTLYST_TERTIARY_COLOR
from src.main.python.plotlyst.core.domain import Character, Novel, RelationsNetwork, CharacterNode
from src.main.python.plotlyst.core.domain import Character, Novel, Diagram, CharacterNode
from src.main.python.plotlyst.view.common import pointy
from src.main.python.plotlyst.view.icons import avatars
from src.main.python.plotlyst.view.widget.graphics import NodeItem, AbstractSocketItem, NetworkItemType, \
Expand Down Expand Up @@ -154,7 +154,7 @@ class RelationsEditorScene(NetworkScene):
def __init__(self, novel: Novel, parent=None):
super(RelationsEditorScene, self).__init__(parent)
self._novel = novel
self._network: Optional[RelationsNetwork] = None
self._network: Optional[Diagram] = None

if self._novel.characters:
node = CharacterNode(50, 50)
Expand All @@ -165,7 +165,7 @@ def __init__(self, novel: Novel, parent=None):
node.set_character(self._novel.characters[1])
self.addItem(CharacterItem(self._novel.characters[1], node))

def setNetwork(self, network: RelationsNetwork):
def setNetwork(self, network: Diagram):
self._network = network

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from PyQt6.QtCore import QTimer
from overrides import overrides

from src.main.python.plotlyst.core.domain import Novel, RelationsNetwork, Character
from src.main.python.plotlyst.core.domain import Novel, Diagram, Character
from src.main.python.plotlyst.view.icons import IconRegistry
from src.main.python.plotlyst.view.widget.character.network.editor import ConnectorEditor
from src.main.python.plotlyst.view.widget.character.network.scene import RelationsEditorScene, CharacterItem, \
Expand All @@ -41,7 +41,7 @@ def __init__(self, novel: Novel, parent=None):
self._btnAddSticker = self._newControlButton(IconRegistry.from_name('mdi6.sticker-circle-outline'),
'Add new sticker', CharacterNetworkItemType.STICKER)

network = RelationsNetwork('Test')
network = Diagram('Test')
self._connectorEditor = ConnectorEditor(network, self)
self._connectorEditor.setVisible(False)

Expand All @@ -54,7 +54,7 @@ def _initScene(self) -> NetworkScene:
def relationsScene(self) -> RelationsEditorScene:
return self._scene

def refresh(self, network: RelationsNetwork):
def refresh(self, network: Diagram):
self._scene.clear()
self._scene.setNetwork(network)
for node in network.nodes:
Expand Down
12 changes: 6 additions & 6 deletions src/main/python/plotlyst/view/widget/character/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from qthandy.filter import OpacityEventFilter, DragEventFilter
from qttoolbox import ToolBox

from src.main.python.plotlyst.core.domain import Character, Novel, RelationsNetwork
from src.main.python.plotlyst.core.domain import Character, Novel, Diagram
from src.main.python.plotlyst.view.icons import avatars, IconRegistry


Expand Down Expand Up @@ -100,7 +100,7 @@ def character(self) -> Character:


class NetworkPanel(QWidget):
def __init__(self, novel: Novel, network: RelationsNetwork, parent=None):
def __init__(self, novel: Novel, network: Diagram, parent=None):
super(NetworkPanel, self).__init__(parent)
self._novel = novel
self._network = network
Expand All @@ -112,7 +112,7 @@ def __init__(self, novel: Novel, network: RelationsNetwork, parent=None):

self.updateAvatars()

def network(self) -> RelationsNetwork:
def network(self) -> Diagram:
return self._network

def updateAvatars(self):
Expand All @@ -125,17 +125,17 @@ def updateAvatars(self):


class RelationsSelectorBox(ToolBox):
relationsSelected = pyqtSignal(RelationsNetwork)
relationsSelected = pyqtSignal(Diagram)

def __init__(self, novel: Novel, parent=None):
super(RelationsSelectorBox, self).__init__(parent)
self._novel = novel

def addNetwork(self, network: RelationsNetwork):
def addNetwork(self, network: Diagram):
wdg = NetworkPanel(self._novel, network)
self.addItem(wdg, network.title, icon=IconRegistry.from_name(network.icon, network.icon_color))

def refreshCharacters(self, network: RelationsNetwork):
def refreshCharacters(self, network: Diagram):
panel = self.currentWidget()
if panel.network() is network:
panel.updateAvatars()

0 comments on commit 3d4a7a8

Please sign in to comment.