Skip to content

Commit

Permalink
fontformat: show custom fonts only
Browse files Browse the repository at this point in the history
  • Loading branch information
kagenihisomi committed Apr 7, 2024
1 parent 73140b1 commit 7428b10
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ui/configpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ def __init__(self, *args, **kwargs) -> None:

global_fntfmt_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding), 0, 2)

# self.let_show_only_custom_fonts = QCheckBox(parent=self)
self.let_show_only_custom_fonts, sublock = checkbox_with_label(self.tr("Font selection"), discription=self.tr("Show only custom fonts"))
global_fntfmt_layout.addWidget(sublock, 4, 0)
self.let_show_only_custom_fonts.stateChanged.connect(self.on_show_only_custom_fonts)


self.let_autolayout_checker, sublock = generalConfigPanel.addCheckBox(self.tr('Auto layout'),
discription=self.tr('Split translation into multi-lines according to the extracted balloon region.'))
self.let_autolayout_adaptive_fntsize_checker, _ = generalConfigPanel.addCheckBox(None, self.tr('Adjust font size adaptively if it is set to \"decide by program.\"'), target_block=sublock)
Expand Down Expand Up @@ -586,6 +592,9 @@ def on_family_flag_changed(self):
def on_effect_flag_changed(self):
pcfg.let_fnteffect_flag = self.let_effect_combox.currentIndex()

def on_show_only_custom_fonts(self):
pcfg.let_show_only_custom_fonts_flag = self.let_show_only_custom_fonts.isChecked()

def focusOnTranslator(self):
idx0, idx1 = self.trans_sub_block.idx0, self.trans_sub_block.idx1
self.configTable.setCurrentItem(idx0, idx1)
Expand Down
31 changes: 29 additions & 2 deletions ui/fontformatpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from qtpy.QtWidgets import QComboBox, QMenu, QMessageBox, QStackedLayout, QGraphicsDropShadowEffect, QLineEdit, QScrollArea, QSizePolicy, QHBoxLayout, QVBoxLayout, QFrame, QFontComboBox, QApplication, QPushButton, QCheckBox, QLabel
from qtpy.QtCore import Signal, Qt, QRectF
from qtpy.QtGui import QDoubleValidator, QFocusEvent, QMouseEvent, QTextCursor, QFontMetrics, QIcon, QColor, QPixmap, QPainter, QContextMenuEvent, QKeyEvent

from qtpy.QtGui import QDoubleValidator, QFocusEvent, QMouseEvent, QTextCursor, QFontMetrics, QIcon, QColor, QPixmap, QPainter, QContextMenuEvent, QKeyEvent, QFontDatabase

from utils.fontformat import FontFormat
from utils import shared
Expand Down Expand Up @@ -330,6 +329,21 @@ def __init__(self, emit_if_focused=True, *args, **kwargs) -> None:
self.emit_if_focused = emit_if_focused
self._current_font = self.currentFont().family()

# Find all custom(application) fonts
application_fonts=[]
i=0
while True:
# Returns ['my_font_name']
font_=QFontDatabase.applicationFontFamilies(i)
if font_:
print(font_)
application_fonts.append(font_[0])
else:
break
i+=1
self.application_fonts=application_fonts


def apply_fontfamily(self):
ffamily = self.currentFont().family()
if ffamily in shared.FONT_FAMILIES:
Expand All @@ -348,6 +362,19 @@ def on_fontfamily_changed(self):
self.apply_fontfamily()


def showPopup(self):
if pcfg.let_show_only_custom_fonts_flag:
current_font = self.currentFont().family()

# Override and set custom textlist of fonts
self.clear()
self.addItems(self.application_fonts)

# Prevent the current font from changing to first in list
self.setCurrentText(current_font)
self.on_fontfamily_changed()
super().showPopup()

CHEVRON_SIZE = 20
def chevron_down():
return QIcon(r'icons/chevron-down.svg').pixmap(CHEVRON_SIZE, CHEVRON_SIZE, mode=QIcon.Mode.Normal)
Expand Down
1 change: 1 addition & 0 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ProgramConfig(Config):
let_autolayout_flag: bool = True
let_autolayout_adaptive_fntsz: bool = True
let_uppercase_flag: bool = True
let_show_only_custom_fonts_flag:bool = False
text_styles_path: str = osp.join(shared.DEFAULT_TEXTSTYLE_DIR, 'default.json')
expand_tstyle_panel: bool = True
fsearch_case: bool = False
Expand Down

0 comments on commit 7428b10

Please sign in to comment.