Skip to content

Commit

Permalink
Add custom fonts (Now you can add your own fonts)
Browse files Browse the repository at this point in the history
  • Loading branch information
chebupelka8 committed Feb 23, 2024
1 parent 867db2f commit 504baa4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
Binary file added assets/fonts/Inter-Medium.otf
Binary file not shown.
Binary file added assets/fonts/Inter.otf
Binary file not shown.
6 changes: 3 additions & 3 deletions scr/data/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"workbench": {
"font": {
"family": "Cascadia Mono",
"size": 14,
"family": "Inter-Medium.otf",
"size": 13,
"bold": false,
"italic": false
}
},
"editor": {
"font": {
"family": "Cascadia Mono",
"size": 17,
"size": 16,
"bold": false,
"italic": false
},
Expand Down
31 changes: 27 additions & 4 deletions scr/scripts/font.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
from PySide6.QtGui import QFontDatabase, QFont

import os


class Font:
@classmethod
def get_all_font_families(cls) -> list[str]:
system_fonts = QFontDatabase.families()

return sorted(system_fonts + cls.__get_additional_fonts())

@staticmethod
def get_all_font_families() -> list[str]:
return QFontDatabase.families()
def __get_additional_fonts() -> list[str]:
res = []

for font in os.listdir("assets/fonts"):
res.append(font)

return res

@staticmethod
def get_font_by_path(__path: str, __size: int | float, __bold: bool = False, __italic: bool = False) -> QFont:
Expand All @@ -16,8 +29,18 @@ def get_font_by_path(__path: str, __size: int | float, __bold: bool = False, __i

return font

@staticmethod
def get_system_font(__family: str, __size: int | float, __bold: bool = False, __italic: bool = False) -> QFont:
@classmethod
def get_system_font(
cls,
__family: str,
__size: int | float,
__bold: bool = False,
__italic: bool = False,
check_exist_additional: bool = True
) -> QFont:
if check_exist_additional and __family in cls.__get_additional_fonts():
return cls.get_font_by_path(f"assets/fonts/{__family}", __size, __bold, __italic)

font = QFont(__family, __size, 1, __italic)
font.setBold(__bold)

Expand Down
1 change: 1 addition & 0 deletions scr/widgets/styles/settings_menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ QListWidget {
border: none;
background-color: #252525;
border-right: 1px solid #3c3c3c;
border-radius: 0;
padding: 2px;
}

Expand Down

0 comments on commit 504baa4

Please sign in to comment.