Skip to content

Commit

Permalink
Changed default font to unifont 16px to allow rendering of unicode ch…
Browse files Browse the repository at this point in the history
…aracters
  • Loading branch information
fIux-dev committed Dec 26, 2021
1 parent e8b0f92 commit d47f691
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ dmypy.json
settings.ini
log.txt
data/
downloads/
downloads/
*.Zone.Identifier
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ work in the series individually.
attempt to retry the request after some timeout, doubling the wait time each time until the request
succeeds. In theory, this means as long as you leave the application open, it should complete the requests eventually,
it might just take a while.
* Non-alphanumeric characters render as `?` right now due to the default font being used.
* Closing the application while downloads are ongoing can take a while to respond if not initiated from the command line.

## License
Expand Down
7 changes: 3 additions & 4 deletions ao3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@

def main() -> None:
LOG.info("Starting...")
engine = None
try:
engine = Engine(os.getcwd())
gui = GUI(engine)
gui.run()
except AO3.utils.HTTPError:
LOG.error("Hit rate limiting error. Please try again later.")
gui_module.display_rate_limiting_error()
exit(1)
gui = GUI(engine)
gui.run()


if __name__ == "__main__":
Expand Down
Binary file added resources/fonts/unifont-14.0.01.ttf
Binary file not shown.
48 changes: 27 additions & 21 deletions source/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,13 @@
LOG = logging.getLogger(__name__)


def display_rate_limiting_error():
dpg.create_context()
dpg.create_viewport(title="Error", width=200, height=100, resizable=False)
dpg.setup_dearpygui()
with dpg.window(label="ao3d", tag="primary_window"):
dpg.add_text("Hit rate limit :(\nPlease try again later.")
dpg.show_viewport()
dpg.set_primary_window("primary_window", True)
dpg.start_dearpygui()
dpg.destroy_context()


class GUI:
engine: Engine
engine: Optional[Engine] = None

_work_ids: Set[int]
_downloaded: Set[int]

def __init__(self, engine: Engine):
def __init__(self, engine: Engine = None):
self.engine = engine
self._work_ids = set()
self._downloaded = set()
Expand Down Expand Up @@ -471,7 +459,7 @@ def _make_settings_tab(self) -> None:
"""Create the layout for the settings tab."""
with dpg.tab(label="Settings", tag="settings_tab"):
with dpg.child_window(
tag="settings_child_window", width=500, height=410,
tag="settings_child_window", width=600, height=600,
):
with dpg.group(tag="login_settings_group"):
dpg.add_text("AO3 Login", tag="login_settings_text")
Expand Down Expand Up @@ -666,14 +654,14 @@ def _show_placeholder_work_item(self, work_id: int) -> None:
return

with dpg.child_window(
tag=window_tag, parent="works_window", autosize_x=True, height=60
tag=window_tag, parent="works_window", autosize_x=True, height=70
):
with dpg.group(tag=f"{work_id}_group", horizontal=True):
dpg.add_button(
label="X",
tag=f"{work_id}_remove_button",
width=40,
height=40,
width=50,
height=50,
callback=self._remove_work_item,
user_data={"work_id": work_id},
show=False,
Expand All @@ -683,8 +671,8 @@ def _show_placeholder_work_item(self, work_id: int) -> None:
dpg.add_button(
label="Open",
tag=f"{work_id}_open_button",
width=40,
height=40,
width=50,
height=50,
callback=self._open_file,
show=False,
enabled=False,
Expand Down Expand Up @@ -722,13 +710,31 @@ def _show_placeholder_work_item(self, work_id: int) -> None:
dpg.add_text(tag=f"{work_id}_date_edited")
dpg.add_spacer(width=60)

def _make_error_window(self):
with dpg.window(label="ao3d", tag="primary_window"):
dpg.add_text("Hit rate limit :(\nPlease try again later.")
dpg.configure_viewport("ao3d", width=200, height=100, resizable=False)

def _setup_fonts(self) -> None:
with dpg.font_registry():
with dpg.font("resources/fonts/unifont-14.0.01.ttf", 16) as unifont:
dpg.add_font_range(0x0080, 0x10FFFD)
dpg.bind_font(unifont)

def run(self) -> None:
"""Starts the GUI."""
dpg.create_context()
self._setup_fonts()

dpg.create_viewport(title="ao3d", width=1280, height=800)
dpg.setup_dearpygui()
self._make_gui()

if self.engine:
self._make_gui()
else:
self._make_error_window()
dpg.set_primary_window("primary_window", True)

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

0 comments on commit d47f691

Please sign in to comment.