Skip to content

Commit

Permalink
添加语言配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyiYo committed Jan 24, 2023
1 parent d5730d2 commit b42172f
Show file tree
Hide file tree
Showing 28 changed files with 49,803 additions and 44,759 deletions.
3 changes: 2 additions & 1 deletion Groove.pro
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ SOURCES += app/View/main_window/main_window.py \
app/components/settings/folder_list_setting_card.py \
app/components/settings/setting_card.py \

TRANSLATIONS += app/resource/i18n/Groove_zh.ts
TRANSLATIONS += app/resource/i18n/Groove_zh.ts \
app/resource/i18n/Groove_hk.ts
17 changes: 10 additions & 7 deletions app/Groove.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from PyQt5.QtWidgets import QApplication

from common.application import SingletonApplication
from common.config import config
from common.dpi_manager import dpi_manager
from common.config import config, Language
from common.dpi_manager import DPI_SCALE
from View.main_window import MainWindow


Expand All @@ -22,10 +22,7 @@

# enable high dpi scale
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0"
if config.get(config.dpiScale) == "Auto":
os.environ["QT_SCALE_FACTOR"] = str(max(1, dpi_manager.scale-0.25))
else:
os.environ["QT_SCALE_FACTOR"] = str(config.get(config.dpiScale))
os.environ["QT_SCALE_FACTOR"] = str(DPI_SCALE)

QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

Expand All @@ -34,7 +31,13 @@

# Internationalization
translator = QTranslator()
translator.load(QLocale.system(), ":/i18n/Groove_")
language = config.get(config.language) # type: Language

if language == Language.AUTO:
translator.load(QLocale.system(), ":/i18n/Groove_")
elif language != Language.ENGLISH:
translator.load(f":/i18n/Groove_{language.value}.qm")

app.installTranslator(translator)

# create main window
Expand Down
7 changes: 5 additions & 2 deletions app/View/my_music_interface/tool_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def paintEvent(self, QPaintEvent):
""" paint horizontal line """
super().paintEvent(QPaintEvent)
painter = QPainter(self)
r = 46 if config.theme == 'dark' else 229
r = 55 if config.theme == 'dark' else 229
painter.setPen(QColor(r, r, r))
painter.drawLine(30, 176, self.width()-20, 176)

Expand Down Expand Up @@ -208,13 +208,16 @@ def __paintLine(self, painter, x1, y1, x2, y2, x3, y3, x4, y4):
QPoint(x3, y3), QPoint(x4, y4)]
painter.drawPolygon(QPolygon(points), 4)

def __paintAllText(self, painter, fontSize=16):
def __paintAllText(self, painter: QPainter, fontSize=16):
""" paint all texts """
isDark = config.theme == 'dark'

if not self.isSelected:
r = 153 if isDark else 102
painter.setPen(QColor(r, r, r))
else:
r = 255 if isDark else 0
painter.setPen(QColor(r, r, r))

if not self.pressedPos:
if self.isEnter:
Expand Down
11 changes: 7 additions & 4 deletions app/View/playlist_card_interface/playlist_card_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
PlaylistSelectionModeInterface, SelectionModeBarType)
from components.widgets.menu import AeroMenu
from PyQt5.QtCore import QMargins, QPoint, pyqtSignal
from PyQt5.QtWidgets import QAction, QLabel, QPushButton, QWidget
from PyQt5.QtWidgets import QAction, QApplication, QLabel, QPushButton, QWidget


class PlaylistCardInterface(PlaylistSelectionModeInterface):
Expand Down Expand Up @@ -82,21 +82,24 @@ def __initLayout(self):
self.playlistLabel.move(30, 54)
self.createPlaylistButton.move(30, 131)
self.sortModeLabel.move(
self.createPlaylistButton.geometry().right()+30, 133)
self.createPlaylistButton.geometry().right()+30, 136)
self.sortModeButton.move(self.sortModeLabel.geometry().right()+7, 132)

def __setQss(self):
""" set style sheet """
self.sortModeLabel.setMinimumSize(50, 28)
self.guideLabel.setMinimumSize(600, 40)
self.playlistLabel.setObjectName("playlistLabel")
self.sortModeLabel.setObjectName("sortModeLabel")
self.sortModeButton.setObjectName("sortModeButton")
self.createPlaylistButton.setObjectName("createPlaylistButton")
self.sortModeMenu.setObjectName("sortModeMenu")
self.sortModeMenu.setProperty("modeNumber", "2")
self.guideLabel.setObjectName('guideLabel')

# force style sheets to take effect
setStyleSheet(self, 'playlist_card_interface')
self.setStyle(QApplication.style())
QApplication.processEvents()

self.createPlaylistButton.adjustSize()
self.sortModeLabel.adjustSize()
self.sortModeButton.adjustSize()
Expand Down
20 changes: 11 additions & 9 deletions app/View/recent_play_interface/recent_play_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from common.database.entity import SongInfo
from common.library import Library
from common.signal_bus import signalBus
from common.style_sheet import getStyleSheet
from common.style_sheet import setStyleSheet
from components.buttons.three_state_button import RandomPlayAllButton
from components.dialog_box.message_dialog import MessageDialog
from components.selection_mode_interface import (SelectionModeBarType,
SongSelectionModeInterface)
from PyQt5.QtCore import QFile, pyqtSignal
from PyQt5.QtWidgets import QLabel, QPushButton, QWidget
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QLabel, QPushButton, QWidget, QApplication

from .song_list_widget import RecentSongListWidget

Expand Down Expand Up @@ -38,26 +38,28 @@ def __init__(self, library: Library, parent=None):
def __initWidget(self):
""" initialize widgets """
self.resize(1300, 970)
self.randomPlayAllButton.setNumber(self.songListWidget.songCardNum)
self.__setQss()

self.randomPlayAllButton.setNumber(self.songListWidget.songCardNum)

self.recentPlayLabel.move(30, 54)
self.randomPlayAllButton.move(30, 131)
self.sortModeLabel.move(
self.randomPlayAllButton.geometry().right()+30, 129)
self.sortModeButton.move(self.sortModeLabel.geometry().right()+7, 129)
self.randomPlayAllButton.geometry().right()+30, 131)
self.sortModeButton.move(self.sortModeLabel.geometry().right()+7, 128)

self.__connectSignalToSlot()

def __setQss(self):
""" set style sheet """
self.sortModeLabel.setMinimumSize(50, 28)
self.recentPlayLabel.setObjectName('recentPlayLabel')
self.sortModeLabel.setObjectName("sortModeLabel")
self.sortModeButton.setObjectName("sortModeButton")

qss = getStyleSheet('recent_play_interface')
self.setStyleSheet(self.styleSheet()+qss)
# force style sheets to take effect
setStyleSheet(self, 'recent_play_interface')
self.setStyle(QApplication.style())
QApplication.processEvents()

self.randomPlayAllButton.adjustSize()
self.sortModeLabel.adjustSize()
Expand Down
22 changes: 14 additions & 8 deletions app/View/setting_interface/setting_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from common.style_sheet import setStyleSheet
from common.thread.crawl_meta_data_thread import CrawlFolderMetaDataThread
from components.layout.expand_layout import ExpandLayout
from components.widgets.scroll_area import ScrollArea
from components.widgets.scroll_area import ScrollArea, SmoothScrollArea, SmoothMode
from components.widgets.tooltip import ToastTooltip, StateTooltip
from components.settings import (SettingCardGroup, SwitchSettingCard, FolderListSettingCard,
OptionsSettingCard, RangeSettingCard, PushSettingCard,
Expand All @@ -15,7 +15,7 @@
from PyQt5.QtWidgets import QWidget, QLabel, QFontDialog, QFileDialog


class SettingInterface(ScrollArea):
class SettingInterface(SmoothScrollArea):
""" Setting interface """

checkUpdateSig = pyqtSignal()
Expand Down Expand Up @@ -64,6 +64,7 @@ def __init__(self, parent=None):
config.themeMode,
SIF.create(SIF.BRUSH),
self.tr('Application theme'),
self.tr('Choose a color theme to personalize Groove Music'),
texts=[
self.tr('Light'), self.tr('Dark'),
self.tr('Use system setting')
Expand All @@ -81,6 +82,14 @@ def __init__(self, parent=None):
],
parent=self.personalGroup
)
self.languageCard=OptionsSettingCard(
config.language,
SIF.create(SIF.LANGUAGE),
self.tr('Language'),
self.tr('Set your preferred language for UI'),
texts=['简体中文', '繁體中文', 'English', self.tr('Use system setting')],
parent=self.personalGroup
)

# media info
self.mediaInfoGroup = SettingCardGroup(
Expand Down Expand Up @@ -257,9 +266,9 @@ def __init__(self, parent=None):
def __initWidget(self):
self.resize(1000, 800)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setViewportMargins(0, 120, 0, 0)
self.setViewportMargins(0, 120, 0, 133)
self.setWidget(self.scrollWidget)
self.scrollWidget.resize(self.width(), 2750)
self.setWidgetResizable(True)

# initialize style sheet
self.scrollWidget.setObjectName('scrollWidget')
Expand All @@ -282,6 +291,7 @@ def __initLayout(self):
self.personalGroup.addSettingCard(self.enableAcrylicCard)
self.personalGroup.addSettingCard(self.themeCard)
self.personalGroup.addSettingCard(self.zoomCard)
self.personalGroup.addSettingCard(self.languageCard)

self.mediaInfoGroup.addSettingCard(self.crawlMetadataCard)

Expand Down Expand Up @@ -324,10 +334,6 @@ def __initLayout(self):
self.expandLayout.addWidget(self.updateSoftwareGroup)
self.expandLayout.addWidget(self.aboutGroup)

def resizeEvent(self, e):
self.scrollWidget.resize(self.width(), self.scrollWidget.height())
super().resizeEvent(e)

def __updateMetaDataCardEnabled(self):
""" set the enabled state of meta data switch button """
self.crawlMetadataCard.switchButton.setEnabled(
Expand Down
11 changes: 11 additions & 0 deletions app/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
from .signal_bus import signalBus


class Language(Enum):
""" Language enumeration """

CHINESE_SIMPLIFIED = "zh"
CHINESE_TRADITIONAL = "hk"
ENGLISH = "en"
AUTO = "Auto"


class ConfigValidator:
""" Config validator """

Expand Down Expand Up @@ -273,6 +282,8 @@ class Config(Singleton):
"MainWindow", "RecentPlayNumbers", 300, RangeValidator(10, 300))
dpiScale = OptionsConfigItem(
"MainWindow", "DpiScale", "Auto", OptionsValidator([1, 1.25, 1.5, 1.75, 2, "Auto"]), restart=True)
language = OptionsConfigItem(
"MainWindow", "Language", Language.AUTO, OptionsValidator(Language), EnumSerializer(Language), restart=True)

# media player
randomPlay = ConfigItem("Player", "RandomPlay", False, BoolValidator())
Expand Down
9 changes: 8 additions & 1 deletion app/common/dpi_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from PyQt5 import sip


from .config import config


class DPIManager:
""" DPI Manager """

Expand Down Expand Up @@ -80,9 +83,13 @@ class MacDPIManager(DPIManager):

def _get_scale(self) -> float:
# for screen in NSScreen.screens():
# return screen.backingScaleFactor()
# return screen.backingScaleFactor()

return 1


dpi_manager = DPIManager()
if config.get(config.dpiScale) == "Auto":
DPI_SCALE = max(1, dpi_manager.scale-0.25)
else:
DPI_SCALE = config.get(config.dpiScale)
Loading

0 comments on commit b42172f

Please sign in to comment.