Skip to content

Commit

Permalink
Merge pull request #171 from dlippok/fix-source-edit-crash
Browse files Browse the repository at this point in the history
Fix crash when editing source code in snap package
  • Loading branch information
dlippok authored May 28, 2024
2 parents aa873a1 + 5ef13e2 commit 5ce69a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion data/io.github.dlippok.photometric-viewer.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
</requires>

<releases>
<release version="3.0.0" date="2024-05-20">
<release version="3.0.0" date="2024-05-28">
<description>
<p>Allow editing the content of opened photometric files</p>
<p xml:lang="de">Ermöglicht die Bearbeitung des Inhalts von geöffneten photometrischen Dateien</p>
Expand Down
20 changes: 16 additions & 4 deletions photometric_viewer/gui/pages/source.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import time
import typing
from concurrent.futures import ThreadPoolExecutor

from gi.repository import Adw, Gtk, GtkSource
from gi.repository.Gtk import ScrolledWindow, PolicyType
Expand Down Expand Up @@ -27,6 +29,8 @@ def __init__(self, **kwargs):
bottom_margin=20,
)

self.executor = ThreadPoolExecutor(max_workers=1)

self.source_text_view.set_show_line_numbers(True)
self.source_text_view.get_buffer().connect("changed", self.on_update_content)
self.connect("shown", self.on_shown)
Expand All @@ -46,16 +50,24 @@ def __init__(self, **kwargs):
self.update_theme()

def on_update_content(self, *args):
self._update_language()
self.executor.submit(self._update_language)

def on_shown(self, *args):
self.source_text_view.grab_focus()

def open_stream(self, f: typing.IO):
self.source_text_view.get_buffer().set_text(f.read())
self.source_text_view.get_buffer().set_modified(False)
try:
self.opening = True
self.source_text_view.get_buffer().set_text(f.read())
self.source_text_view.get_buffer().set_modified(False)
finally:
self.opening = False

def _update_language(self):
time.sleep(0.1)
while self.opening:
time.sleep(0.05)

buffer: Gtk.TextBuffer = self.source_text_view.get_buffer()
start = buffer.get_start_iter()
end: Gtk.TextIter = buffer.get_start_iter()
Expand All @@ -74,4 +86,4 @@ def update_theme(self, *args):
if self.adw_style_manager.get_dark():
buffer.set_style_scheme(style_manager.get_scheme('Adwaita-dark'))
else:
buffer.set_style_scheme(style_manager.get_scheme('Adwaita'))
buffer.set_style_scheme(style_manager.get_scheme('Adwaita'))

0 comments on commit 5ce69a9

Please sign in to comment.