-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcarbon.py
executable file
·1507 lines (1129 loc) · 42.1 KB
/
carbon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/local/bin/python3
# File carbon.py: a library to attack Qt using a text protocol,
# using the standard input and output.
#
# Usage: ./carbon.py
#
# ./carbon.py [-file filename]
# [-echo] [-echo_input] [-echo_output] [-colored]
# [-check_alive]
################################################################################
# Section 1. Import necessary modules
################################################################################
import copy
import csv
import sys
import os
import queue
import re
import threading
import time
import traceback
from pathlib import Path
from PyQt5.QtCore import pyqtSignal, QThread, QPoint, QRect
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QTextEdit
from PyQt5.QtGui import QPixmap
from PyQt5.QtGui import QCursor
from PyQt5.QtGui import QPainter, QColor, QPen, QFont
from PyQt5.Qt import Qt
################################################################################
# Section 2. Analyzing command line arguments
################################################################################
# Parse command line arguments
script_args = sys.argv[1:] # list of arguments to the script
echo = "-echo" in script_args # echo both input and output
echo_input = "-echo_input" in script_args # echo only input
echo_output = "-echo_output" in script_args # echo only output
colored = "-colored" in script_args # use colored echo in Terminal
check_alive = "-check_alive" in script_args # close server after one minute
# -echo implies both -echo_input and -echo_output
if echo :
echo_input = True
echo_output = True
# name of the script to be played
input_file_name = ""
if "-file" in script_args:
f = script_args.index("-file")
if f >= 0:
input_file_name = script_args[f+1]
################################################################################
# Section 3. Define a couple of helpers (time, scheduling, encodings, stats...)
################################################################################
starting_time = time.time() # starting time of the library
def now():
"""
Number of seconds since the start of the server
"""
return time.time() - starting_time
def every(delay, job):
"""
Schedule a "job" function every "delay" seconds.
usage : threading.Thread(target=lambda: every(5, foo)).start()
"""
next_time = now() + delay
while True:
time.sleep(max(0, next_time - now()))
try:
job()
except Exception:
# In production code you might want to have this instead of course:
# logger.exception("Problem while executing repetitive task.")
print(traceback.format_exc())
# skip tasks if we are behind schedule
next_time += (now() - next_time) // delay * delay + delay
def is_main_thread() :
return threading.current_thread() is threading.main_thread()
def my_url_encode(s) :
"""
my_url_encode() encodes space, quotes and newline caracters in the given
string into their url-encoding equivalents. Useful when sending strings
with our server, since the protocol is a textual, line by line protocol.
"""
s = s.replace( ' ' , "%20" )
s = s.replace( '"' , "%22" )
s = s.replace( "'" , "%27" )
s = s.replace( os.linesep , "%0A" ) # linefeed
return s
def my_url_decode(s) :
"""
my_url_decode() is the reverse of my_url_encode()
"""
s = s.replace( "%0A" , os.linesep ) # linefeed
s = s.replace( "%27" , "'" )
s = s.replace( "%22" , '"' )
s = s.replace( "%20" , ' ' )
return s
class ansi:
"""
A class to declare constants for colored ANSI codes in Terminal
"""
GREEN = '\033[92m' # GREEN
YELLOW = '\033[93m' # YELLOW
RED = '\033[91m' # RED
RESET = '\033[0m' # RESET COLOR
class stats:
"""
A class to emit some stats about the commands received, implemented, etc.
"""
total = 0
not_implemented = 0
partially_implemented = 0
implemented = 0
exceptions = 0
@classmethod
def report(cls) :
cls.implemented = cls.total - cls.not_implemented - cls.partially_implemented
return (cls.total,
cls.implemented,
cls.partially_implemented,
cls.not_implemented,
cls.exceptions)
def stat_box():
"""
Returns a box with stats and pourcentages
"""
def pct(n) :
if total <= 0 :
return ""
return " (" + str(round(100 * n / total, 2)) + " %)"
def fmt(x) :
return "{: 5d}".format(x)
(total, implemented, partial, not_implemented, exceptions) = stats.report()
s = ""
s += "\n============================================"
s += "\nexceptions raised : " + fmt(exceptions)
s += "\nCARBON-PROTOCOL lines : " + fmt(total)
s += "\n not implemented : " + fmt(not_implemented) + pct(not_implemented)
s += "\n partially implemented : " + fmt(partial) + pct(partial)
s += "\n implemented : " + fmt(implemented) + pct(implemented)
s += "\n============================================\n"
return s
################################################################################
# Section 4. Implement the CARBON-PROTOCOL
################################################################################
PROTOCOL_PREFIX = "CARBON-PROTOCOL " # prefix for the protocol commands
current_port = None # the current active window for drawing
windows = {} # dictionary of existent windows
pixmaps = {} # dictionary of existent pixmaps
fonts = {} # dictionary (cache) of fonts
pens = {} # dictionary (cache) of pens
class CachedFont() :
"""
A class to create a QFont from family, size, etc.
We keep a cache of the created QFont to speed up things.
"""
def __init__(self, family, size):
self.family = family
self.size = size
self.weight = QFont.Normal
self.italic = False
def __repr__(self) :
result = "{},{},{},{}".format(self.family, self.size, self.weight, self.italic)
return result
def key(self) :
return self.__repr__()
def QFont(self) :
key = self.key()
if (key in fonts) : # already in cache
return fonts[key]
else : # add to cache
font = QFont(self.family, self.size, self.weight, self.italic)
fonts[key] = font
return font
class CachedPen() :
"""
A class to create a QPen from color, width, etc.
We keep a cache of the created QPen to speed up things.
"""
def __init__(self, color, width):
self.color = color
self.width = width
def __repr__(self) :
result = "{},{}".format(self.color, self.width)
return result
def key(self) :
return self.__repr__()
def QPen(self) :
key = self.key()
if (key in pens) : # already in cache
return pens[key]
else : # add to cache
pen = QPen(QColor(self.color), self.width)
pens[key] = pen
return pen
class CarbonWindow(QWidget):
"""
CarbonWindow is just a normal Qt window with a name
"""
def __init__(self, name):
super().__init__(parent=None)
self.setObjectName(name)
self.setWindowFlags(Qt.Window)
self.graphics = {} # dictionary of all the graphic items in the window
self.font = CachedFont("Helvetica", 15)
self.pen = CachedPen("#000000", 1.2)
def scroll_texts(self, dx, dy) :
"""
Change the positions of the strings in the 'graphics' dictionary
"""
# calculate the new positions of the strings
# in the "scrolled" temporary dictionary
scrolled = {}
for key, item in list(self.graphics.items()) :
if item["type"] == "TEXT" :
name = item["name"]
text = item["text"]
h = item["h"] + dx
v = item["v"] + dy
a = item["a"]
b = item["b"]
pen = item["pen"]
font = item["font"]
image = item["image"]
zindex = item["zindex"]
visible = item["visible"]
align = item["align"]
if key.startswith("TEXT:name=") :
new_key = key
else :
new_key = make_key("TEXT", pos=(h,v))
new_item = make_item("TEXT", name, text, h, v, a, b, pen, font, image, zindex, visible, align)
scrolled[new_key] = new_item
# remove old item
self.graphics.pop(key)
# merge the "scrolled" dictionary to the original one
self.graphics.update(scrolled)
return
def paintEvent(self, event):
"""
This function handles the paintEvent for our CarbonWindow class
"""
painter = QPainter()
painter.begin(self)
order = lambda item : item["zindex"]
items = sorted(self.graphics.values(), key=order)
for item in items :
if (item["type"] == "IMG") and item["visible"]:
image = item["image"]
pixmap = image.pixmap()
painter.drawPixmap(image.pos(), pixmap)
if (item["type"] == "TEXT") and item["visible"] :
text = item["text"]
h = item["h"]
v = item["v"]
pen = item["pen"]
font = item["font"]
painter.setFont(font)
painter.setPen(pen)
painter.drawText(h, v, text)
painter.end()
return
def render(self, painter):
#print("\ninside render() for window : ", self.objectName())
pass
def resizeEvent(self, resizeEvent):
#print("\ninside resizeEvent() for window : ", self.objectName())
pass
def find_window(name) :
"""
Find window by name in our list of open windows.
We return the window if found, or None if not found.
"""
global windows
if name and (name in windows) :
return windows[name]
else :
return None
def find_pixmap(name) :
"""
Find pixmap by name in our list of pixmaps.
We return the pixmap if found, or None if not found.
"""
global pixmaps
if name and (name in pixmaps) :
return pixmaps[name]
else :
return None
def make_item(type, name, text, h, v, a, b, pen, font, image, zindex, visible, align) :
"""
Create a description of a graphic item in our window.graphics dictionary
"""
item = {
"type" : type,
"name" : name,
"text" : text,
"h" : h,
"v" : v,
"a" : a,
"b" : b,
"pen" : pen,
"font" : font,
"image" : image,
"zindex" : zindex,
"visible": visible,
"align" : align
}
return item
def make_key(type, name=None, pos=None) :
"""
Create the key for a graphic item in our window.graphics dictionary.
At least one of the name or pos parameter must be set.
"""
key = type + ":"
if name :
return key + "name=" + name + " "
if pos :
return key + "pos=" + str(pos[0]) + ";" + str(pos[1]) + " "
return key
def find_image(window, image_name) :
"""
Find image by name in the given window. Returns an image, or None.
"""
if window and image_name :
key = make_key("IMG", name=image_name)
if (key in window.graphics) :
item = window.graphics[key]
return item["image"]
return None
def get_image_key(window, image_name) :
"""
Returns the key if the image exists in the window, None otherwise.
"""
if window and image_name :
key = make_key("IMG", name=image_name)
if (key in window.graphics) :
return key
return None
def get_port(args):
"""
Returns the name of the current grafport, or the string "None"
"""
global current_port
try :
reference = current_port.objectName()
except Exception :
reference = None
return str(reference)
def set_port(args):
"""
Set the current grafport
"""
global current_port
name = find_named_parameter("name", args, 0, STRING)
window = find_window(name)
if window :
current_port = window
return
def new_window(args):
"""
Create a new window, make it the current port, and return its name.
"""
name = find_named_parameter("name", args, 0, STRING)
if find_window(name) :
error = "ERROR (new-window) : window with name '{}' already exists".format(name)
return error
if not(name) :
return None
else :
# 1. create a new window
# 2. add the window to the 'windows' directory
# 3. set the current port to the window
global windows, current_port
window = CarbonWindow(name)
windows[name] = window
window.show()
current_port = window
return name
def set_window_title(args):
"""
Set the title of a window
"""
name = find_named_parameter("name" , args, 0, STRING)
title = find_named_parameter("title", args, 1, STRING)
window = find_window(name)
if window and title:
window.setWindowTitle(title)
return
def set_window_geometry(args):
"""
Set the geometry of a window
"""
name = find_named_parameter("name", args, 0, STRING)
left = find_named_parameter("left", args, 1, INTEGER)
top = find_named_parameter("top", args, 2, INTEGER)
width = find_named_parameter("width", args, 3, INTEGER)
height = find_named_parameter("height", args, 4, INTEGER)
window = find_window(name)
if window and (left is not None) and (top is not None) and width and height :
window.setGeometry(left, top, width, height)
return
def scroll_window(args):
"""
Scroll the current window content by (dx, dy)
"""
dx = find_named_parameter("dx", args, 0, INTEGER)
dy = find_named_parameter("dy", args, 1, INTEGER)
window = current_port
if window and (dx is not None) and (dy is not None) :
window.scroll_texts(dx, dy)
window.update()
return
def show_window(args):
"""
Show a window on the screen
"""
name = find_named_parameter("name", args, 0, STRING)
window = find_window(name)
if window :
window.show()
return
def set_window_visible(args):
"""
Show/Hide a window, obeying the visible flag
"""
name = find_named_parameter("name", args, 0, STRING)
visible = find_named_parameter("visible", args, 1, BOOLEAN)
window = find_window(name)
if window :
window.setVisible(visible)
return
def close_window(args):
"""
Close a window (and all the widgets inside the window)
"""
global current_port
name = find_named_parameter("name", args, 0, STRING)
window = find_window(name)
if window :
# close window
window.close()
# remove window from the "windows" directory
windows.pop(name)
if current_port.objectName() == name :
current_port = None
return
def clear_window(args):
"""
Clear the content of a window.
If the filter parameter (a string) is given, only the graphic items
whose key contains filter will be removed.
Examples :
clear-window WindowID (clear window)
clear-window WindowID filter="IMG:" (clear images)
clear-window WindowID filter="TEXT:name=foo " (clear text named "foo")
clear-window WindowID filter="TEXT:pos=20;30 " (clear text at pos (20,30))
"""
global current_port
name = find_named_parameter("name", args, 0, STRING)
filter = find_named_parameter("filter", args, -1, STRING)
window = find_window(name)
if window :
if filter :
for key, item in list(window.graphics.items()) :
if (filter in key) :
window.graphics.pop(key)
else :
window.graphics.clear()
window.update()
return
def set_font_family(args):
"""
Set the family (eg "Helevetica") of the font in the current port
"""
name = find_named_parameter("name", args, 0, STRING)
window = current_port
if window and name :
window.font.family = name
return
def set_font_size(args):
"""
Set the size in points of the font in the current port
"""
size = find_named_parameter("size", args, 0, INTEGER)
window = current_port
if window and size :
window.font.size = size
return
def set_font_weight(args):
"""
Set the weight (eg "bold") of the font in the current port
"""
weight = find_named_parameter("weight", args, 0, STRING)
window = current_port
if window and weight :
if (weight == "bold") :
window.font.weight = QFont.Bold
else :
window.font.weight = QFont.Normal
return
def set_font_style(args):
"""
Set the style (eg "italic") of the font in the current port
"""
italic = find_named_parameter("italic", args, 0, BOOLEAN)
window = current_port
if window and (italic is not None) :
window.font.italic = italic
return
def set_pen_width(args):
"""
Set the pen width (which is a float) of the current port
"""
width = find_named_parameter("width", args, 0, FLOAT)
window = current_port
if window and (width is not None) :
window.pen.width = width
return
def set_pen_color(args):
"""
Set the pen color (for instance "#FF0000") of the current port
"""
color = find_named_parameter("color", args, 0, STRING)
window = current_port
if window and color :
window.pen.color = color
return
def draw_text_at(args):
"""
Draw text at the given position
"""
text = find_named_parameter("text", args, 0, STRING)
h = find_named_parameter("h", args, 1, INTEGER)
v = find_named_parameter("v", args, 2, INTEGER)
name = find_named_parameter("name", args, -1, STRING)
width = find_named_parameter("width", args, -1, INTEGER)
height = find_named_parameter("height",args, -1, INTEGER)
zindex = find_named_parameter("zindex",args, -1, INTEGER)
align = find_named_parameter("align", args, -1, STRING)
window = current_port
if window and text and (h is not None) and (v is not None) :
pen = window.pen.QPen()
font = window.font.QFont()
a = width if width else 0
b = height if height else 0
zindex = zindex if zindex else 0
image = None
visible = True
item = make_item("TEXT", name, text, h, v, a, b, pen, font, image, zindex, visible, align)
# insert the description of the text in the "graphics" dictionary
if name is not None :
key = make_key("TEXT", name=name)
else :
key = make_key("TEXT", pos=(h,v))
window.graphics[key] = item
window.update()
return
def init(args):
"""
Init the carbon.py process
"""
return
def get_mouse(args):
"""
Returns the current mouse position as a string
"""
where = QCursor.pos()
return str(where.x()) + " " + str(where.y())
def quit(args):
"""
Clean up the carbon.py process
"""
simulate_server_line("quit")
return
def new_pixmap(args):
"""
Create a new pixmap in memory, stores it in the global pixmaps dictonary
"""
name = find_named_parameter("name" , args, 0, STRING)
imagefile = find_named_parameter("imagefile" , args, 1, STRING)
width = find_named_parameter("width" , args, -1, INTEGER)
height = find_named_parameter("height" , args, -1, INTEGER)
if not(name) or not(imagefile) :
return None
try:
with open(imagefile):
pixmap = QPixmap(imagefile)
if height is not None :
pixmap = pixmap.scaledToHeight(height, Qt.SmoothTransformation)
if width is not None :
pixmap = pixmap.scaledToWidth(width, Qt.SmoothTransformation)
global pixmaps
pixmaps[name] = pixmap
except FileNotFoundError:
return "ERROR (new_pixmap) Image not found:" + imagefile
return None
def new_image_from_pixmap(args) :
"""
Create a new image from a given pixmap (in the current window)
"""
name = find_named_parameter("name" , args, 0, STRING)
pixmapname = find_named_parameter("pixmap" , args, 1, STRING)
zindex = find_named_parameter("zindex" , args, -1, INTEGER)
pixmap = find_pixmap(pixmapname)
window = current_port
if window and name and pixmap :
image = QLabel(window)
image.setObjectName(name)
image.setPixmap(pixmap)
key = make_key("IMG", name=name)
# delete any old image with the same name in the window
old_image = find_image(window, name)
if old_image :
old_image.close()
window.graphics.pop(key)
text = None
h = 0
v = 0
a = 0
b = 0
pen = None
font = None
zindex = zindex if zindex else 0
visible = False
align = None
item = make_item("IMG", name, text, h, v, a, b, pen, font, image, zindex, visible, align)
# insert the description of the image in the "graphics" dictionary
window.graphics[key] = item
return name
return None
def set_image_position(args) :
"""
Set the position of the given image (in the current window)
"""
name = find_named_parameter("name", args, 0, STRING)
h = find_named_parameter("h" , args, 1, INTEGER)
v = find_named_parameter("v" , args, 2, INTEGER)
window = current_port
if window and name and (h is not None) and (v is not None) :
image = find_image(window, name)
if image :
image.move(h, v)
return
def set_image_pixmap(args) :
"""
Set the pixmap of the given image (in the current window)
"""
name = find_named_parameter("name" , args, 0, STRING)
pixmapname = find_named_parameter("pixmap" , args, 1, STRING)
pixmap = find_pixmap(pixmapname)
window = current_port
if window and name and pixmap :
image = find_image(window, name)
if image :
image.setPixmap(pixmap)
return
def draw_image(args) :
"""
Draw the given image (in the current window)
"""
name = find_named_parameter("name" , args, 0, STRING)
zindex = find_named_parameter("zindex", args, -1, INTEGER)
window = current_port
if window and name :
key = get_image_key(window, name)
if key :
window.graphics[key]["visible"] = True
window.graphics[key]["zindex"] = zindex if zindex else 0
window.update()
return
def open_file_dialog(args):
"""
Blocking call, showing the usual system dialog for file selection. The
returned value is the complete path of the file selected by the user, or
the empty string if the user has canceled the dialog.
"""
options = QFileDialog.Options()
#options |= QFileDialog.DontUseNativeDialog
caption = find_named_parameter("prompt", args, -1, STRING)
directory = find_named_parameter("dir" , args, -1, STRING)
filter = find_named_parameter("filter", args, -1, STRING)
if caption is None : caption = args[0]
if directory is None : directory = args[1]
if filter is None : filter = args[2]
caption = my_url_decode(caption)
directory = my_url_decode(directory)
filter = my_url_decode(filter)
filename = QFileDialog.getOpenFileName(
parent = None,
caption = caption,
directory = directory,
filter = filter,
options = options )
if (type(filename) is tuple) : # pyqt5 returns a couple, pyqt4 not
filename = filename[0]
result = ""
if filename :
result = my_url_encode(str(Path(filename)))
return ("\"{}\"".format(result))
def save_file_dialog(args):
"""
Blocking call, showing the usual system dialog for saving a file. The
returned value is the complete path of the file name chosen by the user,
or the empty string if the user has canceled the dialog.
"""
options = QFileDialog.Options()
#options |= QFileDialog.DontUseNativeDialog
caption = find_named_parameter("prompt", args, -1, STRING)
directory = find_named_parameter("dir" , args, -1, STRING)
filter = find_named_parameter("filter", args, -1, STRING)
if caption is None : caption = args[0]
if directory is None : directory = args[1]
if filter is None : filter = args[2]
caption = my_url_decode(caption)
directory = my_url_decode(directory)
filter = my_url_decode(filter)
filename = QFileDialog.getSaveFileName(
parent = None,
caption = caption,
directory = directory,
filter = filter,
options = options )
if (type(filename) is tuple) : # pyqt5 returns a couple, pyqt4 not
filename = filename[0]
result = ""
if filename :
result = my_url_encode(str(Path(filename)))
return ("\"{}\"".format(result))
def keep_alive(args) :
"""
A dummy function, as simply answering OK proves the server is still up :-)
"""
return
def dump(args):
"""
Dump the content of the global variables
"""
global windows, current_port, pixmaps
current = "None" if current_port is None else current_port.objectName()
s = ""