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
Roman Alifanov
eepm-play-gui
Commits
6969d3de
Commit
6969d3de
authored
Oct 30, 2024
by
Roman Alifanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
applicationrow: implemented downloading icons from Etersoft servers and caching
parent
f24534bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
1 deletion
+57
-1
applicationrow.py
src/widgets/applicationrow.py
+57
-1
No files found.
src/widgets/applicationrow.py
View file @
6969d3de
from
gi.repository
import
Adw
,
Gtk
import
os
import
urllib.request
import
threading
from
gi.repository
import
Adw
,
Gtk
,
GdkPixbuf
,
Gio
,
GLib
,
Gdk
class
IconLoader
:
BASE_URL
=
"https://download.etersoft.ru/pub/Etersoft/XimperLinux/eepm_play_gui/icons/"
SUPPORTED_EXTENSIONS
=
[
'png'
,
'jpg'
,
'svg'
]
CACHE_DIR
=
os
.
path
.
join
(
os
.
path
.
expanduser
(
"~"
),
".cache"
,
"ru.eepm.PlayGUI"
,
"apps_icons"
)
@classmethod
def
ensure_cache_dir
(
cls
):
if
not
os
.
path
.
exists
(
cls
.
CACHE_DIR
):
os
.
makedirs
(
cls
.
CACHE_DIR
)
@classmethod
def
get_cached_icon_path
(
cls
,
icon_name
):
return
os
.
path
.
join
(
cls
.
CACHE_DIR
,
f
"{icon_name}.png"
)
# Cache as PNG
@classmethod
def
load_icon_async
(
cls
,
icon_name
,
callback
):
cls
.
ensure_cache_dir
()
# Ensure the cache directory exists
cached_icon_path
=
cls
.
get_cached_icon_path
(
icon_name
)
if
os
.
path
.
exists
(
cached_icon_path
):
pixbuf
=
GdkPixbuf
.
Pixbuf
.
new_from_file
(
cached_icon_path
)
GLib
.
idle_add
(
callback
,
pixbuf
)
return
def
load_icon
():
for
ext
in
cls
.
SUPPORTED_EXTENSIONS
:
icon_url
=
f
"{cls.BASE_URL}{icon_name}.{ext}"
try
:
with
urllib
.
request
.
urlopen
(
icon_url
)
as
response
:
input_stream
=
Gio
.
MemoryInputStream
.
new_from_data
(
response
.
read
(),
None
)
pixbuf
=
GdkPixbuf
.
Pixbuf
.
new_from_stream
(
input_stream
,
None
)
# Save the pixbuf to the local cache
pixbuf
.
savev
(
cached_icon_path
,
"png"
,
[],
[])
GLib
.
idle_add
(
callback
,
pixbuf
)
return
except
Exception
as
e
:
print
(
f
"Icon for {icon_name} not found in {ext}: {e}"
)
threading
.
Thread
(
target
=
load_icon
,
daemon
=
True
)
.
start
()
class
ApplicationRow
(
Adw
.
ActionRow
):
__gtype_name__
=
'ApplicationRow'
...
...
@@ -11,6 +58,12 @@ class ApplicationRow(Adw.ActionRow):
self
.
set_selectable
(
False
)
self
.
set_activatable
(
True
)
self
.
icon_image
=
Gtk
.
Image
.
new_from_icon_name
(
"image-missing"
)
self
.
icon_image
.
set_icon_size
(
Gtk
.
IconSize
.
LARGE
)
self
.
add_prefix
(
self
.
icon_image
)
IconLoader
.
load_icon_async
(
self
.
app
[
'name'
],
self
.
set_icon
)
self
.
checkbox
=
Gtk
.
CheckButton
()
self
.
checkbox
.
add_css_class
(
"selection-mode"
)
self
.
checkbox
.
set_valign
(
Gtk
.
Align
.
CENTER
)
...
...
@@ -23,6 +76,9 @@ class ApplicationRow(Adw.ActionRow):
self
.
on_toggle
=
on_toggle
# Callback for when the checkbox is toggled
def
set_icon
(
self
,
pixbuf
):
self
.
icon_image
.
set_from_pixbuf
(
pixbuf
)
def
on_checkbox_toggled
(
self
,
checkbox
):
self
.
on_toggle
(
self
.
app
[
'name'
],
checkbox
.
get_active
())
self
.
update_row_css
()
# Update the row's style when toggled
...
...
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