Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirMahdaviAM committed Apr 6, 2024
0 parents commit abc95a3
Show file tree
Hide file tree
Showing 57 changed files with 36,980 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Byte-compiled / optimized / DLL files
*/__pycache__
*.py[cod]
*$py.class

# vscode
.vscode/
.VSCodeCounter

# scshub
*.log
tools/config.json
tools/converter_pix.exe
tools/scs_extractor.exe
9 changes: 9 additions & 0 deletions SCSHub.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SOURCES += SCSHub/view/interface/main_window.py \
SCSHub/view/interface/home_interface.py \
SCSHub/view/interface/pix_interface.py \
SCSHub/view/interface/scs_interface.py \
SCSHub/view/interface/setting_interface.py \
SCSHub/view/ui/pix_ui.py \
SCSHub/view/ui/scs_ui.py \

TRANSLATIONS += SCSHub/resource/locale/scshub.ts \
39 changes: 39 additions & 0 deletions SCSHub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import sys
from PyQt5.QtCore import Qt, QTranslator
from PyQt5.QtWidgets import QApplication

from qfluentwidgets import FluentTranslator

from scshub.common.config import cfg
from scshub.view.main_window import MainWindow

# enable dpi scale
if cfg.get(cfg.dpiScale) == "Auto":
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
else:
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0"
os.environ["QT_SCALE_FACTOR"] = str(cfg.get(cfg.dpiScale))

QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

# create application
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)

# internationalization
locale = cfg.get(cfg.language).value
translator = FluentTranslator(locale)
scsHubTranslator = QTranslator()
scsHubTranslator.load(locale, "SCSHub", ".", ":/SCSHub/locale")

app.installTranslator(translator)
app.installTranslator(scsHubTranslator)

# create main window
w = MainWindow()
w.show()

app.exec_()
135 changes: 135 additions & 0 deletions scshub/common/card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtWidgets import QLabel, QVBoxLayout, QWidget, QHBoxLayout

from qfluentwidgets import (IconWidget, TextWrap, SingleDirectionScrollArea, FlowLayout, CardWidget,
ElevatedCardWidget , FluentIcon)

from .tool import StyleSheet, signalBus


class LinkCard(ElevatedCardWidget):

def __init__(self, icon, title, content, url, parent=None):
super().__init__(parent=parent)
self.url = QUrl(url)
self.setFixedSize(198, 220)
self.iconWidget = IconWidget(icon, self)
self.titleLabel = QLabel(title, self)
self.contentLabel = QLabel(TextWrap.wrap(content, 20, False)[0], self)
self.urlWidget = IconWidget(FluentIcon.LINK, self)

self.__initWidget()

def __initWidget(self):
self.setCursor(Qt.PointingHandCursor)

self.iconWidget.setFixedSize(54, 54)
self.urlWidget.setFixedSize(16, 16)

self.vBoxLayout = QVBoxLayout(self)
self.vBoxLayout.setSpacing(0)
self.vBoxLayout.setContentsMargins(24, 24, 24, 24)
self.vBoxLayout.addWidget(self.iconWidget)
self.vBoxLayout.addSpacing(16)
self.vBoxLayout.addWidget(self.titleLabel)
self.vBoxLayout.addSpacing(8)
self.vBoxLayout.addWidget(self.contentLabel)
self.vBoxLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.urlWidget.move(170, 192)

self.titleLabel.setObjectName('titleLabel')
self.contentLabel.setObjectName('contentLabel')

def mouseReleaseEvent(self, e):
super().mouseReleaseEvent(e)
QDesktopServices.openUrl(self.url)

class LinkCardView(SingleDirectionScrollArea):

def __init__(self, parent=None):
super().__init__(parent, Qt.Horizontal)
self.view = QWidget(self)
self.hBoxLayout = QHBoxLayout(self.view)

self.hBoxLayout.setContentsMargins(30, 10, 30, 10)
self.hBoxLayout.setSpacing(16)
self.hBoxLayout.setAlignment(Qt.AlignLeft)

self.setWidget(self.view)
self.setWidgetResizable(True)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

self.view.setObjectName('view')
StyleSheet.LINK_CARD.apply(self)

def addCard(self, icon, title, content, url):
""" add link card """
card = LinkCard(icon, title, content, url, self.view)
self.hBoxLayout.addWidget(card, 0, Qt.AlignLeft)


class InterfaceCard(CardWidget):

def __init__(self, icon, title, content, routeKey, parent=None):
super().__init__(parent=parent)
self.routekey = routeKey

self.setCursor(Qt.PointingHandCursor)

self.iconWidget = IconWidget(icon, self)
self.titleLabel = QLabel(title, self)
self.contentLabel = QLabel(TextWrap.wrap(content, 45, False)[0], self)

self.hBoxLayout = QHBoxLayout(self)
self.vBoxLayout = QVBoxLayout()

self.setFixedSize(360, 90)
self.iconWidget.setFixedSize(48, 48)

self.hBoxLayout.setSpacing(28)
self.hBoxLayout.setContentsMargins(20, 0, 0, 0)
self.vBoxLayout.setSpacing(2)
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
self.vBoxLayout.setAlignment(Qt.AlignVCenter)

self.hBoxLayout.setAlignment(Qt.AlignVCenter)
self.hBoxLayout.addWidget(self.iconWidget)
self.hBoxLayout.addLayout(self.vBoxLayout)
self.vBoxLayout.addStretch(1)
self.vBoxLayout.addWidget(self.titleLabel)
self.vBoxLayout.addWidget(self.contentLabel)
self.vBoxLayout.addStretch(1)

self.titleLabel.setObjectName('titleLabel')
self.contentLabel.setObjectName('contentLabel')

def mouseReleaseEvent(self, e):
super().mouseReleaseEvent(e)
signalBus.switchToInterface.emit(self.routekey)

class InterfaceCardView(QWidget):

def __init__(self, title: str, parent=None):
super().__init__(parent=parent)
self.titleLabel = QLabel(title, self)
self.vBoxLayout = QVBoxLayout(self)
self.flowLayout = FlowLayout()

self.vBoxLayout.setContentsMargins(30, 5, 30, 5)
self.vBoxLayout.setSpacing(10)
self.flowLayout.setContentsMargins(0, 0, 0, 0)
self.flowLayout.setHorizontalSpacing(12)
self.flowLayout.setVerticalSpacing(12)

self.vBoxLayout.addWidget(self.titleLabel)
self.vBoxLayout.addLayout(self.flowLayout, 1)

self.titleLabel.setObjectName('viewTitleLabel')
StyleSheet.SAMPLE_CARD.apply(self)

def addSampleCard(self, icon, title, content, routeKey):
""" add sample card """
card = InterfaceCard(icon, title, content, routeKey, self)
self.flowLayout.addWidget(card)
46 changes: 46 additions & 0 deletions scshub/common/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys, os
from enum import Enum

from PyQt5.QtCore import QLocale

from qfluentwidgets import (qconfig, QConfig, ConfigItem, OptionsConfigItem, BoolValidator,
OptionsValidator, Theme, ConfigSerializer)

from .tool import TOOLS_PATH


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

ENGLISH = QLocale(QLocale.English)
AUTO = QLocale()


class LanguageSerializer(ConfigSerializer):
""" Language serializer """

def serialize(self, language):
return language.value.name() if language != Language.AUTO else "Auto"

def deserialize(self, value: str):
return Language(QLocale(value)) if value != "Auto" else Language.AUTO


def isWin11():
return sys.platform == 'win32' and sys.getwindowsversion().build >= 22000


class Config(QConfig):
""" Config of application """

# main window
micaEnabled = ConfigItem("MainWindow", "MicaEnabled", isWin11(), BoolValidator())
dpiScale = OptionsConfigItem(
"MainWindow", "DpiScale", "Auto", OptionsValidator([1, 1.25, 1.5, 1.75, 2, "Auto"]), restart=True)
language = OptionsConfigItem(
"MainWindow", "Language", Language.ENGLISH, OptionsValidator(Language), LanguageSerializer(), restart=True)


cfg = Config()
cfg.themeMode.value = Theme.AUTO
qconfig.load(os.path.join(TOOLS_PATH, "config.json"), cfg)
Loading

0 comments on commit abc95a3

Please sign in to comment.