Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tuneit
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
tuneit
Commits
3eb64bff
Commit
3eb64bff
authored
Jan 20, 2025
by
Roman Alifanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ServiceNotStartedDialog and threading
parent
33157810
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
6 deletions
+84
-6
main.py
src/main.py
+5
-0
main.py
src/settings/main.py
+11
-2
service_dialog.py
src/settings/widgets/service_dialog.py
+54
-0
window.py
src/window.py
+14
-4
No files found.
src/main.py
View file @
3eb64bff
...
...
@@ -26,6 +26,8 @@ gi.require_version('Adw', '1')
from
gi.repository
import
Gtk
,
Gio
,
Adw
from
.window
import
TuneitWindow
def
get_main_window
():
return
_application
.
props
.
active_window
class
TuneitApplication
(
Adw
.
Application
):
"""The main application singleton class."""
...
...
@@ -33,10 +35,13 @@ class TuneitApplication(Adw.Application):
def
__init__
(
self
):
super
()
.
__init__
(
application_id
=
'ru.ximperlinux.TuneIt'
,
flags
=
Gio
.
ApplicationFlags
.
DEFAULT_FLAGS
)
global
_application
self
.
create_action
(
'quit'
,
lambda
*
_
:
self
.
quit
(),
[
'<primary>q'
])
self
.
create_action
(
'about'
,
self
.
on_about_action
)
self
.
create_action
(
'preferences'
,
self
.
on_preferences_action
)
_application
=
self
def
do_activate
(
self
):
"""Called when the application is activated.
...
...
src/settings/main.py
View file @
3eb64bff
...
...
@@ -7,6 +7,9 @@ from .tools.yml_tools import load_modules, merge_categories_by_name
from
.tools.gvariant
import
convert_by_gvariant
from
.widgets
import
WidgetFactory
from
.widgets.service_dialog
import
ServiceNotStartedDialog
dialog_presented
=
False
class
Setting
:
def
__init__
(
self
,
setting_data
):
...
...
@@ -69,8 +72,14 @@ class Setting:
widget
=
WidgetFactory
.
create_widget
(
self
)
return
widget
.
create_row
()
if
widget
else
None
else
:
# TODO: Окно с предложением включить сервис
print
(
"The service is unavailable, please enable dbus service"
)
global
dialog_presented
if
dialog_presented
is
False
:
from
..main
import
get_main_window
dialog
=
ServiceNotStartedDialog
()
dialog
.
present
(
get_main_window
())
dialog_presented
=
True
return
None
...
...
src/settings/widgets/service_dialog.py
0 → 100644
View file @
3eb64bff
import
os
import
subprocess
import
sys
from
gi.repository
import
Adw
class
ServiceNotStartedDialog
(
Adw
.
AlertDialog
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
sname
=
'tuneit-daemon'
self
.
set_heading
(
"The dbus service is disabled."
)
self
.
set_body
(
"Do you want to enable it?"
)
self
.
add_response
(
"yes"
,
"Yes"
)
self
.
add_response
(
"no"
,
"No"
)
self
.
connect
(
"response"
,
self
.
on_response
)
def
on_response
(
self
,
dialog
,
response
):
if
response
==
"yes"
:
self
.
service_enable
()
dialog
.
close
()
os
.
execv
(
sys
.
argv
[
0
],
sys
.
argv
)
elif
response
in
(
"no"
,
"close"
):
dialog
.
close
()
def
service_status
(
self
):
try
:
# Запускаем команду systemctl is-active <service_name>
result
=
subprocess
.
run
(
[
'systemctl'
,
'is-active'
,
self
.
sname
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
# Проверяем статус
if
result
.
stdout
.
decode
(
'utf-8'
)
.
strip
()
==
'active'
:
return
True
else
:
return
False
except
Exception
as
e
:
print
(
f
"An error occurred: {e}"
)
return
False
def
service_enable
(
self
):
try
:
subprocess
.
run
(
[
'pkexec'
,
'systemctl'
,
'--now'
,
'enable'
,
self
.
sname
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
except
Exception
as
e
:
print
(
f
"An error occurred: {e}"
)
src/window.py
View file @
3eb64bff
...
...
@@ -17,7 +17,8 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
from
gi.repository
import
GObject
,
Adw
,
Gtk
import
threading
from
gi.repository
import
GObject
,
Adw
,
Gtk
,
GLib
from
.settings.main
import
init_settings_stack
...
...
@@ -38,10 +39,18 @@ class TuneitWindow(Adw.ApplicationWindow):
self
.
connect
(
'settings_page_update'
,
self
.
update_settings_page
)
self
.
update_settings_page
()
def
update_settings_page
(
self
,
*
args
):
def
update_settings_page
(
self
):
thread
=
threading
.
Thread
(
target
=
self
.
_update_settings_page
)
thread
.
daemon
=
True
thread
.
start
()
def
_update_settings_page
(
self
,
*
args
):
"""
Можно вызвать вот так, благодаря сигналу:
self.settings_pagestack.get_root().emit("settings_page_update")
"""
init_settings_stack
(
self
.
settings_pagestack
,
self
.
settings_listbox
,
self
.
settings_split_view
)
print
(
"Stack cleared and initialized!"
)
init_settings_stack
(
self
.
settings_pagestack
,
self
.
settings_listbox
,
self
.
settings_split_view
,
)
\ No newline at end of file
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