Skip to content

Commit

Permalink
style: allow switching to dark mode from GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ElpadoCan committed Jun 20, 2023
1 parent 73f4d05 commit e8856cb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 21 deletions.
21 changes: 3 additions & 18 deletions cellacdc/__main__.py
Expand Up @@ -136,6 +136,7 @@ def eventFilter(self, object, event):
from cellacdc import is_win, is_linux, temp_path, issues_url
from cellacdc import settings_csv_path
from cellacdc import printl
from cellacdc import _warnings
except ModuleNotFoundError as e:
src_path = os.path.dirname(os.path.abspath(__file__))
main_path = os.path.dirname(src_path)
Expand Down Expand Up @@ -369,25 +370,9 @@ def onDarkModeToggled(self, checked):
df_settings = pd.read_csv(settings_csv_path, index_col='setting')
df_settings.at['colorScheme', 'value'] = scheme
df_settings.to_csv(settings_csv_path)
msg = widgets.myMessageBox(wrapText=False)
txt = (
'In order for the change to take effect, '
'<b>please restart Cell-ACDC</b>'
_warnings.warnRestartCellACDCcolorModeToggled(
scheme, app_name='Cell-ACDC', parent=self
)
if scheme == 'dark':
issues_href = f'<a href="{issues_url}">GitHub page</a>'
note_txt = (
'NOTE: <b>dark mode</b> is still in <b>beta phase</b> and '
'it is not perfect, but we believe it is usable.<br><br>'
'Many icons are not very visible on a dark background, but '
'if you see anything clearly <b>wrong</b><br>'
'(besides icons) please <b>report it</b> by opening an issue '
f'on our {issues_href}.<br><br>'
'Thanks!'
)
txt = f'{txt}<br><br>{note_txt}'
txt = html_utils.paragraph(txt)
msg.information(self, 'Restart Cell-ACDC', txt)
self.statusBarLayout.addWidget(QLabel(html_utils.paragraph(
'<i>Restart Cell-ACDC for the change to take effect</i>',
font_color='red'
Expand Down
22 changes: 21 additions & 1 deletion cellacdc/_warnings.py
@@ -1,4 +1,5 @@
from . import widgets, html_utils
from . import issues_url

def warnTooManyItems(mainWin, numItems, qparent):
mainWin.logger.info(
Expand All @@ -21,4 +22,23 @@ def warnTooManyItems(mainWin, numItems, qparent):
widgets.reloadPushButton(' Switch to low resolution ')
)
)
return msg.cancel, msg.clickedButton==switchToLowResButton
return msg.cancel, msg.clickedButton==switchToLowResButton

def warnRestartCellACDCcolorModeToggled(scheme, app_name='Cell-ACDC', parent=None):
msg = widgets.myMessageBox(wrapText=False)
txt = (
'In order for the change to take effect, '
f'<b>please restart {app_name}</b>'
)
if scheme == 'dark':
issues_href = f'<a href="{issues_url}">GitHub page</a>'
note_txt = (
'NOTE: <b>dark mode</b> is a recent feature so if you see '
'if you see anything odd,<br>'
'please, <b>report it</b> by opening an issue '
f'on our {issues_href}.<br><br>'
'Thanks!'
)
txt = f'{txt}<br><br>{note_txt}'
txt = html_utils.paragraph(txt)
msg.information(parent, f'Restart {app_name}', txt)
44 changes: 42 additions & 2 deletions cellacdc/gui.py
Expand Up @@ -835,6 +835,7 @@ def __init__(
self.closeGUI = False

self.setAcceptDrops(True)
self._appName = 'Cell-ACDC'

def _printl(
self, *objects, is_decorator=False, **kwargs
Expand Down Expand Up @@ -1063,6 +1064,12 @@ def loadLastSessionSettings(self):
if 'manual_separate_draw_mode' not in self.df_settings.index:
col = 'manual_separate_draw_mode'
self.df_settings.at[col, 'value'] = 'threepoints_arc'

if 'colorScheme' in self.df_settings.index:
col = 'colorScheme'
self._colorScheme = self.df_settings.at[col, 'value']
else:
self._colorScheme = 'light'

def dragEnterEvent(self, event):
file_path = event.mimeData().urls()[0].toLocalFile()
Expand Down Expand Up @@ -1289,6 +1296,7 @@ def gui_createMenuBar(self):
# Settings menu
self.settingsMenu = QMenu("Settings", self)
menuBar.addMenu(self.settingsMenu)
self.settingsMenu.addAction(self.toggleColorSchemeAction)
self.settingsMenu.addAction(self.editShortcutsAction)
self.settingsMenu.addSeparator()

Expand Down Expand Up @@ -2618,6 +2626,11 @@ def gui_createActions(self):
'(from the current session not the saved information)'
)

self.toggleColorSchemeAction = QAction(
'Switch to light mode'
)
self.gui_updateSwitchColorSchemeActionText()

self.editShortcutsAction = QAction(
'Customize keyboard shortcuts...', self
)
Expand Down Expand Up @@ -2809,6 +2822,13 @@ def gui_createActions(self):
# self.imgGradLabelsAlphaUpAction = QAction(self)
# self.imgGradLabelsAlphaUpAction.setVisible(False)
# self.imgGradLabelsAlphaUpAction.setShortcut('Ctrl+Up')

def gui_updateSwitchColorSchemeActionText(self):
if self._colorScheme == 'dark':
txt = 'Switch to light mode'
else:
txt = 'Switch to dark mode'
self.toggleColorSchemeAction.setText(txt)

def gui_connectActions(self):
# Connect File actions
Expand All @@ -2828,6 +2848,7 @@ def gui_connectActions(self):
self.nextAction.triggered.connect(self.nextActionTriggered)
self.prevAction.triggered.connect(self.prevActionTriggered)

self.toggleColorSchemeAction.triggered.connect(self.onToggleColorScheme)
self.editShortcutsAction.triggered.connect(self.editShortcuts_cb)

# Connect Help actions
Expand Down Expand Up @@ -2857,7 +2878,26 @@ def gui_connectActions(self):
)
self.addCustomModelFrameAction.callback = self.segmFrameCallback
self.addCustomModelVideoAction.callback = self.segmVideoCallback


def onToggleColorScheme(self):
if self.toggleColorSchemeAction.text().find('light') != -1:
self._colorScheme = 'light'
setDarkModeToggleChecked = False
else:
self._colorScheme = 'dark'
setDarkModeToggleChecked = True
self.gui_updateSwitchColorSchemeActionText()
_warnings.warnRestartCellACDCcolorModeToggled(
self._colorScheme, app_name=self._appName, parent=self
)
load.rename_qrc_resources_file(self._colorScheme)
self.statusBarLabel.setText(html_utils.paragraph(
f'<i>Restart {self._appName} for the change to take effect</i>',
font_color='red'
))
self.df_settings.at['colorScheme', 'value'] = self._colorScheme
self.df_settings.to_csv(settings_csv_path)

def gui_connectEditActions(self):
self.showInExplorerAction.setEnabled(True)
self.setEnabledFileToolbar(True)
Expand Down Expand Up @@ -3161,7 +3201,7 @@ def gui_createQuickSettingsWidgets(self):
# the new default is True. This requires larger font size.
self.fontSize = 2*self.fontSize
self.df_settings.at['pxMode', 'value'] = 1
self.df_settings.to_csv(self.settings_csv_path)
self.df_settings.to_csv(settings_csv_path)
self.fontSizeSpinBox.setValue(self.fontSize)
self.fontSizeSpinBox.editingFinished.connect(self.changeFontSize)
self.fontSizeSpinBox.sigUpClicked.connect(self.changeFontSize)
Expand Down

0 comments on commit e8856cb

Please sign in to comment.