pyvguicom 1.0.0__py3-none-any.whl → 1.0.1__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/__init__.py +1 -0
- pyvguicom/custwidg.py +110 -0
- pyvguicom/pgbox.py +59 -118
- pyvguicom/pgbutt.py +3 -2
- pyvguicom/pgentry.py +114 -19
- pyvguicom/pggui.py +99 -14
- pyvguicom/pgsel.py +439 -0
- pyvguicom/pgsimp.py +34 -265
- pyvguicom/pgtextview.py +0 -1
- pyvguicom/pgutils.py +495 -157
- pyvguicom/testbutt.py +26 -24
- pyvguicom/testcust.py +49 -0
- pyvguicom/testentry.py +93 -0
- pyvguicom/testlettsel.py +98 -0
- pyvguicom/testnums.py +6 -11
- pyvguicom/testroot.py +7 -6
- pyvguicom/testsimple.py +22 -28
- pyvguicom/testtextv.py +3 -12
- {pyvguicom-1.0.0.dist-info → pyvguicom-1.0.1.dist-info}/METADATA +11 -5
- pyvguicom-1.0.1.dist-info/RECORD +27 -0
- pyvguicom/sutil.py +0 -344
- pyvguicom-1.0.0.dist-info/RECORD +0 -23
- {pyvguicom-1.0.0.dist-info → pyvguicom-1.0.1.dist-info}/WHEEL +0 -0
- {pyvguicom-1.0.0.dist-info → pyvguicom-1.0.1.dist-info}/top_level.txt +0 -0
pyvguicom/pgutils.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/python
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# pylint: disable=C0103
|
|
4
|
+
# pylint: disable=C0209
|
|
5
|
+
# pylint: disable=C0321
|
|
5
6
|
|
|
6
|
-
import os, sys, getopt,
|
|
7
|
-
import random, time,
|
|
7
|
+
import os, sys, getopt, string, math, warnings
|
|
8
|
+
import random, time, traceback, stat
|
|
9
|
+
import platform
|
|
8
10
|
|
|
9
11
|
if sys.version_info.major < 3:
|
|
10
12
|
pass
|
|
@@ -13,13 +15,13 @@ else:
|
|
|
13
15
|
if inspect.isbuiltin(time.process_time):
|
|
14
16
|
time.clock = time.process_time
|
|
15
17
|
|
|
18
|
+
''' General utility fiunctions '''
|
|
19
|
+
|
|
16
20
|
import gi
|
|
17
21
|
gi.require_version("Gtk", "3.0")
|
|
18
22
|
from gi.repository import Gtk
|
|
19
23
|
from gi.repository import Gdk
|
|
20
|
-
from gi.repository import GLib
|
|
21
24
|
from gi.repository import GObject
|
|
22
|
-
from gi.repository import Pango
|
|
23
25
|
|
|
24
26
|
# Add the new line twice for more balaced string
|
|
25
27
|
|
|
@@ -34,26 +36,9 @@ allstr = " " + \
|
|
|
34
36
|
|
|
35
37
|
allasc = string.ascii_lowercase + string.ascii_uppercase + \
|
|
36
38
|
string.digits + "_"
|
|
37
|
-
|
|
38
39
|
alllett = string.ascii_lowercase + string.ascii_uppercase
|
|
39
|
-
|
|
40
|
-
|
|
41
40
|
testmode = 0
|
|
42
41
|
|
|
43
|
-
# -----------------------------------------------------------------------
|
|
44
|
-
# Sleep just a little, but allow the system to breed
|
|
45
|
-
#
|
|
46
|
-
#def usleep2(msec):
|
|
47
|
-
#
|
|
48
|
-
# got_clock = time.clock() + float(msec) / 1000
|
|
49
|
-
# #print( got_clock)
|
|
50
|
-
# while True:
|
|
51
|
-
# if time.clock() > got_clock:
|
|
52
|
-
# break
|
|
53
|
-
# #print ("Sleeping")
|
|
54
|
-
# Gtk.main_iteration_do(False)
|
|
55
|
-
#
|
|
56
|
-
|
|
57
42
|
# -----------------------------------------------------------------------
|
|
58
43
|
# Sleep just a little, but allow the system to breed
|
|
59
44
|
|
|
@@ -78,58 +63,43 @@ def usleep2(msec):
|
|
|
78
63
|
|
|
79
64
|
def message2(strx, title = "Dialog", parent=None):
|
|
80
65
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if parent:
|
|
95
|
-
dialog.set_transient_for(parent)
|
|
96
|
-
|
|
97
|
-
dialog.connect ("response", lambda d, r: d.destroy())
|
|
98
|
-
dialog.show_all()
|
|
99
|
-
|
|
66
|
+
dialog = Gtk.MessageDialog()
|
|
67
|
+
# Close dialog on user response
|
|
68
|
+
dialog.add_button("Close", Gtk.ButtonsType.CLOSE)
|
|
69
|
+
if title:
|
|
70
|
+
dialog.set_title(title)
|
|
71
|
+
#box = dialog.get_content_area()
|
|
72
|
+
#box.add(Gtk.Label(strx))
|
|
73
|
+
dialog.set_markup(strx)
|
|
74
|
+
if parent:
|
|
75
|
+
dialog.set_transient_for(parent)
|
|
76
|
+
dialog.connect ("response", lambda d, r: d.destroy())
|
|
77
|
+
dialog.show_all()
|
|
100
78
|
|
|
101
79
|
def yes_no2(message, title = "Question", parent=None):
|
|
102
80
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
dialog.connect("key-press-event", yn_key, 0)
|
|
120
|
-
|
|
121
|
-
#dialog.connect ("response", lambda d, r: d.destroy())
|
|
122
|
-
|
|
123
|
-
dialog.show_all()
|
|
124
|
-
response = dialog.run()
|
|
125
|
-
dialog.destroy()
|
|
81
|
+
dialog = Gtk.MessageDialog()
|
|
82
|
+
if title:
|
|
83
|
+
dialog.set_title(title)
|
|
84
|
+
dialog.add_button("_Yes", Gtk.ResponseType.YES)
|
|
85
|
+
dialog.add_button("_No", Gtk.ResponseType.NO)
|
|
86
|
+
dialog.set_markup(message)
|
|
87
|
+
img = Gtk.Image.new_from_stock(Gtk.STOCK_DIALOG_QUESTION, Gtk.IconSize.DIALOG)
|
|
88
|
+
dialog.set_image(img)
|
|
89
|
+
if parent:
|
|
90
|
+
dialog.set_transient_for(parent)
|
|
91
|
+
dialog.connect("key-press-event", yn_key, 0)
|
|
92
|
+
#dialog.connect ("response", lambda d, r: d.destroy())
|
|
93
|
+
dialog.show_all()
|
|
94
|
+
response = dialog.run()
|
|
95
|
+
dialog.destroy()
|
|
126
96
|
|
|
127
|
-
|
|
97
|
+
return response
|
|
128
98
|
|
|
129
99
|
# ------------------------------------------------------------------------
|
|
130
100
|
# Do dialog
|
|
131
101
|
|
|
132
|
-
def yes_no_cancel2(message, title = "Question", cancel = True
|
|
102
|
+
def yes_no_cancel2(message, title = "Question", cancel = True):
|
|
133
103
|
|
|
134
104
|
warnings.simplefilter("ignore")
|
|
135
105
|
|
|
@@ -139,22 +109,21 @@ def yes_no_cancel2(message, title = "Question", cancel = True, parent=None):
|
|
|
139
109
|
|
|
140
110
|
dialog.set_default_response(Gtk.ResponseType.YES)
|
|
141
111
|
dialog.set_position(Gtk.WindowPosition.CENTER)
|
|
142
|
-
#dialog.set_transient_for(pedconfig.conf.pedwin.mywin)
|
|
143
112
|
|
|
144
113
|
sp = " "
|
|
145
|
-
label = Gtk.Label(message)
|
|
114
|
+
label = Gtk.Label(message)
|
|
146
115
|
label2 = Gtk.Label(sp); label3 = Gtk.Label(sp)
|
|
147
116
|
label2a = Gtk.Label(sp); label3a = Gtk.Label(sp)
|
|
148
117
|
|
|
149
|
-
hbox = Gtk.HBox()
|
|
118
|
+
hbox = Gtk.HBox()
|
|
150
119
|
|
|
151
|
-
hbox.pack_start(label2, 0, 0, 0)
|
|
152
|
-
hbox.pack_start(label, 1, 1, 0)
|
|
120
|
+
hbox.pack_start(label2, 0, 0, 0)
|
|
121
|
+
hbox.pack_start(label, 1, 1, 0)
|
|
153
122
|
hbox.pack_start(label3, 0, 0, 0)
|
|
154
123
|
|
|
155
|
-
dialog.vbox.pack_start(label2a, 0, 0, 0)
|
|
124
|
+
dialog.vbox.pack_start(label2a, 0, 0, 0)
|
|
156
125
|
dialog.vbox.pack_start(hbox, 0, 0, 0)
|
|
157
|
-
dialog.vbox.pack_start(label3a, 0, 0, 0)
|
|
126
|
+
dialog.vbox.pack_start(label3a, 0, 0, 0)
|
|
158
127
|
|
|
159
128
|
dialog.add_button("_Yes", Gtk.ResponseType.YES)
|
|
160
129
|
dialog.add_button("_No", Gtk.ResponseType.NO)
|
|
@@ -342,7 +311,7 @@ def clean_str2(strx):
|
|
|
342
311
|
skip = False
|
|
343
312
|
for aa in range(len(strx)):
|
|
344
313
|
if skip:
|
|
345
|
-
skip = False
|
|
314
|
+
skip = False
|
|
346
315
|
continue
|
|
347
316
|
if strx[aa] == '\\' and strx[aa+1] == 'r':
|
|
348
317
|
skip = True
|
|
@@ -561,7 +530,7 @@ def unescape(strx):
|
|
|
561
530
|
|
|
562
531
|
chh = strx[pos]
|
|
563
532
|
|
|
564
|
-
if
|
|
533
|
+
if chh == '\\':
|
|
565
534
|
#print "backslash", strx[pos:]
|
|
566
535
|
pos2 = pos + 1; strx2 = ""
|
|
567
536
|
while True:
|
|
@@ -660,58 +629,6 @@ def isfile(fname):
|
|
|
660
629
|
return True
|
|
661
630
|
return False
|
|
662
631
|
|
|
663
|
-
|
|
664
|
-
'''
|
|
665
|
-
# Append to log
|
|
666
|
-
def logentry(kind, startt, fname):
|
|
667
|
-
logfname = "account.txt"
|
|
668
|
-
logfile = pedconfig.conf.log_dir + "/" + logfname
|
|
669
|
-
try:
|
|
670
|
-
fp = open(logfile, "a+")
|
|
671
|
-
except:
|
|
672
|
-
try:
|
|
673
|
-
fp = open(logfile, "w+")
|
|
674
|
-
fp.seek(0, os.SEEK_END);
|
|
675
|
-
except:
|
|
676
|
-
print("Cannot open/create log file", logfile)
|
|
677
|
-
return
|
|
678
|
-
|
|
679
|
-
log_clock = time.time()
|
|
680
|
-
|
|
681
|
-
print("Action:", "%s %s" % (kind, os.path.realpath(fname)), file=fp)
|
|
682
|
-
print("On:", time.ctime(log_clock), file=fp)
|
|
683
|
-
print("Delta:", "%.0f" % (log_clock - startt), file=fp)
|
|
684
|
-
print("Date:", "%.0f %s %s\n" % \
|
|
685
|
-
(log_clock, os.path.basename(fname), kind.split()[0]), file=fp)
|
|
686
|
-
fp.close()
|
|
687
|
-
|
|
688
|
-
# Append to timesheet
|
|
689
|
-
def timesheet(kind, startt, endd):
|
|
690
|
-
|
|
691
|
-
logfname = "timesheet.txt"
|
|
692
|
-
logfile = pedconfig.conf.log_dir + "/" + logfname
|
|
693
|
-
try:
|
|
694
|
-
fp = open(logfile, "a+")
|
|
695
|
-
except:
|
|
696
|
-
try:
|
|
697
|
-
fp = open(logfile, "w+")
|
|
698
|
-
fp.seek(0, os.SEEK_END);
|
|
699
|
-
except:
|
|
700
|
-
print("Cannot open/create log file", logfile)
|
|
701
|
-
return
|
|
702
|
-
|
|
703
|
-
log_clock = time.time()
|
|
704
|
-
|
|
705
|
-
print("Action:", "%s" % (kind), file=fp)
|
|
706
|
-
print("On:", time.ctime(log_clock), file=fp)
|
|
707
|
-
if endd:
|
|
708
|
-
td = endd - startt
|
|
709
|
-
print("Time diff:", "%.0f %d:%d" % (td, td / 3600, (td % 3600) / 60), file=fp)
|
|
710
|
-
|
|
711
|
-
print(file=fp)
|
|
712
|
-
fp.close()
|
|
713
|
-
'''
|
|
714
|
-
|
|
715
632
|
def put_exception2_old(xstr):
|
|
716
633
|
|
|
717
634
|
cumm = xstr + " "
|
|
@@ -756,7 +673,7 @@ def untab_str(strx, tabstop = 4):
|
|
|
756
673
|
if chh == "\t":
|
|
757
674
|
# Generate string
|
|
758
675
|
spaces = tabstop - (cnt % tabstop)
|
|
759
|
-
ttt = ""
|
|
676
|
+
ttt = ""
|
|
760
677
|
for aa in range(spaces):
|
|
761
678
|
ttt += " "
|
|
762
679
|
res += ttt
|
|
@@ -774,14 +691,12 @@ def ampmstr(bb):
|
|
|
774
691
|
|
|
775
692
|
dd = "AM"
|
|
776
693
|
if bb == 12:
|
|
777
|
-
|
|
694
|
+
dd = "PM"
|
|
778
695
|
elif bb > 12:
|
|
779
696
|
bb -= 12
|
|
780
697
|
dd = "PM"
|
|
781
|
-
|
|
782
698
|
return "%02d %s" % (bb, dd)
|
|
783
699
|
|
|
784
|
-
|
|
785
700
|
# It's totally optional to do this, you could just manually insert icons
|
|
786
701
|
# and have them not be themeable, especially if you never expect people
|
|
787
702
|
# to theme your app.
|
|
@@ -790,7 +705,7 @@ def register_stock_icons():
|
|
|
790
705
|
''' This function registers our custom toolbar icons, so they
|
|
791
706
|
can be themed.
|
|
792
707
|
'''
|
|
793
|
-
items = [('demo-gtk-logo', '_GTK!', 0, 0, '')]
|
|
708
|
+
#items = [('demo-gtk-logo', '_GTK!', 0, 0, '')]
|
|
794
709
|
# Register our stock items
|
|
795
710
|
#Gtk.stock_add(items)
|
|
796
711
|
|
|
@@ -827,10 +742,6 @@ def register_stock_icons():
|
|
|
827
742
|
except GObject.GError as error:
|
|
828
743
|
print('failed to load GTK logo for toolbar')
|
|
829
744
|
|
|
830
|
-
|
|
831
|
-
if __name__ == '__main__':
|
|
832
|
-
print("This file was not meant to run directly")
|
|
833
|
-
|
|
834
745
|
# ------------------------------------------------------------------------
|
|
835
746
|
# Let the higher level deal with errors.
|
|
836
747
|
|
|
@@ -875,8 +786,8 @@ def readfile(strx, sep = None):
|
|
|
875
786
|
text = []
|
|
876
787
|
for aa in text2:
|
|
877
788
|
#print("'%s\n" % aa)
|
|
878
|
-
bb = aa.replace("\r", "")
|
|
879
|
-
cc = bb.replace("\n", "")
|
|
789
|
+
bb = aa.replace("\r", "")
|
|
790
|
+
cc = bb.replace("\n", "")
|
|
880
791
|
text.append(cc)
|
|
881
792
|
#text2 = []
|
|
882
793
|
|
|
@@ -951,19 +862,21 @@ def yes_no_cancel(title, message, cancel = True):
|
|
|
951
862
|
#dialog.set_transient_for(pedconfig.conf.pedwin.mywin)
|
|
952
863
|
|
|
953
864
|
sp = " "
|
|
954
|
-
label = Gtk.Label(message)
|
|
955
|
-
label2 = Gtk.Label(sp)
|
|
956
|
-
|
|
865
|
+
label = Gtk.Label(message)
|
|
866
|
+
label2 = Gtk.Label(sp)
|
|
867
|
+
label3 = Gtk.Label(sp)
|
|
868
|
+
label2a = Gtk.Label(sp)
|
|
869
|
+
label3a = Gtk.Label(sp)
|
|
957
870
|
|
|
958
|
-
hbox = Gtk.HBox()
|
|
871
|
+
hbox = Gtk.HBox()
|
|
959
872
|
|
|
960
|
-
hbox.pack_start(label2, 0, 0, 0)
|
|
961
|
-
hbox.pack_start(label, 1, 1, 0)
|
|
873
|
+
hbox.pack_start(label2, 0, 0, 0)
|
|
874
|
+
hbox.pack_start(label, 1, 1, 0)
|
|
962
875
|
hbox.pack_start(label3, 0, 0, 0)
|
|
963
876
|
|
|
964
|
-
dialog.vbox.pack_start(label2a, 0, 0, 0)
|
|
877
|
+
dialog.vbox.pack_start(label2a, 0, 0, 0)
|
|
965
878
|
dialog.vbox.pack_start(hbox, 0, 0, 0)
|
|
966
|
-
dialog.vbox.pack_start(label3a, 0, 0, 0)
|
|
879
|
+
dialog.vbox.pack_start(label3a, 0, 0, 0)
|
|
967
880
|
|
|
968
881
|
dialog.add_button("_Yes", Gtk.ResponseType.YES)
|
|
969
882
|
dialog.add_button("_No", Gtk.ResponseType.NO)
|
|
@@ -1005,17 +918,14 @@ def _yn_key(win, event, cancel):
|
|
|
1005
918
|
event.keyval == Gdk.KEY_C:
|
|
1006
919
|
win.response(Gtk.ResponseType.CANCEL)
|
|
1007
920
|
|
|
1008
|
-
|
|
1009
|
-
# Show About dialog:
|
|
1010
|
-
|
|
1011
|
-
import platform
|
|
921
|
+
def about2(self2):
|
|
1012
922
|
|
|
1013
|
-
|
|
923
|
+
''' Show About dialog: '''
|
|
1014
924
|
|
|
1015
925
|
dialog = Gtk.AboutDialog()
|
|
1016
926
|
dialog.set_name(pedconfig.conf.progname + " - Python Editor ")
|
|
1017
927
|
|
|
1018
|
-
dialog.set_version(str(pedconfig.conf.version))
|
|
928
|
+
dialog.set_version(str(pedconfig.conf.version))
|
|
1019
929
|
gver = (Gtk.get_major_version(), \
|
|
1020
930
|
Gtk.get_minor_version(), \
|
|
1021
931
|
Gtk.get_micro_version())
|
|
@@ -1039,7 +949,7 @@ def about(self2):
|
|
|
1039
949
|
"\nPyedPro Build Date: %s\n" % pedconfig.conf.build_date +\
|
|
1040
950
|
"Exe Path:\n%s\n" % os.path.realpath(ddd)
|
|
1041
951
|
|
|
1042
|
-
dialog.set_comments(comm)
|
|
952
|
+
dialog.set_comments(comm)
|
|
1043
953
|
dialog.set_copyright(pedconfig.conf.progname + " Created by Peter Glen.\n"
|
|
1044
954
|
"Project is in the Public Domain.")
|
|
1045
955
|
dialog.set_program_name(pedconfig.conf.progname)
|
|
@@ -1053,7 +963,7 @@ def about(self2):
|
|
|
1053
963
|
dialog.set_logo(pixbuf)
|
|
1054
964
|
|
|
1055
965
|
except:
|
|
1056
|
-
print("Cannot load logo for about dialog", img_path)
|
|
966
|
+
print("Cannot load logo for about dialog", img_path)
|
|
1057
967
|
print(sys.exc_info())
|
|
1058
968
|
|
|
1059
969
|
#dialog.set_website("")
|
|
@@ -1074,7 +984,7 @@ def about_key(win, event):
|
|
|
1074
984
|
# ------------------------------------------------------------------------
|
|
1075
985
|
# Show a regular message:
|
|
1076
986
|
|
|
1077
|
-
def
|
|
987
|
+
def message3(strx, title = None):
|
|
1078
988
|
|
|
1079
989
|
#print("called: message()", strx)
|
|
1080
990
|
|
|
@@ -1098,6 +1008,434 @@ def message(strx, title = None):
|
|
|
1098
1008
|
dialog.show()
|
|
1099
1009
|
dialog.run()
|
|
1100
1010
|
|
|
1101
|
-
#
|
|
1011
|
+
# -----------------------------------------------------------------------
|
|
1012
|
+
# Call func with all processes, func called with stat as its argument
|
|
1013
|
+
# Function may return True to stop iteration
|
|
1014
|
+
|
|
1015
|
+
def withps(func, opt = None):
|
|
1016
|
+
|
|
1017
|
+
ret = False
|
|
1018
|
+
dl = os.listdir("/proc")
|
|
1019
|
+
for aa in dl:
|
|
1020
|
+
fname = "/proc/" + aa + "/stat"
|
|
1021
|
+
if os.path.isfile(fname):
|
|
1022
|
+
ff = open(fname, "r").read().split()
|
|
1023
|
+
ret = func(ff, opt)
|
|
1024
|
+
if ret:
|
|
1025
|
+
break
|
|
1026
|
+
return ret
|
|
1027
|
+
|
|
1028
|
+
# ------------------------------------------------------------------------
|
|
1029
|
+
# Find
|
|
1030
|
+
|
|
1031
|
+
def find(self):
|
|
1032
|
+
|
|
1033
|
+
head = "Find in text"
|
|
1034
|
+
|
|
1035
|
+
dialog = Gtk.Dialog(head,
|
|
1036
|
+
None,
|
|
1037
|
+
Gtk.DIALOG_MODAL | Gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
1038
|
+
(Gtk.STOCK_CANCEL, Gtk.RESPONSE_REJECT,
|
|
1039
|
+
Gtk.STOCK_OK, Gtk.RESPONSE_ACCEPT))
|
|
1040
|
+
dialog.set_default_response(Gtk.RESPONSE_ACCEPT)
|
|
1041
|
+
|
|
1042
|
+
try:
|
|
1043
|
+
dialog.set_icon_from_file("epub.png")
|
|
1044
|
+
except:
|
|
1045
|
+
print ("Cannot load find dialog icon", sys.exc_info())
|
|
1046
|
+
|
|
1047
|
+
self.dialog = dialog
|
|
1048
|
+
|
|
1049
|
+
label3 = Gtk.Label(" "); label4 = Gtk.Label(" ")
|
|
1050
|
+
label5 = Gtk.Label(" "); label6 = Gtk.Label(" ")
|
|
1051
|
+
label7 = Gtk.Label(" "); label8 = Gtk.Label(" ")
|
|
1052
|
+
|
|
1053
|
+
warnings.simplefilter("ignore")
|
|
1054
|
+
entry = Gtk.Entry()
|
|
1055
|
+
warnings.simplefilter("default")
|
|
1056
|
+
entry.set_text(self.oldfind)
|
|
1057
|
+
|
|
1058
|
+
entry.set_activates_default(True)
|
|
1059
|
+
|
|
1060
|
+
dialog.vbox.pack_start(label4)
|
|
1061
|
+
|
|
1062
|
+
hbox2 = Gtk.HBox()
|
|
1063
|
+
hbox2.pack_start(label6, False)
|
|
1064
|
+
hbox2.pack_start(entry)
|
|
1065
|
+
hbox2.pack_start(label7, False)
|
|
1066
|
+
|
|
1067
|
+
dialog.vbox.pack_start(hbox2)
|
|
1068
|
+
|
|
1069
|
+
dialog.checkbox = Gtk.CheckButton("Search _Backwards")
|
|
1070
|
+
dialog.checkbox2 = Gtk.CheckButton("Case In_sensitive")
|
|
1071
|
+
dialog.vbox.pack_start(label5)
|
|
1072
|
+
|
|
1073
|
+
hbox = Gtk.HBox()
|
|
1074
|
+
#hbox.pack_start(label1); hbox.pack_start(dialog.checkbox)
|
|
1075
|
+
#hbox.pack_start(label2); hbox.pack_start(dialog.checkbox2)
|
|
1076
|
+
hbox.pack_start(label3)
|
|
1077
|
+
dialog.vbox.pack_start(hbox)
|
|
1078
|
+
dialog.vbox.pack_start(label8)
|
|
1079
|
+
|
|
1080
|
+
label32 = Gtk.Label(" ")
|
|
1081
|
+
hbox4 = Gtk.HBox()
|
|
1082
|
+
|
|
1083
|
+
hbox4.pack_start(label32)
|
|
1084
|
+
dialog.vbox.pack_start(hbox4)
|
|
1085
|
+
|
|
1086
|
+
dialog.show_all()
|
|
1087
|
+
response = dialog.run()
|
|
1088
|
+
self.srctxt = entry.get_text()
|
|
1089
|
+
|
|
1090
|
+
dialog.destroy()
|
|
1091
|
+
|
|
1092
|
+
if response != Gtk.RESPONSE_ACCEPT:
|
|
1093
|
+
return None
|
|
1094
|
+
|
|
1095
|
+
return self.srctxt, dialog.checkbox.get_active(), \
|
|
1096
|
+
dialog.checkbox2.get_active()
|
|
1097
|
+
|
|
1098
|
+
disp = Gdk.Display.get_default()
|
|
1099
|
+
scr = disp.get_default_screen()
|
|
1100
|
+
|
|
1101
|
+
#print( "num_mon", scr.get_n_monitors() )
|
|
1102
|
+
#for aa in range(scr.get_n_monitors()):
|
|
1103
|
+
# print( "mon", aa, scr.get_monitor_geometry(aa);)
|
|
1104
|
+
|
|
1105
|
+
# ------------------------------------------------------------------------
|
|
1106
|
+
# Get current screen (monitor) width and height
|
|
1107
|
+
|
|
1108
|
+
def get_screen_wh():
|
|
1109
|
+
|
|
1110
|
+
ptr = disp.get_pointer()
|
|
1111
|
+
mon = scr.get_monitor_at_point(ptr[1], ptr[2])
|
|
1112
|
+
geo = scr.get_monitor_geometry(mon)
|
|
1113
|
+
www = geo.width; hhh = geo.height
|
|
1114
|
+
if www == 0 or hhh == 0:
|
|
1115
|
+
www = Gdk.get_screen_width()
|
|
1116
|
+
hhh = Gdk.get_screen_height()
|
|
1117
|
+
return www, hhh
|
|
1118
|
+
|
|
1119
|
+
# ------------------------------------------------------------------------
|
|
1120
|
+
# Get current screen (monitor) upper left corner xx / yy
|
|
1121
|
+
|
|
1122
|
+
def get_screen_xy():
|
|
1123
|
+
|
|
1124
|
+
ptr = disp.get_pointer()
|
|
1125
|
+
mon = scr.get_monitor_at_point(ptr[1], ptr[2])
|
|
1126
|
+
geo = scr.get_monitor_geometry(mon)
|
|
1127
|
+
return geo.x, geo.y
|
|
1128
|
+
|
|
1129
|
+
# ------------------------------------------------------------------------
|
|
1130
|
+
# Print( an exception as the system would print it)
|
|
1131
|
+
|
|
1132
|
+
def print_exception(xstr):
|
|
1133
|
+
cumm = xstr + " "
|
|
1134
|
+
a,b,c = sys.exc_info()
|
|
1135
|
+
if a != None:
|
|
1136
|
+
cumm += str(a) + " " + str(b) + "\n"
|
|
1137
|
+
try:
|
|
1138
|
+
#cumm += str(traceback.format_tb(c, 10))
|
|
1139
|
+
ttt = traceback.extract_tb(c)
|
|
1140
|
+
for aa in ttt:
|
|
1141
|
+
cumm += "File: " + os.path.basename(aa[0]) + \
|
|
1142
|
+
" Line: " + str(aa[1]) + "\n" + \
|
|
1143
|
+
" Context: " + aa[2] + " -> " + aa[3] + "\n"
|
|
1144
|
+
except:
|
|
1145
|
+
print("Could not print trace stack. ", sys.exc_info())
|
|
1146
|
+
print( cumm)
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
# ------------------------------------------------------------------------
|
|
1150
|
+
# Show a regular message:
|
|
1151
|
+
|
|
1152
|
+
def message(strx, parent = None, title = None, icon = Gtk.MessageType.INFO):
|
|
1153
|
+
|
|
1154
|
+
dialog = Gtk.MessageDialog(parent, Gtk.DialogFlags.DESTROY_WITH_PARENT,
|
|
1155
|
+
icon, Gtk.ButtonsType.CLOSE, strx)
|
|
1156
|
+
|
|
1157
|
+
dialog.set_modal(True)
|
|
1158
|
+
|
|
1159
|
+
if title:
|
|
1160
|
+
dialog.set_title(title)
|
|
1161
|
+
else:
|
|
1162
|
+
dialog.set_title("DBGui Message")
|
|
1163
|
+
|
|
1164
|
+
# Close dialog on user response
|
|
1165
|
+
dialog.connect("response", lambda d, r: d.destroy())
|
|
1166
|
+
dialog.show()
|
|
1167
|
+
|
|
1168
|
+
# -----------------------------------------------------------------------
|
|
1169
|
+
# Sleep just a little, but allow the system to breed
|
|
1170
|
+
|
|
1171
|
+
def usleep(msec):
|
|
1172
|
+
|
|
1173
|
+
if sys.version_info[0] < 3 or \
|
|
1174
|
+
(sys.version_info[0] == 3 and sys.version_info[1] < 3):
|
|
1175
|
+
timefunc = time.clock
|
|
1176
|
+
else:
|
|
1177
|
+
timefunc = time.process_time
|
|
1178
|
+
|
|
1179
|
+
got_clock = timefunc() + float(msec) / 1000
|
|
1180
|
+
#print( got_clock)
|
|
1181
|
+
while True:
|
|
1182
|
+
if timefunc() > got_clock:
|
|
1183
|
+
break
|
|
1184
|
+
#print ("Sleeping")
|
|
1185
|
+
Gtk.main_iteration_do(False)
|
|
1186
|
+
|
|
1187
|
+
# ------------------------------------------------------------------------
|
|
1188
|
+
# Create temporary file, return name. Empty string ("") if error.
|
|
1189
|
+
|
|
1190
|
+
def tmpname(indir, template):
|
|
1191
|
+
|
|
1192
|
+
fname = ""
|
|
1193
|
+
if not os.access(indir, os.W_OK):
|
|
1194
|
+
print( "Cannot access ", indir)
|
|
1195
|
+
return fname
|
|
1196
|
+
|
|
1197
|
+
cnt = 1
|
|
1198
|
+
while True:
|
|
1199
|
+
tmp = indir + "/" + template + "_" + str(cnt)
|
|
1200
|
+
if not os.access(tmp, os.R_OK):
|
|
1201
|
+
fname = tmp
|
|
1202
|
+
break
|
|
1203
|
+
# Safety valve
|
|
1204
|
+
if cnt > 10000:
|
|
1205
|
+
break
|
|
1206
|
+
return fname
|
|
1207
|
+
|
|
1208
|
+
# ------------------------------------------------------------------------
|
|
1209
|
+
# Execute man loop
|
|
1210
|
+
|
|
1211
|
+
def mainloop():
|
|
1212
|
+
while True:
|
|
1213
|
+
ev = Gdk.event_peek()
|
|
1214
|
+
#print( ev)
|
|
1215
|
+
if ev:
|
|
1216
|
+
if ev.type == Gdk.EventType.DELETE:
|
|
1217
|
+
break
|
|
1218
|
+
if ev.type == Gdk.EventType.UNMAP:
|
|
1219
|
+
break
|
|
1220
|
+
if Gtk.main_iteration_do(True):
|
|
1221
|
+
break
|
|
1222
|
+
|
|
1223
|
+
class Unbuffered(object):
|
|
1224
|
+
def __init__(self, stream):
|
|
1225
|
+
self.stream = stream
|
|
1226
|
+
|
|
1227
|
+
def write(self, data):
|
|
1228
|
+
self.stream.write(data)
|
|
1229
|
+
self.stream.flush()
|
|
1230
|
+
|
|
1231
|
+
def writelines(self, datas):
|
|
1232
|
+
self.stream.writelines(datas)
|
|
1233
|
+
self.stream.flush()
|
|
1234
|
+
|
|
1235
|
+
def __getattr__(self, attr):
|
|
1236
|
+
return getattr(self.stream, attr)
|
|
1237
|
+
|
|
1238
|
+
# Time to str and str to time
|
|
1239
|
+
|
|
1240
|
+
def time_n2s(ttt):
|
|
1241
|
+
sss = time.ctime(ttt)
|
|
1242
|
+
return sss
|
|
1243
|
+
|
|
1244
|
+
def time_s2n(sss):
|
|
1245
|
+
rrr = time.strptime(sss)
|
|
1246
|
+
ttt = time.mktime(rrr)
|
|
1247
|
+
return ttt
|
|
1248
|
+
|
|
1249
|
+
def yes_no_cancel(title, message, cancel = True, parent = None):
|
|
1250
|
+
|
|
1251
|
+
#warnings.simplefilter("ignore")
|
|
1252
|
+
dialog = Gtk.Dialog(title,
|
|
1253
|
+
None,
|
|
1254
|
+
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
dialog.set_default_response(Gtk.ResponseType.YES)
|
|
1258
|
+
dialog.set_position(Gtk.WindowPosition.CENTER)
|
|
1259
|
+
dialog.set_transient_for(parent)
|
|
1260
|
+
|
|
1261
|
+
sp = " "
|
|
1262
|
+
label = Gtk.Label(message)
|
|
1263
|
+
label2 = Gtk.Label(sp)
|
|
1264
|
+
label3 = Gtk.Label(sp)
|
|
1265
|
+
label2a = Gtk.Label(sp)
|
|
1266
|
+
label3a = Gtk.Label(sp)
|
|
1102
1267
|
|
|
1268
|
+
hbox = Gtk.HBox()
|
|
1103
1269
|
|
|
1270
|
+
hbox.pack_start(label2, 0, 0, 0)
|
|
1271
|
+
hbox.pack_start(label, 1, 1, 0)
|
|
1272
|
+
hbox.pack_start(label3, 0, 0, 0)
|
|
1273
|
+
|
|
1274
|
+
dialog.vbox.pack_start(label2a, 0, 0, 0)
|
|
1275
|
+
dialog.vbox.pack_start(hbox, 0, 0, 0)
|
|
1276
|
+
dialog.vbox.pack_start(label3a, 0, 0, 0)
|
|
1277
|
+
|
|
1278
|
+
dialog.add_button("_Yes", Gtk.ResponseType.YES)
|
|
1279
|
+
dialog.add_button("_No", Gtk.ResponseType.NO)
|
|
1280
|
+
|
|
1281
|
+
if cancel:
|
|
1282
|
+
dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL)
|
|
1283
|
+
|
|
1284
|
+
dialog.connect("key-press-event", yn_key, cancel)
|
|
1285
|
+
#dialog.connect("key-release-event", yn_key, cancel)
|
|
1286
|
+
#warnings.simplefilter("default")
|
|
1287
|
+
|
|
1288
|
+
dialog.show_all()
|
|
1289
|
+
response = dialog.run()
|
|
1290
|
+
# Convert all responses to cancel
|
|
1291
|
+
if response == Gtk.ResponseType.CANCEL or \
|
|
1292
|
+
response == Gtk.ResponseType.REJECT or \
|
|
1293
|
+
response == Gtk.ResponseType.CLOSE or \
|
|
1294
|
+
response == Gtk.ResponseType.DELETE_EVENT:
|
|
1295
|
+
response = Gtk.ResponseType.CANCEL
|
|
1296
|
+
dialog.destroy()
|
|
1297
|
+
|
|
1298
|
+
return response
|
|
1299
|
+
|
|
1300
|
+
def yn_key(win, event, cancel):
|
|
1301
|
+
#print( event)
|
|
1302
|
+
if event.keyval == Gdk.KEY_y or \
|
|
1303
|
+
event.keyval == Gdk.KEY_Y:
|
|
1304
|
+
win.response(Gtk.ResponseType.YES)
|
|
1305
|
+
|
|
1306
|
+
if event.keyval == Gdk.KEY_n or \
|
|
1307
|
+
event.keyval == Gdk.KEY_N:
|
|
1308
|
+
win.response(Gtk.ResponseType.NO)
|
|
1309
|
+
|
|
1310
|
+
if cancel:
|
|
1311
|
+
if event.keyval == Gdk.KEY_c or \
|
|
1312
|
+
event.keyval == Gdk.KEY_C:
|
|
1313
|
+
win.response(Gtk.ResponseType.CANCEL)
|
|
1314
|
+
|
|
1315
|
+
def opendialog(parent=None):
|
|
1316
|
+
|
|
1317
|
+
# We create an array, so it is passed around by reference
|
|
1318
|
+
fname = [""]
|
|
1319
|
+
|
|
1320
|
+
def makefilter(mask, name):
|
|
1321
|
+
filter = Gtk.FileFilter.new()
|
|
1322
|
+
filter.add_pattern(mask)
|
|
1323
|
+
filter.set_name(name)
|
|
1324
|
+
return filter
|
|
1325
|
+
|
|
1326
|
+
def done_open_fc(win, resp, fname):
|
|
1327
|
+
#print "done_open_fc", win, resp
|
|
1328
|
+
if resp == Gtk.ButtonsType.OK:
|
|
1329
|
+
fname[0] = win.get_filename()
|
|
1330
|
+
if not fname[0]:
|
|
1331
|
+
#print "Must have filename"
|
|
1332
|
+
pass
|
|
1333
|
+
elif os.path.isdir(fname[0]):
|
|
1334
|
+
os.chdir(fname[0])
|
|
1335
|
+
win.set_current_folder(fname[0])
|
|
1336
|
+
return
|
|
1337
|
+
else:
|
|
1338
|
+
#print("OFD", fname[0])
|
|
1339
|
+
pass
|
|
1340
|
+
win.destroy()
|
|
1341
|
+
|
|
1342
|
+
but = "Cancel", Gtk.ButtonsType.CANCEL,\
|
|
1343
|
+
"Open File", Gtk.ButtonsType.OK
|
|
1344
|
+
|
|
1345
|
+
fc = Gtk.FileChooserDialog("Open file", parent, \
|
|
1346
|
+
Gtk.FileChooserAction.OPEN \
|
|
1347
|
+
, but)
|
|
1348
|
+
|
|
1349
|
+
filters = []
|
|
1350
|
+
filters.append(makefilter("*.mup", "MarkUp files (*.py)"))
|
|
1351
|
+
filters.append(makefilter("*.*", "All files (*.*)"))
|
|
1352
|
+
|
|
1353
|
+
if filters:
|
|
1354
|
+
for aa in filters:
|
|
1355
|
+
fc.add_filter(aa)
|
|
1356
|
+
|
|
1357
|
+
fc.set_default_response(Gtk.ButtonsType.OK)
|
|
1358
|
+
fc.set_current_folder(os.getcwd())
|
|
1359
|
+
fc.connect("response", done_open_fc, fname)
|
|
1360
|
+
#fc.connect("current-folder-changed", self.folder_ch )
|
|
1361
|
+
#fc.set_current_name(self.fname)
|
|
1362
|
+
fc.run()
|
|
1363
|
+
#print("OFD2", fname[0])
|
|
1364
|
+
return fname[0]
|
|
1365
|
+
|
|
1366
|
+
def savedialog(resp):
|
|
1367
|
+
|
|
1368
|
+
#print "File dialog"
|
|
1369
|
+
fname = [""] # So it is passed around as a reference
|
|
1370
|
+
|
|
1371
|
+
def makefilter(mask, name):
|
|
1372
|
+
filterx = Gtk.FileFilter.new()
|
|
1373
|
+
filterx.add_pattern(mask)
|
|
1374
|
+
filterx.set_name(name)
|
|
1375
|
+
return filterx
|
|
1376
|
+
|
|
1377
|
+
def done_fc(win, resp, fname):
|
|
1378
|
+
#print( "done_fc", win, resp)
|
|
1379
|
+
if resp == Gtk.ResponseType.OK:
|
|
1380
|
+
fname[0] = win.get_filename()
|
|
1381
|
+
if not fname[0]:
|
|
1382
|
+
print("Must have filename")
|
|
1383
|
+
else:
|
|
1384
|
+
pass
|
|
1385
|
+
win.destroy()
|
|
1386
|
+
|
|
1387
|
+
but = "Cancel", Gtk.ResponseType.CANCEL, \
|
|
1388
|
+
"Save File", Gtk.ResponseType.OK
|
|
1389
|
+
fc = Gtk.FileChooserDialog("Save file as ... ", None,
|
|
1390
|
+
Gtk.FileChooserAction.SAVE, but)
|
|
1391
|
+
|
|
1392
|
+
#fc.set_do_overwrite_confirmation(True)
|
|
1393
|
+
|
|
1394
|
+
filters = []
|
|
1395
|
+
filters.append(makefilter("*.mup", "MarkUp files (*.py)"))
|
|
1396
|
+
filters.append(makefilter("*.*", "All files (*.*)"))
|
|
1397
|
+
|
|
1398
|
+
if filters:
|
|
1399
|
+
for aa in filters:
|
|
1400
|
+
fc.add_filter(aa)
|
|
1401
|
+
|
|
1402
|
+
fc.set_current_name(os.path.basename(fname[0]))
|
|
1403
|
+
fc.set_current_folder(os.path.dirname(fname[0]))
|
|
1404
|
+
fc.set_default_response(Gtk.ResponseType.OK)
|
|
1405
|
+
fc.connect("response", done_fc, fname)
|
|
1406
|
+
fc.run()
|
|
1407
|
+
return fname[0]
|
|
1408
|
+
|
|
1409
|
+
# ------------------------------------------------------------------------
|
|
1410
|
+
|
|
1411
|
+
def leadspace(strx):
|
|
1412
|
+
|
|
1413
|
+
''' Count lead spaces '''
|
|
1414
|
+
|
|
1415
|
+
cnt = 0
|
|
1416
|
+
for aa in range(len(strx)):
|
|
1417
|
+
bb = strx[aa]
|
|
1418
|
+
if bb == " ":
|
|
1419
|
+
cnt += 1
|
|
1420
|
+
elif bb == "\t":
|
|
1421
|
+
cnt += 1
|
|
1422
|
+
elif bb == "\r":
|
|
1423
|
+
cnt += 1
|
|
1424
|
+
elif bb == "\n":
|
|
1425
|
+
cnt += 1
|
|
1426
|
+
else:
|
|
1427
|
+
break
|
|
1428
|
+
return cnt
|
|
1429
|
+
|
|
1430
|
+
def wrapscroll(what):
|
|
1431
|
+
|
|
1432
|
+
scroll2 = Gtk.ScrolledWindow()
|
|
1433
|
+
scroll2.add(what)
|
|
1434
|
+
frame2 = Gtk.Frame()
|
|
1435
|
+
frame2.add(scroll2)
|
|
1436
|
+
return frame2
|
|
1437
|
+
|
|
1438
|
+
if __name__ == '__main__':
|
|
1439
|
+
print("This file was not meant to run directly")
|
|
1440
|
+
|
|
1441
|
+
# EOF
|