This repository has been archived on 2023-09-06. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
py-gtk-notes
Archived
1
0
Fork 0
master
yutent 2023-07-31 19:28:17 +08:00
parent 98023484cf
commit 69c15d3f57
3 changed files with 45 additions and 12 deletions

View File

@ -356,5 +356,8 @@ Object.assign(native, {
handler('window', { action: 'set_keep_below', value: setting }, null)
}
},
notify({ title, summary, icon, progress = 0, urgency = 0 }) {
handler('notify', { title, summary, icon, progress, urgency })
},
handler
})

43
main.py
View File

@ -6,8 +6,9 @@ import gi, json, os, shutil
gi.require_version("Gtk", "3.0")
gi.require_version("WebKit2", "4.1")
gi.require_version("Keybinder", "3.0")
gi.require_version('Notify', '0.7') # gir1.2-notify-0.7
from gi.repository import Gtk, Gdk, WebKit2, GLib, Gio, Keybinder
from gi.repository import Gtk, Gdk, WebKit2, GLib, Gio, Keybinder, Notify
from gi.repository.GdkPixbuf import Pixbuf
from notes.utils import *
@ -23,7 +24,9 @@ except (ValueError, ImportError):
# 初始化 Keybinder
Keybinder.init()
Notify.init(Notify.get_app_name() or 'webapp')
# im_context = Gtk.IMContext()
class WebKitWindow(Gtk.Window):
@ -51,6 +54,7 @@ class WebKitWindow(Gtk.Window):
settings.set_user_agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) weapp/1.0.0 Version/16.4 Safari/605.1.15")
manager = WebKit2.UserContentManager()
script = open(self.file_path('./inject.js'), 'r').read()
@ -69,24 +73,26 @@ class WebKitWindow(Gtk.Window):
context = self.webview.get_context()
context.register_uri_scheme('app', self.resource_request_callback)
# self.webview.connect("resource-load-started", self.resource_request_callback)
im = self.webview.get_input_method_context()
im.set_enable_preedit(True)
# self.webview.load_uri("http://127.0.0.1:10086/index.html")
self.webview.load_uri("app:///index.html")
# self.webview.load_uri("https://benchmark.wkit.fun")
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.add(self.webview)
def resource_request_callback(self, req):
schema = req.get_scheme()
@ -96,11 +102,6 @@ class WebKitWindow(Gtk.Window):
if schema == 'app':
data = open(self.file_path('./webview' + pathname)).read()
data = Gio.MemoryInputStream.new_from_data(data.encode())
# res = WebKit2.URISchemeResponse.new(data, -1)
# res.set_content_type(get_mimetype(ext))
# res.set_http_headers('text/html')
# res.set_status(200)
# req.finish_with_response(res)
req.finish(data, -1, get_mimetype(ext))
return True
else:
@ -344,6 +345,22 @@ class WebKitWindow(Gtk.Window):
elif params['action'] == 'is_visible':
output = self.is_visible()
case 'notify':
title = params.get('title')
summary = params.get('summary')
icon = params.get('icon')
progress = params.get('progress')
urgency = params.get('urgency')
notify = Notify.Notification.new(title, summary, icon)
if progress:
notify.set_hint('value', progress)
notify.set_urgency(urgency)
notify.add_action("click", "Click Me!", my_callback_func)
notify.show()
# 有回调则返回结果
if callback :
@ -352,8 +369,13 @@ class WebKitWindow(Gtk.Window):
def all_quit(win):
print('朕要休息了~~~')
Notify.uninit()
Gtk.main_quit()
def my_callback_func(notification, action_name, user_data):
print("Button clicked! Action name: %s" % action_name)
notification.close()
win = WebKitWindow()
@ -361,6 +383,7 @@ win.connect("destroy", all_quit)
win.show_all()
tray = win.create_tray()
Gtk.main()

View File

@ -80,6 +80,13 @@ class App extends Component {
>
rename
</button>
<button
@click=${async function () {
native.notify({ title: 'hello', icon: 'chrome' })
}}
>
通知
</button>
<img style="width:100px;border:1px solid #09f;" src=${this.img} />
<textarea @paste=${this.pasteImg}></textarea>
`