pyvguicom 1.1.1__py3-none-any.whl → 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyvguicom might be problematic. Click here for more details.
- pyvguicom/docs/__index__.py +0 -0
- pyvguicom/docs/browsewin.html +956 -0
- pyvguicom/docs/htmledit.html +903 -0
- pyvguicom/docs/pgbox.html +2470 -0
- pyvguicom/docs/pgbutt.html +727 -0
- pyvguicom/docs/pgentry.html +1024 -0
- pyvguicom/docs/pggui.html +5476 -0
- pyvguicom/docs/pgsel.html +1539 -0
- pyvguicom/docs/pgsimp.html +1048 -0
- pyvguicom/docs/pgtextview.html +2421 -0
- pyvguicom/docs/pgutils.html +2664 -0
- pyvguicom/docs/pgwkit.html +2277 -0
- pyvguicom/docs/sutil.html +907 -0
- pyvguicom/pggui.py +1 -1
- pyvguicom/pgtests.py +11 -0
- pyvguicom/testtests.py +18 -0
- {pyvguicom-1.1.1.dist-info → pyvguicom-1.2.0.dist-info}/METADATA +8 -11
- {pyvguicom-1.1.1.dist-info → pyvguicom-1.2.0.dist-info}/RECORD +20 -7
- {pyvguicom-1.1.1.dist-info → pyvguicom-1.2.0.dist-info}/WHEEL +0 -0
- {pyvguicom-1.1.1.dist-info → pyvguicom-1.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,2277 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
|
6
|
+
<meta name="generator" content="pdoc 0.10.0" />
|
|
7
|
+
<title>pgwkit API documentation</title>
|
|
8
|
+
<meta name="description" content="This encapsulates the webkit import and failure thereof" />
|
|
9
|
+
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
|
10
|
+
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
|
11
|
+
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
|
12
|
+
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
|
13
|
+
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
|
14
|
+
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
|
15
|
+
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
|
16
|
+
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<main>
|
|
20
|
+
<article id="content">
|
|
21
|
+
<header>
|
|
22
|
+
<h1 class="title">Module <code>pgwkit</code></h1>
|
|
23
|
+
</header>
|
|
24
|
+
<section id="section-intro">
|
|
25
|
+
<p>This encapsulates the webkit import and failure thereof</p>
|
|
26
|
+
<details class="source">
|
|
27
|
+
<summary>
|
|
28
|
+
<span>Expand source code</span>
|
|
29
|
+
</summary>
|
|
30
|
+
<pre><code class="python">#!/usr/bin/env python
|
|
31
|
+
|
|
32
|
+
''' This encapsulates the webkit import and failure thereof '''
|
|
33
|
+
|
|
34
|
+
import os, sys, getopt, signal, random, time, warnings
|
|
35
|
+
import inspect
|
|
36
|
+
|
|
37
|
+
#realinc = os.path.realpath(os.path.dirname(__file__) + os.sep + "../pycommon")
|
|
38
|
+
#sys.path.append(realinc)
|
|
39
|
+
|
|
40
|
+
from pgutils import *
|
|
41
|
+
from pggui import *
|
|
42
|
+
from pgsimp import *
|
|
43
|
+
from pgtextview import *
|
|
44
|
+
|
|
45
|
+
import gi
|
|
46
|
+
gi.require_version("Gtk", "3.0")
|
|
47
|
+
|
|
48
|
+
from gi.repository import Gtk
|
|
49
|
+
from gi.repository import Gdk
|
|
50
|
+
from gi.repository import GLib
|
|
51
|
+
from gi.repository import GObject
|
|
52
|
+
from gi.repository import Pango
|
|
53
|
+
|
|
54
|
+
WebKit2 = None
|
|
55
|
+
|
|
56
|
+
class dummywebview(Gtk.VBox):
|
|
57
|
+
|
|
58
|
+
def __int__(self):
|
|
59
|
+
super().__init__(self)
|
|
60
|
+
#self.pack_start(Gtk.Label(label="No WebView"), 1, 1, 0)
|
|
61
|
+
def set_editable(self, flag):
|
|
62
|
+
self.pack_start(Gtk.Label(label="No WebView Available"), 1, 1, 0)
|
|
63
|
+
pass
|
|
64
|
+
def load_html(self, ff, kk = None):
|
|
65
|
+
pass
|
|
66
|
+
def connect(self, aa, bb):
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
class dummywebkit():
|
|
70
|
+
WebView = dummywebview
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
gi.require_version("WebKit2", '4.1')
|
|
74
|
+
from gi.repository import WebKit2
|
|
75
|
+
#present = 1
|
|
76
|
+
except:
|
|
77
|
+
try:
|
|
78
|
+
#print("Trying V 4.0:", sys.exc_info())
|
|
79
|
+
gi.require_version("WebKit2", '4.0')
|
|
80
|
+
from gi.repository import WebKit2
|
|
81
|
+
except:
|
|
82
|
+
try:
|
|
83
|
+
#print("Trying with jno qualifier")
|
|
84
|
+
#gi.require_version("WebKit2", '4.0')
|
|
85
|
+
from gi.repository import WebKit2
|
|
86
|
+
except:
|
|
87
|
+
# Giving up, patch fake one
|
|
88
|
+
print("Cannot import:", sys.exc_info())
|
|
89
|
+
print("WebWiew is not available.")
|
|
90
|
+
try:
|
|
91
|
+
WebKit2 = dummywebkit
|
|
92
|
+
except:
|
|
93
|
+
print("Fake kit Exc:", sys.exc_info())
|
|
94
|
+
#print("Fake kit:", WebKit2)
|
|
95
|
+
#raise
|
|
96
|
+
|
|
97
|
+
ui_def = """
|
|
98
|
+
<ui>
|
|
99
|
+
<toolbar name="toolbar_format">
|
|
100
|
+
<toolitem action="cut" />
|
|
101
|
+
<toolitem action="copy" />
|
|
102
|
+
<toolitem action="paste" />
|
|
103
|
+
<separator />
|
|
104
|
+
<toolitem action="removeformat" />
|
|
105
|
+
<toolitem action="bold" />
|
|
106
|
+
<toolitem action="italic" />
|
|
107
|
+
<toolitem action="underline" />
|
|
108
|
+
<toolitem action="strikethrough" />
|
|
109
|
+
<separator />
|
|
110
|
+
<toolitem action="justifyleft" />
|
|
111
|
+
<toolitem action="justifyright" />
|
|
112
|
+
<toolitem action="justifycenter" />
|
|
113
|
+
<toolitem action="justifyfull" />
|
|
114
|
+
<separator />
|
|
115
|
+
<toolitem action="undo" />
|
|
116
|
+
<toolitem action="redo" />
|
|
117
|
+
<separator />
|
|
118
|
+
<toolitem action="font" />
|
|
119
|
+
<toolitem action="fontsize" />
|
|
120
|
+
<toolitem action="color" />
|
|
121
|
+
<toolitem action="backgroundcolor" />
|
|
122
|
+
<separator />
|
|
123
|
+
<toolitem action="insertimage" />
|
|
124
|
+
<toolitem action="insertlink" />
|
|
125
|
+
<toolitem action="inserttable" />
|
|
126
|
+
<toolitem action="editmarker" />
|
|
127
|
+
<toolitem action="H1" />
|
|
128
|
+
<toolitem action="H2" />
|
|
129
|
+
<toolitem action="H3" />
|
|
130
|
+
<toolitem action="H4" />
|
|
131
|
+
</toolbar>
|
|
132
|
+
</ui>
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
#unmask_reserved = Gdk.ModifierType.GDK_MODIFIER_RESERVED_13_MASK | \
|
|
136
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_14_MASK | \
|
|
137
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_15_MASK | \
|
|
138
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_16_MASK | \
|
|
139
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_17_MASK | \
|
|
140
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_18_MASK | \
|
|
141
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_19_MASK | \
|
|
142
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_20_MASK | \
|
|
143
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_21_MASK | \
|
|
144
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_22_MASK | \
|
|
145
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_23_MASK | \
|
|
146
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_24_MASK | \
|
|
147
|
+
# Gdk.ModifierType.GDK_MODIFIER_RESERVED_25_MASK
|
|
148
|
+
|
|
149
|
+
# These are not setting the modified flag
|
|
150
|
+
|
|
151
|
+
navkeys = [ \
|
|
152
|
+
Gdk.KEY_Up, Gdk.KEY_KP_Up,
|
|
153
|
+
Gdk.KEY_Down, Gdk.KEY_KP_Down ,
|
|
154
|
+
Gdk.KEY_Left, Gdk.KEY_KP_Left,
|
|
155
|
+
Gdk.KEY_Right, Gdk.KEY_KP_Right,
|
|
156
|
+
Gdk.KEY_Page_Up, Gdk.KEY_KP_Page_Up,
|
|
157
|
+
Gdk.KEY_Page_Down, Gdk.KEY_KP_Page_Down,
|
|
158
|
+
Gdk.KEY_Home, Gdk.KEY_KP_Home,
|
|
159
|
+
Gdk.KEY_End, Gdk.KEY_KP_End,
|
|
160
|
+
|
|
161
|
+
# Also the modifier keys themselves
|
|
162
|
+
Gdk.KEY_Alt_L, Gdk.KEY_Alt_R,
|
|
163
|
+
Gdk.KEY_Control_L, Gdk.KEY_Control_R,
|
|
164
|
+
Gdk.KEY_Super_L, Gdk.KEY_Super_R,
|
|
165
|
+
Gdk.KEY_Shift_L, Gdk.KEY_Shift_R,
|
|
166
|
+
|
|
167
|
+
]
|
|
168
|
+
|
|
169
|
+
# ------------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
class pgwebw(WebKit2.WebView):
|
|
172
|
+
|
|
173
|
+
''' Define our override of the webkit class '''
|
|
174
|
+
|
|
175
|
+
def __init__(self, xlink=None):
|
|
176
|
+
try:
|
|
177
|
+
GObject.GObject.__init__(self)
|
|
178
|
+
except:
|
|
179
|
+
print("Cannot ??? in parent object", sys.exc_info())
|
|
180
|
+
pass
|
|
181
|
+
self.xlink = xlink
|
|
182
|
+
self.set_editable(True)
|
|
183
|
+
|
|
184
|
+
#if editable:
|
|
185
|
+
# self.set_editable(True)
|
|
186
|
+
|
|
187
|
+
self.fname = ""
|
|
188
|
+
self.load_html("", "file:///")
|
|
189
|
+
self.ui = self.generate_ui()
|
|
190
|
+
self.connect("key-release-event", self.keypress)
|
|
191
|
+
self.modified = False
|
|
192
|
+
|
|
193
|
+
def _get_response_data_finish(self, resource, result, user_data=None):
|
|
194
|
+
self.old_html = resource.get_data_finish(result)
|
|
195
|
+
#print((self.old_html))
|
|
196
|
+
|
|
197
|
+
def keypress(self, arg, arg2):
|
|
198
|
+
|
|
199
|
+
''' Here we imitate the way the accelerator works '''
|
|
200
|
+
|
|
201
|
+
state = arg2.get_state() & Gdk.ModifierType.MODIFIER_MASK
|
|
202
|
+
key = arg2.get_keyval()[1]
|
|
203
|
+
#print("key", key, "state", state)
|
|
204
|
+
|
|
205
|
+
#GDK_MODIFIER_RESERVED_25_MASK
|
|
206
|
+
|
|
207
|
+
# Feeding off the accelarator's definitions
|
|
208
|
+
ag = self.ui.get_action_groups()[0]
|
|
209
|
+
acts = ag.list_actions()
|
|
210
|
+
|
|
211
|
+
# Scan - Fire
|
|
212
|
+
for aa in acts:
|
|
213
|
+
if aa.accel:
|
|
214
|
+
#print(nnn, aa.accel, aa.accel_parsed)
|
|
215
|
+
if state == aa.accel_parsed[1]:
|
|
216
|
+
#print("state match")
|
|
217
|
+
if key == aa.accel_parsed[0]:
|
|
218
|
+
#print("Fire ", aa.get_name(), aa.get_label())
|
|
219
|
+
#lab = aa.get_label()
|
|
220
|
+
aa.activate()
|
|
221
|
+
break # Only one accel the other is a mistake
|
|
222
|
+
|
|
223
|
+
# See if nav key
|
|
224
|
+
navkey = False
|
|
225
|
+
for aa in navkeys:
|
|
226
|
+
if key == aa:
|
|
227
|
+
#print("Navkey", aa)
|
|
228
|
+
navkey = True
|
|
229
|
+
if not navkey:
|
|
230
|
+
# Exclude Ctrl-s
|
|
231
|
+
if state == Gdk.ModifierType.CONTROL_MASK and key == 115:
|
|
232
|
+
#print("Control s")
|
|
233
|
+
pass
|
|
234
|
+
else:
|
|
235
|
+
#print("set on key", key)
|
|
236
|
+
self.modified = True
|
|
237
|
+
|
|
238
|
+
def do_ready_to_show(self):
|
|
239
|
+
print("do_ready_to_show() was called")
|
|
240
|
+
pass
|
|
241
|
+
|
|
242
|
+
def do_load_changed(self, status):
|
|
243
|
+
|
|
244
|
+
#print("do_load_changed()", status)
|
|
245
|
+
if status == WebKit2.LoadEvent.FINISHED:
|
|
246
|
+
''' Create a shadow of content '''
|
|
247
|
+
|
|
248
|
+
# This gets it without spaces
|
|
249
|
+
#resource = self.get_main_resource()
|
|
250
|
+
#resource.get_data(None, self._get_response_data_finish, None)
|
|
251
|
+
|
|
252
|
+
# Get it by JS
|
|
253
|
+
def completion(html, user_data):
|
|
254
|
+
self.old_html = html
|
|
255
|
+
self.get_html(completion, '')
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
if self.get_uri():
|
|
259
|
+
if self.xlink:
|
|
260
|
+
self.xlink.set_status("Loading ... " + self.get_uri()[:64])
|
|
261
|
+
|
|
262
|
+
if status == 3: #WebKit2.LoadEvent.WEBKIT_LOAD_FINISHED:
|
|
263
|
+
#print("got WEBKIT_LOAD_FINISHED")
|
|
264
|
+
if self.get_uri():
|
|
265
|
+
if self.xlink:
|
|
266
|
+
self.xlink.edit.set_text(self.get_uri()[:64])
|
|
267
|
+
self.xlink.set_status("Finished: " + self.get_uri()[:64])
|
|
268
|
+
self.grab_focus()
|
|
269
|
+
|
|
270
|
+
def do_load_failed(self, load_event, failing_uri, error):
|
|
271
|
+
print("do_load_failed() was called", failing_uri)
|
|
272
|
+
if self.xlink:
|
|
273
|
+
self.xlink.set_status("Failed: " + failing_uri[:64])
|
|
274
|
+
|
|
275
|
+
def on_header(self, action):
|
|
276
|
+
#print("on_aheader", action.get_name())
|
|
277
|
+
ddd = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
278
|
+
ccc = None
|
|
279
|
+
while True:
|
|
280
|
+
#target = Gdk.Atom.intern ("text/html", True);
|
|
281
|
+
#ccc = ddd.wait_for_contents(target)
|
|
282
|
+
#if ccc:
|
|
283
|
+
# break
|
|
284
|
+
target2 = Gdk.Atom.intern ("text/plain", True);
|
|
285
|
+
ccc = ddd.wait_for_contents(target2)
|
|
286
|
+
if ccc:
|
|
287
|
+
break
|
|
288
|
+
break
|
|
289
|
+
|
|
290
|
+
if not ccc:
|
|
291
|
+
return
|
|
292
|
+
|
|
293
|
+
dddd = ccc.get_data().decode()
|
|
294
|
+
if not dddd:
|
|
295
|
+
return
|
|
296
|
+
#print("dddd", dddd)
|
|
297
|
+
htmlx = "<%s>%s</%s>" % (action.get_name(), dddd, action.get_name())
|
|
298
|
+
self.run_javascript("document.execCommand \
|
|
299
|
+
('insertHTML', null, '%s');" % htmlx)
|
|
300
|
+
Gtk.Clipboard.clear(ddd)
|
|
301
|
+
self.modified = True
|
|
302
|
+
|
|
303
|
+
def on_action(self, action):
|
|
304
|
+
#print("on_action", action.get_name())
|
|
305
|
+
# Make it caller neutral
|
|
306
|
+
if type(action) == str:
|
|
307
|
+
nnn = action
|
|
308
|
+
else:
|
|
309
|
+
nnn = action.get_name()
|
|
310
|
+
self.run_javascript("document.execCommand('%s', false, false);" % nnn)
|
|
311
|
+
self.modified = True
|
|
312
|
+
|
|
313
|
+
def on_paste(self, action = ""):
|
|
314
|
+
print("Paste")
|
|
315
|
+
self.execute_editing_command(WebKit2.EDITING_COMMAND_PASTE)
|
|
316
|
+
|
|
317
|
+
def on_new(self, action):
|
|
318
|
+
self.load_html("", "file:///")
|
|
319
|
+
self.modified = False
|
|
320
|
+
|
|
321
|
+
def on_fontsize(self, action):
|
|
322
|
+
#print("on_fontsize")
|
|
323
|
+
sizex = sizedialog()
|
|
324
|
+
#print("sizex", sizex)
|
|
325
|
+
if not sizex:
|
|
326
|
+
return
|
|
327
|
+
|
|
328
|
+
c = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
329
|
+
sel = c.wait_for_targets()
|
|
330
|
+
#print("sel", sel)
|
|
331
|
+
target = Gdk.Atom.intern ("text/plain", True);
|
|
332
|
+
ccc = c.wait_for_contents(target)
|
|
333
|
+
if not ccc:
|
|
334
|
+
htmlx = "<span style=\"font-size: %dpx;\">%s</span>" % (int(sizex), "")
|
|
335
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
336
|
+
return
|
|
337
|
+
|
|
338
|
+
ddd = ccc.get_data().decode()
|
|
339
|
+
if not ddd:
|
|
340
|
+
return
|
|
341
|
+
|
|
342
|
+
#print("ddd", ddd)
|
|
343
|
+
htmlx = "<span style=\"font-size: %dpx;\">%s</span>" % (int(sizex), ddd)
|
|
344
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
345
|
+
Gtk.Clipboard.clear(c)
|
|
346
|
+
self.modified = True
|
|
347
|
+
|
|
348
|
+
def on_select_font(self, action):
|
|
349
|
+
dialog = Gtk.FontChooserDialog("Select a font")
|
|
350
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
351
|
+
fname = dialog.get_font_desc().get_family()
|
|
352
|
+
fsize = dialog.get_font_desc().get_size() / Pango.SCALE
|
|
353
|
+
ttt = int(1 + round(fsize / 10)) % 9
|
|
354
|
+
print("Setting font", fname, fsize, ttt)
|
|
355
|
+
self.run_javascript("document.execCommand('fontname', null, '%s');" % fname)
|
|
356
|
+
self.run_javascript("document.execCommand('fontsize', null, '%s');" % ttt)
|
|
357
|
+
dialog.destroy()
|
|
358
|
+
|
|
359
|
+
def on_select_color(self, action):
|
|
360
|
+
dialog = Gtk.ColorChooserDialog("Select Color")
|
|
361
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
362
|
+
(r, g, b, a) = dialog.get_rgba()
|
|
363
|
+
color = "#%0.2x%0.2x%0.2x%0.2x" % (
|
|
364
|
+
int(r * 255),
|
|
365
|
+
int(g * 255),
|
|
366
|
+
int(b * 255),
|
|
367
|
+
int(a * 255))
|
|
368
|
+
self.run_javascript("document.execCommand('forecolor', null, '%s');" % color)
|
|
369
|
+
dialog.destroy()
|
|
370
|
+
|
|
371
|
+
def on_select_bgcolor(self, action):
|
|
372
|
+
dialog = Gtk.ColorChooserDialog("Select Background Color")
|
|
373
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
374
|
+
(r, g, b, a) = dialog.get_rgba()
|
|
375
|
+
color = "#%0.2x%0.2x%0.2x%0.2x" % (
|
|
376
|
+
int(r * 255),
|
|
377
|
+
int(g * 255),
|
|
378
|
+
int(b * 255),
|
|
379
|
+
int(a * 255))
|
|
380
|
+
self.run_javascript("document.execCommand('backcolor', null, '%s');" % color)
|
|
381
|
+
dialog.destroy()
|
|
382
|
+
|
|
383
|
+
def on_edit_marker(self, action):
|
|
384
|
+
print("on_edit_marker", action.get_name())
|
|
385
|
+
|
|
386
|
+
c = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
387
|
+
sel = c.wait_for_targets()
|
|
388
|
+
target = Gdk.Atom.intern ("text/html", True);
|
|
389
|
+
ccc = c.wait_for_contents(target)
|
|
390
|
+
#print("sel", ccc.get_data())
|
|
391
|
+
#ccc.free()
|
|
392
|
+
htmlx = markdialog(ccc.get_data().decode())
|
|
393
|
+
if htmlx:
|
|
394
|
+
print("markdialog result:\n", htmlx)
|
|
395
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
396
|
+
|
|
397
|
+
def on_insert_table(self, action):
|
|
398
|
+
htmlx = "<table align=center border=0 contentEditable=true>" + \
|
|
399
|
+
"<tr><td>TR1 C1 <td>| TR1 C2 <tr><td>TR2 C1<td>| TR2 C1</table><br>"
|
|
400
|
+
|
|
401
|
+
#print("table", htmlx)
|
|
402
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
403
|
+
self.modified = True
|
|
404
|
+
|
|
405
|
+
def on_insert_link(self, action):
|
|
406
|
+
dialog = Gtk.Dialog(" Enter a URL: ", None, 0,
|
|
407
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK))
|
|
408
|
+
|
|
409
|
+
entry = Gtk.Entry()
|
|
410
|
+
dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
411
|
+
hbox = Gtk.HBox()
|
|
412
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
413
|
+
hbox.pack_start(entry, False, False, 0)
|
|
414
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
415
|
+
dialog.vbox.pack_start(hbox, False, False, 0)
|
|
416
|
+
|
|
417
|
+
dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
418
|
+
dialog.show_all()
|
|
419
|
+
|
|
420
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
421
|
+
self.run_javascript(
|
|
422
|
+
"document.execCommand('createLink', True, '%s');" % entry.get_text())
|
|
423
|
+
dialog.destroy()
|
|
424
|
+
self.modified = True
|
|
425
|
+
|
|
426
|
+
def on_insert_image(self, action):
|
|
427
|
+
dialog = Gtk.FileChooserDialog("Select an image file", None, Gtk.FileChooserAction.OPEN,
|
|
428
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
|
429
|
+
|
|
430
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
431
|
+
fn = dialog.get_filename()
|
|
432
|
+
if os.path.exists(fn):
|
|
433
|
+
self.run_javascript(
|
|
434
|
+
"document.execCommand('insertImage', null, '%s');" % fn)
|
|
435
|
+
dialog.destroy()
|
|
436
|
+
self.modified = True
|
|
437
|
+
|
|
438
|
+
def on_open(self, action):
|
|
439
|
+
dialog = Gtk.FileChooserDialog("Select an HTML file", self, Gtk.FileChooserAction.OPEN,
|
|
440
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
|
441
|
+
|
|
442
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
443
|
+
fn = dialog.get_filename()
|
|
444
|
+
if os.path.exists(fn):
|
|
445
|
+
self.fname = fn
|
|
446
|
+
with open(fn) as fd:
|
|
447
|
+
self.load_html(fd.read(), "file:///")
|
|
448
|
+
dialog.destroy()
|
|
449
|
+
|
|
450
|
+
def on_save(self, action):
|
|
451
|
+
def completion(html, user_data):
|
|
452
|
+
open_mode = user_data
|
|
453
|
+
with open(self.fname, open_mode) as fd:
|
|
454
|
+
fd.write(html)
|
|
455
|
+
|
|
456
|
+
if self.fname:
|
|
457
|
+
self.get_html(completion, 'w')
|
|
458
|
+
else:
|
|
459
|
+
dialog = Gtk.FileChooserDialog("Select an HTML file", None,
|
|
460
|
+
Gtk.FileChooserAction.SAVE,
|
|
461
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
|
462
|
+
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
|
|
463
|
+
|
|
464
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
465
|
+
self.fname = dialog.get_filename()
|
|
466
|
+
print("Saving", self.fname)
|
|
467
|
+
self.get_html(completion, "w+")
|
|
468
|
+
dialog.destroy()
|
|
469
|
+
|
|
470
|
+
def get_html(self, completion_function, user_data):
|
|
471
|
+
|
|
472
|
+
#print("get_html")
|
|
473
|
+
def javascript_completion(obj, result, user_data):
|
|
474
|
+
#print("javascript_completion", result)
|
|
475
|
+
fin = self.run_javascript_finish(result)
|
|
476
|
+
#print("fin", fin)
|
|
477
|
+
html = fin.get_js_value().to_string()
|
|
478
|
+
#print("len html", len(html), "\n")
|
|
479
|
+
completion_function(html, user_data)
|
|
480
|
+
self.run_javascript("document.documentElement.innerHTML;",
|
|
481
|
+
None,
|
|
482
|
+
javascript_completion,
|
|
483
|
+
user_data)
|
|
484
|
+
|
|
485
|
+
def get_lastmod(self, completion_function, user_data):
|
|
486
|
+
|
|
487
|
+
print("get_lastmod")
|
|
488
|
+
def javascript_completion(obj, result, user_data):
|
|
489
|
+
print("javascript_completion", result)
|
|
490
|
+
fin = self.run_javascript_finish(result)
|
|
491
|
+
#print("fin", fin)
|
|
492
|
+
html = fin.get_js_value().to_string()
|
|
493
|
+
print("lastmod", html, "\n")
|
|
494
|
+
#completion_function(html, user_data)
|
|
495
|
+
self.run_javascript("document.lastModified",
|
|
496
|
+
None,
|
|
497
|
+
javascript_completion,
|
|
498
|
+
user_data)
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def generate_ui(self):
|
|
502
|
+
|
|
503
|
+
''' define toolbar items and actions here '''
|
|
504
|
+
|
|
505
|
+
actions = Gtk.ActionGroup("Actions")
|
|
506
|
+
# ----------------------------------------------------------------
|
|
507
|
+
# Name, Stock Icon, Accelerator, ToolTip, Action
|
|
508
|
+
|
|
509
|
+
# Some already has app accels
|
|
510
|
+
|
|
511
|
+
accel_arr = [ \
|
|
512
|
+
|
|
513
|
+
#("menuFile", None, "_File"),
|
|
514
|
+
#("menuEdit", None, "_Edit"),
|
|
515
|
+
#("menuInsert", None, "_Insert"),
|
|
516
|
+
#("menuFormat", None, "_Format"),
|
|
517
|
+
#("new", Gtk.STOCK_NEW, "_New", None, None, self.on_new),
|
|
518
|
+
#("open", Gtk.STOCK_OPEN, "_Open", None, None, self.on_open),
|
|
519
|
+
#("save", Gtk.STOCK_SAVE, "_Save", None, None, self.on_save),
|
|
520
|
+
|
|
521
|
+
("cut", Gtk.STOCK_CUT, "_Cut", None, None, self.on_action),
|
|
522
|
+
("copy", Gtk.STOCK_COPY, "_Copy", None, None, self.on_action),
|
|
523
|
+
("paste", Gtk.STOCK_PASTE, "_Paste", None, None, self.on_paste),
|
|
524
|
+
|
|
525
|
+
("undo", Gtk.STOCK_UNDO, "_Undo", "<Control>z", "Undo Last Edit", self.on_action),
|
|
526
|
+
("redo", Gtk.STOCK_REDO, "_Redo", "<Control>y", "Redo Last Undo", self.on_action),
|
|
527
|
+
|
|
528
|
+
("removeformat", Gtk.STOCK_PROPERTIES, "_removeFormat", "<Control>M", "Remove Formatting", self.on_action),
|
|
529
|
+
("bold", Gtk.STOCK_BOLD, "_Bold", "", "Bold / UnBold Selection", self.on_action),
|
|
530
|
+
("italic", Gtk.STOCK_ITALIC, "_Italic", "", None, self.on_action),
|
|
531
|
+
("underline", Gtk.STOCK_UNDERLINE, "_Underline", "", None, self.on_action),
|
|
532
|
+
("strikethrough", Gtk.STOCK_STRIKETHROUGH, "_Strike", "", None, self.on_action),
|
|
533
|
+
("font", Gtk.STOCK_SELECT_FONT, "Select _Font", "", None, self.on_select_font),
|
|
534
|
+
("fontsize", None, "Select Font _Size", "<Control>f", "Set Absolute Size (removes color)", self.on_fontsize),
|
|
535
|
+
("color", Gtk.STOCK_SELECT_COLOR, "Select _Color", None, None, self.on_select_color),
|
|
536
|
+
("backgroundcolor", Gtk.STOCK_COLOR_PICKER, "Select Back Color", None, None, self.on_select_bgcolor),
|
|
537
|
+
|
|
538
|
+
("justifyleft", Gtk.STOCK_JUSTIFY_LEFT, "Justify _Left", None, None, self.on_action),
|
|
539
|
+
("justifyright", Gtk.STOCK_JUSTIFY_RIGHT, "Justify _Right", None, None, self.on_action),
|
|
540
|
+
("justifycenter", Gtk.STOCK_JUSTIFY_CENTER, "Justify _Center", None, None, self.on_action),
|
|
541
|
+
("justifyfull", Gtk.STOCK_JUSTIFY_FILL, "Justify _Full", None, None, self.on_action),
|
|
542
|
+
|
|
543
|
+
# Pad Images by name (may not be present in all styles)
|
|
544
|
+
("insertimage", "insert-image", "Insert _Image", None, None, self.on_insert_image),
|
|
545
|
+
("insertlink", "insert-link", "Insert _Link", None, None, self.on_insert_link),
|
|
546
|
+
("inserttable", "insert-table", "Insert _Table", None, None, self.on_insert_table),
|
|
547
|
+
("editmarker", "edit-marker", "edit _Marker", None, None, self.on_edit_marker),
|
|
548
|
+
|
|
549
|
+
("H1", Gtk.STOCK_EXECUTE, "Header 1", None, "Insert Header 1", self.on_header),
|
|
550
|
+
("H2", Gtk.STOCK_EXECUTE, "Header 2", None, "Insert Header 2", self.on_header),
|
|
551
|
+
("H3", Gtk.STOCK_EXECUTE, "Header 3", None, "Insert Header 3", self.on_header),
|
|
552
|
+
("H4", Gtk.STOCK_EXECUTE, "Header 4", None, "Insert Header 4", self.on_header),
|
|
553
|
+
|
|
554
|
+
]
|
|
555
|
+
|
|
556
|
+
actions.add_actions(accel_arr)
|
|
557
|
+
|
|
558
|
+
#print(dir(actions))
|
|
559
|
+
for aa in accel_arr:
|
|
560
|
+
# print("acc arr", dir(aa))
|
|
561
|
+
# break
|
|
562
|
+
# act = actions.get_action(aa[0])
|
|
563
|
+
# print("act", act.get_name(), act.get_tooltip())
|
|
564
|
+
pass
|
|
565
|
+
# try:
|
|
566
|
+
# act = Gtk.Action.new(aa[0], aa[2], aa[4], aa[1])
|
|
567
|
+
# actions.add_action_with_accel(act, aa[3])
|
|
568
|
+
# except:
|
|
569
|
+
# #print("Exc on", aa)
|
|
570
|
+
# pass
|
|
571
|
+
|
|
572
|
+
actions.get_action("insertimage").set_property("icon-name", "insert-image")
|
|
573
|
+
actions.get_action("insertlink").set_property("icon-name", "insert-link")
|
|
574
|
+
actions.get_action("inserttable").set_property("icon-name", "appointment-new")
|
|
575
|
+
actions.get_action("editmarker").set_property("icon-name", "text-editor")
|
|
576
|
+
actions.get_action("fontsize").set_property("icon-name", "preferences-desktop-font")
|
|
577
|
+
actions.get_action("removeformat").set_property("icon-name", "text-direction")
|
|
578
|
+
|
|
579
|
+
ui = Gtk.UIManager()
|
|
580
|
+
ui.insert_action_group(actions)
|
|
581
|
+
ui.add_ui_from_string(ui_def)
|
|
582
|
+
|
|
583
|
+
# Fill in defaults
|
|
584
|
+
xxx = ui.get_action_groups()[0].list_actions()
|
|
585
|
+
for aa in xxx:
|
|
586
|
+
nnn = aa.get_name()
|
|
587
|
+
# Find the original, patth missing info
|
|
588
|
+
for bb in accel_arr:
|
|
589
|
+
# Convert tuple
|
|
590
|
+
bbb = list(bb)
|
|
591
|
+
if bb[0] == nnn:
|
|
592
|
+
# Pad for this round
|
|
593
|
+
for cc in range(5 - len(bbb)):
|
|
594
|
+
bbb.append("")
|
|
595
|
+
|
|
596
|
+
#print("lab", bb[2], aa.get_label())
|
|
597
|
+
#print("found", nnn, bbb[3])
|
|
598
|
+
|
|
599
|
+
setattr(aa, "accel", bbb[3])
|
|
600
|
+
if bbb[3]:
|
|
601
|
+
try:
|
|
602
|
+
nn, ss = Gtk.accelerator_parse(bbb[3])
|
|
603
|
+
setattr(aa, "accel_parsed", (nn, ss))
|
|
604
|
+
except:
|
|
605
|
+
pass
|
|
606
|
+
|
|
607
|
+
# Pad it with capitalize name if not there
|
|
608
|
+
if not aa.get_tooltip():
|
|
609
|
+
aa.set_tooltip(nnn[0].upper() + nnn[1:])
|
|
610
|
+
|
|
611
|
+
return ui
|
|
612
|
+
|
|
613
|
+
# This is kicked in if there is no library (is it used?)
|
|
614
|
+
|
|
615
|
+
class pgwebw_fake(Gtk.VBox):
|
|
616
|
+
|
|
617
|
+
def __init__(self):
|
|
618
|
+
super(pgwebw_fake, self).__init__();
|
|
619
|
+
pass
|
|
620
|
+
|
|
621
|
+
def load_uri(self, url):
|
|
622
|
+
pass
|
|
623
|
+
|
|
624
|
+
def markdialog(sss):
|
|
625
|
+
|
|
626
|
+
spaceneed = 64
|
|
627
|
+
# Wrap tesxt if long
|
|
628
|
+
ssss = ""
|
|
629
|
+
cnt = 0; fff = 0
|
|
630
|
+
for aa in sss:
|
|
631
|
+
if cnt > spaceneed:
|
|
632
|
+
fff = 1
|
|
633
|
+
if fff and aa.isspace():
|
|
634
|
+
cnt = 0; fff = 0
|
|
635
|
+
ssss += "\n"
|
|
636
|
+
ssss += aa
|
|
637
|
+
cnt += 1
|
|
638
|
+
|
|
639
|
+
dialog = Gtk.Dialog(" Edit markup ", None, 0,
|
|
640
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK))
|
|
641
|
+
|
|
642
|
+
textview = Gtk.TextView()
|
|
643
|
+
textview.set_editable(True)
|
|
644
|
+
|
|
645
|
+
textbuffer = textview.get_buffer()
|
|
646
|
+
textbuffer.set_text(ssss)
|
|
647
|
+
|
|
648
|
+
scrolledwindow = Gtk.ScrolledWindow()
|
|
649
|
+
scrolledwindow.set_hexpand(True)
|
|
650
|
+
scrolledwindow.set_vexpand(True)
|
|
651
|
+
scrolledwindow.add(textview)
|
|
652
|
+
scrolledwindow.set_size_request(640, 480)
|
|
653
|
+
|
|
654
|
+
hhh = "\n " \
|
|
655
|
+
"In general, any valid html can go here. Keep it simple.\n" \
|
|
656
|
+
"The editor already decorated this sufficiently, "\
|
|
657
|
+
"try to edit existing items in place.\n"
|
|
658
|
+
|
|
659
|
+
lll = Gtk.Label(hhh)
|
|
660
|
+
fd = Pango.FontDescription("Sans 9")
|
|
661
|
+
lll.override_font(fd)
|
|
662
|
+
thbox = Gtk.HBox()
|
|
663
|
+
thbox.pack_start(lll, 1, 1, 1)
|
|
664
|
+
dialog.vbox.pack_start(thbox, False, False, 0)
|
|
665
|
+
hbox = Gtk.HBox()
|
|
666
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
667
|
+
hbox.pack_start(scrolledwindow, 1, 1, 0)
|
|
668
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
669
|
+
dialog.vbox.pack_start(hbox, 1, 1, 0)
|
|
670
|
+
#dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
671
|
+
dialog.show_all()
|
|
672
|
+
|
|
673
|
+
htmlx = ""
|
|
674
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
675
|
+
bi = textbuffer.get_start_iter()
|
|
676
|
+
ei = textbuffer.get_end_iter()
|
|
677
|
+
htmlx = textbuffer.get_text(bi, ei, False)
|
|
678
|
+
|
|
679
|
+
dialog.destroy()
|
|
680
|
+
|
|
681
|
+
# Unwrap it
|
|
682
|
+
usss = ""
|
|
683
|
+
cnt = 0; fff = 0
|
|
684
|
+
for aa in htmlx:
|
|
685
|
+
if aa == '\n':
|
|
686
|
+
pass
|
|
687
|
+
else:
|
|
688
|
+
usss += aa
|
|
689
|
+
return usss
|
|
690
|
+
|
|
691
|
+
def treecallb(ddd):
|
|
692
|
+
global sizex
|
|
693
|
+
#print("tree cb", ddd[0])
|
|
694
|
+
sizex = ddd[0]
|
|
695
|
+
|
|
696
|
+
def sizedialog():
|
|
697
|
+
|
|
698
|
+
''' Present a selection Dialog for font sizes '''
|
|
699
|
+
|
|
700
|
+
dialog = Gtk.Dialog(" Font Size ", None, 0, () )
|
|
701
|
+
|
|
702
|
+
#(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK))
|
|
703
|
+
|
|
704
|
+
global sizex
|
|
705
|
+
sizex = ""
|
|
706
|
+
treedat = ["8", "9", "10", "12", "14", "20", "24", "32", "48", "56", "64",
|
|
707
|
+
"72", "96", "128"]
|
|
708
|
+
|
|
709
|
+
tree = SimpleTree(["Font Sizes"])
|
|
710
|
+
for aa in treedat:
|
|
711
|
+
tree.append((aa,))
|
|
712
|
+
|
|
713
|
+
def actcallb(ddd):
|
|
714
|
+
#print("Activate cb", ddd, dialog)
|
|
715
|
+
dialog.response(Gtk.ResponseType.OK)
|
|
716
|
+
#print("Activate cb2", ddd, dialog)
|
|
717
|
+
|
|
718
|
+
scrolledwindow = Gtk.ScrolledWindow()
|
|
719
|
+
scrolledwindow.set_hexpand(True)
|
|
720
|
+
scrolledwindow.set_vexpand(True)
|
|
721
|
+
scrolledwindow.add(tree)
|
|
722
|
+
scrolledwindow.set_size_request(120, 300)
|
|
723
|
+
|
|
724
|
+
tree.setcallb(treecallb)
|
|
725
|
+
tree.setActcallb(actcallb)
|
|
726
|
+
|
|
727
|
+
hhh = "\n " \
|
|
728
|
+
"In general, any valid html can go here. Keep it simple.\n" \
|
|
729
|
+
"The editor already decorated this sufficiently, "\
|
|
730
|
+
"try to edit existing items in place.\n"
|
|
731
|
+
|
|
732
|
+
lll = Gtk.Label(hhh)
|
|
733
|
+
fd = Pango.FontDescription("Sans 9")
|
|
734
|
+
lll.override_font(fd)
|
|
735
|
+
thbox = Gtk.HBox()
|
|
736
|
+
thbox.pack_start(lll, 1, 1, 1)
|
|
737
|
+
#dialog.vbox.pack_start(thbox, False, False, 0)
|
|
738
|
+
|
|
739
|
+
hbox = Gtk.HBox()
|
|
740
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
741
|
+
hbox.pack_start(scrolledwindow, 1, 1, 0)
|
|
742
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
743
|
+
dialog.vbox.pack_start(hbox, 1, 1, 0)
|
|
744
|
+
#dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
745
|
+
dialog.show_all()
|
|
746
|
+
|
|
747
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
748
|
+
#print("ok", sizex)
|
|
749
|
+
pass
|
|
750
|
+
else:
|
|
751
|
+
sizex = 0
|
|
752
|
+
|
|
753
|
+
dialog.destroy()
|
|
754
|
+
return sizex
|
|
755
|
+
|
|
756
|
+
# EOF</code></pre>
|
|
757
|
+
</details>
|
|
758
|
+
</section>
|
|
759
|
+
<section>
|
|
760
|
+
</section>
|
|
761
|
+
<section>
|
|
762
|
+
</section>
|
|
763
|
+
<section>
|
|
764
|
+
<h2 class="section-title" id="header-functions">Functions</h2>
|
|
765
|
+
<dl>
|
|
766
|
+
<dt id="pgwkit.markdialog"><code class="name flex">
|
|
767
|
+
<span>def <span class="ident">markdialog</span></span>(<span>sss)</span>
|
|
768
|
+
</code></dt>
|
|
769
|
+
<dd>
|
|
770
|
+
<div class="desc"></div>
|
|
771
|
+
<details class="source">
|
|
772
|
+
<summary>
|
|
773
|
+
<span>Expand source code</span>
|
|
774
|
+
</summary>
|
|
775
|
+
<pre><code class="python">def markdialog(sss):
|
|
776
|
+
|
|
777
|
+
spaceneed = 64
|
|
778
|
+
# Wrap tesxt if long
|
|
779
|
+
ssss = ""
|
|
780
|
+
cnt = 0; fff = 0
|
|
781
|
+
for aa in sss:
|
|
782
|
+
if cnt > spaceneed:
|
|
783
|
+
fff = 1
|
|
784
|
+
if fff and aa.isspace():
|
|
785
|
+
cnt = 0; fff = 0
|
|
786
|
+
ssss += "\n"
|
|
787
|
+
ssss += aa
|
|
788
|
+
cnt += 1
|
|
789
|
+
|
|
790
|
+
dialog = Gtk.Dialog(" Edit markup ", None, 0,
|
|
791
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK))
|
|
792
|
+
|
|
793
|
+
textview = Gtk.TextView()
|
|
794
|
+
textview.set_editable(True)
|
|
795
|
+
|
|
796
|
+
textbuffer = textview.get_buffer()
|
|
797
|
+
textbuffer.set_text(ssss)
|
|
798
|
+
|
|
799
|
+
scrolledwindow = Gtk.ScrolledWindow()
|
|
800
|
+
scrolledwindow.set_hexpand(True)
|
|
801
|
+
scrolledwindow.set_vexpand(True)
|
|
802
|
+
scrolledwindow.add(textview)
|
|
803
|
+
scrolledwindow.set_size_request(640, 480)
|
|
804
|
+
|
|
805
|
+
hhh = "\n " \
|
|
806
|
+
"In general, any valid html can go here. Keep it simple.\n" \
|
|
807
|
+
"The editor already decorated this sufficiently, "\
|
|
808
|
+
"try to edit existing items in place.\n"
|
|
809
|
+
|
|
810
|
+
lll = Gtk.Label(hhh)
|
|
811
|
+
fd = Pango.FontDescription("Sans 9")
|
|
812
|
+
lll.override_font(fd)
|
|
813
|
+
thbox = Gtk.HBox()
|
|
814
|
+
thbox.pack_start(lll, 1, 1, 1)
|
|
815
|
+
dialog.vbox.pack_start(thbox, False, False, 0)
|
|
816
|
+
hbox = Gtk.HBox()
|
|
817
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
818
|
+
hbox.pack_start(scrolledwindow, 1, 1, 0)
|
|
819
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
820
|
+
dialog.vbox.pack_start(hbox, 1, 1, 0)
|
|
821
|
+
#dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
822
|
+
dialog.show_all()
|
|
823
|
+
|
|
824
|
+
htmlx = ""
|
|
825
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
826
|
+
bi = textbuffer.get_start_iter()
|
|
827
|
+
ei = textbuffer.get_end_iter()
|
|
828
|
+
htmlx = textbuffer.get_text(bi, ei, False)
|
|
829
|
+
|
|
830
|
+
dialog.destroy()
|
|
831
|
+
|
|
832
|
+
# Unwrap it
|
|
833
|
+
usss = ""
|
|
834
|
+
cnt = 0; fff = 0
|
|
835
|
+
for aa in htmlx:
|
|
836
|
+
if aa == '\n':
|
|
837
|
+
pass
|
|
838
|
+
else:
|
|
839
|
+
usss += aa
|
|
840
|
+
return usss</code></pre>
|
|
841
|
+
</details>
|
|
842
|
+
</dd>
|
|
843
|
+
<dt id="pgwkit.sizedialog"><code class="name flex">
|
|
844
|
+
<span>def <span class="ident">sizedialog</span></span>(<span>)</span>
|
|
845
|
+
</code></dt>
|
|
846
|
+
<dd>
|
|
847
|
+
<div class="desc"><p>Present a selection Dialog for font sizes</p></div>
|
|
848
|
+
<details class="source">
|
|
849
|
+
<summary>
|
|
850
|
+
<span>Expand source code</span>
|
|
851
|
+
</summary>
|
|
852
|
+
<pre><code class="python">def sizedialog():
|
|
853
|
+
|
|
854
|
+
''' Present a selection Dialog for font sizes '''
|
|
855
|
+
|
|
856
|
+
dialog = Gtk.Dialog(" Font Size ", None, 0, () )
|
|
857
|
+
|
|
858
|
+
#(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK))
|
|
859
|
+
|
|
860
|
+
global sizex
|
|
861
|
+
sizex = ""
|
|
862
|
+
treedat = ["8", "9", "10", "12", "14", "20", "24", "32", "48", "56", "64",
|
|
863
|
+
"72", "96", "128"]
|
|
864
|
+
|
|
865
|
+
tree = SimpleTree(["Font Sizes"])
|
|
866
|
+
for aa in treedat:
|
|
867
|
+
tree.append((aa,))
|
|
868
|
+
|
|
869
|
+
def actcallb(ddd):
|
|
870
|
+
#print("Activate cb", ddd, dialog)
|
|
871
|
+
dialog.response(Gtk.ResponseType.OK)
|
|
872
|
+
#print("Activate cb2", ddd, dialog)
|
|
873
|
+
|
|
874
|
+
scrolledwindow = Gtk.ScrolledWindow()
|
|
875
|
+
scrolledwindow.set_hexpand(True)
|
|
876
|
+
scrolledwindow.set_vexpand(True)
|
|
877
|
+
scrolledwindow.add(tree)
|
|
878
|
+
scrolledwindow.set_size_request(120, 300)
|
|
879
|
+
|
|
880
|
+
tree.setcallb(treecallb)
|
|
881
|
+
tree.setActcallb(actcallb)
|
|
882
|
+
|
|
883
|
+
hhh = "\n " \
|
|
884
|
+
"In general, any valid html can go here. Keep it simple.\n" \
|
|
885
|
+
"The editor already decorated this sufficiently, "\
|
|
886
|
+
"try to edit existing items in place.\n"
|
|
887
|
+
|
|
888
|
+
lll = Gtk.Label(hhh)
|
|
889
|
+
fd = Pango.FontDescription("Sans 9")
|
|
890
|
+
lll.override_font(fd)
|
|
891
|
+
thbox = Gtk.HBox()
|
|
892
|
+
thbox.pack_start(lll, 1, 1, 1)
|
|
893
|
+
#dialog.vbox.pack_start(thbox, False, False, 0)
|
|
894
|
+
|
|
895
|
+
hbox = Gtk.HBox()
|
|
896
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
897
|
+
hbox.pack_start(scrolledwindow, 1, 1, 0)
|
|
898
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
899
|
+
dialog.vbox.pack_start(hbox, 1, 1, 0)
|
|
900
|
+
#dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
901
|
+
dialog.show_all()
|
|
902
|
+
|
|
903
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
904
|
+
#print("ok", sizex)
|
|
905
|
+
pass
|
|
906
|
+
else:
|
|
907
|
+
sizex = 0
|
|
908
|
+
|
|
909
|
+
dialog.destroy()
|
|
910
|
+
return sizex</code></pre>
|
|
911
|
+
</details>
|
|
912
|
+
</dd>
|
|
913
|
+
<dt id="pgwkit.treecallb"><code class="name flex">
|
|
914
|
+
<span>def <span class="ident">treecallb</span></span>(<span>ddd)</span>
|
|
915
|
+
</code></dt>
|
|
916
|
+
<dd>
|
|
917
|
+
<div class="desc"></div>
|
|
918
|
+
<details class="source">
|
|
919
|
+
<summary>
|
|
920
|
+
<span>Expand source code</span>
|
|
921
|
+
</summary>
|
|
922
|
+
<pre><code class="python">def treecallb(ddd):
|
|
923
|
+
global sizex
|
|
924
|
+
#print("tree cb", ddd[0])
|
|
925
|
+
sizex = ddd[0]</code></pre>
|
|
926
|
+
</details>
|
|
927
|
+
</dd>
|
|
928
|
+
</dl>
|
|
929
|
+
</section>
|
|
930
|
+
<section>
|
|
931
|
+
<h2 class="section-title" id="header-classes">Classes</h2>
|
|
932
|
+
<dl>
|
|
933
|
+
<dt id="pgwkit.dummywebkit"><code class="flex name class">
|
|
934
|
+
<span>class <span class="ident">dummywebkit</span></span>
|
|
935
|
+
</code></dt>
|
|
936
|
+
<dd>
|
|
937
|
+
<div class="desc"></div>
|
|
938
|
+
<details class="source">
|
|
939
|
+
<summary>
|
|
940
|
+
<span>Expand source code</span>
|
|
941
|
+
</summary>
|
|
942
|
+
<pre><code class="python">class dummywebkit():
|
|
943
|
+
WebView = dummywebview</code></pre>
|
|
944
|
+
</details>
|
|
945
|
+
<h3>Class variables</h3>
|
|
946
|
+
<dl>
|
|
947
|
+
<dt id="pgwkit.dummywebkit.WebView"><code class="name">var <span class="ident">WebView</span></code></dt>
|
|
948
|
+
<dd>
|
|
949
|
+
<div class="desc"><p>:Constructors:</p>
|
|
950
|
+
<p>::</p>
|
|
951
|
+
<pre><code>VBox(**properties)
|
|
952
|
+
new(homogeneous:bool, spacing:int) -> Gtk.Widget
|
|
953
|
+
</code></pre></div>
|
|
954
|
+
</dd>
|
|
955
|
+
</dl>
|
|
956
|
+
</dd>
|
|
957
|
+
<dt id="pgwkit.dummywebview"><code class="flex name class">
|
|
958
|
+
<span>class <span class="ident">dummywebview</span></span>
|
|
959
|
+
<span>(</span><span>*args, **kwargs)</span>
|
|
960
|
+
</code></dt>
|
|
961
|
+
<dd>
|
|
962
|
+
<div class="desc"><p>:Constructors:</p>
|
|
963
|
+
<p>::</p>
|
|
964
|
+
<pre><code>VBox(**properties)
|
|
965
|
+
new(homogeneous:bool, spacing:int) -> Gtk.Widget
|
|
966
|
+
</code></pre>
|
|
967
|
+
<p>Initializer for a GObject based classes with support for property
|
|
968
|
+
sets through the use of explicit keyword arguments.</p></div>
|
|
969
|
+
<details class="source">
|
|
970
|
+
<summary>
|
|
971
|
+
<span>Expand source code</span>
|
|
972
|
+
</summary>
|
|
973
|
+
<pre><code class="python">class dummywebview(Gtk.VBox):
|
|
974
|
+
|
|
975
|
+
def __int__(self):
|
|
976
|
+
super().__init__(self)
|
|
977
|
+
#self.pack_start(Gtk.Label(label="No WebView"), 1, 1, 0)
|
|
978
|
+
def set_editable(self, flag):
|
|
979
|
+
self.pack_start(Gtk.Label(label="No WebView Available"), 1, 1, 0)
|
|
980
|
+
pass
|
|
981
|
+
def load_html(self, ff, kk = None):
|
|
982
|
+
pass
|
|
983
|
+
def connect(self, aa, bb):
|
|
984
|
+
pass</code></pre>
|
|
985
|
+
</details>
|
|
986
|
+
<h3>Ancestors</h3>
|
|
987
|
+
<ul class="hlist">
|
|
988
|
+
<li>gi.repository.Gtk.VBox</li>
|
|
989
|
+
<li>gi.overrides.Gtk.Box</li>
|
|
990
|
+
<li>gi.repository.Gtk.Box</li>
|
|
991
|
+
<li>gi.overrides.Gtk.Container</li>
|
|
992
|
+
<li>gi.repository.Gtk.Container</li>
|
|
993
|
+
<li>gi.overrides.Gtk.Widget</li>
|
|
994
|
+
<li>gi.repository.Gtk.Widget</li>
|
|
995
|
+
<li>gi.repository.GObject.InitiallyUnowned</li>
|
|
996
|
+
<li>gi.overrides.GObject.Object</li>
|
|
997
|
+
<li>gi.repository.GObject.Object</li>
|
|
998
|
+
<li>gi._gi.GObject</li>
|
|
999
|
+
<li>gi.repository.Atk.ImplementorIface</li>
|
|
1000
|
+
<li>gi.repository.Gtk.Buildable</li>
|
|
1001
|
+
<li>gi.repository.Gtk.Orientable</li>
|
|
1002
|
+
<li>gobject.GInterface</li>
|
|
1003
|
+
</ul>
|
|
1004
|
+
<h3>Methods</h3>
|
|
1005
|
+
<dl>
|
|
1006
|
+
<dt id="pgwkit.dummywebview.connect"><code class="name flex">
|
|
1007
|
+
<span>def <span class="ident">connect</span></span>(<span>self, aa, bb)</span>
|
|
1008
|
+
</code></dt>
|
|
1009
|
+
<dd>
|
|
1010
|
+
<div class="desc"></div>
|
|
1011
|
+
<details class="source">
|
|
1012
|
+
<summary>
|
|
1013
|
+
<span>Expand source code</span>
|
|
1014
|
+
</summary>
|
|
1015
|
+
<pre><code class="python">def connect(self, aa, bb):
|
|
1016
|
+
pass</code></pre>
|
|
1017
|
+
</details>
|
|
1018
|
+
</dd>
|
|
1019
|
+
<dt id="pgwkit.dummywebview.load_html"><code class="name flex">
|
|
1020
|
+
<span>def <span class="ident">load_html</span></span>(<span>self, ff, kk=None)</span>
|
|
1021
|
+
</code></dt>
|
|
1022
|
+
<dd>
|
|
1023
|
+
<div class="desc"></div>
|
|
1024
|
+
<details class="source">
|
|
1025
|
+
<summary>
|
|
1026
|
+
<span>Expand source code</span>
|
|
1027
|
+
</summary>
|
|
1028
|
+
<pre><code class="python">def load_html(self, ff, kk = None):
|
|
1029
|
+
pass</code></pre>
|
|
1030
|
+
</details>
|
|
1031
|
+
</dd>
|
|
1032
|
+
<dt id="pgwkit.dummywebview.set_editable"><code class="name flex">
|
|
1033
|
+
<span>def <span class="ident">set_editable</span></span>(<span>self, flag)</span>
|
|
1034
|
+
</code></dt>
|
|
1035
|
+
<dd>
|
|
1036
|
+
<div class="desc"></div>
|
|
1037
|
+
<details class="source">
|
|
1038
|
+
<summary>
|
|
1039
|
+
<span>Expand source code</span>
|
|
1040
|
+
</summary>
|
|
1041
|
+
<pre><code class="python">def set_editable(self, flag):
|
|
1042
|
+
self.pack_start(Gtk.Label(label="No WebView Available"), 1, 1, 0)
|
|
1043
|
+
pass</code></pre>
|
|
1044
|
+
</details>
|
|
1045
|
+
</dd>
|
|
1046
|
+
</dl>
|
|
1047
|
+
</dd>
|
|
1048
|
+
<dt id="pgwkit.pgwebw"><code class="flex name class">
|
|
1049
|
+
<span>class <span class="ident">pgwebw</span></span>
|
|
1050
|
+
<span>(</span><span>xlink=None)</span>
|
|
1051
|
+
</code></dt>
|
|
1052
|
+
<dd>
|
|
1053
|
+
<div class="desc"><p>Define our override of the webkit class</p></div>
|
|
1054
|
+
<details class="source">
|
|
1055
|
+
<summary>
|
|
1056
|
+
<span>Expand source code</span>
|
|
1057
|
+
</summary>
|
|
1058
|
+
<pre><code class="python">class pgwebw(WebKit2.WebView):
|
|
1059
|
+
|
|
1060
|
+
''' Define our override of the webkit class '''
|
|
1061
|
+
|
|
1062
|
+
def __init__(self, xlink=None):
|
|
1063
|
+
try:
|
|
1064
|
+
GObject.GObject.__init__(self)
|
|
1065
|
+
except:
|
|
1066
|
+
print("Cannot ??? in parent object", sys.exc_info())
|
|
1067
|
+
pass
|
|
1068
|
+
self.xlink = xlink
|
|
1069
|
+
self.set_editable(True)
|
|
1070
|
+
|
|
1071
|
+
#if editable:
|
|
1072
|
+
# self.set_editable(True)
|
|
1073
|
+
|
|
1074
|
+
self.fname = ""
|
|
1075
|
+
self.load_html("", "file:///")
|
|
1076
|
+
self.ui = self.generate_ui()
|
|
1077
|
+
self.connect("key-release-event", self.keypress)
|
|
1078
|
+
self.modified = False
|
|
1079
|
+
|
|
1080
|
+
def _get_response_data_finish(self, resource, result, user_data=None):
|
|
1081
|
+
self.old_html = resource.get_data_finish(result)
|
|
1082
|
+
#print((self.old_html))
|
|
1083
|
+
|
|
1084
|
+
def keypress(self, arg, arg2):
|
|
1085
|
+
|
|
1086
|
+
''' Here we imitate the way the accelerator works '''
|
|
1087
|
+
|
|
1088
|
+
state = arg2.get_state() & Gdk.ModifierType.MODIFIER_MASK
|
|
1089
|
+
key = arg2.get_keyval()[1]
|
|
1090
|
+
#print("key", key, "state", state)
|
|
1091
|
+
|
|
1092
|
+
#GDK_MODIFIER_RESERVED_25_MASK
|
|
1093
|
+
|
|
1094
|
+
# Feeding off the accelarator's definitions
|
|
1095
|
+
ag = self.ui.get_action_groups()[0]
|
|
1096
|
+
acts = ag.list_actions()
|
|
1097
|
+
|
|
1098
|
+
# Scan - Fire
|
|
1099
|
+
for aa in acts:
|
|
1100
|
+
if aa.accel:
|
|
1101
|
+
#print(nnn, aa.accel, aa.accel_parsed)
|
|
1102
|
+
if state == aa.accel_parsed[1]:
|
|
1103
|
+
#print("state match")
|
|
1104
|
+
if key == aa.accel_parsed[0]:
|
|
1105
|
+
#print("Fire ", aa.get_name(), aa.get_label())
|
|
1106
|
+
#lab = aa.get_label()
|
|
1107
|
+
aa.activate()
|
|
1108
|
+
break # Only one accel the other is a mistake
|
|
1109
|
+
|
|
1110
|
+
# See if nav key
|
|
1111
|
+
navkey = False
|
|
1112
|
+
for aa in navkeys:
|
|
1113
|
+
if key == aa:
|
|
1114
|
+
#print("Navkey", aa)
|
|
1115
|
+
navkey = True
|
|
1116
|
+
if not navkey:
|
|
1117
|
+
# Exclude Ctrl-s
|
|
1118
|
+
if state == Gdk.ModifierType.CONTROL_MASK and key == 115:
|
|
1119
|
+
#print("Control s")
|
|
1120
|
+
pass
|
|
1121
|
+
else:
|
|
1122
|
+
#print("set on key", key)
|
|
1123
|
+
self.modified = True
|
|
1124
|
+
|
|
1125
|
+
def do_ready_to_show(self):
|
|
1126
|
+
print("do_ready_to_show() was called")
|
|
1127
|
+
pass
|
|
1128
|
+
|
|
1129
|
+
def do_load_changed(self, status):
|
|
1130
|
+
|
|
1131
|
+
#print("do_load_changed()", status)
|
|
1132
|
+
if status == WebKit2.LoadEvent.FINISHED:
|
|
1133
|
+
''' Create a shadow of content '''
|
|
1134
|
+
|
|
1135
|
+
# This gets it without spaces
|
|
1136
|
+
#resource = self.get_main_resource()
|
|
1137
|
+
#resource.get_data(None, self._get_response_data_finish, None)
|
|
1138
|
+
|
|
1139
|
+
# Get it by JS
|
|
1140
|
+
def completion(html, user_data):
|
|
1141
|
+
self.old_html = html
|
|
1142
|
+
self.get_html(completion, '')
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
if self.get_uri():
|
|
1146
|
+
if self.xlink:
|
|
1147
|
+
self.xlink.set_status("Loading ... " + self.get_uri()[:64])
|
|
1148
|
+
|
|
1149
|
+
if status == 3: #WebKit2.LoadEvent.WEBKIT_LOAD_FINISHED:
|
|
1150
|
+
#print("got WEBKIT_LOAD_FINISHED")
|
|
1151
|
+
if self.get_uri():
|
|
1152
|
+
if self.xlink:
|
|
1153
|
+
self.xlink.edit.set_text(self.get_uri()[:64])
|
|
1154
|
+
self.xlink.set_status("Finished: " + self.get_uri()[:64])
|
|
1155
|
+
self.grab_focus()
|
|
1156
|
+
|
|
1157
|
+
def do_load_failed(self, load_event, failing_uri, error):
|
|
1158
|
+
print("do_load_failed() was called", failing_uri)
|
|
1159
|
+
if self.xlink:
|
|
1160
|
+
self.xlink.set_status("Failed: " + failing_uri[:64])
|
|
1161
|
+
|
|
1162
|
+
def on_header(self, action):
|
|
1163
|
+
#print("on_aheader", action.get_name())
|
|
1164
|
+
ddd = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
1165
|
+
ccc = None
|
|
1166
|
+
while True:
|
|
1167
|
+
#target = Gdk.Atom.intern ("text/html", True);
|
|
1168
|
+
#ccc = ddd.wait_for_contents(target)
|
|
1169
|
+
#if ccc:
|
|
1170
|
+
# break
|
|
1171
|
+
target2 = Gdk.Atom.intern ("text/plain", True);
|
|
1172
|
+
ccc = ddd.wait_for_contents(target2)
|
|
1173
|
+
if ccc:
|
|
1174
|
+
break
|
|
1175
|
+
break
|
|
1176
|
+
|
|
1177
|
+
if not ccc:
|
|
1178
|
+
return
|
|
1179
|
+
|
|
1180
|
+
dddd = ccc.get_data().decode()
|
|
1181
|
+
if not dddd:
|
|
1182
|
+
return
|
|
1183
|
+
#print("dddd", dddd)
|
|
1184
|
+
htmlx = "<%s>%s</%s>" % (action.get_name(), dddd, action.get_name())
|
|
1185
|
+
self.run_javascript("document.execCommand \
|
|
1186
|
+
('insertHTML', null, '%s');" % htmlx)
|
|
1187
|
+
Gtk.Clipboard.clear(ddd)
|
|
1188
|
+
self.modified = True
|
|
1189
|
+
|
|
1190
|
+
def on_action(self, action):
|
|
1191
|
+
#print("on_action", action.get_name())
|
|
1192
|
+
# Make it caller neutral
|
|
1193
|
+
if type(action) == str:
|
|
1194
|
+
nnn = action
|
|
1195
|
+
else:
|
|
1196
|
+
nnn = action.get_name()
|
|
1197
|
+
self.run_javascript("document.execCommand('%s', false, false);" % nnn)
|
|
1198
|
+
self.modified = True
|
|
1199
|
+
|
|
1200
|
+
def on_paste(self, action = ""):
|
|
1201
|
+
print("Paste")
|
|
1202
|
+
self.execute_editing_command(WebKit2.EDITING_COMMAND_PASTE)
|
|
1203
|
+
|
|
1204
|
+
def on_new(self, action):
|
|
1205
|
+
self.load_html("", "file:///")
|
|
1206
|
+
self.modified = False
|
|
1207
|
+
|
|
1208
|
+
def on_fontsize(self, action):
|
|
1209
|
+
#print("on_fontsize")
|
|
1210
|
+
sizex = sizedialog()
|
|
1211
|
+
#print("sizex", sizex)
|
|
1212
|
+
if not sizex:
|
|
1213
|
+
return
|
|
1214
|
+
|
|
1215
|
+
c = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
1216
|
+
sel = c.wait_for_targets()
|
|
1217
|
+
#print("sel", sel)
|
|
1218
|
+
target = Gdk.Atom.intern ("text/plain", True);
|
|
1219
|
+
ccc = c.wait_for_contents(target)
|
|
1220
|
+
if not ccc:
|
|
1221
|
+
htmlx = "<span style=\"font-size: %dpx;\">%s</span>" % (int(sizex), "")
|
|
1222
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
1223
|
+
return
|
|
1224
|
+
|
|
1225
|
+
ddd = ccc.get_data().decode()
|
|
1226
|
+
if not ddd:
|
|
1227
|
+
return
|
|
1228
|
+
|
|
1229
|
+
#print("ddd", ddd)
|
|
1230
|
+
htmlx = "<span style=\"font-size: %dpx;\">%s</span>" % (int(sizex), ddd)
|
|
1231
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
1232
|
+
Gtk.Clipboard.clear(c)
|
|
1233
|
+
self.modified = True
|
|
1234
|
+
|
|
1235
|
+
def on_select_font(self, action):
|
|
1236
|
+
dialog = Gtk.FontChooserDialog("Select a font")
|
|
1237
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1238
|
+
fname = dialog.get_font_desc().get_family()
|
|
1239
|
+
fsize = dialog.get_font_desc().get_size() / Pango.SCALE
|
|
1240
|
+
ttt = int(1 + round(fsize / 10)) % 9
|
|
1241
|
+
print("Setting font", fname, fsize, ttt)
|
|
1242
|
+
self.run_javascript("document.execCommand('fontname', null, '%s');" % fname)
|
|
1243
|
+
self.run_javascript("document.execCommand('fontsize', null, '%s');" % ttt)
|
|
1244
|
+
dialog.destroy()
|
|
1245
|
+
|
|
1246
|
+
def on_select_color(self, action):
|
|
1247
|
+
dialog = Gtk.ColorChooserDialog("Select Color")
|
|
1248
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1249
|
+
(r, g, b, a) = dialog.get_rgba()
|
|
1250
|
+
color = "#%0.2x%0.2x%0.2x%0.2x" % (
|
|
1251
|
+
int(r * 255),
|
|
1252
|
+
int(g * 255),
|
|
1253
|
+
int(b * 255),
|
|
1254
|
+
int(a * 255))
|
|
1255
|
+
self.run_javascript("document.execCommand('forecolor', null, '%s');" % color)
|
|
1256
|
+
dialog.destroy()
|
|
1257
|
+
|
|
1258
|
+
def on_select_bgcolor(self, action):
|
|
1259
|
+
dialog = Gtk.ColorChooserDialog("Select Background Color")
|
|
1260
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1261
|
+
(r, g, b, a) = dialog.get_rgba()
|
|
1262
|
+
color = "#%0.2x%0.2x%0.2x%0.2x" % (
|
|
1263
|
+
int(r * 255),
|
|
1264
|
+
int(g * 255),
|
|
1265
|
+
int(b * 255),
|
|
1266
|
+
int(a * 255))
|
|
1267
|
+
self.run_javascript("document.execCommand('backcolor', null, '%s');" % color)
|
|
1268
|
+
dialog.destroy()
|
|
1269
|
+
|
|
1270
|
+
def on_edit_marker(self, action):
|
|
1271
|
+
print("on_edit_marker", action.get_name())
|
|
1272
|
+
|
|
1273
|
+
c = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
1274
|
+
sel = c.wait_for_targets()
|
|
1275
|
+
target = Gdk.Atom.intern ("text/html", True);
|
|
1276
|
+
ccc = c.wait_for_contents(target)
|
|
1277
|
+
#print("sel", ccc.get_data())
|
|
1278
|
+
#ccc.free()
|
|
1279
|
+
htmlx = markdialog(ccc.get_data().decode())
|
|
1280
|
+
if htmlx:
|
|
1281
|
+
print("markdialog result:\n", htmlx)
|
|
1282
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
1283
|
+
|
|
1284
|
+
def on_insert_table(self, action):
|
|
1285
|
+
htmlx = "<table align=center border=0 contentEditable=true>" + \
|
|
1286
|
+
"<tr><td>TR1 C1 <td>| TR1 C2 <tr><td>TR2 C1<td>| TR2 C1</table><br>"
|
|
1287
|
+
|
|
1288
|
+
#print("table", htmlx)
|
|
1289
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
1290
|
+
self.modified = True
|
|
1291
|
+
|
|
1292
|
+
def on_insert_link(self, action):
|
|
1293
|
+
dialog = Gtk.Dialog(" Enter a URL: ", None, 0,
|
|
1294
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK))
|
|
1295
|
+
|
|
1296
|
+
entry = Gtk.Entry()
|
|
1297
|
+
dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
1298
|
+
hbox = Gtk.HBox()
|
|
1299
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
1300
|
+
hbox.pack_start(entry, False, False, 0)
|
|
1301
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
1302
|
+
dialog.vbox.pack_start(hbox, False, False, 0)
|
|
1303
|
+
|
|
1304
|
+
dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
1305
|
+
dialog.show_all()
|
|
1306
|
+
|
|
1307
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1308
|
+
self.run_javascript(
|
|
1309
|
+
"document.execCommand('createLink', True, '%s');" % entry.get_text())
|
|
1310
|
+
dialog.destroy()
|
|
1311
|
+
self.modified = True
|
|
1312
|
+
|
|
1313
|
+
def on_insert_image(self, action):
|
|
1314
|
+
dialog = Gtk.FileChooserDialog("Select an image file", None, Gtk.FileChooserAction.OPEN,
|
|
1315
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
|
1316
|
+
|
|
1317
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1318
|
+
fn = dialog.get_filename()
|
|
1319
|
+
if os.path.exists(fn):
|
|
1320
|
+
self.run_javascript(
|
|
1321
|
+
"document.execCommand('insertImage', null, '%s');" % fn)
|
|
1322
|
+
dialog.destroy()
|
|
1323
|
+
self.modified = True
|
|
1324
|
+
|
|
1325
|
+
def on_open(self, action):
|
|
1326
|
+
dialog = Gtk.FileChooserDialog("Select an HTML file", self, Gtk.FileChooserAction.OPEN,
|
|
1327
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
|
1328
|
+
|
|
1329
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1330
|
+
fn = dialog.get_filename()
|
|
1331
|
+
if os.path.exists(fn):
|
|
1332
|
+
self.fname = fn
|
|
1333
|
+
with open(fn) as fd:
|
|
1334
|
+
self.load_html(fd.read(), "file:///")
|
|
1335
|
+
dialog.destroy()
|
|
1336
|
+
|
|
1337
|
+
def on_save(self, action):
|
|
1338
|
+
def completion(html, user_data):
|
|
1339
|
+
open_mode = user_data
|
|
1340
|
+
with open(self.fname, open_mode) as fd:
|
|
1341
|
+
fd.write(html)
|
|
1342
|
+
|
|
1343
|
+
if self.fname:
|
|
1344
|
+
self.get_html(completion, 'w')
|
|
1345
|
+
else:
|
|
1346
|
+
dialog = Gtk.FileChooserDialog("Select an HTML file", None,
|
|
1347
|
+
Gtk.FileChooserAction.SAVE,
|
|
1348
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
|
1349
|
+
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
|
|
1350
|
+
|
|
1351
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1352
|
+
self.fname = dialog.get_filename()
|
|
1353
|
+
print("Saving", self.fname)
|
|
1354
|
+
self.get_html(completion, "w+")
|
|
1355
|
+
dialog.destroy()
|
|
1356
|
+
|
|
1357
|
+
def get_html(self, completion_function, user_data):
|
|
1358
|
+
|
|
1359
|
+
#print("get_html")
|
|
1360
|
+
def javascript_completion(obj, result, user_data):
|
|
1361
|
+
#print("javascript_completion", result)
|
|
1362
|
+
fin = self.run_javascript_finish(result)
|
|
1363
|
+
#print("fin", fin)
|
|
1364
|
+
html = fin.get_js_value().to_string()
|
|
1365
|
+
#print("len html", len(html), "\n")
|
|
1366
|
+
completion_function(html, user_data)
|
|
1367
|
+
self.run_javascript("document.documentElement.innerHTML;",
|
|
1368
|
+
None,
|
|
1369
|
+
javascript_completion,
|
|
1370
|
+
user_data)
|
|
1371
|
+
|
|
1372
|
+
def get_lastmod(self, completion_function, user_data):
|
|
1373
|
+
|
|
1374
|
+
print("get_lastmod")
|
|
1375
|
+
def javascript_completion(obj, result, user_data):
|
|
1376
|
+
print("javascript_completion", result)
|
|
1377
|
+
fin = self.run_javascript_finish(result)
|
|
1378
|
+
#print("fin", fin)
|
|
1379
|
+
html = fin.get_js_value().to_string()
|
|
1380
|
+
print("lastmod", html, "\n")
|
|
1381
|
+
#completion_function(html, user_data)
|
|
1382
|
+
self.run_javascript("document.lastModified",
|
|
1383
|
+
None,
|
|
1384
|
+
javascript_completion,
|
|
1385
|
+
user_data)
|
|
1386
|
+
|
|
1387
|
+
|
|
1388
|
+
def generate_ui(self):
|
|
1389
|
+
|
|
1390
|
+
''' define toolbar items and actions here '''
|
|
1391
|
+
|
|
1392
|
+
actions = Gtk.ActionGroup("Actions")
|
|
1393
|
+
# ----------------------------------------------------------------
|
|
1394
|
+
# Name, Stock Icon, Accelerator, ToolTip, Action
|
|
1395
|
+
|
|
1396
|
+
# Some already has app accels
|
|
1397
|
+
|
|
1398
|
+
accel_arr = [ \
|
|
1399
|
+
|
|
1400
|
+
#("menuFile", None, "_File"),
|
|
1401
|
+
#("menuEdit", None, "_Edit"),
|
|
1402
|
+
#("menuInsert", None, "_Insert"),
|
|
1403
|
+
#("menuFormat", None, "_Format"),
|
|
1404
|
+
#("new", Gtk.STOCK_NEW, "_New", None, None, self.on_new),
|
|
1405
|
+
#("open", Gtk.STOCK_OPEN, "_Open", None, None, self.on_open),
|
|
1406
|
+
#("save", Gtk.STOCK_SAVE, "_Save", None, None, self.on_save),
|
|
1407
|
+
|
|
1408
|
+
("cut", Gtk.STOCK_CUT, "_Cut", None, None, self.on_action),
|
|
1409
|
+
("copy", Gtk.STOCK_COPY, "_Copy", None, None, self.on_action),
|
|
1410
|
+
("paste", Gtk.STOCK_PASTE, "_Paste", None, None, self.on_paste),
|
|
1411
|
+
|
|
1412
|
+
("undo", Gtk.STOCK_UNDO, "_Undo", "<Control>z", "Undo Last Edit", self.on_action),
|
|
1413
|
+
("redo", Gtk.STOCK_REDO, "_Redo", "<Control>y", "Redo Last Undo", self.on_action),
|
|
1414
|
+
|
|
1415
|
+
("removeformat", Gtk.STOCK_PROPERTIES, "_removeFormat", "<Control>M", "Remove Formatting", self.on_action),
|
|
1416
|
+
("bold", Gtk.STOCK_BOLD, "_Bold", "", "Bold / UnBold Selection", self.on_action),
|
|
1417
|
+
("italic", Gtk.STOCK_ITALIC, "_Italic", "", None, self.on_action),
|
|
1418
|
+
("underline", Gtk.STOCK_UNDERLINE, "_Underline", "", None, self.on_action),
|
|
1419
|
+
("strikethrough", Gtk.STOCK_STRIKETHROUGH, "_Strike", "", None, self.on_action),
|
|
1420
|
+
("font", Gtk.STOCK_SELECT_FONT, "Select _Font", "", None, self.on_select_font),
|
|
1421
|
+
("fontsize", None, "Select Font _Size", "<Control>f", "Set Absolute Size (removes color)", self.on_fontsize),
|
|
1422
|
+
("color", Gtk.STOCK_SELECT_COLOR, "Select _Color", None, None, self.on_select_color),
|
|
1423
|
+
("backgroundcolor", Gtk.STOCK_COLOR_PICKER, "Select Back Color", None, None, self.on_select_bgcolor),
|
|
1424
|
+
|
|
1425
|
+
("justifyleft", Gtk.STOCK_JUSTIFY_LEFT, "Justify _Left", None, None, self.on_action),
|
|
1426
|
+
("justifyright", Gtk.STOCK_JUSTIFY_RIGHT, "Justify _Right", None, None, self.on_action),
|
|
1427
|
+
("justifycenter", Gtk.STOCK_JUSTIFY_CENTER, "Justify _Center", None, None, self.on_action),
|
|
1428
|
+
("justifyfull", Gtk.STOCK_JUSTIFY_FILL, "Justify _Full", None, None, self.on_action),
|
|
1429
|
+
|
|
1430
|
+
# Pad Images by name (may not be present in all styles)
|
|
1431
|
+
("insertimage", "insert-image", "Insert _Image", None, None, self.on_insert_image),
|
|
1432
|
+
("insertlink", "insert-link", "Insert _Link", None, None, self.on_insert_link),
|
|
1433
|
+
("inserttable", "insert-table", "Insert _Table", None, None, self.on_insert_table),
|
|
1434
|
+
("editmarker", "edit-marker", "edit _Marker", None, None, self.on_edit_marker),
|
|
1435
|
+
|
|
1436
|
+
("H1", Gtk.STOCK_EXECUTE, "Header 1", None, "Insert Header 1", self.on_header),
|
|
1437
|
+
("H2", Gtk.STOCK_EXECUTE, "Header 2", None, "Insert Header 2", self.on_header),
|
|
1438
|
+
("H3", Gtk.STOCK_EXECUTE, "Header 3", None, "Insert Header 3", self.on_header),
|
|
1439
|
+
("H4", Gtk.STOCK_EXECUTE, "Header 4", None, "Insert Header 4", self.on_header),
|
|
1440
|
+
|
|
1441
|
+
]
|
|
1442
|
+
|
|
1443
|
+
actions.add_actions(accel_arr)
|
|
1444
|
+
|
|
1445
|
+
#print(dir(actions))
|
|
1446
|
+
for aa in accel_arr:
|
|
1447
|
+
# print("acc arr", dir(aa))
|
|
1448
|
+
# break
|
|
1449
|
+
# act = actions.get_action(aa[0])
|
|
1450
|
+
# print("act", act.get_name(), act.get_tooltip())
|
|
1451
|
+
pass
|
|
1452
|
+
# try:
|
|
1453
|
+
# act = Gtk.Action.new(aa[0], aa[2], aa[4], aa[1])
|
|
1454
|
+
# actions.add_action_with_accel(act, aa[3])
|
|
1455
|
+
# except:
|
|
1456
|
+
# #print("Exc on", aa)
|
|
1457
|
+
# pass
|
|
1458
|
+
|
|
1459
|
+
actions.get_action("insertimage").set_property("icon-name", "insert-image")
|
|
1460
|
+
actions.get_action("insertlink").set_property("icon-name", "insert-link")
|
|
1461
|
+
actions.get_action("inserttable").set_property("icon-name", "appointment-new")
|
|
1462
|
+
actions.get_action("editmarker").set_property("icon-name", "text-editor")
|
|
1463
|
+
actions.get_action("fontsize").set_property("icon-name", "preferences-desktop-font")
|
|
1464
|
+
actions.get_action("removeformat").set_property("icon-name", "text-direction")
|
|
1465
|
+
|
|
1466
|
+
ui = Gtk.UIManager()
|
|
1467
|
+
ui.insert_action_group(actions)
|
|
1468
|
+
ui.add_ui_from_string(ui_def)
|
|
1469
|
+
|
|
1470
|
+
# Fill in defaults
|
|
1471
|
+
xxx = ui.get_action_groups()[0].list_actions()
|
|
1472
|
+
for aa in xxx:
|
|
1473
|
+
nnn = aa.get_name()
|
|
1474
|
+
# Find the original, patth missing info
|
|
1475
|
+
for bb in accel_arr:
|
|
1476
|
+
# Convert tuple
|
|
1477
|
+
bbb = list(bb)
|
|
1478
|
+
if bb[0] == nnn:
|
|
1479
|
+
# Pad for this round
|
|
1480
|
+
for cc in range(5 - len(bbb)):
|
|
1481
|
+
bbb.append("")
|
|
1482
|
+
|
|
1483
|
+
#print("lab", bb[2], aa.get_label())
|
|
1484
|
+
#print("found", nnn, bbb[3])
|
|
1485
|
+
|
|
1486
|
+
setattr(aa, "accel", bbb[3])
|
|
1487
|
+
if bbb[3]:
|
|
1488
|
+
try:
|
|
1489
|
+
nn, ss = Gtk.accelerator_parse(bbb[3])
|
|
1490
|
+
setattr(aa, "accel_parsed", (nn, ss))
|
|
1491
|
+
except:
|
|
1492
|
+
pass
|
|
1493
|
+
|
|
1494
|
+
# Pad it with capitalize name if not there
|
|
1495
|
+
if not aa.get_tooltip():
|
|
1496
|
+
aa.set_tooltip(nnn[0].upper() + nnn[1:])
|
|
1497
|
+
|
|
1498
|
+
return ui</code></pre>
|
|
1499
|
+
</details>
|
|
1500
|
+
<h3>Ancestors</h3>
|
|
1501
|
+
<ul class="hlist">
|
|
1502
|
+
<li>gi.repository.WebKit2.WebView</li>
|
|
1503
|
+
<li>gi.repository.WebKit2.WebViewBase</li>
|
|
1504
|
+
<li>gi.overrides.Gtk.Container</li>
|
|
1505
|
+
<li>gi.repository.Gtk.Container</li>
|
|
1506
|
+
<li>gi.overrides.Gtk.Widget</li>
|
|
1507
|
+
<li>gi.repository.Gtk.Widget</li>
|
|
1508
|
+
<li>gi.repository.GObject.InitiallyUnowned</li>
|
|
1509
|
+
<li>gi.overrides.GObject.Object</li>
|
|
1510
|
+
<li>gi.repository.GObject.Object</li>
|
|
1511
|
+
<li>gi._gi.GObject</li>
|
|
1512
|
+
<li>gi.repository.Atk.ImplementorIface</li>
|
|
1513
|
+
<li>gi.repository.Gtk.Buildable</li>
|
|
1514
|
+
<li>gobject.GInterface</li>
|
|
1515
|
+
</ul>
|
|
1516
|
+
<h3>Methods</h3>
|
|
1517
|
+
<dl>
|
|
1518
|
+
<dt id="pgwkit.pgwebw.do_load_changed"><code class="name flex">
|
|
1519
|
+
<span>def <span class="ident">do_load_changed</span></span>(<span>self, status)</span>
|
|
1520
|
+
</code></dt>
|
|
1521
|
+
<dd>
|
|
1522
|
+
<div class="desc"><p>load_changed(self, load_event:WebKit2.LoadEvent)</p></div>
|
|
1523
|
+
<details class="source">
|
|
1524
|
+
<summary>
|
|
1525
|
+
<span>Expand source code</span>
|
|
1526
|
+
</summary>
|
|
1527
|
+
<pre><code class="python">def do_load_changed(self, status):
|
|
1528
|
+
|
|
1529
|
+
#print("do_load_changed()", status)
|
|
1530
|
+
if status == WebKit2.LoadEvent.FINISHED:
|
|
1531
|
+
''' Create a shadow of content '''
|
|
1532
|
+
|
|
1533
|
+
# This gets it without spaces
|
|
1534
|
+
#resource = self.get_main_resource()
|
|
1535
|
+
#resource.get_data(None, self._get_response_data_finish, None)
|
|
1536
|
+
|
|
1537
|
+
# Get it by JS
|
|
1538
|
+
def completion(html, user_data):
|
|
1539
|
+
self.old_html = html
|
|
1540
|
+
self.get_html(completion, '')
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
if self.get_uri():
|
|
1544
|
+
if self.xlink:
|
|
1545
|
+
self.xlink.set_status("Loading ... " + self.get_uri()[:64])
|
|
1546
|
+
|
|
1547
|
+
if status == 3: #WebKit2.LoadEvent.WEBKIT_LOAD_FINISHED:
|
|
1548
|
+
#print("got WEBKIT_LOAD_FINISHED")
|
|
1549
|
+
if self.get_uri():
|
|
1550
|
+
if self.xlink:
|
|
1551
|
+
self.xlink.edit.set_text(self.get_uri()[:64])
|
|
1552
|
+
self.xlink.set_status("Finished: " + self.get_uri()[:64])
|
|
1553
|
+
self.grab_focus()</code></pre>
|
|
1554
|
+
</details>
|
|
1555
|
+
</dd>
|
|
1556
|
+
<dt id="pgwkit.pgwebw.do_load_failed"><code class="name flex">
|
|
1557
|
+
<span>def <span class="ident">do_load_failed</span></span>(<span>self, load_event, failing_uri, error)</span>
|
|
1558
|
+
</code></dt>
|
|
1559
|
+
<dd>
|
|
1560
|
+
<div class="desc"><p>load_failed(self, load_event:WebKit2.LoadEvent, failing_uri:str, error:error) -> bool</p></div>
|
|
1561
|
+
<details class="source">
|
|
1562
|
+
<summary>
|
|
1563
|
+
<span>Expand source code</span>
|
|
1564
|
+
</summary>
|
|
1565
|
+
<pre><code class="python">def do_load_failed(self, load_event, failing_uri, error):
|
|
1566
|
+
print("do_load_failed() was called", failing_uri)
|
|
1567
|
+
if self.xlink:
|
|
1568
|
+
self.xlink.set_status("Failed: " + failing_uri[:64])</code></pre>
|
|
1569
|
+
</details>
|
|
1570
|
+
</dd>
|
|
1571
|
+
<dt id="pgwkit.pgwebw.do_ready_to_show"><code class="name flex">
|
|
1572
|
+
<span>def <span class="ident">do_ready_to_show</span></span>(<span>self)</span>
|
|
1573
|
+
</code></dt>
|
|
1574
|
+
<dd>
|
|
1575
|
+
<div class="desc"><p>ready_to_show(self)</p></div>
|
|
1576
|
+
<details class="source">
|
|
1577
|
+
<summary>
|
|
1578
|
+
<span>Expand source code</span>
|
|
1579
|
+
</summary>
|
|
1580
|
+
<pre><code class="python">def do_ready_to_show(self):
|
|
1581
|
+
print("do_ready_to_show() was called")
|
|
1582
|
+
pass</code></pre>
|
|
1583
|
+
</details>
|
|
1584
|
+
</dd>
|
|
1585
|
+
<dt id="pgwkit.pgwebw.generate_ui"><code class="name flex">
|
|
1586
|
+
<span>def <span class="ident">generate_ui</span></span>(<span>self)</span>
|
|
1587
|
+
</code></dt>
|
|
1588
|
+
<dd>
|
|
1589
|
+
<div class="desc"><p>define toolbar items and actions here</p></div>
|
|
1590
|
+
<details class="source">
|
|
1591
|
+
<summary>
|
|
1592
|
+
<span>Expand source code</span>
|
|
1593
|
+
</summary>
|
|
1594
|
+
<pre><code class="python">def generate_ui(self):
|
|
1595
|
+
|
|
1596
|
+
''' define toolbar items and actions here '''
|
|
1597
|
+
|
|
1598
|
+
actions = Gtk.ActionGroup("Actions")
|
|
1599
|
+
# ----------------------------------------------------------------
|
|
1600
|
+
# Name, Stock Icon, Accelerator, ToolTip, Action
|
|
1601
|
+
|
|
1602
|
+
# Some already has app accels
|
|
1603
|
+
|
|
1604
|
+
accel_arr = [ \
|
|
1605
|
+
|
|
1606
|
+
#("menuFile", None, "_File"),
|
|
1607
|
+
#("menuEdit", None, "_Edit"),
|
|
1608
|
+
#("menuInsert", None, "_Insert"),
|
|
1609
|
+
#("menuFormat", None, "_Format"),
|
|
1610
|
+
#("new", Gtk.STOCK_NEW, "_New", None, None, self.on_new),
|
|
1611
|
+
#("open", Gtk.STOCK_OPEN, "_Open", None, None, self.on_open),
|
|
1612
|
+
#("save", Gtk.STOCK_SAVE, "_Save", None, None, self.on_save),
|
|
1613
|
+
|
|
1614
|
+
("cut", Gtk.STOCK_CUT, "_Cut", None, None, self.on_action),
|
|
1615
|
+
("copy", Gtk.STOCK_COPY, "_Copy", None, None, self.on_action),
|
|
1616
|
+
("paste", Gtk.STOCK_PASTE, "_Paste", None, None, self.on_paste),
|
|
1617
|
+
|
|
1618
|
+
("undo", Gtk.STOCK_UNDO, "_Undo", "<Control>z", "Undo Last Edit", self.on_action),
|
|
1619
|
+
("redo", Gtk.STOCK_REDO, "_Redo", "<Control>y", "Redo Last Undo", self.on_action),
|
|
1620
|
+
|
|
1621
|
+
("removeformat", Gtk.STOCK_PROPERTIES, "_removeFormat", "<Control>M", "Remove Formatting", self.on_action),
|
|
1622
|
+
("bold", Gtk.STOCK_BOLD, "_Bold", "", "Bold / UnBold Selection", self.on_action),
|
|
1623
|
+
("italic", Gtk.STOCK_ITALIC, "_Italic", "", None, self.on_action),
|
|
1624
|
+
("underline", Gtk.STOCK_UNDERLINE, "_Underline", "", None, self.on_action),
|
|
1625
|
+
("strikethrough", Gtk.STOCK_STRIKETHROUGH, "_Strike", "", None, self.on_action),
|
|
1626
|
+
("font", Gtk.STOCK_SELECT_FONT, "Select _Font", "", None, self.on_select_font),
|
|
1627
|
+
("fontsize", None, "Select Font _Size", "<Control>f", "Set Absolute Size (removes color)", self.on_fontsize),
|
|
1628
|
+
("color", Gtk.STOCK_SELECT_COLOR, "Select _Color", None, None, self.on_select_color),
|
|
1629
|
+
("backgroundcolor", Gtk.STOCK_COLOR_PICKER, "Select Back Color", None, None, self.on_select_bgcolor),
|
|
1630
|
+
|
|
1631
|
+
("justifyleft", Gtk.STOCK_JUSTIFY_LEFT, "Justify _Left", None, None, self.on_action),
|
|
1632
|
+
("justifyright", Gtk.STOCK_JUSTIFY_RIGHT, "Justify _Right", None, None, self.on_action),
|
|
1633
|
+
("justifycenter", Gtk.STOCK_JUSTIFY_CENTER, "Justify _Center", None, None, self.on_action),
|
|
1634
|
+
("justifyfull", Gtk.STOCK_JUSTIFY_FILL, "Justify _Full", None, None, self.on_action),
|
|
1635
|
+
|
|
1636
|
+
# Pad Images by name (may not be present in all styles)
|
|
1637
|
+
("insertimage", "insert-image", "Insert _Image", None, None, self.on_insert_image),
|
|
1638
|
+
("insertlink", "insert-link", "Insert _Link", None, None, self.on_insert_link),
|
|
1639
|
+
("inserttable", "insert-table", "Insert _Table", None, None, self.on_insert_table),
|
|
1640
|
+
("editmarker", "edit-marker", "edit _Marker", None, None, self.on_edit_marker),
|
|
1641
|
+
|
|
1642
|
+
("H1", Gtk.STOCK_EXECUTE, "Header 1", None, "Insert Header 1", self.on_header),
|
|
1643
|
+
("H2", Gtk.STOCK_EXECUTE, "Header 2", None, "Insert Header 2", self.on_header),
|
|
1644
|
+
("H3", Gtk.STOCK_EXECUTE, "Header 3", None, "Insert Header 3", self.on_header),
|
|
1645
|
+
("H4", Gtk.STOCK_EXECUTE, "Header 4", None, "Insert Header 4", self.on_header),
|
|
1646
|
+
|
|
1647
|
+
]
|
|
1648
|
+
|
|
1649
|
+
actions.add_actions(accel_arr)
|
|
1650
|
+
|
|
1651
|
+
#print(dir(actions))
|
|
1652
|
+
for aa in accel_arr:
|
|
1653
|
+
# print("acc arr", dir(aa))
|
|
1654
|
+
# break
|
|
1655
|
+
# act = actions.get_action(aa[0])
|
|
1656
|
+
# print("act", act.get_name(), act.get_tooltip())
|
|
1657
|
+
pass
|
|
1658
|
+
# try:
|
|
1659
|
+
# act = Gtk.Action.new(aa[0], aa[2], aa[4], aa[1])
|
|
1660
|
+
# actions.add_action_with_accel(act, aa[3])
|
|
1661
|
+
# except:
|
|
1662
|
+
# #print("Exc on", aa)
|
|
1663
|
+
# pass
|
|
1664
|
+
|
|
1665
|
+
actions.get_action("insertimage").set_property("icon-name", "insert-image")
|
|
1666
|
+
actions.get_action("insertlink").set_property("icon-name", "insert-link")
|
|
1667
|
+
actions.get_action("inserttable").set_property("icon-name", "appointment-new")
|
|
1668
|
+
actions.get_action("editmarker").set_property("icon-name", "text-editor")
|
|
1669
|
+
actions.get_action("fontsize").set_property("icon-name", "preferences-desktop-font")
|
|
1670
|
+
actions.get_action("removeformat").set_property("icon-name", "text-direction")
|
|
1671
|
+
|
|
1672
|
+
ui = Gtk.UIManager()
|
|
1673
|
+
ui.insert_action_group(actions)
|
|
1674
|
+
ui.add_ui_from_string(ui_def)
|
|
1675
|
+
|
|
1676
|
+
# Fill in defaults
|
|
1677
|
+
xxx = ui.get_action_groups()[0].list_actions()
|
|
1678
|
+
for aa in xxx:
|
|
1679
|
+
nnn = aa.get_name()
|
|
1680
|
+
# Find the original, patth missing info
|
|
1681
|
+
for bb in accel_arr:
|
|
1682
|
+
# Convert tuple
|
|
1683
|
+
bbb = list(bb)
|
|
1684
|
+
if bb[0] == nnn:
|
|
1685
|
+
# Pad for this round
|
|
1686
|
+
for cc in range(5 - len(bbb)):
|
|
1687
|
+
bbb.append("")
|
|
1688
|
+
|
|
1689
|
+
#print("lab", bb[2], aa.get_label())
|
|
1690
|
+
#print("found", nnn, bbb[3])
|
|
1691
|
+
|
|
1692
|
+
setattr(aa, "accel", bbb[3])
|
|
1693
|
+
if bbb[3]:
|
|
1694
|
+
try:
|
|
1695
|
+
nn, ss = Gtk.accelerator_parse(bbb[3])
|
|
1696
|
+
setattr(aa, "accel_parsed", (nn, ss))
|
|
1697
|
+
except:
|
|
1698
|
+
pass
|
|
1699
|
+
|
|
1700
|
+
# Pad it with capitalize name if not there
|
|
1701
|
+
if not aa.get_tooltip():
|
|
1702
|
+
aa.set_tooltip(nnn[0].upper() + nnn[1:])
|
|
1703
|
+
|
|
1704
|
+
return ui</code></pre>
|
|
1705
|
+
</details>
|
|
1706
|
+
</dd>
|
|
1707
|
+
<dt id="pgwkit.pgwebw.get_html"><code class="name flex">
|
|
1708
|
+
<span>def <span class="ident">get_html</span></span>(<span>self, completion_function, user_data)</span>
|
|
1709
|
+
</code></dt>
|
|
1710
|
+
<dd>
|
|
1711
|
+
<div class="desc"></div>
|
|
1712
|
+
<details class="source">
|
|
1713
|
+
<summary>
|
|
1714
|
+
<span>Expand source code</span>
|
|
1715
|
+
</summary>
|
|
1716
|
+
<pre><code class="python">def get_html(self, completion_function, user_data):
|
|
1717
|
+
|
|
1718
|
+
#print("get_html")
|
|
1719
|
+
def javascript_completion(obj, result, user_data):
|
|
1720
|
+
#print("javascript_completion", result)
|
|
1721
|
+
fin = self.run_javascript_finish(result)
|
|
1722
|
+
#print("fin", fin)
|
|
1723
|
+
html = fin.get_js_value().to_string()
|
|
1724
|
+
#print("len html", len(html), "\n")
|
|
1725
|
+
completion_function(html, user_data)
|
|
1726
|
+
self.run_javascript("document.documentElement.innerHTML;",
|
|
1727
|
+
None,
|
|
1728
|
+
javascript_completion,
|
|
1729
|
+
user_data)</code></pre>
|
|
1730
|
+
</details>
|
|
1731
|
+
</dd>
|
|
1732
|
+
<dt id="pgwkit.pgwebw.get_lastmod"><code class="name flex">
|
|
1733
|
+
<span>def <span class="ident">get_lastmod</span></span>(<span>self, completion_function, user_data)</span>
|
|
1734
|
+
</code></dt>
|
|
1735
|
+
<dd>
|
|
1736
|
+
<div class="desc"></div>
|
|
1737
|
+
<details class="source">
|
|
1738
|
+
<summary>
|
|
1739
|
+
<span>Expand source code</span>
|
|
1740
|
+
</summary>
|
|
1741
|
+
<pre><code class="python">def get_lastmod(self, completion_function, user_data):
|
|
1742
|
+
|
|
1743
|
+
print("get_lastmod")
|
|
1744
|
+
def javascript_completion(obj, result, user_data):
|
|
1745
|
+
print("javascript_completion", result)
|
|
1746
|
+
fin = self.run_javascript_finish(result)
|
|
1747
|
+
#print("fin", fin)
|
|
1748
|
+
html = fin.get_js_value().to_string()
|
|
1749
|
+
print("lastmod", html, "\n")
|
|
1750
|
+
#completion_function(html, user_data)
|
|
1751
|
+
self.run_javascript("document.lastModified",
|
|
1752
|
+
None,
|
|
1753
|
+
javascript_completion,
|
|
1754
|
+
user_data)</code></pre>
|
|
1755
|
+
</details>
|
|
1756
|
+
</dd>
|
|
1757
|
+
<dt id="pgwkit.pgwebw.keypress"><code class="name flex">
|
|
1758
|
+
<span>def <span class="ident">keypress</span></span>(<span>self, arg, arg2)</span>
|
|
1759
|
+
</code></dt>
|
|
1760
|
+
<dd>
|
|
1761
|
+
<div class="desc"><p>Here we imitate the way the accelerator works</p></div>
|
|
1762
|
+
<details class="source">
|
|
1763
|
+
<summary>
|
|
1764
|
+
<span>Expand source code</span>
|
|
1765
|
+
</summary>
|
|
1766
|
+
<pre><code class="python">def keypress(self, arg, arg2):
|
|
1767
|
+
|
|
1768
|
+
''' Here we imitate the way the accelerator works '''
|
|
1769
|
+
|
|
1770
|
+
state = arg2.get_state() & Gdk.ModifierType.MODIFIER_MASK
|
|
1771
|
+
key = arg2.get_keyval()[1]
|
|
1772
|
+
#print("key", key, "state", state)
|
|
1773
|
+
|
|
1774
|
+
#GDK_MODIFIER_RESERVED_25_MASK
|
|
1775
|
+
|
|
1776
|
+
# Feeding off the accelarator's definitions
|
|
1777
|
+
ag = self.ui.get_action_groups()[0]
|
|
1778
|
+
acts = ag.list_actions()
|
|
1779
|
+
|
|
1780
|
+
# Scan - Fire
|
|
1781
|
+
for aa in acts:
|
|
1782
|
+
if aa.accel:
|
|
1783
|
+
#print(nnn, aa.accel, aa.accel_parsed)
|
|
1784
|
+
if state == aa.accel_parsed[1]:
|
|
1785
|
+
#print("state match")
|
|
1786
|
+
if key == aa.accel_parsed[0]:
|
|
1787
|
+
#print("Fire ", aa.get_name(), aa.get_label())
|
|
1788
|
+
#lab = aa.get_label()
|
|
1789
|
+
aa.activate()
|
|
1790
|
+
break # Only one accel the other is a mistake
|
|
1791
|
+
|
|
1792
|
+
# See if nav key
|
|
1793
|
+
navkey = False
|
|
1794
|
+
for aa in navkeys:
|
|
1795
|
+
if key == aa:
|
|
1796
|
+
#print("Navkey", aa)
|
|
1797
|
+
navkey = True
|
|
1798
|
+
if not navkey:
|
|
1799
|
+
# Exclude Ctrl-s
|
|
1800
|
+
if state == Gdk.ModifierType.CONTROL_MASK and key == 115:
|
|
1801
|
+
#print("Control s")
|
|
1802
|
+
pass
|
|
1803
|
+
else:
|
|
1804
|
+
#print("set on key", key)
|
|
1805
|
+
self.modified = True</code></pre>
|
|
1806
|
+
</details>
|
|
1807
|
+
</dd>
|
|
1808
|
+
<dt id="pgwkit.pgwebw.on_action"><code class="name flex">
|
|
1809
|
+
<span>def <span class="ident">on_action</span></span>(<span>self, action)</span>
|
|
1810
|
+
</code></dt>
|
|
1811
|
+
<dd>
|
|
1812
|
+
<div class="desc"></div>
|
|
1813
|
+
<details class="source">
|
|
1814
|
+
<summary>
|
|
1815
|
+
<span>Expand source code</span>
|
|
1816
|
+
</summary>
|
|
1817
|
+
<pre><code class="python">def on_action(self, action):
|
|
1818
|
+
#print("on_action", action.get_name())
|
|
1819
|
+
# Make it caller neutral
|
|
1820
|
+
if type(action) == str:
|
|
1821
|
+
nnn = action
|
|
1822
|
+
else:
|
|
1823
|
+
nnn = action.get_name()
|
|
1824
|
+
self.run_javascript("document.execCommand('%s', false, false);" % nnn)
|
|
1825
|
+
self.modified = True</code></pre>
|
|
1826
|
+
</details>
|
|
1827
|
+
</dd>
|
|
1828
|
+
<dt id="pgwkit.pgwebw.on_edit_marker"><code class="name flex">
|
|
1829
|
+
<span>def <span class="ident">on_edit_marker</span></span>(<span>self, action)</span>
|
|
1830
|
+
</code></dt>
|
|
1831
|
+
<dd>
|
|
1832
|
+
<div class="desc"></div>
|
|
1833
|
+
<details class="source">
|
|
1834
|
+
<summary>
|
|
1835
|
+
<span>Expand source code</span>
|
|
1836
|
+
</summary>
|
|
1837
|
+
<pre><code class="python">def on_edit_marker(self, action):
|
|
1838
|
+
print("on_edit_marker", action.get_name())
|
|
1839
|
+
|
|
1840
|
+
c = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
1841
|
+
sel = c.wait_for_targets()
|
|
1842
|
+
target = Gdk.Atom.intern ("text/html", True);
|
|
1843
|
+
ccc = c.wait_for_contents(target)
|
|
1844
|
+
#print("sel", ccc.get_data())
|
|
1845
|
+
#ccc.free()
|
|
1846
|
+
htmlx = markdialog(ccc.get_data().decode())
|
|
1847
|
+
if htmlx:
|
|
1848
|
+
print("markdialog result:\n", htmlx)
|
|
1849
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)</code></pre>
|
|
1850
|
+
</details>
|
|
1851
|
+
</dd>
|
|
1852
|
+
<dt id="pgwkit.pgwebw.on_fontsize"><code class="name flex">
|
|
1853
|
+
<span>def <span class="ident">on_fontsize</span></span>(<span>self, action)</span>
|
|
1854
|
+
</code></dt>
|
|
1855
|
+
<dd>
|
|
1856
|
+
<div class="desc"></div>
|
|
1857
|
+
<details class="source">
|
|
1858
|
+
<summary>
|
|
1859
|
+
<span>Expand source code</span>
|
|
1860
|
+
</summary>
|
|
1861
|
+
<pre><code class="python">def on_fontsize(self, action):
|
|
1862
|
+
#print("on_fontsize")
|
|
1863
|
+
sizex = sizedialog()
|
|
1864
|
+
#print("sizex", sizex)
|
|
1865
|
+
if not sizex:
|
|
1866
|
+
return
|
|
1867
|
+
|
|
1868
|
+
c = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
1869
|
+
sel = c.wait_for_targets()
|
|
1870
|
+
#print("sel", sel)
|
|
1871
|
+
target = Gdk.Atom.intern ("text/plain", True);
|
|
1872
|
+
ccc = c.wait_for_contents(target)
|
|
1873
|
+
if not ccc:
|
|
1874
|
+
htmlx = "<span style=\"font-size: %dpx;\">%s</span>" % (int(sizex), "")
|
|
1875
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
1876
|
+
return
|
|
1877
|
+
|
|
1878
|
+
ddd = ccc.get_data().decode()
|
|
1879
|
+
if not ddd:
|
|
1880
|
+
return
|
|
1881
|
+
|
|
1882
|
+
#print("ddd", ddd)
|
|
1883
|
+
htmlx = "<span style=\"font-size: %dpx;\">%s</span>" % (int(sizex), ddd)
|
|
1884
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
1885
|
+
Gtk.Clipboard.clear(c)
|
|
1886
|
+
self.modified = True</code></pre>
|
|
1887
|
+
</details>
|
|
1888
|
+
</dd>
|
|
1889
|
+
<dt id="pgwkit.pgwebw.on_header"><code class="name flex">
|
|
1890
|
+
<span>def <span class="ident">on_header</span></span>(<span>self, action)</span>
|
|
1891
|
+
</code></dt>
|
|
1892
|
+
<dd>
|
|
1893
|
+
<div class="desc"></div>
|
|
1894
|
+
<details class="source">
|
|
1895
|
+
<summary>
|
|
1896
|
+
<span>Expand source code</span>
|
|
1897
|
+
</summary>
|
|
1898
|
+
<pre><code class="python">def on_header(self, action):
|
|
1899
|
+
#print("on_aheader", action.get_name())
|
|
1900
|
+
ddd = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
|
|
1901
|
+
ccc = None
|
|
1902
|
+
while True:
|
|
1903
|
+
#target = Gdk.Atom.intern ("text/html", True);
|
|
1904
|
+
#ccc = ddd.wait_for_contents(target)
|
|
1905
|
+
#if ccc:
|
|
1906
|
+
# break
|
|
1907
|
+
target2 = Gdk.Atom.intern ("text/plain", True);
|
|
1908
|
+
ccc = ddd.wait_for_contents(target2)
|
|
1909
|
+
if ccc:
|
|
1910
|
+
break
|
|
1911
|
+
break
|
|
1912
|
+
|
|
1913
|
+
if not ccc:
|
|
1914
|
+
return
|
|
1915
|
+
|
|
1916
|
+
dddd = ccc.get_data().decode()
|
|
1917
|
+
if not dddd:
|
|
1918
|
+
return
|
|
1919
|
+
#print("dddd", dddd)
|
|
1920
|
+
htmlx = "<%s>%s</%s>" % (action.get_name(), dddd, action.get_name())
|
|
1921
|
+
self.run_javascript("document.execCommand \
|
|
1922
|
+
('insertHTML', null, '%s');" % htmlx)
|
|
1923
|
+
Gtk.Clipboard.clear(ddd)
|
|
1924
|
+
self.modified = True</code></pre>
|
|
1925
|
+
</details>
|
|
1926
|
+
</dd>
|
|
1927
|
+
<dt id="pgwkit.pgwebw.on_insert_image"><code class="name flex">
|
|
1928
|
+
<span>def <span class="ident">on_insert_image</span></span>(<span>self, action)</span>
|
|
1929
|
+
</code></dt>
|
|
1930
|
+
<dd>
|
|
1931
|
+
<div class="desc"></div>
|
|
1932
|
+
<details class="source">
|
|
1933
|
+
<summary>
|
|
1934
|
+
<span>Expand source code</span>
|
|
1935
|
+
</summary>
|
|
1936
|
+
<pre><code class="python">def on_insert_image(self, action):
|
|
1937
|
+
dialog = Gtk.FileChooserDialog("Select an image file", None, Gtk.FileChooserAction.OPEN,
|
|
1938
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
|
1939
|
+
|
|
1940
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1941
|
+
fn = dialog.get_filename()
|
|
1942
|
+
if os.path.exists(fn):
|
|
1943
|
+
self.run_javascript(
|
|
1944
|
+
"document.execCommand('insertImage', null, '%s');" % fn)
|
|
1945
|
+
dialog.destroy()
|
|
1946
|
+
self.modified = True</code></pre>
|
|
1947
|
+
</details>
|
|
1948
|
+
</dd>
|
|
1949
|
+
<dt id="pgwkit.pgwebw.on_insert_link"><code class="name flex">
|
|
1950
|
+
<span>def <span class="ident">on_insert_link</span></span>(<span>self, action)</span>
|
|
1951
|
+
</code></dt>
|
|
1952
|
+
<dd>
|
|
1953
|
+
<div class="desc"></div>
|
|
1954
|
+
<details class="source">
|
|
1955
|
+
<summary>
|
|
1956
|
+
<span>Expand source code</span>
|
|
1957
|
+
</summary>
|
|
1958
|
+
<pre><code class="python">def on_insert_link(self, action):
|
|
1959
|
+
dialog = Gtk.Dialog(" Enter a URL: ", None, 0,
|
|
1960
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK))
|
|
1961
|
+
|
|
1962
|
+
entry = Gtk.Entry()
|
|
1963
|
+
dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
1964
|
+
hbox = Gtk.HBox()
|
|
1965
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
1966
|
+
hbox.pack_start(entry, False, False, 0)
|
|
1967
|
+
hbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
1968
|
+
dialog.vbox.pack_start(hbox, False, False, 0)
|
|
1969
|
+
|
|
1970
|
+
dialog.vbox.pack_start(Gtk.Label(" "), False, False, 0)
|
|
1971
|
+
dialog.show_all()
|
|
1972
|
+
|
|
1973
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
1974
|
+
self.run_javascript(
|
|
1975
|
+
"document.execCommand('createLink', True, '%s');" % entry.get_text())
|
|
1976
|
+
dialog.destroy()
|
|
1977
|
+
self.modified = True</code></pre>
|
|
1978
|
+
</details>
|
|
1979
|
+
</dd>
|
|
1980
|
+
<dt id="pgwkit.pgwebw.on_insert_table"><code class="name flex">
|
|
1981
|
+
<span>def <span class="ident">on_insert_table</span></span>(<span>self, action)</span>
|
|
1982
|
+
</code></dt>
|
|
1983
|
+
<dd>
|
|
1984
|
+
<div class="desc"></div>
|
|
1985
|
+
<details class="source">
|
|
1986
|
+
<summary>
|
|
1987
|
+
<span>Expand source code</span>
|
|
1988
|
+
</summary>
|
|
1989
|
+
<pre><code class="python">def on_insert_table(self, action):
|
|
1990
|
+
htmlx = "<table align=center border=0 contentEditable=true>" + \
|
|
1991
|
+
"<tr><td>TR1 C1 <td>| TR1 C2 <tr><td>TR2 C1<td>| TR2 C1</table><br>"
|
|
1992
|
+
|
|
1993
|
+
#print("table", htmlx)
|
|
1994
|
+
self.run_javascript("document.execCommand('insertHTML', null, '%s');" % htmlx)
|
|
1995
|
+
self.modified = True</code></pre>
|
|
1996
|
+
</details>
|
|
1997
|
+
</dd>
|
|
1998
|
+
<dt id="pgwkit.pgwebw.on_new"><code class="name flex">
|
|
1999
|
+
<span>def <span class="ident">on_new</span></span>(<span>self, action)</span>
|
|
2000
|
+
</code></dt>
|
|
2001
|
+
<dd>
|
|
2002
|
+
<div class="desc"></div>
|
|
2003
|
+
<details class="source">
|
|
2004
|
+
<summary>
|
|
2005
|
+
<span>Expand source code</span>
|
|
2006
|
+
</summary>
|
|
2007
|
+
<pre><code class="python">def on_new(self, action):
|
|
2008
|
+
self.load_html("", "file:///")
|
|
2009
|
+
self.modified = False</code></pre>
|
|
2010
|
+
</details>
|
|
2011
|
+
</dd>
|
|
2012
|
+
<dt id="pgwkit.pgwebw.on_open"><code class="name flex">
|
|
2013
|
+
<span>def <span class="ident">on_open</span></span>(<span>self, action)</span>
|
|
2014
|
+
</code></dt>
|
|
2015
|
+
<dd>
|
|
2016
|
+
<div class="desc"></div>
|
|
2017
|
+
<details class="source">
|
|
2018
|
+
<summary>
|
|
2019
|
+
<span>Expand source code</span>
|
|
2020
|
+
</summary>
|
|
2021
|
+
<pre><code class="python">def on_open(self, action):
|
|
2022
|
+
dialog = Gtk.FileChooserDialog("Select an HTML file", self, Gtk.FileChooserAction.OPEN,
|
|
2023
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
|
2024
|
+
|
|
2025
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
2026
|
+
fn = dialog.get_filename()
|
|
2027
|
+
if os.path.exists(fn):
|
|
2028
|
+
self.fname = fn
|
|
2029
|
+
with open(fn) as fd:
|
|
2030
|
+
self.load_html(fd.read(), "file:///")
|
|
2031
|
+
dialog.destroy()</code></pre>
|
|
2032
|
+
</details>
|
|
2033
|
+
</dd>
|
|
2034
|
+
<dt id="pgwkit.pgwebw.on_paste"><code class="name flex">
|
|
2035
|
+
<span>def <span class="ident">on_paste</span></span>(<span>self, action='')</span>
|
|
2036
|
+
</code></dt>
|
|
2037
|
+
<dd>
|
|
2038
|
+
<div class="desc"></div>
|
|
2039
|
+
<details class="source">
|
|
2040
|
+
<summary>
|
|
2041
|
+
<span>Expand source code</span>
|
|
2042
|
+
</summary>
|
|
2043
|
+
<pre><code class="python">def on_paste(self, action = ""):
|
|
2044
|
+
print("Paste")
|
|
2045
|
+
self.execute_editing_command(WebKit2.EDITING_COMMAND_PASTE)</code></pre>
|
|
2046
|
+
</details>
|
|
2047
|
+
</dd>
|
|
2048
|
+
<dt id="pgwkit.pgwebw.on_save"><code class="name flex">
|
|
2049
|
+
<span>def <span class="ident">on_save</span></span>(<span>self, action)</span>
|
|
2050
|
+
</code></dt>
|
|
2051
|
+
<dd>
|
|
2052
|
+
<div class="desc"></div>
|
|
2053
|
+
<details class="source">
|
|
2054
|
+
<summary>
|
|
2055
|
+
<span>Expand source code</span>
|
|
2056
|
+
</summary>
|
|
2057
|
+
<pre><code class="python">def on_save(self, action):
|
|
2058
|
+
def completion(html, user_data):
|
|
2059
|
+
open_mode = user_data
|
|
2060
|
+
with open(self.fname, open_mode) as fd:
|
|
2061
|
+
fd.write(html)
|
|
2062
|
+
|
|
2063
|
+
if self.fname:
|
|
2064
|
+
self.get_html(completion, 'w')
|
|
2065
|
+
else:
|
|
2066
|
+
dialog = Gtk.FileChooserDialog("Select an HTML file", None,
|
|
2067
|
+
Gtk.FileChooserAction.SAVE,
|
|
2068
|
+
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
|
2069
|
+
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
|
|
2070
|
+
|
|
2071
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
2072
|
+
self.fname = dialog.get_filename()
|
|
2073
|
+
print("Saving", self.fname)
|
|
2074
|
+
self.get_html(completion, "w+")
|
|
2075
|
+
dialog.destroy()</code></pre>
|
|
2076
|
+
</details>
|
|
2077
|
+
</dd>
|
|
2078
|
+
<dt id="pgwkit.pgwebw.on_select_bgcolor"><code class="name flex">
|
|
2079
|
+
<span>def <span class="ident">on_select_bgcolor</span></span>(<span>self, action)</span>
|
|
2080
|
+
</code></dt>
|
|
2081
|
+
<dd>
|
|
2082
|
+
<div class="desc"></div>
|
|
2083
|
+
<details class="source">
|
|
2084
|
+
<summary>
|
|
2085
|
+
<span>Expand source code</span>
|
|
2086
|
+
</summary>
|
|
2087
|
+
<pre><code class="python">def on_select_bgcolor(self, action):
|
|
2088
|
+
dialog = Gtk.ColorChooserDialog("Select Background Color")
|
|
2089
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
2090
|
+
(r, g, b, a) = dialog.get_rgba()
|
|
2091
|
+
color = "#%0.2x%0.2x%0.2x%0.2x" % (
|
|
2092
|
+
int(r * 255),
|
|
2093
|
+
int(g * 255),
|
|
2094
|
+
int(b * 255),
|
|
2095
|
+
int(a * 255))
|
|
2096
|
+
self.run_javascript("document.execCommand('backcolor', null, '%s');" % color)
|
|
2097
|
+
dialog.destroy()</code></pre>
|
|
2098
|
+
</details>
|
|
2099
|
+
</dd>
|
|
2100
|
+
<dt id="pgwkit.pgwebw.on_select_color"><code class="name flex">
|
|
2101
|
+
<span>def <span class="ident">on_select_color</span></span>(<span>self, action)</span>
|
|
2102
|
+
</code></dt>
|
|
2103
|
+
<dd>
|
|
2104
|
+
<div class="desc"></div>
|
|
2105
|
+
<details class="source">
|
|
2106
|
+
<summary>
|
|
2107
|
+
<span>Expand source code</span>
|
|
2108
|
+
</summary>
|
|
2109
|
+
<pre><code class="python">def on_select_color(self, action):
|
|
2110
|
+
dialog = Gtk.ColorChooserDialog("Select Color")
|
|
2111
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
2112
|
+
(r, g, b, a) = dialog.get_rgba()
|
|
2113
|
+
color = "#%0.2x%0.2x%0.2x%0.2x" % (
|
|
2114
|
+
int(r * 255),
|
|
2115
|
+
int(g * 255),
|
|
2116
|
+
int(b * 255),
|
|
2117
|
+
int(a * 255))
|
|
2118
|
+
self.run_javascript("document.execCommand('forecolor', null, '%s');" % color)
|
|
2119
|
+
dialog.destroy()</code></pre>
|
|
2120
|
+
</details>
|
|
2121
|
+
</dd>
|
|
2122
|
+
<dt id="pgwkit.pgwebw.on_select_font"><code class="name flex">
|
|
2123
|
+
<span>def <span class="ident">on_select_font</span></span>(<span>self, action)</span>
|
|
2124
|
+
</code></dt>
|
|
2125
|
+
<dd>
|
|
2126
|
+
<div class="desc"></div>
|
|
2127
|
+
<details class="source">
|
|
2128
|
+
<summary>
|
|
2129
|
+
<span>Expand source code</span>
|
|
2130
|
+
</summary>
|
|
2131
|
+
<pre><code class="python">def on_select_font(self, action):
|
|
2132
|
+
dialog = Gtk.FontChooserDialog("Select a font")
|
|
2133
|
+
if dialog.run() == Gtk.ResponseType.OK:
|
|
2134
|
+
fname = dialog.get_font_desc().get_family()
|
|
2135
|
+
fsize = dialog.get_font_desc().get_size() / Pango.SCALE
|
|
2136
|
+
ttt = int(1 + round(fsize / 10)) % 9
|
|
2137
|
+
print("Setting font", fname, fsize, ttt)
|
|
2138
|
+
self.run_javascript("document.execCommand('fontname', null, '%s');" % fname)
|
|
2139
|
+
self.run_javascript("document.execCommand('fontsize', null, '%s');" % ttt)
|
|
2140
|
+
dialog.destroy()</code></pre>
|
|
2141
|
+
</details>
|
|
2142
|
+
</dd>
|
|
2143
|
+
</dl>
|
|
2144
|
+
</dd>
|
|
2145
|
+
<dt id="pgwkit.pgwebw_fake"><code class="flex name class">
|
|
2146
|
+
<span>class <span class="ident">pgwebw_fake</span></span>
|
|
2147
|
+
</code></dt>
|
|
2148
|
+
<dd>
|
|
2149
|
+
<div class="desc"><p>:Constructors:</p>
|
|
2150
|
+
<p>::</p>
|
|
2151
|
+
<pre><code>VBox(**properties)
|
|
2152
|
+
new(homogeneous:bool, spacing:int) -> Gtk.Widget
|
|
2153
|
+
</code></pre>
|
|
2154
|
+
<p>Initializer for a GObject based classes with support for property
|
|
2155
|
+
sets through the use of explicit keyword arguments.</p></div>
|
|
2156
|
+
<details class="source">
|
|
2157
|
+
<summary>
|
|
2158
|
+
<span>Expand source code</span>
|
|
2159
|
+
</summary>
|
|
2160
|
+
<pre><code class="python">class pgwebw_fake(Gtk.VBox):
|
|
2161
|
+
|
|
2162
|
+
def __init__(self):
|
|
2163
|
+
super(pgwebw_fake, self).__init__();
|
|
2164
|
+
pass
|
|
2165
|
+
|
|
2166
|
+
def load_uri(self, url):
|
|
2167
|
+
pass</code></pre>
|
|
2168
|
+
</details>
|
|
2169
|
+
<h3>Ancestors</h3>
|
|
2170
|
+
<ul class="hlist">
|
|
2171
|
+
<li>gi.repository.Gtk.VBox</li>
|
|
2172
|
+
<li>gi.overrides.Gtk.Box</li>
|
|
2173
|
+
<li>gi.repository.Gtk.Box</li>
|
|
2174
|
+
<li>gi.overrides.Gtk.Container</li>
|
|
2175
|
+
<li>gi.repository.Gtk.Container</li>
|
|
2176
|
+
<li>gi.overrides.Gtk.Widget</li>
|
|
2177
|
+
<li>gi.repository.Gtk.Widget</li>
|
|
2178
|
+
<li>gi.repository.GObject.InitiallyUnowned</li>
|
|
2179
|
+
<li>gi.overrides.GObject.Object</li>
|
|
2180
|
+
<li>gi.repository.GObject.Object</li>
|
|
2181
|
+
<li>gi._gi.GObject</li>
|
|
2182
|
+
<li>gi.repository.Atk.ImplementorIface</li>
|
|
2183
|
+
<li>gi.repository.Gtk.Buildable</li>
|
|
2184
|
+
<li>gi.repository.Gtk.Orientable</li>
|
|
2185
|
+
<li>gobject.GInterface</li>
|
|
2186
|
+
</ul>
|
|
2187
|
+
<h3>Methods</h3>
|
|
2188
|
+
<dl>
|
|
2189
|
+
<dt id="pgwkit.pgwebw_fake.load_uri"><code class="name flex">
|
|
2190
|
+
<span>def <span class="ident">load_uri</span></span>(<span>self, url)</span>
|
|
2191
|
+
</code></dt>
|
|
2192
|
+
<dd>
|
|
2193
|
+
<div class="desc"></div>
|
|
2194
|
+
<details class="source">
|
|
2195
|
+
<summary>
|
|
2196
|
+
<span>Expand source code</span>
|
|
2197
|
+
</summary>
|
|
2198
|
+
<pre><code class="python">def load_uri(self, url):
|
|
2199
|
+
pass</code></pre>
|
|
2200
|
+
</details>
|
|
2201
|
+
</dd>
|
|
2202
|
+
</dl>
|
|
2203
|
+
</dd>
|
|
2204
|
+
</dl>
|
|
2205
|
+
</section>
|
|
2206
|
+
</article>
|
|
2207
|
+
<nav id="sidebar">
|
|
2208
|
+
<h1>Index</h1>
|
|
2209
|
+
<div class="toc">
|
|
2210
|
+
<ul></ul>
|
|
2211
|
+
</div>
|
|
2212
|
+
<ul id="index">
|
|
2213
|
+
<li><h3><a href="#header-functions">Functions</a></h3>
|
|
2214
|
+
<ul class="">
|
|
2215
|
+
<li><code><a title="pgwkit.markdialog" href="#pgwkit.markdialog">markdialog</a></code></li>
|
|
2216
|
+
<li><code><a title="pgwkit.sizedialog" href="#pgwkit.sizedialog">sizedialog</a></code></li>
|
|
2217
|
+
<li><code><a title="pgwkit.treecallb" href="#pgwkit.treecallb">treecallb</a></code></li>
|
|
2218
|
+
</ul>
|
|
2219
|
+
</li>
|
|
2220
|
+
<li><h3><a href="#header-classes">Classes</a></h3>
|
|
2221
|
+
<ul>
|
|
2222
|
+
<li>
|
|
2223
|
+
<h4><code><a title="pgwkit.dummywebkit" href="#pgwkit.dummywebkit">dummywebkit</a></code></h4>
|
|
2224
|
+
<ul class="">
|
|
2225
|
+
<li><code><a title="pgwkit.dummywebkit.WebView" href="#pgwkit.dummywebkit.WebView">WebView</a></code></li>
|
|
2226
|
+
</ul>
|
|
2227
|
+
</li>
|
|
2228
|
+
<li>
|
|
2229
|
+
<h4><code><a title="pgwkit.dummywebview" href="#pgwkit.dummywebview">dummywebview</a></code></h4>
|
|
2230
|
+
<ul class="">
|
|
2231
|
+
<li><code><a title="pgwkit.dummywebview.connect" href="#pgwkit.dummywebview.connect">connect</a></code></li>
|
|
2232
|
+
<li><code><a title="pgwkit.dummywebview.load_html" href="#pgwkit.dummywebview.load_html">load_html</a></code></li>
|
|
2233
|
+
<li><code><a title="pgwkit.dummywebview.set_editable" href="#pgwkit.dummywebview.set_editable">set_editable</a></code></li>
|
|
2234
|
+
</ul>
|
|
2235
|
+
</li>
|
|
2236
|
+
<li>
|
|
2237
|
+
<h4><code><a title="pgwkit.pgwebw" href="#pgwkit.pgwebw">pgwebw</a></code></h4>
|
|
2238
|
+
<ul class="two-column">
|
|
2239
|
+
<li><code><a title="pgwkit.pgwebw.do_load_changed" href="#pgwkit.pgwebw.do_load_changed">do_load_changed</a></code></li>
|
|
2240
|
+
<li><code><a title="pgwkit.pgwebw.do_load_failed" href="#pgwkit.pgwebw.do_load_failed">do_load_failed</a></code></li>
|
|
2241
|
+
<li><code><a title="pgwkit.pgwebw.do_ready_to_show" href="#pgwkit.pgwebw.do_ready_to_show">do_ready_to_show</a></code></li>
|
|
2242
|
+
<li><code><a title="pgwkit.pgwebw.generate_ui" href="#pgwkit.pgwebw.generate_ui">generate_ui</a></code></li>
|
|
2243
|
+
<li><code><a title="pgwkit.pgwebw.get_html" href="#pgwkit.pgwebw.get_html">get_html</a></code></li>
|
|
2244
|
+
<li><code><a title="pgwkit.pgwebw.get_lastmod" href="#pgwkit.pgwebw.get_lastmod">get_lastmod</a></code></li>
|
|
2245
|
+
<li><code><a title="pgwkit.pgwebw.keypress" href="#pgwkit.pgwebw.keypress">keypress</a></code></li>
|
|
2246
|
+
<li><code><a title="pgwkit.pgwebw.on_action" href="#pgwkit.pgwebw.on_action">on_action</a></code></li>
|
|
2247
|
+
<li><code><a title="pgwkit.pgwebw.on_edit_marker" href="#pgwkit.pgwebw.on_edit_marker">on_edit_marker</a></code></li>
|
|
2248
|
+
<li><code><a title="pgwkit.pgwebw.on_fontsize" href="#pgwkit.pgwebw.on_fontsize">on_fontsize</a></code></li>
|
|
2249
|
+
<li><code><a title="pgwkit.pgwebw.on_header" href="#pgwkit.pgwebw.on_header">on_header</a></code></li>
|
|
2250
|
+
<li><code><a title="pgwkit.pgwebw.on_insert_image" href="#pgwkit.pgwebw.on_insert_image">on_insert_image</a></code></li>
|
|
2251
|
+
<li><code><a title="pgwkit.pgwebw.on_insert_link" href="#pgwkit.pgwebw.on_insert_link">on_insert_link</a></code></li>
|
|
2252
|
+
<li><code><a title="pgwkit.pgwebw.on_insert_table" href="#pgwkit.pgwebw.on_insert_table">on_insert_table</a></code></li>
|
|
2253
|
+
<li><code><a title="pgwkit.pgwebw.on_new" href="#pgwkit.pgwebw.on_new">on_new</a></code></li>
|
|
2254
|
+
<li><code><a title="pgwkit.pgwebw.on_open" href="#pgwkit.pgwebw.on_open">on_open</a></code></li>
|
|
2255
|
+
<li><code><a title="pgwkit.pgwebw.on_paste" href="#pgwkit.pgwebw.on_paste">on_paste</a></code></li>
|
|
2256
|
+
<li><code><a title="pgwkit.pgwebw.on_save" href="#pgwkit.pgwebw.on_save">on_save</a></code></li>
|
|
2257
|
+
<li><code><a title="pgwkit.pgwebw.on_select_bgcolor" href="#pgwkit.pgwebw.on_select_bgcolor">on_select_bgcolor</a></code></li>
|
|
2258
|
+
<li><code><a title="pgwkit.pgwebw.on_select_color" href="#pgwkit.pgwebw.on_select_color">on_select_color</a></code></li>
|
|
2259
|
+
<li><code><a title="pgwkit.pgwebw.on_select_font" href="#pgwkit.pgwebw.on_select_font">on_select_font</a></code></li>
|
|
2260
|
+
</ul>
|
|
2261
|
+
</li>
|
|
2262
|
+
<li>
|
|
2263
|
+
<h4><code><a title="pgwkit.pgwebw_fake" href="#pgwkit.pgwebw_fake">pgwebw_fake</a></code></h4>
|
|
2264
|
+
<ul class="">
|
|
2265
|
+
<li><code><a title="pgwkit.pgwebw_fake.load_uri" href="#pgwkit.pgwebw_fake.load_uri">load_uri</a></code></li>
|
|
2266
|
+
</ul>
|
|
2267
|
+
</li>
|
|
2268
|
+
</ul>
|
|
2269
|
+
</li>
|
|
2270
|
+
</ul>
|
|
2271
|
+
</nav>
|
|
2272
|
+
</main>
|
|
2273
|
+
<footer id="footer">
|
|
2274
|
+
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
|
2275
|
+
</footer>
|
|
2276
|
+
</body>
|
|
2277
|
+
</html>
|