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

增加md5支持

master
yutent 2023-08-01 18:40:52 +08:00
parent 511302f72d
commit 5b0ec56c5b
3 changed files with 17 additions and 25 deletions

View File

@ -227,12 +227,6 @@ Object.assign(native, {
},
copy(filepath, target) {
return handler('fs', { action: 'copy', filepath, target })
},
async upload(file) {
return handler('fs', {
action: 'upload',
file: new Uint8Array(await file.arrayBuffer())
})
}
},
image(filepath) {
@ -387,5 +381,10 @@ Object.assign(native, {
null
)
},
md5(value = '') {
return handler('md5', { value })
},
handler
})

30
main.py
View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
import gi, json, os, shutil
import gi, json, os, shutil, hashlib
gi.require_version("Gtk", "3.0")
@ -27,8 +27,6 @@ except (ValueError, ImportError):
Keybinder.init()
# im_context = Gtk.IMContext()
class WebKitWindow(Gtk.Window):
def __init__(self):
@ -37,7 +35,7 @@ class WebKitWindow(Gtk.Window):
Gtk.Window.__init__(self, title="WebKit Example")
self.notify = Notification(self)
# Notification.__init__(self.notify, )
self.display = Gdk.Display.get_default()
self.set_default_size(800, 600)
@ -48,7 +46,6 @@ class WebKitWindow(Gtk.Window):
settings.set_enable_developer_extras(True)
# settings.set_disable_web_security(True)
settings.set_enable_html5_database(True)
@ -85,9 +82,8 @@ class WebKitWindow(Gtk.Window):
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.webview.load_uri("app:///index.html")
self.webview.load_uri("https://benchmark.wkit.fun")
# 解决输入法候选框跟随问题
@ -104,8 +100,7 @@ class WebKitWindow(Gtk.Window):
def on_preedit_changed(self, im):
display = Gdk.Display.get_default()
p = display.get_pointer() # 光标位置
p = self.display.get_pointer() # 光标位置
x, y = self.get_position() # 窗口位置
im.notify_focus_in()
@ -246,11 +241,7 @@ class WebKitWindow(Gtk.Window):
if params['action'] == 'isdir':
output = os.path.isdir(filepath)
if params['action'] == 'upload':
print(params)
case 'clipboard':
# 读文本
@ -296,14 +287,12 @@ class WebKitWindow(Gtk.Window):
case 'monitor':
if params['action'] == 'get-all':
display = Gdk.Display.get_default()
monitor_num = display.get_n_monitors()
monitors = [display.get_monitor(i) for i in range(monitor_num)]
monitor_num = self.display.get_n_monitors()
monitors = [self.display.get_monitor(i) for i in range(monitor_num)]
output = [get_monitor_info(m) for m in monitors]
elif params['action'] == 'get-primary':
display = Gdk.Display.get_default()
monitor = display.get_primary_monitor()
monitor = self.display.get_primary_monitor()
output = get_monitor_info(monitor)
case 'keybinder':
@ -389,6 +378,9 @@ class WebKitWindow(Gtk.Window):
self.notify.create(title, summary, icon, progress, urgency, params.get('callback'))
case 'md5':
output = hashlib.md5(str(params.get('value'))).hexdigest()
# 有回调则返回结果
if callback:
self.call_js(callback, output)

View File

@ -114,6 +114,7 @@ class App extends Component {
let file = ev.target.files[0]
let u8 = new Uint8Array(await file.arrayBuffer())
console.log(u8)
// 分片写入
for (let i = 0; i <= u8.length; i += 2048) {
await native.fs.write(
'/code/gtk/webkit/demo.png',