Skip to content

Commit

Permalink
Merge pull request #365 from Zack-Code-UIUC/adding_icon
Browse files Browse the repository at this point in the history
  • Loading branch information
wpfff committed Feb 8, 2023
2 parents 6459f2e + df9521f commit f062b10
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 5 deletions.
9 changes: 5 additions & 4 deletions plottr/apps/monitr.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from ..apps.watchdog_classes import WatcherClient
from ..gui.widgets import Collapsible
from .json_viewer import JsonModel, JsonTreeView
from ..icons import get_starIcon as get_star_icon, get_trashIcon as get_trash_icon
from ..icons import get_starIcon as get_star_icon, get_trashIcon as get_trash_icon, get_imageIcon as get_img_icon, get_jsonIcon as get_json_icon, get_mdIcon as get_md_icon
from .appmanager import AppManager

TIMESTRFORMAT = "%Y-%m-%dT%H%M%S"
Expand Down Expand Up @@ -3153,7 +3153,8 @@ def add_all_files(self, files_data: List[Tuple[Path, str, ContentType]]) -> None
expand = False
if file in self.collapsed_state_dictionary:
expand = self.collapsed_state_dictionary[file]
json_view = Collapsible(widget=JsonTreeView(path=file), title=name, expanding=expand)
json_view = Collapsible(widget=JsonTreeView(path=file), title=name, expanding=expand,
icon=get_json_icon())
json_view.widget.setVisible(expand)
json_view.btn.setChecked(expand)
if expand:
Expand All @@ -3179,7 +3180,7 @@ def add_all_files(self, files_data: List[Tuple[Path, str, ContentType]]) -> None
if file in self.collapsed_state_dictionary:
expand = self.collapsed_state_dictionary[file]
plain_text_edit = Collapsible(widget=TextEditWidget(path=file),
title=name, expanding=expand)
title=name, expanding=expand, icon=get_md_icon())

plain_text_edit.widget.setVisible(expand)
plain_text_edit.btn.setChecked(expand)
Expand All @@ -3196,7 +3197,7 @@ def add_all_files(self, files_data: List[Tuple[Path, str, ContentType]]) -> None
if file in self.collapsed_state_dictionary:
expand = self.collapsed_state_dictionary[file]
label = Collapsible(ImageViewer(file, parent=self.right_side_dummy_widget),
title=name, expanding=expand)
title=name, expanding=expand, icon=get_img_icon())
label.widget.setVisible(expand)
label.btn.setChecked(expand)
if expand:
Expand Down
6 changes: 5 additions & 1 deletion plottr/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,15 @@ class Collapsible(QtWidgets.QWidget):

def __init__(self, widget: QtWidgets.QWidget, title: str = '',
parent: Optional[QtWidgets.QWidget] = None,
expanding: bool = True) -> None:
expanding: bool = True, icon: Optional[QtGui.QIcon] = None) -> None:
"""Constructor.
:param widget: the widget we'd like to collapse.
:param title: title of the widget. will appear on the toolbutton that
we use to trigger collapse/expansion.
:param parent: parent widget.
:param expanding: determine if the collapsible is expanded vertically.
:param icon: the icon that is added in front of the title.
"""
super().__init__(parent=parent)

Expand All @@ -294,6 +296,8 @@ def __init__(self, widget: QtWidgets.QWidget, title: str = '',
self.btn.setChecked(True)
setHExpanding(self.btn)
self.btn.clicked.connect(self._onButton)
if icon is not None:
self.btn.setIcon(icon)

layout = QtWidgets.QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
Expand Down
29 changes: 29 additions & 0 deletions plottr/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,32 @@ def get_starIcon() -> QtGui.QIcon:
)
return starIcon


def get_imageIcon() -> QtGui.QIcon:
"""
Icon taken from: https://www.svgrepo.com/collection/file-type-collection/
"""
imageIcon = QtGui.QIcon(
os.path.join(gfxPath, "png_file_icon.svg")
)
return imageIcon


def get_mdIcon() -> QtGui.QIcon:
"""
Icon taken from: https://www.svgrepo.com/collection/file-type-collection/
"""
jpgIcon = QtGui.QIcon(
os.path.join(gfxPath, "txt_file_icon.svg")
)
return jpgIcon


def get_jsonIcon() -> QtGui.QIcon:
"""
Icon taken from: https://www.svgrepo.com/collection/file-type-collection/
"""
jpgIcon = QtGui.QIcon(
os.path.join(gfxPath, "json_file_icon.svg")
)
return jpgIcon
19 changes: 19 additions & 0 deletions plottr/resource/gfx/default_file_icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions plottr/resource/gfx/json_file_icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f062b10

Please sign in to comment.