Skip to content

Commit

Permalink
Merge pull request #20 from Vilez0/add-show-logs-button
Browse files Browse the repository at this point in the history
feature: Add a show logs button to the installer
  • Loading branch information
sulincix authored Jun 25, 2024
2 parents daec2a6 + b1697fa commit ed1fa9d
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 23 deletions.
54 changes: 54 additions & 0 deletions live-installer/frontend/gtk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from frontend.dialogs import QuestionDialog, ErrorDialog, WarningDialog
from frontend.keyboardview import kbdpreview
from installer import InstallerEngine, Setup, NON_LATIN_KB_LAYOUTS
from logger import _file as LOG_FILE_PATH

gettext.bindtextdomain('xkeyboard-config', '/usr/share/locale')
gettext.textdomain('xkeyboard-config')
Expand Down Expand Up @@ -314,12 +315,23 @@ def enter_event(widget=None, name=""):
# install page
self.builder.get_object("label_install_progress").set_text(
_("Calculating file indexes ..."))
self.builder.get_object("button_logs").connect_after(
"toggled", self.show_logs)

img = self.builder.get_object("image_welcome")
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
"branding/welcome.png", 832, 468, False)
img.set_from_pixbuf(pixbuf)
self.gtkimages.append(img)
self.gtkpixbufs.append(pixbuf)
self.buffer = Gtk.TextBuffer()
self.text_logs = self.builder.get_object("text_logs")
self.text_logs_container = self.builder.get_object("text_logs_container")
self.slidebox = self.builder.get_object("slidebox")
self.log_file = open(LOG_FILE_PATH, "r")
threading.Thread(target=self.monitor_logs,daemon=True).start()
self.size_allocation_handler = self.text_logs.connect("size-allocate", self.scroll_to_bottom)
self.text_logs.connect("map", self.scroll_to_bottom)

# build partition list
self.should_pulse = False
Expand Down Expand Up @@ -1567,6 +1579,48 @@ def bold(strvar):
bold(_("enabled") if _lux else _("disabled")),))
self.builder.get_object("treeview_overview").expand_all()

def continuously_read_file(self, file_path):
with open(file_path, 'r') as file:
file.seek(0,2)
while True:
line = file.readline()
if not line:
time.sleep(0.1)
continue
yield line

def monitor_logs(self):
for line in self.continuously_read_file(LOG_FILE_PATH):
self.buffer.insert(self.buffer.get_end_iter(), line)
self.text_logs.set_buffer(self.buffer)
# This is neccecary to prevent a bug that sometimes causes the text_logs_containers not scrolling to the bottom
time.sleep(0.1)

# Scroll to the bottom of the text_logs_container if necessary
adj = self.text_logs_container.get_vadjustment()
adj_value = adj.get_upper() - adj.get_page_size()
if adj_value - adj.get_page_size() < adj.get_value():
GLib.idle_add(adj.set_value, adj_value)

def show_logs(self, widget):
if widget.get_active():
self.slidebox.set_visible(False)
self.text_logs_container.set_visible(True)
# Scroll to the bottom of the text_logs GtkTextView when the text_logs_container is visible
self.text_logs.handler_unblock(self.size_allocation_handler)
else:
self.text_logs_container.set_visible(False)
self.slidebox.set_visible(True)
# This will prevent a bug that sometimes causes the text_logs_containers not scrolling to the bottom
self.text_logs.handler_unblock(self.size_allocation_handler)

def scroll_to_bottom(self, widget, *args):
adj = self.text_logs_container.get_vadjustment()
adj_value = adj.get_upper() - adj.get_page_size()
GLib.idle_add(adj.set_value, adj_value)
# Blocking the handler allows the user to scroll to the top of the text_logs_container
self.text_logs.handler_block(self.size_allocation_handler)

@idle
def show_error_dialog(self, message, detail):
ErrorDialog(message, detail)
Expand Down
3 changes: 2 additions & 1 deletion live-installer/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
def set_logfile(path):
if os.getuid() != 0:
return
global logfile
global logfile, _file
if logfile:
logfile.flush()
logfile.close()
if os.path.isfile(path):
os.unlink(path)
_file=path
logfile = open(path,"a")

if os.getuid() != 0:
Expand Down
117 changes: 95 additions & 22 deletions live-installer/resources/interface.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,62 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="text_logs_container">
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hscroll-policy">natural</property>
<property name="vscroll-policy">natural</property>
<child>
<object class="GtkTextView" id="text_logs">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hscroll-policy">natural</property>
<property name="vscroll-policy">natural</property>
<property name="editable">False</property>
<property name="left-margin">5</property>
<property name="right-margin">5</property>
<property name="top-margin">5</property>
<property name="bottom-margin">5</property>
<property name="overwrite">True</property>
<property name="accepts-tab">False</property>
<property name="input-purpose">terminal</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="slidebox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">False</property>
<property name="vexpand">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="vbox16">
<property name="visible">True</property>
Expand Down Expand Up @@ -1978,16 +2034,49 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="label_install_percent">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">0.0</property>
<property name="spacing">6</property>
<child>
<object class="GtkToggleButton" id="button_logs">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">dialog-information-symbolic</property>
<property name="use-fallback">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_install_percent">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">0.0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
Expand Down Expand Up @@ -2026,27 +2115,11 @@
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="slidebox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">False</property>
<property name="vexpand">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
<placeholder/>
</child>
</object>
<packing>
Expand Down

0 comments on commit ed1fa9d

Please sign in to comment.