Skip to content

Commit

Permalink
Edit entity icons and names
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Jul 25, 2023
1 parent f7322b5 commit 71eeac8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/python/plotlyst/view/widget/world/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def addChildWdg(parent: WorldBuildingEntity, child: WorldBuildingEntity):
recursive(entity, lambda parent: parent.children, addChildWdg)
self._centralWidget.layout().addWidget(vspacer())

def updateEntity(self, entity: WorldBuildingEntity):
self._entities[entity].refresh()

def clearSelection(self):
for entity in self._selectedEntities:
self._entities[entity].deselect()
Expand Down
21 changes: 19 additions & 2 deletions src/main/python/plotlyst/view/world_building_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from typing import Optional

from PyQt6.QtGui import QColor
from overrides import overrides
from qthandy import incr_font, transparent

Expand All @@ -40,6 +43,8 @@ def __init__(self, novel: Novel):
self.ui = Ui_WorldBuildingView()
self.ui.setupUi(self.widget)

self._entity: Optional[WorldBuildingEntity] = None

self.ui.btnNew.setIcon(IconRegistry.plus_icon(color='white'))
self.ui.btnNew.installEventFilter(ButtonPressResizeEventFilter(self.ui.btnNew))
self._additionMenu = EntityAdditionMenu(self.ui.btnNew)
Expand All @@ -51,7 +56,9 @@ def __init__(self, novel: Novel):
self._lineName.setPlaceholderText('Name')
transparent(self._lineName)
incr_font(self._lineName, 15)
self._lineName.textEdited.connect(self._name_edited)
self._btnIcon = IconSelectorButton()
self._btnIcon.iconSelected.connect(self._icon_changed)
self.ui.wdgName.layout().addWidget(self._btnIcon)
self.ui.wdgName.layout().addWidget(self._lineName)

Expand All @@ -69,8 +76,18 @@ def refresh(self):
pass

def _selection_changed(self, entity: WorldBuildingEntity):
self._lineName.setText(entity.name)
self._entity = entity
self._lineName.setText(self._entity.name)
if entity.icon:
self._btnIcon.selectIcon(entity.icon, entity.icon_color)
self._btnIcon.selectIcon(self._entity.icon, self._entity.icon_color)
else:
self._btnIcon.reset()

def _name_edited(self, name: str):
self._entity.name = name
self.ui.treeWorld.updateEntity(self._entity)

def _icon_changed(self, icon_name: str, color: QColor):
self._entity.icon = icon_name
self._entity.icon_color = color.name()
self.ui.treeWorld.updateEntity(self._entity)

0 comments on commit 71eeac8

Please sign in to comment.