This commit is contained in:
Izalia Mae 2022-09-25 06:47:55 -04:00
parent 2e62ee6517
commit d0b4640e32
8 changed files with 169 additions and 163 deletions

View file

@ -1,5 +1,6 @@
import sys
import asyncio
import click
import sys
from izzylib import signal_handler
from os import environ as env
@ -10,6 +11,9 @@ from .database.base import default_config
from .dbus import Client
from .functions import install_desktop_file
try: from gi.events import GLibEventLoopPolicy
except ImportError: GLibEventLoopPolicy = None
context_settings = dict(
show_default = True
@ -42,6 +46,9 @@ def cli(ctx, profile):
def cli_run(ctx, urls):
v = sys.version_info
if GLibEventLoopPolicy:
asyncio.set_event_loop_policy(events.GLibEventLoopPolicy())
# Set gui scale
with ctx.obj.app.db.session as s:
env['GDK_SCALE'] = str(s.get_config('scale'))

View file

@ -1,3 +1,5 @@
import asyncio
from izzylib.misc import random_str
from .. import cache, var
@ -216,7 +218,8 @@ class StatusBar(ComponentBase):
tab = self.tab
if name == 'debug':
self.window.notification('Merp!', 'INFO', timeout=0, system=True)
#self.window.notification('Merp!', 'INFO', timeout=0, system=True)
print(asyncio.get_running_loop())
#if self.window.themes.current:
#self.window.themes.unset()

View file

@ -1,7 +1,7 @@
from .. import protocol, var
from ..extensions import WebExtensions
from ..functions import connect
from ..widgets import FileChooser
from ..widgets import Download, FileChooser
class WebContext(WebKit2.WebContext):
@ -85,147 +85,4 @@ class WebContext(WebKit2.WebContext):
def handle_new_download(self, context, download):
NewDownload(self, download)
class NewDownload(Gtk.Builder):
# Might use a response instead of a class var for the dialog
response = DotDict(
accept = Gtk.ResponseType.ACCEPT,
reject = Gtk.ResponseType.REJECT,
close = Gtk.ResponseType.CLOSE,
none = Gtk.ResponseType.NONE
)
def __init__(self, context, download):
super().__init__()
self.add_from_file(context.app.path.resources.join('download.ui'))
with context.app.db.session as s:
download_dir = s.get_config('download_dir')
self.app = context.app
self.context = context
self.window = context.window
self.download = download
self.cancel = False
self.data = DotDict(
filename = None,
path = download_dir,
url = download.get_request().get_uri()
)
self.dialog = self['download-window']
self.dialog.set_attached_to(context.window)
self.download.set_allow_overwrite(True)
# Connect dialog signals
self.Connect('download-filename', 'changed', self.handle_dialog_change_filename)
self.Connect('download-filename-set', 'clicked', self.handle_dialog_set_filename)
self.Connect('download-cancel', 'clicked', self.handle_dialog_close, True)
self.Connect('download-save', 'clicked', self.handle_dialog_close, False)
self.Connect('download-window', 'delete-event', self.dialog.destroy)
# Connect download signals
connect(download, 'decide-destination', self.handle_download_decide_destination, original_args=True)
connect(download, 'created-destination', self.handle_download_created_destination)
connect(download, 'failed', self.handle_download_failed, original_args=True)
connect(download, 'finished', self.handle_download_finish)
def __getitem__(self, key):
return self.get_object(key)
@property
def filename(self):
return Path(self['download-filename'].get_text())
@filename.setter
def filename(self, text):
self['download-filename'].set_text(text or '')
@property
def url(self):
return self['download-url'].get_text()
@url.setter
def url(self, text):
self['download-url'].set_text(text or '')
def Connect(self, name, signal, callback, *args, **kwargs):
return connect(self[name], signal, callback, *args, **kwargs)
def target_path(self, full=True):
path = self.data.path.join(self.data.filename)
if full:
return f'file://{path}'
return path
def handle_dialog_close(self, cancel):
self.cancel = cancel
self.dialog.destroy()
def handle_dialog_change_filename(self):
self.data.path, self.data.filename = self.filename.parent, self.filename.name
self['download-save'].set_label('Overwrite' if self.filename.exists() else 'Save')
def handle_dialog_set_filename(self):
with FileChooser(self.dialog, self.data.path, self.data.filename) as fc:
if not fc:
logging.verbose('Canceled file selector')
return
self.filename = fc
def handle_download_created_destination(self):
logging.debug(f'Created desination for file: {self.target_path(False)}')
def handle_download_decide_destination(self, download, filename):
self.data.filename = filename
self.url = self.data.url
self.filename = self.target_path(False)
self.handle_dialog_change_filename()
self.dialog.run()
if self.cancel:
download.cancel()
else:
download.set_destination(self.target_path())
def handle_download_failed(self, download, error):
if error.code == 400:
self.cancel = True
return
data = DotDict({
'args': error.args,
'code': error.code,
'domain': error.domain,
'message': error.message
})
logging.debug(data.to_json(4))
self.window.notification(f'Download failed: {self.target_path(False)}', system=True)
def handle_download_finish(self):
if not self.cancel:
self.window.notification(f'Download finished: {self.target_path(False)}', system=True)
Download(download)

View file

@ -415,7 +415,7 @@ class WebTab(BuilderBase, Gtk.Box):
def setup_signals(self):
## Navigation bar
self.connect('label-close', 'clicked', self.webview.try_close)
self.connect('label-close', 'clicked', self.close)
self.connect('label-favicon', 'clicked', self.state_unload)
self.connect('navbar-prev', 'clicked', self.page_action, 'back')
self.connect('navbar-next', 'clicked', self.page_action, 'forward')

View file

@ -433,11 +433,7 @@ class Window(BuilderBase, Gtk.ApplicationWindow):
self.taborder.insert(0, tab.id)
self.set_button_state(tab.id)
#progress = tab.webview.get_estimated_load_progress()
#self['navbar-url'].set_progress_fraction(0 if progress == 1.0 else progress)
## save tab urls and titles on close to reopen them on startup
def handle_window_close(self, *args):
logging.verbose('Saving data')

View file

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="chooser">
<property name="width-request">640</property>
<property name="height-request">480</property>
<property name="can-focus">False</property>
<property name="window-position">center</property>
<property name="window-position">center-on-parent</property>
<property name="type-hint">dialog</property>
<child>
<object class="GtkBox">

View file

@ -11,6 +11,141 @@ from .enums import FileChooserAction, FileChooserResponse
from .functions import connect, set_image
class Download(BuilderBase):
valid_response_types = [FileChooserResponse.OK, FileChooserResponse.CANCEL]
def __init__(self, download):
BuilderBase.__init__(self, scriptpath.join('resources/download.ui'))
with self.db.session as s:
download_dir = s.get_config('download_dir')
self.download = download
self.cancel = False
self.data = DotDict(
filename = None,
path = download_dir,
url = download.get_request().get_uri()
)
self['download-window'].set_transient_for(self.window)
download.set_allow_overwrite(True)
# Connect dialog signals
self.connect('download-filename', 'changed', self.handle_dialog_change_filename)
self.connect('download-filename-set', 'clicked', self.handle_dialog_set_filename)
self.connect('download-cancel', 'clicked', self.handle_dialog_close, True)
self.connect('download-save', 'clicked', self.handle_dialog_close, False)
self.connect('download-window', 'delete-event', self.handle_dialog_close, False)
# Connect download signals
connect(download, 'decide-destination', self.handle_download_decide_destination, original_args=True)
connect(download, 'created-destination', self.handle_download_created_destination)
connect(download, 'failed', self.handle_download_failed, original_args=True)
connect(download, 'finished', self.handle_download_finish)
@property
def context(self):
return self.app.context
@property
def filename(self):
return Path(self['download-filename'].get_text())
@filename.setter
def filename(self, text):
self['download-filename'].set_text(text or '')
@property
def url(self):
return self['download-url'].get_text()
@url.setter
def url(self, text):
self['download-url'].set_text(text or '')
def target_path(self, full=True):
path = self.data.path.join(self.data.filename)
if full:
return f'file://{path}'
return path
def handle_dialog_close(self, cancel):
if self.cancel != None:
return
self.cancel = cancel
self.destroy()
def handle_dialog_change_filename(self):
self.data.path, self.data.filename = self.filename.parent, self.filename.name
self['download-save'].set_label('Overwrite' if self.filename.exists() else 'Save')
def handle_dialog_set_filename(self):
with FileChooser(self.dialog, self.data.path, self.data.filename) as fc:
if not fc:
logging.verbose('Canceled file selector')
return
self.filename = fc
def handle_download_created_destination(self):
logging.verbose(f'Created desination for file: {self.target_path(False)}')
def handle_download_decide_destination(self, download, filename):
self.data.filename = filename
self.url = self.data.url
self.filename = self.target_path(False)
self.handle_dialog_change_filename()
self['download-window'].run()
if self.cancel:
download.cancel()
else:
download.set_destination(self.target_path())
def handle_download_failed(self, download, error):
if error.code == 400:
self.cancel = True
return
data = DotDict({
'args': error.args,
'code': error.code,
'domain': error.domain,
'message': error.message
})
logging.debug(data.to_json(4))
self.window.notification(f'Download failed: {self.target_path(False)}', system=True)
self.destroy
def handle_download_finish(self):
if not self.cancel:
self.window.notification(f'Download finished: {self.target_path(False)}', system=True)
self.destroy()
class FileChooser(BuilderBase):
valid_response_types = [FileChooserResponse.OK, FileChooserResponse.CANCEL]
@ -27,7 +162,10 @@ class FileChooser(BuilderBase):
if filename:
self['chooser-main'].set_current_name(filename)
self['chooser'].set_transient_for(parent)
self.connect('chooser', 'delete-event', self.handle_response, FileChooserResponse.CANCEL)
self.connect('chooser', 'key-press-event', self.handle_key_press, original_args=True)
self.connect('chooser-main', 'update-preview', self.handle_image_preview)
self.connect('chooser-preview-size', 'state-set', self.handle_image_preview)
self.connect('chooser-okay', 'clicked', self.handle_response, FileChooserResponse.OK)
@ -102,6 +240,11 @@ class FileChooser(BuilderBase):
self.response_callback[response] = partial(callback, *args, **kwargs)
def handle_key_press(self, _, event):
if event.keyval == Gdk.KEY_Escape:
self.do_response(FileChooserResponse.CANCEL)
def handle_image_preview(self, *_):
path = Path(self['chooser-main'].get_preview_filename())
widget = self['chooser-main'].get_preview_widget()

View file

@ -2,19 +2,19 @@
"name": "barkshark_web",
"modules": {
"beautifulsoup4": {
"version": "4.9.3",
"version": "4.11.1",
"options": [],
"url": null
},
"click": {
"version": "8.1.0",
"version": "8.1.3",
"options": [],
"url": null
},
"configobj": {
"version": "5.1.0.dev0",
"version": "5.0.6",
"options": [],
"url": "git+https://github.com/DiffSK/configobj"
"url": "git+https://github.com/DiffSK/configobj@v5.0.6"
},
"dasbus": {
"version": "1.6",
@ -42,7 +42,7 @@
"url": "git+https://git.barkshark.xyz/izaliamae/izzylib-sql"
},
"lxml": {
"version": "4.6.3",
"version": "4.9.1",
"options": [],
"url": null
},
@ -57,12 +57,12 @@
"url": null
},
"pillow": {
"version": "8.3.2",
"version": "9.2.0",
"options": [],
"url": null
},
"psutil": {
"version": "5.8.0",
"version": "5.9.1",
"options": [],
"url": null
},
@ -72,7 +72,7 @@
"url": null
},
"pygobject": {
"version": "3.38.0",
"version": "3.38.2",
"options": [],
"url": null
},
@ -115,4 +115,4 @@
"pyvenv.py"
]
}
}
}