Skip to content

Commit

Permalink
improve teleprompter mirroring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Dec 17, 2024
1 parent 3c21118 commit 7160cc2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 49 deletions.
2 changes: 1 addition & 1 deletion io.github.nokse22.teleprompter.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app-id" : "io.github.nokse22.teleprompter",
"runtime" : "org.gnome.Platform",
"runtime-version" : "47",
"runtime-version" : "master",
"sdk" : "org.gnome.Sdk",
"command" : "teleprompter",
"finish-args" : [
Expand Down
23 changes: 23 additions & 0 deletions src/gtk/help-overlay.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<property name="action-name">app.quit</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcut window">Teleprompter</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Play/Pause</property>
Expand All @@ -39,6 +44,24 @@
<property name="action-name">app.fullscreen</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Mirror Horizonatlly</property>
<property name="action-name">app.hmirror</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Mirror Vertically</property>
<property name="action-name">app.vmirror</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Reset View</property>
<property name="action-name">app.reset-mirrors</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
1 change: 1 addition & 0 deletions src/gtk/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<property name="width-request">360</property>
<property name="height-request">294</property>
<property name="title" translatable="yes">Teleprompter</property>
<signal name="notify::fullscreened" handler="on_fullscreened_changed"/>
<child>
<object class="AdwBreakpoint">
<condition>max-width: 480px</condition>
Expand Down
42 changes: 22 additions & 20 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,47 @@ def __init__(self):
theme_action.connect("activate", self.on_theme_setting_changed)
self.add_action(theme_action)

vmirror_action = Gio.SimpleAction.new_stateful(
self.vmirror_action = Gio.SimpleAction.new_stateful(
"vmirror",
None,
GLib.Variant("b", self.saved_settings.get_boolean("vmirror")),
GLib.Variant("b", self.saved_settings.get_boolean("vmirror"))
)
vmirror_action.connect("activate", self.on_v_mirror)
self.add_action(vmirror_action)
self.vmirror_action.connect("activate", self.on_vmirror)
self.set_accels_for_action("app.vmirror", ['<primary><shift>V'])
self.add_action(self.vmirror_action)

hmirror_action = Gio.SimpleAction.new_stateful(
self.hmirror_action = Gio.SimpleAction.new_stateful(
"hmirror",
None,
GLib.Variant("b", self.saved_settings.get_boolean("hmirror")),
GLib.Variant("b", self.saved_settings.get_boolean("hmirror"))
)
hmirror_action.connect("activate", self.on_h_mirror)
self.add_action(hmirror_action)
self.hmirror_action.connect("activate", self.on_hmirror)
self.set_accels_for_action("app.hmirror", ['<primary><shift>H'])
self.add_action(self.hmirror_action)

self.create_action(
'reset-mirrors', self.on_reset_mirrors, ['<primary><shift>R'])

self.update_theme()

def on_v_mirror(self, action, state):
def on_vmirror(self, action, state):
new_state = not action.get_state().get_boolean()
action.set_state(GLib.Variant.new_boolean(new_state))
self.saved_settings.set_boolean("vmirror", new_state)

self.win.scroll_text_view.vmirror = new_state

def on_h_mirror(self, action, state):
def on_hmirror(self, action, state):
new_state = not action.get_state().get_boolean()
action.set_state(GLib.Variant.new_boolean(new_state))
self.saved_settings.set_boolean("hmirror", new_state)

self.win.scroll_text_view.hmirror = new_state

def on_reset_mirrors(self, *_args):
self.vmirror_action.set_state(GLib.Variant.new_boolean(False))
self.hmirror_action.set_state(GLib.Variant.new_boolean(False))

def on_theme_setting_changed(self, action, state):
action.set_state(state)
self.saved_settings.set_string("theme", state.get_string())
Expand Down Expand Up @@ -140,8 +149,7 @@ def on_preferences_action(self, *args):

pref = Adw.PreferencesDialog()

preferences_page = Adw.PreferencesPage(
title=_("Generals"))
preferences_page = Adw.PreferencesPage(title=_("Generals"))
preferences_page.set_icon_name("applications-system-symbolic")
pref.add(preferences_page)

Expand All @@ -166,14 +174,14 @@ def on_preferences_action(self, *args):
text_group.add(highlight_color_picker_row)

highlight_color_picker = Gtk.ColorButton(valign=Gtk.Align.CENTER)
highlight_color_picker.set_rgba(self.win.settings.highlightColor)
highlight_color_picker.set_rgba(self.win.settings.highlight_color)
highlight_color_picker_row.add_suffix(highlight_color_picker)

bold_highlight_row = Adw.ActionRow(title=_("Bold Highlight"))
text_group.add(bold_highlight_row)

bold_highlight_switch = Gtk.Switch(valign=Gtk.Align.CENTER)
bold_highlight_switch.set_active(self.win.settings.bold_highlight_row)
bold_highlight_switch.set_active(self.win.settings.bold_highlight)

bold_highlight_row.add_suffix(bold_highlight_switch)

Expand Down Expand Up @@ -220,11 +228,9 @@ def create_action(self, name, callback, shortcuts=None):
self.set_accels_for_action(f"app.{name}", shortcuts)

def on_background_color_changed(self, colorWidget):
# print("background color changed")
self.win.settings.backgroundColor = colorWidget.get_rgba()

def on_text_color_changed(self, colorWidget):
# print("font color changed")
self.win.settings.textColor = colorWidget.get_rgba()

self.win.apply_text_tags()
Expand All @@ -233,7 +239,6 @@ def on_text_color_changed(self, colorWidget):
self.win.save_app_settings(self.win.settings)

def on_highlight_color_changed(self, colorWidget):
# print("highlight color changed")
self.win.settings.highlightColor = colorWidget.get_rgba()

self.win.apply_text_tags()
Expand All @@ -242,7 +247,6 @@ def on_highlight_color_changed(self, colorWidget):
self.win.save_app_settings(self.win.settings)

def on_font_changed(self, fontWidget):
# print("font changed")
font_properties = fontWidget.get_font().split()
font_size = font_properties[-1]

Expand All @@ -251,10 +255,8 @@ def on_font_changed(self, fontWidget):
else:
new_font_size = 10

# Update the font size in the font properties list
font_properties[-1] = str(new_font_size)

# Construct the updated font string
self.win.settings.font = ' '.join(font_properties)

self.win.update_font()
Expand Down
2 changes: 1 addition & 1 deletion src/scroll_text_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def get_scrolled_window(self):
return self.scrolled_window

def get_width(self):
return self.text_view.get_allocation().width
return self.text_view._text_view.get_allocation().width
48 changes: 21 additions & 27 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def __init__(self):
self.textColor = Gdk.RGBA()
self.textColor.parse("#62A0EA")
self.speed = 150
self.highlightColor = Gdk.RGBA()
self.highlightColor.parse("#ED333B")
self.boldHighlight = True
self.highlight_color = Gdk.RGBA()
self.highlight_color.parse("#ED333B")
self.bold_highlight = True


@Gtk.Template(resource_path='/io/github/nokse22/teleprompter/gtk/window.ui')
Expand All @@ -45,7 +45,6 @@ class TeleprompterWindow(Adw.ApplicationWindow):
sidebar_controls = Gtk.Template.Child()

playing = False
fullscreened = False

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand All @@ -62,7 +61,6 @@ def __init__(self, **kwargs):
self.scroll_text_view.vmirror = self.saved_settings.get_boolean("vmirror")

self.text_buffer.connect("paste-done", self.on_text_pasted)

self.text_buffer.connect("changed", self.on_text_inserted, "", 0, 0)

start = self.text_buffer.get_start_iter()
Expand Down Expand Up @@ -96,7 +94,7 @@ def save_app_settings(self, settings):
self.saved_settings.set_string(
"text", self.color_to_hex(settings.textColor))
self.saved_settings.set_string(
"highlight", self.color_to_hex(settings.highlightColor))
"highlight", self.color_to_hex(settings.highlight_color))

self.saved_settings.set_string(
"font", settings.font)
Expand All @@ -105,7 +103,7 @@ def save_app_settings(self, settings):
"speed", settings.speed * 10)

self.saved_settings.set_boolean(
"bold-highlight", settings.boldHighlight)
"bold-highlight", settings.bold_highlight)

def show_file_chooser_dialog(self):
dialog = Gtk.FileDialog(
Expand Down Expand Up @@ -144,20 +142,19 @@ def load_app_settings(self):
settings = AppSettings()

color1 = Gdk.RGBA()
color2 = Gdk.RGBA()
color3 = Gdk.RGBA()

color1.parse(self.saved_settings.get_string("text"))
settings.textColor = color1

color3.parse(self.saved_settings.get_string("highlight"))
settings.highlightColor = color3
settings.highlight_color = color3

settings.font = self.saved_settings.get_string("font")

settings.speed = self.saved_settings.get_int("speed") / 10

settings.boldHighlight = self.saved_settings.get_boolean(
settings.bold_highlight = self.saved_settings.get_boolean(
"bold-highlight")

return settings
Expand Down Expand Up @@ -191,7 +188,7 @@ def apply_text_tags(self):

tag_color2 = Gtk.TextTag()
tag_color2.set_property(
"foreground", self.color_to_hex(self.settings.highlightColor))
"foreground", self.color_to_hex(self.settings.highlight_color))
self.text_buffer.get_tag_table().add(tag_color2)

start_iter = self.text_buffer.get_start_iter()
Expand All @@ -205,9 +202,9 @@ def search_and_mark_highlight(self, start):

tag_color2 = Gtk.TextTag()
tag_color2.set_property(
"foreground", self.color_to_hex(self.settings.highlightColor))
"foreground", self.color_to_hex(self.settings.highlight_color))

if self.settings.boldHighlight:
if self.settings.bold_highlight:
tag_color2.set_property("weight", Pango.Weight.BOLD)

self.text_buffer.get_tag_table().add(tag_color2)
Expand All @@ -225,10 +222,7 @@ def search_and_mark_highlight(self, start):
def search_end_highlight(self, start):
end = self.text_buffer.get_end_iter()

# Perform forward search for "]" from the starting position
match_right = start.forward_search("]", Gtk.TextSearchFlags(0), end)

# Perform forward search for "[" from the starting position
match_left = start.forward_search("[", Gtk.TextSearchFlags(0), end)

if match_right is not None:
Expand All @@ -246,9 +240,10 @@ def update_font(self):
tag = self.text_buffer.create_tag(
None, font_desc=Pango.FontDescription(self.settings.font))

# Apply the tag to the entire text buffer
self.text_buffer.apply_tag(
tag, self.text_buffer.get_start_iter(), self.text_buffer.get_end_iter())
tag,
self.text_buffer.get_start_iter(),
self.text_buffer.get_end_iter())

def wpm_to_speed(self, speed):
font_properties = self.settings.font.split()
Expand All @@ -264,7 +259,6 @@ def wpm_to_speed(self, speed):
return speed

def change_font_size(self, amount):
# Split the font string into font properties and size
font_properties = self.settings.font.split()
font_size = font_properties[-1]

Expand All @@ -273,15 +267,12 @@ def change_font_size(self, amount):
else:
new_font_size = 10

# Update the font size in the font properties list
font_properties[-1] = str(new_font_size)

# Construct the updated font string
self.settings.font = ' '.join(font_properties)

@Gtk.Template.Callback("play_button_clicked")
def play(self, *args):
# print("play")
if not self.playing:
self.start_button1.set_icon_name("media-playback-pause-symbolic")
self.playing = True
Expand Down Expand Up @@ -346,14 +337,10 @@ def increase_font_button_clicked(self, *args):

@Gtk.Template.Callback("fullscreen_button_clicked")
def toggle_fullscreen(self, *args):
if self.fullscreened:
if self.is_fullscreen():
self.unfullscreen()
self.fullscreen_button.set_icon_name("view-fullscreen-symbolic")
self.fullscreened = False
else:
self.fullscreen()
self.fullscreen_button.set_icon_name("view-restore-symbolic")
self.fullscreened = True

@Gtk.Template.Callback("on_apply_breakpoint")
def on_apply_breakpoint(self, *args):
Expand All @@ -364,3 +351,10 @@ def on_apply_breakpoint(self, *args):
def on_unapply_breakpoint(self, *args):
self.sidebar_controls.add_css_class("card")
self.sidebar_controls.add_css_class("overlay_toolbar")

@Gtk.Template.Callback("on_fullscreened_changed")
def on_fullscreened_changed(self, *_args):
if self.is_fullscreen():
self.fullscreen_button.set_icon_name("view-restore-symbolic")
else:
self.fullscreen_button.set_icon_name("view-fullscreen-symbolic")

0 comments on commit 7160cc2

Please sign in to comment.