Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eepm-play-gui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladimir Vaskov
eepm-play-gui
Commits
3dfa9d39
Commit
3dfa9d39
authored
Oct 02, 2024
by
Roman Alifanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now code is not in one file
parent
5b6c153d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
112 deletions
+121
-112
appsmanager.py
src/appsmanager.py
+65
-0
command_runner.py
src/command_runner.py
+51
-0
meson.build
src/meson.build
+2
-0
window.py
src/window.py
+3
-112
No files found.
src/appsmanager.py
0 → 100644
View file @
3dfa9d39
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
]
src/command_runner.py
0 → 100644
View file @
3dfa9d39
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
()
src/meson.build
View file @
3dfa9d39
...
...
@@ -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)
src/window.py
View file @
3dfa9d39
...
...
@@ -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'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment