pyvguicom 1.0.0__py3-none-any.whl → 1.1.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/pgutils.py CHANGED
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/python
2
2
 
3
- from __future__ import absolute_import
4
- from __future__ import print_function
3
+ # pylint: disable=C0103
4
+ # pylint: disable=C0209
5
+ # pylint: disable=C0321
5
6
 
6
- import os, sys, getopt, signal, string, fnmatch, math, warnings
7
- import random, time, subprocess, traceback, glob, stat
7
+ import os, sys, getopt, string, math
8
+ import random, time, traceback, stat
9
+ import platform
10
+
11
+ #import warmings
8
12
 
9
13
  if sys.version_info.major < 3:
10
14
  pass
@@ -13,188 +17,14 @@ else:
13
17
  if inspect.isbuiltin(time.process_time):
14
18
  time.clock = time.process_time
15
19
 
20
+ ''' General utility fiunctions '''
21
+
16
22
  import gi
17
23
  gi.require_version("Gtk", "3.0")
18
24
  from gi.repository import Gtk
19
25
  from gi.repository import Gdk
20
- from gi.repository import GLib
21
26
  from gi.repository import GObject
22
- from gi.repository import Pango
23
-
24
- # Add the new line twice for more balaced string
25
-
26
- allcr = " " + "\r" + "\n" + \
27
- "\r" + "\n"
28
-
29
- #string.punctuation +
30
-
31
- allstr = " " + \
32
- string.ascii_lowercase + string.ascii_uppercase + \
33
- string.digits
34
-
35
- allasc = string.ascii_lowercase + string.ascii_uppercase + \
36
- string.digits + "_"
37
-
38
- alllett = string.ascii_lowercase + string.ascii_uppercase
39
-
40
-
41
- testmode = 0
42
-
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
- # -----------------------------------------------------------------------
58
- # Sleep just a little, but allow the system to breed
59
-
60
- def usleep2(msec):
61
-
62
- if sys.version_info[0] < 3 or \
63
- (sys.version_info[0] == 3 and sys.version_info[1] < 3):
64
- timefunc = time.clock
65
- else:
66
- timefunc = time.process_time
67
-
68
- got_clock = timefunc() + float(msec) / 1000
69
- #print( got_clock)
70
- while True:
71
- if timefunc() > got_clock:
72
- break
73
- #print ("Sleeping")
74
- Gtk.main_iteration_do(False)
75
-
76
- # -----------------------------------------------------------------------
77
- # Pull up a message box
78
-
79
- def message2(strx, title = "Dialog", parent=None):
80
-
81
- dialog = Gtk.MessageDialog()
82
-
83
- # Close dialog on user response
84
- dialog.add_button("Close", Gtk.ButtonsType.CLOSE)
85
-
86
- if title:
87
- dialog.set_title(title)
88
-
89
- #box = dialog.get_content_area()
90
- #box.add(Gtk.Label(strx))
91
-
92
- dialog.set_markup(strx)
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
-
100
-
101
- def yes_no2(message, title = "Question", parent=None):
102
-
103
- dialog = Gtk.MessageDialog()
104
-
105
- if title:
106
- dialog.set_title(title)
107
-
108
- dialog.add_button("_Yes", Gtk.ResponseType.YES)
109
- dialog.add_button("_No", Gtk.ResponseType.NO)
110
-
111
- dialog.set_markup(message)
112
-
113
- img = Gtk.Image.new_from_stock(Gtk.STOCK_DIALOG_QUESTION, Gtk.IconSize.DIALOG)
114
- dialog.set_image(img)
115
-
116
- if parent:
117
- dialog.set_transient_for(parent)
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()
126
-
127
- return response
128
-
129
- # ------------------------------------------------------------------------
130
- # Do dialog
131
-
132
- def yes_no_cancel2(message, title = "Question", cancel = True, parent=None):
133
-
134
- warnings.simplefilter("ignore")
135
-
136
- dialog = Gtk.Dialog(title,
137
- None,
138
- Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
139
-
140
- dialog.set_default_response(Gtk.ResponseType.YES)
141
- dialog.set_position(Gtk.WindowPosition.CENTER)
142
- #dialog.set_transient_for(pedconfig.conf.pedwin.mywin)
143
-
144
- sp = " "
145
- label = Gtk.Label(message);
146
- label2 = Gtk.Label(sp); label3 = Gtk.Label(sp)
147
- label2a = Gtk.Label(sp); label3a = Gtk.Label(sp)
148
-
149
- hbox = Gtk.HBox() ;
150
-
151
- hbox.pack_start(label2, 0, 0, 0);
152
- hbox.pack_start(label, 1, 1, 0);
153
- hbox.pack_start(label3, 0, 0, 0)
154
-
155
- dialog.vbox.pack_start(label2a, 0, 0, 0);
156
- dialog.vbox.pack_start(hbox, 0, 0, 0)
157
- dialog.vbox.pack_start(label3a, 0, 0, 0);
158
-
159
- dialog.add_button("_Yes", Gtk.ResponseType.YES)
160
- dialog.add_button("_No", Gtk.ResponseType.NO)
161
-
162
- if cancel:
163
- dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL)
164
-
165
- dialog.connect("key-press-event", _yn_key, cancel)
166
- #dialog.connect("key-release-event", _yn_key, cancel)
167
- warnings.simplefilter("default")
168
-
169
- dialog.show_all()
170
- response = dialog.run()
171
-
172
- # Convert all responses to cancel
173
- if response == Gtk.ResponseType.CANCEL or \
174
- response == Gtk.ResponseType.REJECT or \
175
- response == Gtk.ResponseType.CLOSE or \
176
- response == Gtk.ResponseType.DELETE_EVENT:
177
- response = Gtk.ResponseType.CANCEL
178
-
179
- dialog.destroy()
180
-
181
- #print("YNC result:", response);
182
- return response
183
-
184
- def _yn_key(win, event, cancel):
185
- #print event
186
- if event.keyval == Gdk.KEY_y or \
187
- event.keyval == Gdk.KEY_Y:
188
- win.response(Gtk.ResponseType.YES)
189
-
190
- if event.keyval == Gdk.KEY_n or \
191
- event.keyval == Gdk.KEY_N:
192
- win.response(Gtk.ResponseType.NO)
193
-
194
- if cancel:
195
- if event.keyval == Gdk.KEY_c or \
196
- event.keyval == Gdk.KEY_C:
197
- win.response(Gtk.ResponseType.CANCEL)
27
+ from gi.repository import GdkPixbuf
198
28
 
199
29
  # ------------------------------------------------------------------------
200
30
  # Resolve path name
@@ -211,12 +41,6 @@ def respath(fname):
211
41
  print ("Cannot resolve path", fname, sys.exc_info())
212
42
  return None
213
43
 
214
- # ------------------------------------------------------------------------
215
- # Random colors
216
-
217
- def randcol():
218
- return random.randint(0, 255)
219
-
220
44
  # ------------------------------------------------------------------------
221
45
  # Color conversions
222
46
 
@@ -280,7 +104,7 @@ def put_debug2(xstr):
280
104
  print( "Failed on debug output.")
281
105
  print( sys.exc_info())
282
106
 
283
- def put_exception_old(xstr):
107
+ def put_exception(xstr):
284
108
 
285
109
  cumm = xstr + " "
286
110
  a,b,c = sys.exc_info()
@@ -296,7 +120,7 @@ def put_exception_old(xstr):
296
120
  except:
297
121
  print( "Could not print trace stack. ", sys.exc_info())
298
122
 
299
- put_debug2(cumm)
123
+ print(cumm)
300
124
  #syslog.syslog("%s %s %s" % (xstr, a, b))
301
125
 
302
126
  def decode_bits(numx):
@@ -313,13 +137,6 @@ def decode_bits(numx):
313
137
 
314
138
  return retx
315
139
 
316
- def randcolstr(start = 0, endd = 255):
317
- rr = random.randint(start, endd)
318
- gg = random.randint(start, endd)
319
- bb = random.randint(start, endd)
320
- strx = "#%02x%02x%02x" % (rr, gg, bb)
321
- return strx
322
-
323
140
  # ------------------------------------------------------------------------
324
141
  # Remove non printables
325
142
 
@@ -342,7 +159,7 @@ def clean_str2(strx):
342
159
  skip = False
343
160
  for aa in range(len(strx)):
344
161
  if skip:
345
- skip = False;
162
+ skip = False
346
163
  continue
347
164
  if strx[aa] == '\\' and strx[aa+1] == 'r':
348
165
  skip = True
@@ -417,39 +234,6 @@ def serial_ports():
417
234
  return result
418
235
  '''
419
236
 
420
- # ------------------------------------------------------------------------
421
- # Get random str
422
-
423
- def randstr(lenx):
424
-
425
- strx = ""
426
- for aa in range(lenx):
427
- ridx = random.randint(0, len(allstr)-1)
428
- rr = allstr[ridx]
429
- strx += str(rr)
430
-
431
- return strx
432
-
433
- def randasc(lenx):
434
-
435
- strx = ""
436
- for aa in range(lenx):
437
- ridx = random.randint(0, len(allasc)-1)
438
- rr = allasc[ridx]
439
- strx += str(rr)
440
-
441
- return strx
442
-
443
- def randlett(lenx):
444
-
445
- strx = ""
446
- for aa in range(lenx):
447
- ridx = random.randint(0, len(alllett)-1)
448
- rr = alllett[ridx]
449
- strx += str(rr)
450
-
451
- return strx
452
-
453
237
  # ------------------------------------------------------------------------
454
238
  # Convert octal string to integer
455
239
 
@@ -561,7 +345,7 @@ def unescape(strx):
561
345
 
562
346
  chh = strx[pos]
563
347
 
564
- if(chh == '\\'):
348
+ if chh == '\\':
565
349
  #print "backslash", strx[pos:]
566
350
  pos2 = pos + 1; strx2 = ""
567
351
  while True:
@@ -660,58 +444,6 @@ def isfile(fname):
660
444
  return True
661
445
  return False
662
446
 
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
447
  def put_exception2_old(xstr):
716
448
 
717
449
  cumm = xstr + " "
@@ -756,7 +488,7 @@ def untab_str(strx, tabstop = 4):
756
488
  if chh == "\t":
757
489
  # Generate string
758
490
  spaces = tabstop - (cnt % tabstop)
759
- ttt = "";
491
+ ttt = ""
760
492
  for aa in range(spaces):
761
493
  ttt += " "
762
494
  res += ttt
@@ -774,14 +506,12 @@ def ampmstr(bb):
774
506
 
775
507
  dd = "AM"
776
508
  if bb == 12:
777
- dd = "PM"
509
+ dd = "PM"
778
510
  elif bb > 12:
779
511
  bb -= 12
780
512
  dd = "PM"
781
-
782
513
  return "%02d %s" % (bb, dd)
783
514
 
784
-
785
515
  # It's totally optional to do this, you could just manually insert icons
786
516
  # and have them not be themeable, especially if you never expect people
787
517
  # to theme your app.
@@ -790,7 +520,7 @@ def register_stock_icons():
790
520
  ''' This function registers our custom toolbar icons, so they
791
521
  can be themed.
792
522
  '''
793
- items = [('demo-gtk-logo', '_GTK!', 0, 0, '')]
523
+ #items = [('demo-gtk-logo', '_GTK!', 0, 0, '')]
794
524
  # Register our stock items
795
525
  #Gtk.stock_add(items)
796
526
 
@@ -827,10 +557,6 @@ def register_stock_icons():
827
557
  except GObject.GError as error:
828
558
  print('failed to load GTK logo for toolbar')
829
559
 
830
-
831
- if __name__ == '__main__':
832
- print("This file was not meant to run directly")
833
-
834
560
  # ------------------------------------------------------------------------
835
561
  # Let the higher level deal with errors.
836
562
 
@@ -875,8 +601,8 @@ def readfile(strx, sep = None):
875
601
  text = []
876
602
  for aa in text2:
877
603
  #print("'%s\n" % aa)
878
- bb = aa.replace("\r", "");
879
- cc = bb.replace("\n", "");
604
+ bb = aa.replace("\r", "")
605
+ cc = bb.replace("\n", "")
880
606
  text.append(cc)
881
607
  #text2 = []
882
608
 
@@ -936,116 +662,39 @@ class Config:
936
662
  self.optarr[bb][3]()
937
663
  return args
938
664
 
939
- # ------------------------------------------------------------------------
940
-
941
- def yes_no_cancel(title, message, cancel = True):
942
-
943
- warnings.simplefilter("ignore")
944
-
945
- dialog = Gtk.Dialog(title,
946
- None,
947
- Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT)
948
-
949
- dialog.set_default_response(Gtk.ResponseType.YES)
950
- dialog.set_position(Gtk.WindowPosition.CENTER)
951
- #dialog.set_transient_for(pedconfig.conf.pedwin.mywin)
952
-
953
- sp = " "
954
- label = Gtk.Label(message);
955
- label2 = Gtk.Label(sp); label3 = Gtk.Label(sp)
956
- label2a = Gtk.Label(sp); label3a = Gtk.Label(sp)
957
-
958
- hbox = Gtk.HBox() ;
959
-
960
- hbox.pack_start(label2, 0, 0, 0);
961
- hbox.pack_start(label, 1, 1, 0);
962
- hbox.pack_start(label3, 0, 0, 0)
665
+ def about(progname, verstr = "1.0.0", imgfile = "icon.png"):
963
666
 
964
- dialog.vbox.pack_start(label2a, 0, 0, 0);
965
- dialog.vbox.pack_start(hbox, 0, 0, 0)
966
- dialog.vbox.pack_start(label3a, 0, 0, 0);
967
-
968
- dialog.add_button("_Yes", Gtk.ResponseType.YES)
969
- dialog.add_button("_No", Gtk.ResponseType.NO)
970
-
971
- if cancel:
972
- dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL)
973
-
974
- dialog.connect("key-press-event", _yn_key, cancel)
975
- #dialog.connect("key-release-event", _yn_key, cancel)
976
- warnings.simplefilter("default")
977
-
978
- dialog.show_all()
979
- response = dialog.run()
980
-
981
- # Convert all responses to cancel
982
- if response == Gtk.ResponseType.CANCEL or \
983
- response == Gtk.ResponseType.REJECT or \
984
- response == Gtk.ResponseType.CLOSE or \
985
- response == Gtk.ResponseType.DELETE_EVENT:
986
- response = Gtk.ResponseType.CANCEL
987
-
988
- dialog.destroy()
989
-
990
- #print("YNC result:", response);
991
- return response
992
-
993
- def _yn_key(win, event, cancel):
994
- #print event
995
- if event.keyval == Gdk.KEY_y or \
996
- event.keyval == Gdk.KEY_Y:
997
- win.response(Gtk.ResponseType.YES)
998
-
999
- if event.keyval == Gdk.KEY_n or \
1000
- event.keyval == Gdk.KEY_N:
1001
- win.response(Gtk.ResponseType.NO)
1002
-
1003
- if cancel:
1004
- if event.keyval == Gdk.KEY_c or \
1005
- event.keyval == Gdk.KEY_C:
1006
- win.response(Gtk.ResponseType.CANCEL)
1007
-
1008
- # ------------------------------------------------------------------------
1009
- # Show About dialog:
1010
-
1011
- import platform
1012
-
1013
- def about(self2):
667
+ ''' Show About dialog: '''
1014
668
 
1015
669
  dialog = Gtk.AboutDialog()
1016
- dialog.set_name(pedconfig.conf.progname + " - Python Editor ")
670
+ dialog.set_name(progname)
1017
671
 
1018
- dialog.set_version(str(pedconfig.conf.version));
672
+ dialog.set_version(verstr)
1019
673
  gver = (Gtk.get_major_version(), \
1020
674
  Gtk.get_minor_version(), \
1021
675
  Gtk.get_micro_version())
1022
676
 
1023
677
  dialog.set_position(Gtk.WindowPosition.CENTER)
1024
- dialog.set_transient_for(pedconfig.conf.pedwin.mywin)
678
+ #dialog.set_transient_for(pedconfig.conf.pedwin.mywin)
1025
679
 
1026
680
  #"\nRunning PyGObject %d.%d.%d" % GObject.pygobject_version +\
1027
681
 
1028
- ddd = os.path.join(os.path.dirname(__file__), "../")
682
+ ddd = os.path.join(os.path.dirname(__file__))
1029
683
 
1030
684
  # GLib.pyglib_version
1031
685
  vvv = gi.version_info
1032
- comm = "Python based easily configurable editor\n"\
1033
- "with time accounting module, spell "\
1034
- "check \n and macro recording.\n"\
1035
- "\nRunning PyGtk %d.%d.%d" % vvv +\
1036
- "\non GTK %d.%d.%d\n" % gver +\
686
+ comm = \
687
+ "Running PyGtk %d.%d.%d" % vvv +\
688
+ "\non GTK %d.%d.%d" % gver +\
1037
689
  "\nRunning Python %s" % platform.python_version() +\
1038
- "\non %s %s\n" % (platform.system(), platform.release()) +\
1039
- "\nPyedPro Build Date: %s\n" % pedconfig.conf.build_date +\
1040
- "Exe Path:\n%s\n" % os.path.realpath(ddd)
690
+ "\non %s %s" % (platform.system(), platform.release()) +\
691
+ "\nExe Path:\n%s" % os.path.realpath(ddd)
1041
692
 
1042
- dialog.set_comments(comm);
1043
- dialog.set_copyright(pedconfig.conf.progname + " Created by Peter Glen.\n"
693
+ dialog.set_comments(comm)
694
+ dialog.set_copyright(progname + " Created by Peter Glen.\n"
1044
695
  "Project is in the Public Domain.")
1045
- dialog.set_program_name(pedconfig.conf.progname)
1046
- img_dir = os.path.join(os.path.dirname(__file__), 'images')
1047
- #img_path = os.path.join(img_dir, 'gtk-logo-rgb.gif')
1048
- img_path = os.path.join(img_dir, 'pyedpro.png')
696
+ dialog.set_program_name(progname)
697
+ img_path = os.path.join(os.path.dirname(__file__), imgfile)
1049
698
 
1050
699
  try:
1051
700
  pixbuf = GdkPixbuf.Pixbuf.new_from_file(img_path)
@@ -1053,18 +702,18 @@ def about(self2):
1053
702
  dialog.set_logo(pixbuf)
1054
703
 
1055
704
  except:
1056
- print("Cannot load logo for about dialog", img_path);
705
+ print("Cannot load logo for about dialog", img_path)
1057
706
  print(sys.exc_info())
1058
707
 
1059
708
  #dialog.set_website("")
1060
709
 
1061
710
  ## Close dialog on user response
1062
711
  dialog.connect ("response", lambda d, r: d.destroy())
1063
- dialog.connect("key-press-event", about_key)
712
+ dialog.connect("key-press-event", _about_key)
1064
713
 
1065
714
  dialog.show()
1066
715
 
1067
- def about_key(win, event):
716
+ def _about_key(win, event):
1068
717
  #print "about_key", event
1069
718
  if event.type == Gdk.EventType.KEY_PRESS:
1070
719
  if event.keyval == Gdk.KEY_x or event.keyval == Gdk.KEY_X:
@@ -1073,31 +722,368 @@ def about_key(win, event):
1073
722
 
1074
723
  # ------------------------------------------------------------------------
1075
724
  # Show a regular message:
725
+ #
726
+ #def message3(strx, title = None):
727
+ #
728
+ # #print("called: message()", strx)
729
+ #
730
+ # icon = Gtk.STOCK_INFO
731
+ # dialog = Gtk.MessageDialog(buttons=Gtk.ButtonsType.CLOSE,
732
+ # message_type=Gtk.MessageType.INFO)
733
+ # dialog.props.text = strx
734
+ # #dialog.set_transient_for()
735
+ # if title:
736
+ # dialog.set_title(title)
737
+ # else:
738
+ # dialog.set_title("PyEdPro")
739
+ # dialog.set_position(Gtk.WindowPosition.CENTER)
740
+ # # Close dialog on user response
741
+ # dialog.connect("response", lambda d, r: d.destroy())
742
+ # dialog.show()
743
+ # dialog.run()
744
+
745
+ # -----------------------------------------------------------------------
746
+ # Call func with all processes, func called with stat as its argument
747
+ # Function may return True to stop iteration
748
+
749
+ def withps(func, opt = None):
750
+
751
+ ret = False
752
+ dl = os.listdir("/proc")
753
+ for aa in dl:
754
+ fname = "/proc/" + aa + "/stat"
755
+ if os.path.isfile(fname):
756
+ ff = open(fname, "r").read().split()
757
+ ret = func(ff, opt)
758
+ if ret:
759
+ break
760
+ return ret
761
+
762
+ # ------------------------------------------------------------------------
763
+ # Find
764
+
765
+ def find(self):
766
+
767
+ head = "Find in text"
768
+
769
+ dialog = Gtk.Dialog(head,
770
+ None,
771
+ Gtk.DIALOG_MODAL | Gtk.DIALOG_DESTROY_WITH_PARENT,
772
+ (Gtk.STOCK_CANCEL, Gtk.RESPONSE_REJECT,
773
+ Gtk.STOCK_OK, Gtk.RESPONSE_ACCEPT))
774
+ dialog.set_default_response(Gtk.RESPONSE_ACCEPT)
775
+
776
+ try:
777
+ dialog.set_icon_from_file("epub.png")
778
+ except:
779
+ print ("Cannot load find dialog icon", sys.exc_info())
1076
780
 
1077
- def message(strx, title = None):
781
+ self.dialog = dialog
1078
782
 
1079
- #print("called: message()", strx)
783
+ label3 = Gtk.Label(" "); label4 = Gtk.Label(" ")
784
+ label5 = Gtk.Label(" "); label6 = Gtk.Label(" ")
785
+ label7 = Gtk.Label(" "); label8 = Gtk.Label(" ")
1080
786
 
1081
- icon = Gtk.STOCK_INFO
1082
- dialog = Gtk.MessageDialog(buttons=Gtk.ButtonsType.CLOSE,
1083
- message_type=Gtk.MessageType.INFO)
787
+ #warmings.simplefilter("ignore")
788
+ entry = Gtk.Entry()
789
+ #warmings.simplefilter("default")
790
+ entry.set_text(self.oldfind)
1084
791
 
1085
- dialog.props.text = strx
792
+ entry.set_activates_default(True)
1086
793
 
1087
- #dialog.set_transient_for()
794
+ dialog.vbox.pack_start(label4)
1088
795
 
1089
- if title:
1090
- dialog.set_title(title)
796
+ hbox2 = Gtk.HBox()
797
+ hbox2.pack_start(label6, False)
798
+ hbox2.pack_start(entry)
799
+ hbox2.pack_start(label7, False)
800
+
801
+ dialog.vbox.pack_start(hbox2)
802
+
803
+ dialog.checkbox = Gtk.CheckButton("Search _Backwards")
804
+ dialog.checkbox2 = Gtk.CheckButton("Case In_sensitive")
805
+ dialog.vbox.pack_start(label5)
806
+
807
+ hbox = Gtk.HBox()
808
+ #hbox.pack_start(label1); hbox.pack_start(dialog.checkbox)
809
+ #hbox.pack_start(label2); hbox.pack_start(dialog.checkbox2)
810
+ hbox.pack_start(label3)
811
+ dialog.vbox.pack_start(hbox)
812
+ dialog.vbox.pack_start(label8)
813
+
814
+ label32 = Gtk.Label(" ")
815
+ hbox4 = Gtk.HBox()
816
+
817
+ hbox4.pack_start(label32)
818
+ dialog.vbox.pack_start(hbox4)
819
+
820
+ dialog.show_all()
821
+ response = dialog.run()
822
+ self.srctxt = entry.get_text()
823
+
824
+ dialog.destroy()
825
+
826
+ if response != Gtk.RESPONSE_ACCEPT:
827
+ return None
828
+
829
+ return self.srctxt, dialog.checkbox.get_active(), \
830
+ dialog.checkbox2.get_active()
831
+
832
+ disp = Gdk.Display.get_default()
833
+ scr = disp.get_default_screen()
834
+
835
+ #print( "num_mon", scr.get_n_monitors() )
836
+ #for aa in range(scr.get_n_monitors()):
837
+ # print( "mon", aa, scr.get_monitor_geometry(aa);)
838
+
839
+ # ------------------------------------------------------------------------
840
+ # Get current screen (monitor) width and height
841
+
842
+ def get_screen_wh():
843
+
844
+ ptr = disp.get_pointer()
845
+ mon = scr.get_monitor_at_point(ptr[1], ptr[2])
846
+ geo = scr.get_monitor_geometry(mon)
847
+ www = geo.width; hhh = geo.height
848
+ if www == 0 or hhh == 0:
849
+ www = Gdk.get_screen_width()
850
+ hhh = Gdk.get_screen_height()
851
+ return www, hhh
852
+
853
+ # ------------------------------------------------------------------------
854
+ # Get current screen (monitor) upper left corner xx / yy
855
+
856
+ def get_screen_xy():
857
+
858
+ ptr = disp.get_pointer()
859
+ mon = scr.get_monitor_at_point(ptr[1], ptr[2])
860
+ geo = scr.get_monitor_geometry(mon)
861
+ return geo.x, geo.y
862
+
863
+ # ------------------------------------------------------------------------
864
+ # Print( an exception as the system would print it)
865
+
866
+ def print_exception(xstr):
867
+ cumm = xstr + " "
868
+ a,b,c = sys.exc_info()
869
+ if a != None:
870
+ cumm += str(a) + " " + str(b) + "\n"
871
+ try:
872
+ #cumm += str(traceback.format_tb(c, 10))
873
+ ttt = traceback.extract_tb(c)
874
+ for aa in ttt:
875
+ cumm += "File: " + os.path.basename(aa[0]) + \
876
+ " Line: " + str(aa[1]) + "\n" + \
877
+ " Context: " + aa[2] + " -> " + aa[3] + "\n"
878
+ except:
879
+ print("Could not print trace stack. ", sys.exc_info())
880
+ print( cumm)
881
+
882
+ # -----------------------------------------------------------------------
883
+ # Sleep just a little, but allow the system to breed
884
+
885
+ def usleep(msec):
886
+
887
+ if sys.version_info[0] < 3 or \
888
+ (sys.version_info[0] == 3 and sys.version_info[1] < 3):
889
+ timefunc = time.clock
1091
890
  else:
1092
- dialog.set_title("PyEdPro")
891
+ timefunc = time.process_time
1093
892
 
1094
- dialog.set_position(Gtk.WindowPosition.CENTER)
893
+ got_clock = timefunc() + float(msec) / 1000
894
+ #print( got_clock)
895
+ while True:
896
+ if timefunc() > got_clock:
897
+ break
898
+ #print ("Sleeping")
899
+ Gtk.main_iteration_do(False)
1095
900
 
1096
- # Close dialog on user response
1097
- dialog.connect("response", lambda d, r: d.destroy())
1098
- dialog.show()
1099
- dialog.run()
901
+ # ------------------------------------------------------------------------
902
+ # Create temporary file, return name. Empty string ("") if error.
1100
903
 
1101
- # EOF
904
+ def tmpname(indir, template):
905
+
906
+ fname = ""
907
+ if not os.access(indir, os.W_OK):
908
+ print( "Cannot access ", indir)
909
+ return fname
910
+
911
+ cnt = 1
912
+ while True:
913
+ tmp = indir + "/" + template + "_" + str(cnt)
914
+ if not os.access(tmp, os.R_OK):
915
+ fname = tmp
916
+ break
917
+ # Safety valve
918
+ if cnt > 10000:
919
+ break
920
+ return fname
921
+
922
+ # ------------------------------------------------------------------------
923
+ # Execute man loop
924
+
925
+ def mainloop():
926
+ while True:
927
+ ev = Gdk.event_peek()
928
+ #print( ev)
929
+ if ev:
930
+ if ev.type == Gdk.EventType.DELETE:
931
+ break
932
+ if ev.type == Gdk.EventType.UNMAP:
933
+ break
934
+ if Gtk.main_iteration_do(True):
935
+ break
936
+
937
+ class Unbuffered(object):
938
+ def __init__(self, stream):
939
+ self.stream = stream
940
+
941
+ def write(self, data):
942
+ self.stream.write(data)
943
+ self.stream.flush()
944
+
945
+ def writelines(self, datas):
946
+ self.stream.writelines(datas)
947
+ self.stream.flush()
1102
948
 
949
+ def __getattr__(self, attr):
950
+ return getattr(self.stream, attr)
1103
951
 
952
+ # Time to str and str to time
953
+
954
+ def time_n2s(ttt):
955
+ sss = time.ctime(ttt)
956
+ return sss
957
+
958
+ def time_s2n(sss):
959
+ rrr = time.strptime(sss)
960
+ ttt = time.mktime(rrr)
961
+ return ttt
962
+
963
+ def opendialog(parent=None):
964
+
965
+ # We create an array, so it is passed around by reference
966
+ fname = [""]
967
+
968
+ def makefilter(mask, name):
969
+ filter = Gtk.FileFilter.new()
970
+ filter.add_pattern(mask)
971
+ filter.set_name(name)
972
+ return filter
973
+
974
+ def done_open_fc(win, resp, fname):
975
+ #print "done_open_fc", win, resp
976
+ if resp == Gtk.ButtonsType.OK:
977
+ fname[0] = win.get_filename()
978
+ if not fname[0]:
979
+ #print "Must have filename"
980
+ pass
981
+ elif os.path.isdir(fname[0]):
982
+ os.chdir(fname[0])
983
+ win.set_current_folder(fname[0])
984
+ return
985
+ else:
986
+ #print("OFD", fname[0])
987
+ pass
988
+ win.destroy()
989
+
990
+ but = "Cancel", Gtk.ButtonsType.CANCEL,\
991
+ "Open File", Gtk.ButtonsType.OK
992
+
993
+ fc = Gtk.FileChooserDialog("Open file", parent, \
994
+ Gtk.FileChooserAction.OPEN \
995
+ , but)
996
+
997
+ filters = []
998
+ filters.append(makefilter("*.mup", "MarkUp files (*.py)"))
999
+ filters.append(makefilter("*.*", "All files (*.*)"))
1000
+
1001
+ if filters:
1002
+ for aa in filters:
1003
+ fc.add_filter(aa)
1004
+
1005
+ fc.set_default_response(Gtk.ButtonsType.OK)
1006
+ fc.set_current_folder(os.getcwd())
1007
+ fc.connect("response", done_open_fc, fname)
1008
+ #fc.connect("current-folder-changed", self.folder_ch )
1009
+ #fc.set_current_name(self.fname)
1010
+ fc.run()
1011
+ #print("OFD2", fname[0])
1012
+ return fname[0]
1013
+
1014
+ def savedialog(resp):
1015
+
1016
+ #print "File dialog"
1017
+ fname = [""] # So it is passed around as a reference
1018
+
1019
+ def makefilter(mask, name):
1020
+ filterx = Gtk.FileFilter.new()
1021
+ filterx.add_pattern(mask)
1022
+ filterx.set_name(name)
1023
+ return filterx
1024
+
1025
+ def done_fc(win, resp, fname):
1026
+ #print( "done_fc", win, resp)
1027
+ if resp == Gtk.ResponseType.OK:
1028
+ fname[0] = win.get_filename()
1029
+ if not fname[0]:
1030
+ print("Must have filename")
1031
+ else:
1032
+ pass
1033
+ win.destroy()
1034
+
1035
+ but = "Cancel", Gtk.ResponseType.CANCEL, \
1036
+ "Save File", Gtk.ResponseType.OK
1037
+ fc = Gtk.FileChooserDialog("Save file as ... ", None,
1038
+ Gtk.FileChooserAction.SAVE, but)
1039
+
1040
+ #fc.set_do_overwrite_confirmation(True)
1041
+
1042
+ filters = []
1043
+ filters.append(makefilter("*.mup", "MarkUp files (*.py)"))
1044
+ filters.append(makefilter("*.*", "All files (*.*)"))
1045
+
1046
+ if filters:
1047
+ for aa in filters:
1048
+ fc.add_filter(aa)
1049
+
1050
+ fc.set_current_name(os.path.basename(fname[0]))
1051
+ fc.set_current_folder(os.path.dirname(fname[0]))
1052
+ fc.set_default_response(Gtk.ResponseType.OK)
1053
+ fc.connect("response", done_fc, fname)
1054
+ fc.run()
1055
+ return fname[0]
1056
+
1057
+ # ------------------------------------------------------------------------
1058
+
1059
+ def leadspace(strx):
1060
+
1061
+ ''' Count lead spaces '''
1062
+
1063
+ cnt = 0
1064
+ for aa in range(len(strx)):
1065
+ bb = strx[aa]
1066
+ if bb == " ":
1067
+ cnt += 1
1068
+ elif bb == "\t":
1069
+ cnt += 1
1070
+ elif bb == "\r":
1071
+ cnt += 1
1072
+ elif bb == "\n":
1073
+ cnt += 1
1074
+ else:
1075
+ break
1076
+ return cnt
1077
+
1078
+ def wrapscroll(what):
1079
+
1080
+ scroll2 = Gtk.ScrolledWindow()
1081
+ scroll2.add(what)
1082
+ frame2 = Gtk.Frame()
1083
+ frame2.add(scroll2)
1084
+ return frame2
1085
+
1086
+ if __name__ == '__main__':
1087
+ print("This file was not meant to run directly")
1088
+
1089
+ # EOF