-
Notifications
You must be signed in to change notification settings - Fork 3
/
webenginecontextmenudata.py
104 lines (77 loc) · 2.64 KB
/
webenginecontextmenudata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
from typing import List
from qtpy import PYQT5, PYSIDE2
if PYQT5:
from PyQt5 import QtWebEngineWidgets # type: ignore
elif PYSIDE2:
from PySide2 import QtWebEngineWidgets
from prettyqt import core
from prettyqt.utils import bidict
mod = QtWebEngineWidgets.QWebEngineContextMenuData
EDIT_FLAGS = bidict(
undo=mod.CanUndo,
redo=mod.CanRedo,
cut=mod.CanCut,
copy=mod.CanCopy,
paste=mod.CanPaste,
delete=mod.CanDelete,
select_all=mod.CanSelectAll,
translate=mod.CanTranslate,
edit_richly=mod.CanEditRichly,
)
MEDIA_FLAGS = bidict(
in_error=mod.MediaInError,
paused=mod.MediaPaused,
muted=mod.MediaMuted,
loop=mod.MediaLoop,
can_save=mod.MediaCanSave,
has_audio=mod.MediaHasAudio,
can_toggle_controls=mod.MediaCanToggleControls,
controls=mod.MediaControls,
can_print=mod.MediaCanPrint,
can_rotate=mod.MediaCanRotate,
)
MEDIA_TYPES = bidict(
none=mod.MediaTypeNone,
image=mod.MediaTypeImage,
video=mod.MediaTypeVideo,
audio=mod.MediaTypeAudio,
canvas=mod.MediaTypeCanvas,
file=mod.MediaTypeFile,
plugin=mod.MediaTypePlugin,
)
class WebEngineContextMenuData(QtWebEngineWidgets.QWebEngineContextMenuData):
def get_media_url(self) -> core.Url:
return core.Url(self.mediaUrl())
def get_link_url(self) -> core.Url:
return core.Url(self.linkUrl())
def get_media_type(self) -> str:
return MEDIA_TYPES.inv[self.mediaType()]
def get_media_flags(self) -> List[str]:
return [k for k, v in MEDIA_FLAGS.items() if v & self.mediaFlags()]
def get_edit_flags(self) -> List[str]:
return [k for k, v in EDIT_FLAGS.items() if v & self.editFlags()]
def can_undo(self) -> bool:
return mod.CanUndo & self.editFlags()
def can_redo(self) -> bool:
return mod.CanRedo & self.editFlags()
def can_cut(self) -> bool:
return mod.CanCut & self.editFlags()
def can_copy(self) -> bool:
return mod.CanCopy & self.editFlags()
def can_paste(self) -> bool:
return mod.CanPaste & self.editFlags()
def can_delete(self) -> bool:
return mod.CanDelete & self.editFlags()
def can_select_all(self) -> bool:
return mod.CanSelectAll & self.editFlags()
def can_translate(self) -> bool:
return mod.CanTranslate & self.editFlags()
def can_edit_richly(self) -> bool:
return mod.CanEditRichly & self.editFlags()
if __name__ == "__main__":
from prettyqt import widgets, webenginewidgets
app = widgets.app()
page = webenginewidgets.WebEnginePage()
context_menu_data = page.get_context_menu_data()
app.main_loop()