Commit 3dfa9d39 authored by Roman Alifanov's avatar Roman Alifanov

now code is not in one file

parent 5b6c153d
import subprocess
import threading
from gi.repository import GLib
class ApplicationManager:
@staticmethod
def get_available_applications(callback):
threading.Thread(target=ApplicationManager._get_available_applications, args=(callback,)).start()
@staticmethod
def _get_available_applications(callback):
process = subprocess.Popen(["epm", "play", "--list-all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
def read_output():
stdout, stderr = process.communicate()
if process.returncode == 0:
applications = ApplicationManager.parse_applications_output(stdout)
GLib.idle_add(callback, applications)
else:
GLib.idle_add(callback, [], stderr) # Pass error message
threading.Thread(target=read_output).start()
@staticmethod
def get_installed_applications(callback):
threading.Thread(target=ApplicationManager._get_installed_applications, args=(callback,)).start()
@staticmethod
def _get_installed_applications(callback):
process = subprocess.Popen(["epm", "play", "--list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
def read_output():
stdout, stderr = process.communicate()
if process.returncode == 0:
installed_apps = ApplicationManager.parse_installed_applications_output(stdout)
GLib.idle_add(callback, installed_apps)
else:
GLib.idle_add(callback, [], stderr) # Pass error message
threading.Thread(target=read_output).start()
@staticmethod
def parse_applications_output(output):
applications = []
for line in output.splitlines()[1:]: # Пропустить заголовок
parts = line.split(' - ', 1) # Ограничить сплит до 2 частей
if len(parts) == 2:
name, dscr = map(str.strip, parts)
applications.append({
'name': name.replace('&', '&'),
'dscr': dscr.replace('&', '&')
})
else:
# Логгирование некорректной строки для диагностики
print(f"Неправильный формат строки: {line}")
return applications
@staticmethod
def parse_installed_applications_output(output):
lines = output.splitlines()[1:]
return [line.split(' - ')[0].strip().split()[0] for line in lines]
import subprocess
import threading
from gi.repository import GLib
class CommandRunner:
def __init__(self, on_done=None):
self.dialog = None
self.textbuffer = None
self.on_done = on_done # Callback function to be called after completion
def run_command(self, command, dialog):
self.dialog = dialog
self.textbuffer = dialog.get_child().get_child().get_child().get_buffer()
def append_log(text):
GLib.idle_add(self.textbuffer.insert_at_cursor, text)
GLib.idle_add(dialog.get_child().get_child().get_child().scroll_to_mark,
self.textbuffer.get_insert(), 0, False, 0.0, 1.0)
def read_output(source):
while True:
line = source.readline()
if line:
GLib.idle_add(append_log, line)
else:
break
def process_runner():
try:
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True)
threading.Thread(target=read_output, args=(process.stdout,)).start()
threading.Thread(target=read_output, args=(process.stderr,)).start()
process.wait()
GLib.idle_add(dialog.close)
if self.on_done:
GLib.idle_add(self.on_done) # Call the callback function after completion
except subprocess.CalledProcessError as e:
GLib.idle_add(append_log, f"Ошибка: {str(e)}\n")
GLib.idle_add(dialog.close)
if self.on_done:
GLib.idle_add(self.on_done) # Call the callback function after completion
threading.Thread(target=process_runner).start()
......@@ -30,6 +30,8 @@ eepm_play_gui_sources = [
'__init__.py',
'main.py',
'window.py',
'command_runner.py',
'appsmanager.py',
]
install_data(eepm_play_gui_sources, install_dir: moduledir)
......@@ -17,119 +17,10 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later
import sys
import gi
import subprocess
import threading
from gi.repository import Gtk, Adw
from gi.repository import Gtk, Adw, GLib
class CommandRunner:
def __init__(self, on_done=None):
self.dialog = None
self.textbuffer = None
self.on_done = on_done # Callback function to be called after completion
def run_command(self, command, dialog):
self.dialog = dialog
self.textbuffer = dialog.get_child().get_child().get_child().get_buffer()
def append_log(text):
GLib.idle_add(self.textbuffer.insert_at_cursor, text)
GLib.idle_add(dialog.get_child().get_child().get_child().scroll_to_mark,
self.textbuffer.get_insert(), 0, False, 0.0, 1.0)
def read_output(source):
while True:
line = source.readline()
if line:
GLib.idle_add(append_log, line)
else:
break
def process_runner():
try:
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True)
threading.Thread(target=read_output, args=(process.stdout,)).start()
threading.Thread(target=read_output, args=(process.stderr,)).start()
process.wait()
GLib.idle_add(dialog.close)
if self.on_done:
GLib.idle_add(self.on_done) # Call the callback function after completion
except subprocess.CalledProcessError as e:
GLib.idle_add(append_log, f"Ошибка: {str(e)}\n")
GLib.idle_add(dialog.close)
if self.on_done:
GLib.idle_add(self.on_done) # Call the callback function after completion
threading.Thread(target=process_runner).start()
class ApplicationManager:
@staticmethod
def get_available_applications(callback):
threading.Thread(target=ApplicationManager._get_available_applications, args=(callback,)).start()
@staticmethod
def _get_available_applications(callback):
process = subprocess.Popen(["epm", "play", "--list-all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
def read_output():
stdout, stderr = process.communicate()
if process.returncode == 0:
applications = ApplicationManager.parse_applications_output(stdout)
GLib.idle_add(callback, applications)
else:
GLib.idle_add(callback, [], stderr) # Pass error message
threading.Thread(target=read_output).start()
@staticmethod
def get_installed_applications(callback):
threading.Thread(target=ApplicationManager._get_installed_applications, args=(callback,)).start()
@staticmethod
def _get_installed_applications(callback):
process = subprocess.Popen(["epm", "play", "--list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
def read_output():
stdout, stderr = process.communicate()
if process.returncode == 0:
installed_apps = ApplicationManager.parse_installed_applications_output(stdout)
GLib.idle_add(callback, installed_apps)
else:
GLib.idle_add(callback, [], stderr) # Pass error message
threading.Thread(target=read_output).start()
@staticmethod
def parse_applications_output(output):
applications = []
for line in output.splitlines()[1:]: # Пропустить заголовок
parts = line.split(' - ', 1) # Ограничить сплит до 2 частей
if len(parts) == 2:
name, dscr = map(str.strip, parts)
applications.append({
'name': name.replace('&', '&'),
'dscr': dscr.replace('&', '&')
})
else:
# Логгирование некорректной строки для диагностики
print(f"Неправильный формат строки: {line}")
return applications
@staticmethod
def parse_installed_applications_output(output):
lines = output.splitlines()[1:]
return [line.split(' - ')[0].strip().split()[0] for line in lines]
from .appsmanager import ApplicationManager
from .command_runner import CommandRunner
@Gtk.Template(resource_path='/ru/eepm/PlayGUI/window.ui')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment