Skip to content

Commit

Permalink
Revised layout of main window and preview panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
psb1558 committed May 13, 2023
1 parent 33564df commit b15bf9b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
28 changes: 8 additions & 20 deletions src/ygt/window.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# ApplicationSpecificRole
# import inspect
from typing import Any, TypeVar, Union, Optional
import sys
Expand Down Expand Up @@ -140,7 +139,6 @@ def __init__(
def run(self) -> None:
try:
font = copy.deepcopy(self.ft_font)
# failed_glyph_list = compile_all(font, self.source, self.output_font)
err, failed_glyph_list = xgf_run(
font = font,
yaml = self.source,
Expand Down Expand Up @@ -176,10 +174,8 @@ def __init__(
else:
self.win_list = win_list
self.filename = ""
# self.filename_extension = ""
self.font_info_editor: Optional[fontInfoWindow] = None
self.cvt_editor: Optional[editorDialog] = None
# self.cvar_editor = None
self.prep_editor: Optional[editorDialog] = None
self.function_editor: Optional[editorDialog] = None
self.macro_editor: Optional[editorDialog] = None
Expand Down Expand Up @@ -891,7 +887,6 @@ def setup_hint_connections(self) -> None:
)
self.shift_action.triggered.connect(self.glyph_pane.make_hint_from_selection)
self.align_action.triggered.connect(self.glyph_pane.make_hint_from_selection)
# self.make_set_action.triggered.connect(self.glyph_pane.make_set)
self.make_cv_action.triggered.connect(self.glyph_pane.make_control_value)
self.make_cv_guess_action.triggered.connect(self.glyph_pane.guess_cv)
self.vertical_action.toggled.connect(self.glyph_pane.switch_to_y)
Expand All @@ -900,7 +895,6 @@ def setup_hint_connections(self) -> None:
def setup_edit_connections(self) -> None:
self.edit_cvt_action.triggered.connect(self.edit_cvt)
self.edit_prep_action.triggered.connect(self.edit_prep)
# self.edit_cvar_action.triggered.connect(self.edit_cvar)
self.edit_functions_action.triggered.connect(self.edit_functions)
self.edit_macros_action.triggered.connect(self.edit_macros)
self.edit_defaults_action.triggered.connect(self.edit_defaults)
Expand Down Expand Up @@ -1017,13 +1011,11 @@ def set_size_and_position(self):
height = qg.height() * 0.75
self.setGeometry(int(x), int(y), int(width), int(height))

def add_preview(self, previewer: ygPreview) -> None:
self.yg_preview = previewer
def add_preview(self) -> None:
self.yg_preview = ygPreview(self)
self.yg_string_preview = ygStringPreview(self.yg_preview, self)
self.yg_string_preview.set_go_to_signal(self.go_to_glyph)
self.preview_scroller = QScrollArea()
self.preview_scroller.setWidget(self.yg_preview)
ygpc = ygPreviewContainer(self.preview_scroller, self.yg_string_preview)
ygpc = ygPreviewContainer(self.yg_preview, self.yg_string_preview)
self.qs.addWidget(ygpc)
self.setup_preview_connections()

Expand Down Expand Up @@ -1133,7 +1125,7 @@ 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")) # ***
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"))
Expand Down Expand Up @@ -1359,8 +1351,7 @@ def _open(self, f: FileNameVar) -> int:

self.preferences["current_font"] = filename

self.yg_preview = ygPreview(self)
self.add_preview(self.yg_preview)
self.add_preview()
self.yg_preview.set_up_signal(self.update_string_preview)
self.source_editor = ygYAMLEditor(self.preferences)
self.add_editor(self.source_editor)
Expand All @@ -1387,6 +1378,8 @@ def _open(self, f: FileNameVar) -> int:
view = ygGlyphView(self.preferences, yg_glyph_scene, self.yg_font)
yg_glyph_scene.owner = view
self.add_glyph_pane(view)
w = self.width()
self.qs.setSizes([int(w * 0.2961), int(w * 0.1497), int(w * 0.5542)])
view.centerOn(view.yg_glyph_scene.center_x, view.sceneRect().center().y())
self.set_window_title()
self.set_up_instance_list()
Expand Down Expand Up @@ -1423,7 +1416,6 @@ def selection_changed(self, selection_profile: list):
self.shift_action.setEnabled(False)
self.align_action.setEnabled(False)
self.interpolate_action.setEnabled(False)
# self.make_set_action.setEnabled(False)
elif selection_profile[0] == 1 and selection_profile[1] >= 1:
if selection_profile[1] == 1:
self.stem_action.setEnabled(True)
Expand Down Expand Up @@ -1453,7 +1445,6 @@ def selection_changed(self, selection_profile: list):
self.align_action.setEnabled(False)
self.interpolate_action.setEnabled(False)
self.anchor_action.setEnabled(False)
#self.make_set_action.setEnabled(False)

@pyqtSlot()
def clean_changed(self):
Expand Down Expand Up @@ -1771,22 +1762,19 @@ def main():
app = QApplication([])

if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
# font_path = os.path.split(sys._MEIPASS)[0]
print(sys._MEIPASS)
font_path = os.path.join(
sys._MEIPASS,
"fonts",
"SourceCodePro-Regular.ttf"
)
print(font_path)
# font_path += "/Resources/fonts/SourceCodePro-Regular.ttf"
else:
font_path = os.path.join(
os.path.dirname(__file__),
"fonts/SourceCodePro-Regular.ttf"
)
#font_path = os.path.dirname(__file__) + "/fonts/SourceCodePro-Regular.ttf"


font_id = QFontDatabase.addApplicationFont(font_path)
if font_id == -1:
print("Can't find font Source Code Pro.")
Expand Down
39 changes: 28 additions & 11 deletions src/ygt/ygPreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@
QPushButton,
QHBoxLayout,
QVBoxLayout,
QScrollArea,
QSizePolicy,
)
from PyQt6.QtGui import QPainter, QBrush, QColor, QPalette, QPixmap
from PyQt6.QtCore import Qt, QRect, pyqtSignal, pyqtSlot, QLine


PREVIEW_WIDTH = 450
PREVIEW_HEIGHT = 700
STRING_PREVIEW_HEIGHT = 150
PREVIEW_HEIGHT = 500
STRING_PREVIEW_HEIGHT = 200
PREVIEW_HORI_MARGIN = 25
PREVIEW_VERT_MARGIN = 50


class ygPreviewContainer(QWidget):
class ygPreviewContainer(QScrollArea):
def __init__(self, preview, string_preview):
super().__init__()
self._layout = QVBoxLayout()
self._layout.setSpacing(0)
self._layout.setSpacing(10)
self._layout.setContentsMargins(0, 0, 0, 0)
self._layout.addWidget(preview)
self._layout.addWidget(string_preview)
Expand All @@ -46,11 +48,14 @@ def __init__(self, top_window) -> None:
self.label.setText(str(self.char_size) + "ppem")
self.label.setParent(self)
self.label.move(50, 30)

self.minimum_x = PREVIEW_WIDTH
self.minimum_y = PREVIEW_HEIGHT
self.setMinimumSize(self.minimum_x, self.minimum_y)
self.setFixedWidth(self.minimum_x)
self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Expanding)
self.vertical_margin = PREVIEW_VERT_MARGIN
self.horizontal_margin = PREVIEW_HORI_MARGIN

self.max_pixel_size = 12
self.pixel_size = 12
# absolute height of the glyph, from top pixel to bottom pixel.
Expand All @@ -59,9 +64,9 @@ def __init__(self, top_window) -> None:
self.ascender = 0
# Corresponds to the font's descender number
self.descender = 0
# The height of the glyph above the baseline. Should be able to subtract
# this from self.ascender to get where on the grid we should start laying
# down pixels. If the result of the subtraction is negative, we need to
# The height of the glyph above the baseline. Subtract this from
# self.ascender to get where on the grid we should start laying down
# pixels. If the result of the subtraction is negative, we need to
# display grid above the ascender number.
self.bitmap_top = 0
self.grid_height = 0
Expand All @@ -71,10 +76,13 @@ def __init__(self, top_window) -> None:
# The pixels of the glyph start this far down.
self.top_char_margin = 0
self.show_grid = True

# Two- or three-dimensional array shaped by numpy.
self.Z: list = []
self.instance_dict: Optional[dict] = None
self.instance: Optional[str] = None

# Figure out if we have a dark or a light theme.
text_hsv_value = self.palette().color(QPalette.ColorRole.WindowText).value()
self.background_color = self.default_background = self.palette().color(QPalette.ColorRole.Base)
bg_hsv_value = self.background_color.value()
Expand All @@ -85,6 +93,7 @@ def __init__(self, top_window) -> None:

self.render_mode = RENDER_LCD_1
self.hinting_on = True

# We display the preview by painting on a QPixmap and adding that to this widget.
# There are three methods for grayscale, lcd1, and lcd2. These are assigned to
# self.make_pixmap, which can be called whenever display needs to be refreshed--
Expand Down Expand Up @@ -178,10 +187,10 @@ def _build_glyph(self) -> bool:
char_width = ft_width
if self.render_mode != RENDER_GRAYSCALE:
char_width = ft_width / 3
preview_display_width = PREVIEW_WIDTH - (PREVIEW_HORI_MARGIN * 2)
preview_display_width = self.width() - (PREVIEW_HORI_MARGIN * 2)
if char_width * self.pixel_size > preview_display_width:
self.pixel_size = round(preview_display_width / char_width)
preview_display_height = PREVIEW_HEIGHT - (PREVIEW_VERT_MARGIN * 2)
preview_display_height = self.height() - (PREVIEW_VERT_MARGIN * 2)
if self.total_height * self.pixel_size > preview_display_height:
self.pixel_size = round(preview_display_height / self.total_height)
if self.render_mode == RENDER_LCD_2:
Expand Down Expand Up @@ -536,7 +545,8 @@ def __init__(self, yg_preview: ygPreview, top_window) -> None:
self._text = ""
self.minimum_x = PREVIEW_WIDTH
self.minimum_y = 200
self.setMinimumSize(self.minimum_x, self.minimum_y)
self.setFixedSize(PREVIEW_WIDTH, STRING_PREVIEW_HEIGHT)
self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
self.paintEvent = self.paintEvent_a # type: ignore
self.rect_list: list = []

Expand Down Expand Up @@ -660,7 +670,14 @@ def __init__(self, yg_preview: ygPreview, top_window) -> None:
self.yg_preview = yg_preview
self.top_window = top_window

self.vertical_margin = PREVIEW_VERT_MARGIN
self.horizontal_margin = PREVIEW_HORI_MARGIN

self._layout = QVBoxLayout()
self._layout.setContentsMargins(0,0,0,0)

self.setFixedWidth(PREVIEW_WIDTH)
self.setMinimumHeight(STRING_PREVIEW_HEIGHT)

self.panel = ygStringPreviewPanel(yg_preview, top_window)

Expand Down

0 comments on commit b15bf9b

Please sign in to comment.