Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mijorus committed Dec 28, 2023
1 parent d226b66 commit 5e52727
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 47 deletions.
1 change: 1 addition & 0 deletions .flatpak-builder/cache/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
repo_version=1
mode=bare-user-only
min-free-space-percent=0
indexed-deltas=true
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4fd05c7d363ee9d8b06631d1818a5f6c82a0cf1f1a5dc11a9a312ffcd1712686
3fe13763b5e891075ca7467169949f1f95536c38d08cd630bfb05f5b0b8cb9e0
37 changes: 1 addition & 36 deletions it.mijorus.collector.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"--share=network",
"--share=ipc",
"--socket=fallback-x11",
"--socket=wayland",
"--device=dri"
],
"cleanup": [
Expand All @@ -23,42 +24,6 @@
"*.a"
],
"modules": [
{
"name": "libwnck",
"buildsystem": "meson",
"config-opts": [
"-Dgtk_doc=false"
],
"cleanup": [
"/include",
"/lib/pkgconfig",
"/bin"
],
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/GNOME/libwnck.git",
"tag": "43.0",
"commit": "6147abd0c1fe35b96e1fbb63fa94d23f91fb2934"
}
]
},
{
"name": "raise",
"buildsystem": "simple",
"build-commands": [
"ls",
"cp raise.py ${FLATPAK_DEST}/bin",
"ls /app/bin",
"chmod +x /app/bin/raise.py"
],
"sources": [
{
"type": "file",
"path": "src/raise.py"
}
]
},
{
"name": "collector",
"builddir": true,
Expand Down
3 changes: 0 additions & 3 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"exclude": [
"src/precompile/*"
],
"include": [
"src"
],
Expand Down
4 changes: 3 additions & 1 deletion src/lib/DroppedItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ def __init__(self, item) -> None:
self.display_value = ''
self.preview_image = Gtk.Image(icon_name='paper-symbolic', pixel_size=70)
self.item = item
self.size = 0

if isinstance(item, Gio.File):
self.target_path = item.get_path()
print(self.target_path)
self.display_value = item.get_basename()
info = item.query_info('standard::icon' , 0 , Gio.Cancellable())
self.preview_image.set_from_gicon(info.get_icon())
self.size = os.stat(item.get_path()).st_size

elif isinstance(item, str):
base_filename = 'collected_text_'
Expand All @@ -31,6 +32,7 @@ def __init__(self, item) -> None:
with open(self.target_path, 'w+') as f:
f.write(text_string)

self.size = os.stat(self.target_path).st_size
self.preview_image.set_from_icon_name('text-justify-left-symbolic')

self.display_value = text_string[:15]
Expand Down
5 changes: 4 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import sys
import os
import gi
import subprocess
import threading
import time

gi.require_version('Gtk', '4.0')
gi.require_version('Gdk', '4.0')
gi.require_version('Adw', '1')

from gi.repository import Gtk, Gio, Adw
from gi.repository import Gtk, Gio, Adw, GLib
from .window import CollectorWindow


Expand Down
27 changes: 22 additions & 5 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import gi
import shutil
import subprocess

gi.require_version('Gdk', '4.0')

Expand All @@ -35,7 +36,7 @@ class CollectorWindow(Adw.ApplicationWindow):
CAROUSEL_ICONS_PIX_SIZE=50

def __init__(self, **kwargs):
super().__init__(**kwargs)
super().__init__(**kwargs, title='CollectorMainWindow')

header_bar = Adw.HeaderBar(
show_title=False,
Expand Down Expand Up @@ -116,10 +117,14 @@ def __init__(self, **kwargs):
self.set_resizable(False)
self.set_content(overlay)

self.init_cache_folder()


def init_cache_folder(self):
drops_cache_path = GLib.get_user_cache_dir() + f'/drops'
if os.path.exists(drops_cache_path):
shutil.rmtree(drops_cache_path)

os.mkdir(drops_cache_path)

def on_drag_prepare(self, source, x, y):
Expand All @@ -131,6 +136,7 @@ def on_drag_prepare(self, source, x, y):
uri_list = '\n'.join([f'file://{f.target_path}' for f in self.dropped_items])

return Gdk.ContentProvider.new_union([
Gdk.ContentProvider.new_for_value(dropped_files[0]),
Gdk.ContentProvider.new_for_value(path_list),
Gdk.ContentProvider.new_for_value(uri_list),
Gdk.ContentProvider.new_for_bytes(
Expand Down Expand Up @@ -178,15 +184,26 @@ def on_drop_leave(self, widget):
if not self.is_dragging_away:
if self.dropped_items:
self.icon_stack.set_visible_child(self.carousel_container)
tot_size = sum([d.size for d in self.dropped_items])

if tot_size > (1024 * 1024 * 1024):
tot_size = f'{round(tot_size / (1024 * 1024 * 1024), 1)} GB'
elif tot_size > (1024 * 1024):
tot_size = f'{round(tot_size / (1024 * 1024), 1)} MB'
else:
tot_size = f'{round(tot_size / (1024), 1)} KB'

if len(self.dropped_items) == 1:
self.drops_label.set_label(_('1 File'))
self.drops_label.set_label(_('1 File | {size}').format(size=tot_size))
else:
self.drops_label.set_label(_('{files_count} Files').format(files_count=len(self.dropped_items)))
self.drops_label.set_label(_('{files_count} Files | {size}').format(
files_count=len(self.dropped_items),
size=tot_size
))
else:
self.drops_label.set_label(self.EMPTY_DROP_TEXT)
self.icon_stack.set_visible_child(self.default_drop_icon)

def on_key_pressed(self, widget, keyval, keycode, state):
if keyval == Gdk.KEY_Escape:
self.close()
self.close()

0 comments on commit 5e52727

Please sign in to comment.