-
Notifications
You must be signed in to change notification settings - Fork 0
/
HtmlPanel.py
53 lines (37 loc) · 1.53 KB
/
HtmlPanel.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
import wx
import wx.html as html
# TODO: Ver como quitar el tamaño fijo del HtmlPanel
class HtmlPanel(wx.Panel):
def __init__ (self, parent, parent_frame, size=(400, 600), *args, **kwargs):
super(HtmlPanel, self).__init__(parent, *args, **kwargs)
self.parent = parent_frame
self.SetMinSize((800, 700))
self.browser = wx.html2.WebView.New(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.browser, 1, wx.EXPAND)
self.SetSizer(sizer)
# Bind the key event to the frame
self.browser.Bind(wx.EVT_CHAR_HOOK, self.on_key_char)
def on_key_char(self, event):
keycode = event.GetKeyCode()
modifiers = self.get_modifiers(event)
# Redirect the key event to the main app's handlers
if self.parent.handle_key_event(modifiers, keycode):
return # Prevent default behavior if handled
event.Skip()
def get_modifiers(self, event):
modifiers = 0
if event.ControlDown():
modifiers |= wx.ACCEL_CTRL
if event.ShiftDown():
modifiers |= wx.ACCEL_SHIFT
if event.AltDown():
modifiers |= wx.ACCEL_ALT
if event.MetaDown():
modifiers |= wx.ACCEL_CMD
return modifiers
def setHtmlContent(self, HtmlContent):
self.browser.SetPage(HtmlContent, "")
def moveToHeader(self, headerId):
script = f"document.getElementById('{headerId}').scrollIntoView();"
self.browser.RunScript(script)