Skip to content

Commit

Permalink
added actions to increase/decrease font size
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Aug 7, 2023
1 parent bcc7cdb commit fd76ad9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion data/io.github.nokse22.minitext.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>
<p>A very small and minimalistic text viewer with minimal editing capabilities. Best used with 'Always on Top' and/or 'Always on Visible Workspace'. It doesn't save or load files, just your clipboard. It is meant to be used as a place where to edit text to be pasted.</p>
</description>
<summary>Ephemeral text</summary>
<summary>Ephemeral text edits</summary>

<content_rating type="oars-1.0">
</content_rating>
Expand Down
3 changes: 3 additions & 0 deletions data/io.github.nokse22.minitext.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
</key>
<key name="window-height" type="i">
<default>400</default>
</key>
<key name="font-size" type="i">
<default>12</default>
</key>
</schema>
</schemalist>
23 changes: 19 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,32 @@ def __init__(self):
self.create_action('quit', lambda *_: self.quit(), ['<primary>q'])
self.create_action('about', self.on_about_action)
self.create_action('preferences', self.on_preferences_action)
self.create_action('increase-font', self.on_increase_font_action, ['<control>plus'])
self.create_action('decrease-font', self.on_decrease_font_action, ['<control>minus'])

def on_increase_font_action(self, widget, _):
size = self.win.settings.get_int('font-size')
self.win.settings.set_int('font-size', size + 1)
self.win.change_font()
print(size + 1)

def on_decrease_font_action(self, widget, _):
size = self.win.settings.get_int('font-size')
if size > 10:
self.win.settings.set_int('font-size', size - 1)
self.win.change_font()
print(size - 1)

def do_activate(self):
"""Called when the application is activated.
We raise the application's main window, creating it if
necessary.
"""
win = self.props.active_window
if not win:
win = MiniTextWindow(application=self)
win.present()
self.win = self.props.active_window
if not self.win:
self.win = MiniTextWindow(application=self)
self.win.present()

def on_about_action(self, widget, _):
"""Callback for the app.about action."""
Expand Down
16 changes: 16 additions & 0 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ def __init__(self, **kwargs):
"window-height", self, "default-height", Gio.SettingsBindFlags.DEFAULT
)

self.change_font()

def change_font(self):
css_data = f"""
textview {{
font-size: {self.settings.get_int('font-size')}pt;
}}
"""

style_provider = Gtk.CssProvider()
style_provider.load_from_data(css_data, -1)

# Apply the theme to the GTK app
context = self.text_view.get_style_context()
context.add_provider(style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

@Gtk.Template.Callback("on_copy_action")
def on_copy_action(self, *args):
print("copy")
Expand Down
2 changes: 0 additions & 2 deletions src/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<requires lib="gtk" version="4.0"/>
<requires lib="Adw" version="1.0"/>
<template class="MiniTextWindow" parent="AdwApplicationWindow">
<property name="default-width">600</property>
<property name="default-height">300</property>
<property name="modal">true</property>
<property name="title"></property>
<child>
Expand Down

0 comments on commit fd76ad9

Please sign in to comment.