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) { copy(filepath, target) {
return handler('fs', { action: '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) { image(filepath) {
@ -387,5 +381,10 @@ Object.assign(native, {
null null
) )
}, },
md5(value = '') {
return handler('md5', { value })
},
handler handler
}) })

30
main.py
View File

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

View File

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