Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fontformat: show custom fonts only #368

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=[]
dmMaze marked this conversation as resolved.
Show resolved Hide resolved
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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will "show all fonts" be applied properly? After you check and uncheck "show only custom fonts" will all fonts be listed again? I haven't run it locally but it seems there are no means to restore all fonts here. Also, it's probably not a good idea to reset the font list every time it popup, it should be updated only once when let_show_only_custom_fonts.stateChanged triggered.

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