Skip to content

Commit

Permalink
Enhancements for merge; corrected non-portable file code; winreg now …
Browse files Browse the repository at this point in the history
…keeps recents
  • Loading branch information
psb1558 committed May 11, 2023
1 parent eeccd42 commit 5764151
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 24 deletions.
72 changes: 63 additions & 9 deletions src/ygt/makeCVDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
QDialog,
QVBoxLayout,
QHBoxLayout,
QGridLayout,
QDialogButtonBox,
QComboBox,
QLineEdit,
Expand Down Expand Up @@ -856,7 +857,9 @@ def __init__(self, yg_font: ygFont) -> None:
super().__init__()
self.yg_font = yg_font
self.defaults = yg_font.defaults
self.layout_obj = QVBoxLayout()
self.layout_obj = QGridLayout()
self.layout_obj.setHorizontalSpacing(20)
self.layout_obj.setVerticalSpacing(0)
self.ignore_signal = False

self.tt_defaults = QCheckBox("Use TrueType defaults")
Expand Down Expand Up @@ -907,13 +910,25 @@ def __init__(self, yg_font: ygFont) -> None:
self.replaceprep.setToolTip(s)
self.replaceprep.stateChanged.connect(self.toggle_replaceprep)

self.layout_obj.addWidget(self.tt_defaults)
self.layout_obj.addWidget(self.init_graphics)
self.layout_obj.addWidget(self.assume_always_y)
self.layout_obj.addWidget(self.counterclockwise)
self.layout_obj.addWidget(self.cleartype)
self.layout_obj.addWidget(self.mergemode)
self.layout_obj.addWidget(self.replaceprep)
self.functionbase = functionBaseWidget(self.defaults)
s = "In merge mode, <span>set</span> 'function-base' to a non-zero value if Ygt guesses wrongly "
s += "about the highest-numbered function in the font to which you are adding hints."
self.functionbase.setToolTip(s)

self.layout_obj.addWidget(self.tt_defaults, 1, 1)
self.layout_obj.addWidget(self.init_graphics, 2, 1)
self.layout_obj.addWidget(self.cleartype, 3, 1)
self.layout_obj.addWidget(self.assume_always_y, 4, 1)
self.layout_obj.addWidget(self.counterclockwise, 1, 2)
self.layout_obj.addWidget(self.mergemode, 2, 2)
self.layout_obj.addWidget(self.replaceprep, 3, 2)
self.functionbase.setFixedWidth(int(self.functionbase.width() /4))
function_base_layout = QHBoxLayout()
# function_base_layout.setAlignment(Qt.AlignmentFlag.AlignLeft)
function_base_layout.addWidget(QLabel("function base"))
function_base_layout.addWidget(self.functionbase, alignment = Qt.AlignmentFlag.AlignLeft)
self.layout_obj.addLayout(function_base_layout, 4, 2)

self.setLayout(self.layout_obj)

self.refresh()
Expand Down Expand Up @@ -964,10 +979,11 @@ def toggle_mergemode(self) -> None:
if self.mergemode.isChecked():
self.defaults.set_default({"merge-mode": True})
self.replaceprep.setEnabled(True)
self.functionbase.setEnabled(True)
else:
self.defaults.del_default("merge-mode")
self.toggle_replaceprep()
self.replaceprep.setEnabled(False)
self.functionbase.setEnabled(False)

def toggle_replaceprep(self) -> None:
if self.ignore_signal:
Expand Down Expand Up @@ -1473,6 +1489,44 @@ def refresh(self, cv_source: cvSource) -> None:
self.set_clean()


class functionBaseWidget(QLineEdit):
def __init__(self, defaults):
super().__init__()
self.defaults = defaults
init_val = self.defaults.get_default("function-base")
if init_val == None:
init_val = 0
self.setText(str(init_val))
self.setValidator(QIntValidator(0, 255))
self.editingFinished.connect(self.text_changed)
self.last_val = self.text()

def _text(self) -> str:
return self.text().strip()

def fixup(self) -> None:
t = self._text()
if t != self.last_val:
try:
i = int(t)
except ValueError:
i = 0
self.defaults.set_default({"function-base": i})

def text_changed(self) -> None:
t = self._text()
if t != self.last_val:
self.fixup()
self.last_val = t

def refresh(self) -> None:
fb = self.defaults.get_default("function-base")
if fb == None:
self.setText("0")
else:
self.setText(str(fb))


class cvValueWidget(QLineEdit):
"""Widget for editing the value of a CV.
Expand Down
54 changes: 39 additions & 15 deletions src/ygt/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ def __init__(
font: ttLib.TTFont,
source: dict,
output_font: str,
mergemode: bool,
replaceprep: bool,
mergemode: bool = False,
replaceprep: bool = False,
functionbase: int = 0,
initgraphics: bool = False,
assume_y: bool = False,
cleartype: bool = True, # Not yet hooked up
use_truetype_defaults: bool = False, # Not yet hooked up
) -> None:
super().__init__()
self.ft_font = font
Expand All @@ -121,6 +126,15 @@ def __init__(
self.error = False
self.mergemode = mergemode
self.replaceprep = replaceprep
self.functionbase = functionbase
self.initgraphics = initgraphics
self.assume_y = "no"
if assume_y:
self.assume_y = "yes"
self.cleartype = "no"
if cleartype:
self.cleartype = "yes"
self.use_truetype_defaults = use_truetype_defaults

def run(self) -> None:
try:
Expand All @@ -132,7 +146,10 @@ def run(self) -> None:
outputfont = self.output_font,
quiet = 3,
mergemode = self.mergemode,
replaceprep = self.replaceprep
replaceprep = self.replaceprep,
functionbase = self.functionbase,
initgraphics = self.initgraphics,
assume_y = self.assume_y,
)
self.sig_font_gen_done.emit(failed_glyph_list)
except KeyError as e:
Expand Down Expand Up @@ -174,20 +191,12 @@ def __init__(
)
self.statusbar.addWidget(self.statusbar_label)

#self.prog_path = os.path.split(__file__)[0]
#self.icon_path = self.prog_path + "/icons/"
# self.icon_path = "Resources/icons/"
# self.show_error_message(['Ho', 'Hum', str(self.icon_path)])

if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
self.icon_path = os.path.split(sys._MEIPASS)[0]
# self.icon_path += "/Resources/icons/"
self.icon_path = os.path.join(sys._MEIPASS, "icons")
self.show_error_message(['', '', self.icon_path])
else:
self.icon_path = os.path.split(__file__)[0]
self.icon_path = os.path.join(self.icon_path, "/icons/")
# self.show_error_message(['', '', 'running in a normal Python process'])
self.icon_path = os.path.join(self.icon_path, "icons/")

self.setAttribute(Qt.WidgetAttribute.WA_AcceptTouchEvents, False)
self.setWindowTitle("YGT")
Expand Down Expand Up @@ -1123,8 +1132,21 @@ def export_font(self) -> None:
return
mergemode = bool(self.yg_font.defaults.get_default("merge-mode"))
replaceprep = bool(self.yg_font.defaults.get_default("replace-prep"))
initgraphics = bool(self.yg_font.defaults.get_default("init-graphics")) # ***
assume_y = bool(self.yg_font.defaults.get_default("assume-always-y"))
try:
functionbase = int(self.yg_font.defaults.get_default("function-base"))
except TypeError:
functionbase = 0
self.font_generator = ygFontGenerator(
font, source, new_file_name, mergemode, replaceprep
font,
source,
new_file_name,
mergemode = mergemode,
replaceprep = replaceprep,
functionbase = functionbase,
initgraphics = initgraphics,
assume_y = assume_y
)
self.font_generator.finished.connect(self.font_generator.deleteLater)
self.font_generator.sig_font_gen_done.connect(self.font_gen_finished)
Expand Down Expand Up @@ -1700,7 +1722,8 @@ def resizeEvent(self, event):
)

def moveEvent(self, event):
self.preferences.set_top_window_pos(event.pos().x(), event.pos().y())
if hasattr(self, "preferences"):
self.preferences.set_top_window_pos(event.pos().x(), event.pos().y())

def event(self, event) -> bool:
if event.type() == event.Type.WindowActivate and self.glyph_pane:
Expand Down Expand Up @@ -1751,7 +1774,8 @@ def main():
print(sys._MEIPASS)
font_path = os.path.join(
sys._MEIPASS,
"fonts/SourceCodePro-Regular.ttf"
"fonts",
"SourceCodePro-Regular.ttf"
)
print(font_path)
# font_path += "/Resources/fonts/SourceCodePro-Regular.ttf"
Expand Down
3 changes: 3 additions & 0 deletions src/ygt/ygPreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def write_win_registry(prefs):
winreg.SetValueEx(
yg_key, "auto_preview", 0, winreg.REG_DWORD, int(prefs["auto_preview"])
)
winreg.SetValueEx(
yg_key, "recents", 0, winreg.REG_MULTI_SZ, prefs["recents"]
)
winreg.SetValueEx(
yg_key, "top_window_pos_x", 0, winreg.REG_DWORD, prefs["top_window_pos_x"]
)
Expand Down
1 change: 1 addition & 0 deletions src/ygt/ygSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def is_round_valid(r: bool | str) -> bool:
Optional("cv_vars_generated"): bool,
Optional("merge-mode"): bool,
Optional("replace-prep"): bool,
Optional("function-base"): int,
}

properties_struct = {
Expand Down

0 comments on commit 5764151

Please sign in to comment.