ability to change language
This commit is contained in:
Binary file not shown.
@@ -5,8 +5,8 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: RavenLog\n"
|
"Project-Id-Version: RavenLog\n"
|
||||||
"POT-Creation-Date: 2022-02-03 18:28+0100\n"
|
"POT-Creation-Date: 2022-02-06 08:14+0100\n"
|
||||||
"PO-Revision-Date: 2022-02-03 18:35+0100\n"
|
"PO-Revision-Date: 2022-02-06 08:19+0100\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
"Language: de\n"
|
"Language: de\n"
|
||||||
@@ -21,7 +21,7 @@ msgstr ""
|
|||||||
msgid "About RavenLog"
|
msgid "About RavenLog"
|
||||||
msgstr "Über RavenLog"
|
msgstr "Über RavenLog"
|
||||||
|
|
||||||
#: aboutdialog.py:23 raven/mainwindow.py:40 ravenui.py:19
|
#: aboutdialog.py:23 raven/mainwindow.py:39 ravenui.py:19
|
||||||
msgid "RavenLog"
|
msgid "RavenLog"
|
||||||
msgstr "RavenLog"
|
msgstr "RavenLog"
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ msgstr "In &Datei Kopieren"
|
|||||||
msgid "Select &All"
|
msgid "Select &All"
|
||||||
msgstr "&Alles Selektieren"
|
msgstr "&Alles Selektieren"
|
||||||
|
|
||||||
#: bigtext.py:188 raven/mainwindow.py:117
|
#: bigtext.py:188 raven/mainwindow.py:101
|
||||||
msgid "&Highlighter"
|
msgid "&Highlighter"
|
||||||
msgstr "&Hervorhebungen"
|
msgstr "&Hervorhebungen"
|
||||||
|
|
||||||
@@ -87,19 +87,19 @@ msgstr "Passion Fruit Sugar"
|
|||||||
|
|
||||||
#: colorbutton.py:24
|
#: colorbutton.py:24
|
||||||
msgid "Sunrise Yellow"
|
msgid "Sunrise Yellow"
|
||||||
msgstr ""
|
msgstr "Sonnenaufganggelb"
|
||||||
|
|
||||||
#: colorbutton.py:25
|
#: colorbutton.py:25
|
||||||
msgid "Magical Mustard"
|
msgid "Magical Mustard"
|
||||||
msgstr ""
|
msgstr "Magischer Senf"
|
||||||
|
|
||||||
#: colorbutton.py:27
|
#: colorbutton.py:27
|
||||||
msgid "Trendy Green"
|
msgid "Trendy Green"
|
||||||
msgstr ""
|
msgstr "Trendiges Grün"
|
||||||
|
|
||||||
#: colorbutton.py:28
|
#: colorbutton.py:28
|
||||||
msgid "Garden Of Sweden"
|
msgid "Garden Of Sweden"
|
||||||
msgstr ""
|
msgstr "Garten von Schweden"
|
||||||
|
|
||||||
#: colorbutton.py:30
|
#: colorbutton.py:30
|
||||||
msgid "Light Sky Blue"
|
msgid "Light Sky Blue"
|
||||||
@@ -119,7 +119,7 @@ msgstr ""
|
|||||||
|
|
||||||
#: colorbutton.py:36
|
#: colorbutton.py:36
|
||||||
msgid "Breeze of Mist"
|
msgid "Breeze of Mist"
|
||||||
msgstr ""
|
msgstr "Nebelbriese"
|
||||||
|
|
||||||
#: colorbutton.py:37
|
#: colorbutton.py:37
|
||||||
msgid "Light Grey"
|
msgid "Light Grey"
|
||||||
@@ -201,32 +201,32 @@ msgstr "Nicht Gespeicherte Änderungen"
|
|||||||
msgid "You have unsaved changes."
|
msgid "You have unsaved changes."
|
||||||
msgstr "Du hast nicht gespeicherte Änderungen."
|
msgstr "Du hast nicht gespeicherte Änderungen."
|
||||||
|
|
||||||
#: raven/mainwindow.py:48 raven/plugins/openfileplugin.py:31
|
#: raven/mainwindow.py:47 raven/plugins/openfileplugin.py:31
|
||||||
msgid "Open &Recent"
|
msgid "Open &Recent"
|
||||||
msgstr "Zu&letzt geöffnete Dateien"
|
msgstr "Zu&letzt geöffnete Dateien"
|
||||||
|
|
||||||
#: raven/mainwindow.py:67
|
#: raven/mainwindow.py:66
|
||||||
#: venv310/lib/python3.10/site-packages/PySide6/examples/widgets/gettext/main.py:57
|
#: venv310/lib/python3.10/site-packages/PySide6/examples/widgets/gettext/main.py:57
|
||||||
msgid "&File"
|
msgid "&File"
|
||||||
msgstr "&Datei"
|
msgstr "&Datei"
|
||||||
|
|
||||||
#: raven/mainwindow.py:68
|
#: raven/mainwindow.py:67
|
||||||
msgid "&Settings"
|
msgid "&Settings"
|
||||||
msgstr "&Einstellungen"
|
msgstr "&Einstellungen"
|
||||||
|
|
||||||
#: raven/mainwindow.py:69
|
#: raven/mainwindow.py:68
|
||||||
msgid "&Window"
|
msgid "&Window"
|
||||||
msgstr "&Fenster"
|
msgstr "&Fenster"
|
||||||
|
|
||||||
#: raven/mainwindow.py:70
|
#: raven/mainwindow.py:69
|
||||||
msgid "&Help"
|
msgid "&Help"
|
||||||
msgstr "&Hilfe"
|
msgstr "&Hilfe"
|
||||||
|
|
||||||
#: raven/mainwindow.py:125
|
#: raven/mainwindow.py:109
|
||||||
msgid "Highlight &Searches"
|
msgid "Highlight &Searches"
|
||||||
msgstr "&Suchtreffer Hervorheben"
|
msgstr "&Suchtreffer Hervorheben"
|
||||||
|
|
||||||
#: raven/mainwindow.py:134
|
#: raven/mainwindow.py:118
|
||||||
msgid "Open Tab on Save As File"
|
msgid "Open Tab on Save As File"
|
||||||
msgstr "Öffne neues Tab wenn Selektion als neue Datei gespeichert wird"
|
msgstr "Öffne neues Tab wenn Selektion als neue Datei gespeichert wird"
|
||||||
|
|
||||||
@@ -254,27 +254,39 @@ msgstr "&Öffnen..."
|
|||||||
msgid "Open File"
|
msgid "Open File"
|
||||||
msgstr "Öffne Datei"
|
msgstr "Öffne Datei"
|
||||||
|
|
||||||
#: raven/plugins/ravenlogplugin.py:40
|
#: raven/plugins/ravenlogplugin.py:43
|
||||||
msgid "&Languages"
|
msgid "&Languages"
|
||||||
msgstr "&Sprachen"
|
msgstr "&Sprachen"
|
||||||
|
|
||||||
#: raven/plugins/ravenlogplugin.py:41
|
#: raven/plugins/ravenlogplugin.py:44
|
||||||
msgid "&Default"
|
msgid "&Default"
|
||||||
msgstr "&Standard"
|
msgstr "&Standard"
|
||||||
|
|
||||||
#: raven/plugins/ravenlogplugin.py:42
|
#: raven/plugins/ravenlogplugin.py:45
|
||||||
msgid "&English"
|
msgid "&English"
|
||||||
msgstr "&English"
|
msgstr "&English"
|
||||||
|
|
||||||
#: raven/plugins/ravenlogplugin.py:43
|
#: raven/plugins/ravenlogplugin.py:46
|
||||||
msgid "&German"
|
msgid "&German"
|
||||||
msgstr "&Deutsch"
|
msgstr "&Deutsch"
|
||||||
|
|
||||||
#: raven/plugins/ravenlogplugin.py:65
|
#: raven/plugins/ravenlogplugin.py:70
|
||||||
|
msgid "Language Changed"
|
||||||
|
msgstr "Sprache geändert"
|
||||||
|
|
||||||
|
#: raven/plugins/ravenlogplugin.py:71
|
||||||
|
msgid ""
|
||||||
|
"The language for this application has been changed. The change will take "
|
||||||
|
"effect the next time the application is started."
|
||||||
|
msgstr ""
|
||||||
|
"Die Anwendungssprache wurde geändert. Die Änderung wird erst beim "
|
||||||
|
"nächsten Start der Anwendung wirksam."
|
||||||
|
|
||||||
|
#: raven/plugins/ravenlogplugin.py:88
|
||||||
msgid "&About"
|
msgid "&About"
|
||||||
msgstr "&Über RavenLog"
|
msgstr "&Über RavenLog"
|
||||||
|
|
||||||
#: raven/plugins/ravenlogplugin.py:73
|
#: raven/plugins/ravenlogplugin.py:96
|
||||||
msgid "E&xit"
|
msgid "E&xit"
|
||||||
msgstr "&Beenden"
|
msgstr "&Beenden"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"POT-Creation-Date: 2022-02-03 18:28+0100\n"
|
"POT-Creation-Date: 2022-02-06 08:14+0100\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@@ -19,7 +19,7 @@ msgstr ""
|
|||||||
msgid "About RavenLog"
|
msgid "About RavenLog"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./aboutdialog.py:23 ./raven/mainwindow.py:40 ./ravenui.py:19
|
#: ./aboutdialog.py:23 ./raven/mainwindow.py:39 ./ravenui.py:19
|
||||||
msgid "RavenLog"
|
msgid "RavenLog"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ msgstr ""
|
|||||||
msgid "Select &All"
|
msgid "Select &All"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./bigtext.py:188 ./raven/mainwindow.py:117
|
#: ./bigtext.py:188 ./raven/mainwindow.py:101
|
||||||
msgid "&Highlighter"
|
msgid "&Highlighter"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -199,32 +199,32 @@ msgstr ""
|
|||||||
msgid "You have unsaved changes."
|
msgid "You have unsaved changes."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/mainwindow.py:48 ./raven/plugins/openfileplugin.py:31
|
#: ./raven/mainwindow.py:47 ./raven/plugins/openfileplugin.py:31
|
||||||
msgid "Open &Recent"
|
msgid "Open &Recent"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/mainwindow.py:67
|
#: ./raven/mainwindow.py:66
|
||||||
#: ./venv310/lib/python3.10/site-packages/PySide6/examples/widgets/gettext/main.py:57
|
#: ./venv310/lib/python3.10/site-packages/PySide6/examples/widgets/gettext/main.py:57
|
||||||
msgid "&File"
|
msgid "&File"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/mainwindow.py:68
|
#: ./raven/mainwindow.py:67
|
||||||
msgid "&Settings"
|
msgid "&Settings"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/mainwindow.py:69
|
#: ./raven/mainwindow.py:68
|
||||||
msgid "&Window"
|
msgid "&Window"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/mainwindow.py:70
|
#: ./raven/mainwindow.py:69
|
||||||
msgid "&Help"
|
msgid "&Help"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/mainwindow.py:125
|
#: ./raven/mainwindow.py:109
|
||||||
msgid "Highlight &Searches"
|
msgid "Highlight &Searches"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/mainwindow.py:134
|
#: ./raven/mainwindow.py:118
|
||||||
msgid "Open Tab on Save As File"
|
msgid "Open Tab on Save As File"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -252,27 +252,35 @@ msgstr ""
|
|||||||
msgid "Open File"
|
msgid "Open File"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/plugins/ravenlogplugin.py:40
|
#: ./raven/plugins/ravenlogplugin.py:43
|
||||||
msgid "&Languages"
|
msgid "&Languages"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/plugins/ravenlogplugin.py:41
|
#: ./raven/plugins/ravenlogplugin.py:44
|
||||||
msgid "&Default"
|
msgid "&Default"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/plugins/ravenlogplugin.py:42
|
#: ./raven/plugins/ravenlogplugin.py:45
|
||||||
msgid "&English"
|
msgid "&English"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/plugins/ravenlogplugin.py:43
|
#: ./raven/plugins/ravenlogplugin.py:46
|
||||||
msgid "&German"
|
msgid "&German"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/plugins/ravenlogplugin.py:65
|
#: ./raven/plugins/ravenlogplugin.py:70
|
||||||
|
msgid "Language Changed"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ./raven/plugins/ravenlogplugin.py:71
|
||||||
|
msgid "The language for this application has been changed. The change will take effect the next time the application is started."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ./raven/plugins/ravenlogplugin.py:88
|
||||||
msgid "&About"
|
msgid "&About"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ./raven/plugins/ravenlogplugin.py:73
|
#: ./raven/plugins/ravenlogplugin.py:96
|
||||||
msgid "E&xit"
|
msgid "E&xit"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
7
main.py
7
main.py
@@ -1,12 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import signal
|
import signal
|
||||||
import ctypes
|
import ctypes
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from PySide6 import QtCore
|
from PySide6 import QtCore
|
||||||
from PySide6.QtWidgets import QApplication
|
from PySide6.QtWidgets import QApplication
|
||||||
from PySide6.QtCore import QTimer, QLibraryInfo, QTranslator, QLocale
|
from PySide6.QtCore import QTimer
|
||||||
from PySide6.QtGui import QIcon
|
from PySide6.QtGui import QIcon
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -15,9 +13,6 @@ from raven.pluginregistry import PluginRegistry
|
|||||||
from ravenui import RavenUI
|
from ravenui import RavenUI
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
from settingsstore import SettingsStore
|
|
||||||
|
|
||||||
gettext.install('ravenlog', 'locale')
|
gettext.install('ravenlog', 'locale')
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ import gettext
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from raven.pluginregistry import PluginRegistry
|
||||||
from settingsstore import SettingsStore
|
from settingsstore import SettingsStore
|
||||||
|
|
||||||
settings = SettingsStore.load()
|
settings = SettingsStore.load()
|
||||||
locale = os.environ['LANG'] if os.environ['LANG'] else "en"
|
locale = os.environ['LANG'] if os.environ['LANG'] else "en"
|
||||||
|
print("locale1: %s" % locale)
|
||||||
locale = settings.session.get('general', 'lang', fallback=locale)
|
locale = settings.session.get('general', 'lang', fallback=locale)
|
||||||
|
print("locale2: %s" % locale)
|
||||||
|
|
||||||
_ = False
|
_ = False
|
||||||
src_dir = Path(__file__).resolve().parent.parent
|
src_dir = Path(__file__).resolve().parent.parent
|
||||||
@@ -16,9 +19,11 @@ try:
|
|||||||
translation.install()
|
translation.install()
|
||||||
_ = translation.gettext
|
_ = translation.gettext
|
||||||
ngettext = translation.ngettext
|
ngettext = translation.ngettext
|
||||||
|
PluginRegistry.execute("set_locale", locale)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
if not _:
|
if not _:
|
||||||
_ = gettext.gettext
|
_ = gettext.gettext
|
||||||
ngettext = gettext.ngettext
|
ngettext = gettext.ngettext
|
||||||
|
PluginRegistry.execute("set_locale", '')
|
||||||
print('No translation found')
|
print('No translation found')
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from raven.pluginregistry import PluginRegistry
|
|||||||
from raven.plugins.domain.menucontribution import MenuContribution, sort_menu_contributions
|
from raven.plugins.domain.menucontribution import MenuContribution, sort_menu_contributions
|
||||||
from raven.plugins.domain.raction import RAction
|
from raven.plugins.domain.raction import RAction
|
||||||
from raven.plugins.domain.rmenu import RMenu
|
from raven.plugins.domain.rmenu import RMenu
|
||||||
from raven.plugins.ravenlog.Tab import Tab
|
|
||||||
from settingsstore import SettingsStore
|
from settingsstore import SettingsStore
|
||||||
from highlightingdialog import HighlightingDialog
|
from highlightingdialog import HighlightingDialog
|
||||||
from tabs import Tabs
|
from tabs import Tabs
|
||||||
@@ -77,7 +76,7 @@ class MainWindow(QMainWindow):
|
|||||||
continue
|
continue
|
||||||
for menu_contribution in mcs:
|
for menu_contribution in mcs:
|
||||||
if menu_contribution.action:
|
if menu_contribution.action:
|
||||||
action = self._raction_to_qaction(menu_contribution.action, menu)
|
action = menu_contribution.action.to_qaction(menu)
|
||||||
menu.addAction(action)
|
menu.addAction(action)
|
||||||
if menu_contribution.menu:
|
if menu_contribution.menu:
|
||||||
submenu = QMenu(menu_contribution.menu.label, menu_bar)
|
submenu = QMenu(menu_contribution.menu.label, menu_bar)
|
||||||
@@ -93,25 +92,10 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def _rmenu_update(self, qmenu: QMenu, rmenu: RMenu):
|
def _rmenu_update(self, qmenu: QMenu, rmenu: RMenu):
|
||||||
qmenu.clear()
|
qmenu.clear()
|
||||||
for action in rmenu.actions:
|
for raction in rmenu.actions:
|
||||||
action = self._raction_to_qaction(action, qmenu)
|
action = raction.to_qaction(qmenu)
|
||||||
qmenu.addAction(action)
|
qmenu.addAction(action)
|
||||||
|
|
||||||
def _raction_to_qaction(self, raction: RAction, qmenu: QMenu) -> QAction:
|
|
||||||
action = QAction(_(raction.label), qmenu)
|
|
||||||
if raction.icon_from_theme:
|
|
||||||
action.setIcon(QIcon.fromTheme(raction.icon_from_theme))
|
|
||||||
if raction.icon_file:
|
|
||||||
action.setIcon(QIcon(raction.icon_file))
|
|
||||||
if raction.shortcut:
|
|
||||||
action.setShortcut(raction.shortcut)
|
|
||||||
if raction.action:
|
|
||||||
action.triggered.connect(raction.action)
|
|
||||||
if raction.checkable:
|
|
||||||
action.setCheckable(raction.checkable)
|
|
||||||
action.setChecked(raction.checked)
|
|
||||||
return action
|
|
||||||
|
|
||||||
def _action_highlighter(self):
|
def _action_highlighter(self):
|
||||||
manage = RAction(
|
manage = RAction(
|
||||||
_("&Highlighter"),
|
_("&Highlighter"),
|
||||||
@@ -121,13 +105,11 @@ class MainWindow(QMainWindow):
|
|||||||
return manage
|
return manage
|
||||||
|
|
||||||
def _action_highlight_search_terms(self):
|
def _action_highlight_search_terms(self):
|
||||||
highlight_search_terms = RAction(
|
highlight_search_terms = RAction(_("Highlight &Searches"))
|
||||||
_("Highlight &Searches"),
|
|
||||||
action=lambda checked: self.settings.set_session("general", "highlight_search_term",
|
|
||||||
str(checked)) or self.update()
|
|
||||||
)
|
|
||||||
highlight_search_terms.set_checkable(True)
|
highlight_search_terms.set_checkable(True)
|
||||||
highlight_search_terms.set_checked(self.settings.session.getboolean("general", "highlight_search_term"))
|
highlight_search_terms.set_checked(self.settings.session.getboolean("general", "highlight_search_term"))
|
||||||
|
highlight_search_terms.set_action(lambda: self.settings.set_session("general", "highlight_search_term",
|
||||||
|
str(highlight_search_terms.checked)) or self.update())
|
||||||
return highlight_search_terms
|
return highlight_search_terms
|
||||||
|
|
||||||
def _action_new_tab(self):
|
def _action_new_tab(self):
|
||||||
@@ -135,7 +117,7 @@ class MainWindow(QMainWindow):
|
|||||||
new_tab.set_checkable(True)
|
new_tab.set_checkable(True)
|
||||||
new_tab.set_checked(self.settings.session.getboolean("general", "open_tab_on_save_as_file"))
|
new_tab.set_checked(self.settings.session.getboolean("general", "open_tab_on_save_as_file"))
|
||||||
new_tab.set_action(
|
new_tab.set_action(
|
||||||
lambda checked: self.settings.set_session("general", "open_tab_on_save_as_file", str(checked)))
|
lambda: self.settings.set_session("general", "open_tab_on_save_as_file", str(new_tab.checked)))
|
||||||
return new_tab
|
return new_tab
|
||||||
|
|
||||||
def dragEnterEvent(self, e: QDragEnterEvent):
|
def dragEnterEvent(self, e: QDragEnterEvent):
|
||||||
|
|||||||
@@ -1,14 +1,30 @@
|
|||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
from PySide6.QtGui import QAction, QIcon
|
||||||
|
from PySide6.QtWidgets import QMenu
|
||||||
|
|
||||||
|
|
||||||
class RAction():
|
class RAction():
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
label: str,
|
label: str,
|
||||||
action=None,
|
action: Callable[[], None] = None,
|
||||||
shortcut: str = None,
|
shortcut: str = None,
|
||||||
icon_from_theme: str = None,
|
icon_from_theme: str = None,
|
||||||
icon_file: str = None,
|
icon_file: str = None,
|
||||||
checkable: bool = False,
|
checkable: bool = False,
|
||||||
checked: bool = False
|
checked: bool = False
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
|
||||||
|
:param label: the label
|
||||||
|
:param action: the callback to be executed when clicked. Note: use the setter when creating a checkable menu item
|
||||||
|
:param shortcut: the shortcut, e.g. 'Ctrl+X'
|
||||||
|
:param icon_from_theme: environment specific name of an icon. On Linux: /usr/share/icons
|
||||||
|
:param icon_file: path to an icon
|
||||||
|
:param checkable: if this menu item behaves like a checkbox
|
||||||
|
:param checked: if it is checked
|
||||||
|
"""
|
||||||
super(RAction, self).__init__()
|
super(RAction, self).__init__()
|
||||||
self.label = label
|
self.label = label
|
||||||
self.action = action
|
self.action = action
|
||||||
@@ -17,9 +33,16 @@ class RAction():
|
|||||||
self.icon_file = icon_file
|
self.icon_file = icon_file
|
||||||
self.checkable = checkable
|
self.checkable = checkable
|
||||||
self.checked = checked
|
self.checked = checked
|
||||||
|
self._action: QAction = None
|
||||||
|
|
||||||
def set_action(self, action):
|
def set_action(self, action):
|
||||||
self.action = action
|
self.action = lambda *args: self.decorated_action(action)
|
||||||
|
|
||||||
|
def decorated_action(self, action):
|
||||||
|
if self.checkable:
|
||||||
|
self.checked = not self.checked
|
||||||
|
self._update_check_state()
|
||||||
|
action()
|
||||||
|
|
||||||
def set_icon_from_theme(self, icon_from_theme: str):
|
def set_icon_from_theme(self, icon_from_theme: str):
|
||||||
self.icon_from_theme = icon_from_theme
|
self.icon_from_theme = icon_from_theme
|
||||||
@@ -35,3 +58,31 @@ class RAction():
|
|||||||
|
|
||||||
def set_checked(self, checked: bool):
|
def set_checked(self, checked: bool):
|
||||||
self.checked = checked
|
self.checked = checked
|
||||||
|
self._update_check_state()
|
||||||
|
|
||||||
|
def _update_check_state(self):
|
||||||
|
if self._action:
|
||||||
|
if self.checked:
|
||||||
|
self._action.setIcon(QIcon("icons/ionicons/checkbox-outline.svg"))
|
||||||
|
else:
|
||||||
|
self._action.setIcon(QIcon("icons/ionicons/square-outline.svg"))
|
||||||
|
|
||||||
|
def set_label(self, label: str):
|
||||||
|
if self._action:
|
||||||
|
self._action.setText(label)
|
||||||
|
|
||||||
|
def to_qaction(self, qmenu: QMenu) -> QAction:
|
||||||
|
action = QAction(self.label, qmenu)
|
||||||
|
self._action = action
|
||||||
|
if self.icon_from_theme:
|
||||||
|
action.setIcon(QIcon.fromTheme(self.icon_from_theme))
|
||||||
|
if self.icon_file:
|
||||||
|
action.setIcon(QIcon(self.icon_file))
|
||||||
|
if self.shortcut:
|
||||||
|
action.setShortcut(self.shortcut)
|
||||||
|
if self.action:
|
||||||
|
action.triggered.connect(self.action)
|
||||||
|
if self.checkable:
|
||||||
|
self._update_check_state()
|
||||||
|
|
||||||
|
return action
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
from typing import Optional, Callable
|
from typing import Optional, Callable, Dict
|
||||||
|
|
||||||
from PySide6.QtCore import Qt
|
from PySide6.QtCore import Qt
|
||||||
from PySide6.QtWidgets import QDockWidget
|
from PySide6.QtWidgets import QDockWidget, QMessageBox
|
||||||
|
|
||||||
import constants
|
import constants
|
||||||
from aboutdialog import AboutDialog
|
from aboutdialog import AboutDialog
|
||||||
@@ -12,7 +12,7 @@ from raven.plugins.domain.menucontribution import MenuContribution
|
|||||||
from raven.plugins.domain.raction import RAction
|
from raven.plugins.domain.raction import RAction
|
||||||
from raven.plugins.domain.rmenu import RMenu
|
from raven.plugins.domain.rmenu import RMenu
|
||||||
from raven.plugins.ravenlog.Tab import Tab
|
from raven.plugins.ravenlog.Tab import Tab
|
||||||
from raven.i18n import _
|
from raven.i18n import _, locale
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
|
||||||
|
|
||||||
@@ -20,6 +20,9 @@ class RavenLogPlugin(PluginBase):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(RavenLogPlugin, self).__init__()
|
super(RavenLogPlugin, self).__init__()
|
||||||
self.main_window = None
|
self.main_window = None
|
||||||
|
self._locale = locale
|
||||||
|
self._locale_actions = {}
|
||||||
|
self.settings = None
|
||||||
|
|
||||||
def set_settings(self, settings: Settings):
|
def set_settings(self, settings: Settings):
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
@@ -38,16 +41,36 @@ class RavenLogPlugin(PluginBase):
|
|||||||
|
|
||||||
def _sub_menu_languages(self) -> RMenu:
|
def _sub_menu_languages(self) -> RMenu:
|
||||||
menu = RMenu(_("&Languages"))
|
menu = RMenu(_("&Languages"))
|
||||||
menu.add_action(RAction(_("&Default"), lambda: self._set_lang('')))
|
self._locale_actions[''] = RAction(_("&Default"), lambda: self._change_locale(''), checkable=True)
|
||||||
menu.add_action(RAction(_("&English"), lambda: self._set_lang('en')))
|
self._locale_actions['en'] = RAction(_("&English"), lambda: self._change_locale('en'), checkable=True)
|
||||||
menu.add_action(RAction(_("&German"), lambda: self._set_lang('de')))
|
self._locale_actions['de'] = RAction(_("&German"), lambda: self._change_locale('de'), checkable=True)
|
||||||
|
|
||||||
|
for (key, action) in self._locale_actions.items():
|
||||||
|
action.checked = self._locale == key
|
||||||
|
menu.add_action(action)
|
||||||
|
|
||||||
|
if not self._locale in self._locale_actions.keys():
|
||||||
|
self._locale_actions[''].checked = True
|
||||||
return menu
|
return menu
|
||||||
|
|
||||||
def _set_lang(self, lang: str):
|
def _change_locale(self, locale: str):
|
||||||
if (lang == ''):
|
if self._locale != locale:
|
||||||
self.settings.session.remove_option('general', 'lang')
|
if self._locale in self._locale_actions:
|
||||||
else:
|
self._locale_actions[self._locale].set_checked(False)
|
||||||
self.settings.session.set('general', 'lang', lang)
|
|
||||||
|
self._locale_actions[locale].set_checked(True)
|
||||||
|
self._locale = locale
|
||||||
|
if locale == '':
|
||||||
|
self.settings.session.remove_option('general', 'lang')
|
||||||
|
else:
|
||||||
|
self.settings.session.set('general', 'lang', locale)
|
||||||
|
|
||||||
|
info = QMessageBox(
|
||||||
|
QMessageBox.Icon.Information,
|
||||||
|
_("Language Changed"),
|
||||||
|
_("The language for this application has been changed. The change will take effect the next time the application is started."))
|
||||||
|
info.setStandardButtons(QMessageBox.Ok)
|
||||||
|
info.exec()
|
||||||
|
|
||||||
def current_file(self) -> Optional[str]:
|
def current_file(self) -> Optional[str]:
|
||||||
return self.main_window.tabs.current_file()
|
return self.main_window.tabs.current_file()
|
||||||
|
|||||||
Reference in New Issue
Block a user