Skip to content

Commit

Permalink
Merge pull request #54 from Noloxs/task/Change_default_font
Browse files Browse the repository at this point in the history
task/Change default font
  • Loading branch information
Noloxs authored Aug 4, 2024
2 parents 07a581e + 1da6898 commit c05cc33
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
1 change: 1 addition & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
RESOURCE_PATH = "src/res/"
ICON_BASE_PATH = RESOURCE_PATH+"icons/"
STRATAGEM_ICON_PATH = ICON_BASE_PATH+"stratagems/"
FONT_BASE_PATH = RESOURCE_PATH+"fonts/"
SETTINGS_PATH = "settings.json"
LOADOUTS_PATH = "loadouts.json"

Expand Down
Binary file added src/res/fonts/ChakraPetch-Bold.ttf
Binary file not shown.
Binary file added src/res/fonts/ChakraPetch-Medium.ttf
Binary file not shown.
9 changes: 5 additions & 4 deletions src/view/pyqt5/edit_config_dialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import constants
from PyQt5.QtWidgets import QDialog, QTabWidget, QVBoxLayout, QLabel, QGridLayout, QPushButton, QWidget, QFrame
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtGui import QFont, QIcon, QFontDatabase
from PyQt5.QtCore import Qt
from src.view.pyqt5.util import show_capture_key_dialog, DropdownDialog, NumberInputDialog

Expand All @@ -12,7 +12,7 @@ def __init__(self, controller):

# Set up the dialog
self.setWindowTitle("Edit settings")
self.setGeometry(100, 100, 400, 300)
self.setGeometry(100, 100, 425, 300)

# Create a QTabWidget
self.tabs = QTabWidget()
Expand Down Expand Up @@ -215,11 +215,12 @@ def add_key_binding(self, grid_layout, desc, key, add_separator, callback):
grid_layout.addWidget(self.create_button(callback), row, 2)

def add_settings_headline(self, grid_layout, headline):
headline = QLabel(headline)
headline = QLabel(headline.upper())
headline.setFixedHeight(35)
headline.setContentsMargins(20,0,0,0)
headline.setStyleSheet("background-color: "+constants.COLOR_SETTINGS_HEADLINE_BACKGROUND)
font = QFont("Arial", 14)
chakra_petch_bold = QFontDatabase.applicationFontFamilies(1)[0]
font = QFont(chakra_petch_bold, 12)
font.setBold(True)
headline.setFont(font)

Expand Down
11 changes: 6 additions & 5 deletions src/view/pyqt5/edit_loadout_dialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import constants
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QComboBox, QHBoxLayout, QLineEdit, QPushButton, QListWidget, QAbstractItemView, QMenuBar, QAction, QWidget, QLabel, QListWidgetItem, QInputDialog
from PyQt5.QtGui import QIcon, QFont
from PyQt5.QtGui import QIcon, QFont, QFontDatabase
from PyQt5.QtCore import QSize, Qt
from PyQt5.QtSvg import QSvgWidget
from copy import deepcopy
Expand All @@ -15,8 +15,8 @@ def __init__(self, controller):

self.setWindowTitle("Edit loadouts")
self.setWindowIcon(QIcon(constants.ICON_BASE_PATH+"hell_snake.png"))
self.setMinimumSize(300, 300)
self.resize(300,600)
self.setMinimumSize(400, 300)
self.resize(400,600)

iconSize = QSize(30, 30)
# Layout
Expand Down Expand Up @@ -208,7 +208,8 @@ def __init__ (self, parent = None):
self.key = QLabel()
self.key.setFixedSize(25, 25)
self.key.setAlignment(Qt.AlignCenter)
font = QFont("Arial", 18)
chakra_petch_medium = QFontDatabase.applicationFontFamilies(0)[0]
font = QFont(chakra_petch_medium, 18)
font.setBold(True)
self.key.setFont(font)
self.hBox.addWidget(self.key)
Expand All @@ -220,7 +221,7 @@ def __init__ (self, parent = None):
self.setLayout(self.hBox)

def setStratagem(self, stratagem):
self.name.setText(stratagem.name)
self.name.setText(stratagem.name.upper())
svg_widget = QSvgWidget(constants.STRATAGEM_ICON_PATH+stratagem.icon_name)
svg_widget.setFixedSize(20,20)
svg_widget.setStyleSheet("background-color: transparent")
Expand Down
4 changes: 2 additions & 2 deletions src/view/pyqt5/filter_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def __init__(self, controller, key, callback = None):

self.controller = controller
self.key = key
self.setMinimumSize(300, 300)
self.resize(300,800)
self.setMinimumSize(325, 300)
self.resize(325,800)

self.setWindowTitle("Select new stratagem for: "+self.key)
self.setWindowIcon(QIcon(constants.ICON_BASE_PATH+"hell_snake.png"))
Expand Down
19 changes: 10 additions & 9 deletions src/view/pyqt5/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PyQt5.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QListWidget, QAbstractItemView, QAction, QListWidgetItem, QFrame, QApplication
from PyQt5.QtGui import QIcon, QFont, QPixmap
from PyQt5.QtGui import QIcon, QFont, QPixmap, QFontDatabase
from PyQt5.QtCore import Qt
from PyQt5.QtSvg import QSvgWidget
import constants
Expand All @@ -15,8 +15,8 @@ def __init__(self, controller : Controller):
self.controller = controller
self.setWindowTitle("Hell snake")
self.setWindowIcon(QIcon(constants.ICON_BASE_PATH+"hell_snake.png"))
self.setMinimumSize(350, 225)
self.resize(350,225)
self.setMinimumSize(400, 225)
self.resize(400,225)
self.update_view_settings()

central_widget = QWidget()
Expand All @@ -42,7 +42,9 @@ def __init__(self, controller : Controller):

self.loadout = QLabel()
self.loadout.setAlignment(Qt.AlignVCenter|Qt.AlignLeft)
font = QFont("Arial", 24)

chakra_petch_bold = QFontDatabase.applicationFontFamilies(1)[0]
font = QFont(chakra_petch_bold, 24)
font.setBold(True)
self.loadout.setFont(font)
self.title_box.addWidget(self.loadout)
Expand All @@ -55,8 +57,6 @@ def __init__(self, controller : Controller):

self.loadout_desc = QLabel()
self.loadout_desc.setAlignment(Qt.AlignTop|Qt.AlignLeft)
font = QFont("Arial", 12)
self.loadout_desc.setFont(font)
self.loadout_desc.setVisible(False)
self.title_box.addWidget(self.loadout_desc)

Expand Down Expand Up @@ -129,7 +129,7 @@ def update_title_description(self, description):
def update_current_loadout(self):
currentLoadout = self.controller.get_active_loadout()
if currentLoadout is not None:
self.loadout.setText(currentLoadout.name)
self.loadout.setText(currentLoadout.name.upper())
else:
self.loadout.setText("")

Expand Down Expand Up @@ -232,7 +232,8 @@ def __init__ (self, parent = None):
self.key = QLabel()
self.key.setFixedSize(50, 50)
self.key.setAlignment(Qt.AlignCenter)
font = QFont("Arial", 24)
chakra_petch_medium = QFontDatabase.applicationFontFamilies(0)[0]
font = QFont(chakra_petch_medium, 24)
font.setBold(True)
self.key.setFont(font)
self.hBox.addWidget(self.key)
Expand All @@ -244,7 +245,7 @@ def __init__ (self, parent = None):
self.setLayout(self.hBox)

def setStratagem(self, stratagem):
self.name.setText(stratagem.name)
self.name.setText(stratagem.name.upper())
svg_widget = QSvgWidget(constants.STRATAGEM_ICON_PATH+stratagem.icon_name)
svg_widget.setFixedSize(40,40)
svg_widget.setStyleSheet("background-color: transparent")
Expand Down
15 changes: 15 additions & 0 deletions src/view/pyqt5/pyqt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from src.view.view_base import BaseView
from PyQt5.QtWidgets import QApplication,QMessageBox
from PyQt5.QtCore import pyqtSignal, QObject
from PyQt5.QtGui import QFontDatabase, QFont
from src.view.pyqt5.main import MainWindow
from src.view.view_base import SettingsItem
from src.view.pyqt5.util import KEY_ALWAYS_ON_TOP, KEY_ALWAYS_ON_TOP_DEFAULT
Expand All @@ -12,6 +13,7 @@ def __init__(self, controller : Controller):
super().__init__()
self.controller = controller
self.gui = QApplication([])
self.load_fonts()
self.window = MainWindow(controller)
self.setup_ui_update_listener()

Expand Down Expand Up @@ -85,6 +87,19 @@ def on_exit(self):
# This method will be called when the application is about to quit
# You can add your cleanup code here
self.controller.on_exit()

def load_fonts(self):
font_id = QFontDatabase.addApplicationFont(constants.FONT_BASE_PATH+'ChakraPetch-Medium.ttf')
if font_id == -1:
print("Failed to load font: ChakraPetch-Medium")
else:
chakra_petch_medium = QFontDatabase.applicationFontFamilies(0)[0]
font = QFont(chakra_petch_medium, 12)
self.gui.setFont(font)

font_id = QFontDatabase.addApplicationFont(constants.FONT_BASE_PATH+'ChakraPetch-Bold.ttf')
if font_id == -1:
print("Failed to load font: ChakraPetch-Bold")

class UiUpdateListener(QObject):
ui = pyqtSignal(str, list)
Expand Down

0 comments on commit c05cc33

Please sign in to comment.