One more check on valid display which is known to be in the startup
[xcircuit.git] / lib / python / gettext.py
blob5deda9af9791fdd84cfa09c2a49a3c59531dd742
1 # gettext.py
2 #-----------------------------------------------------------
3 # Python script which creates a function "gettext(filename)"
4 # that reads an ASCII file and turns the contents into a
5 # text label.
6 # Execute this script using menu option "File/Execute Script",
7 # if Python has been compiled in.
9 # Also: defines a function which can be called with a key
10 # macro (gets the filename via popup prompt) and binds it
11 # to key "^G" (ctrl-"g"), and defines a button named "Get Text"
12 # under the "Edit" menu which does the same.
13 #-----------------------------------------------------------
15 def newlabel(x, y, l):
16 h1=newelement("Label")
17 d = {"scale": 1.0, "rotation": 0, "justify": 0, "pin": 0,
18 "position": (x, y), "string": l}
19 setattr(h1, d)
20 return h1
22 def gettext(f):
23 try:
24 fi = open(f, 'r')
25 except IOError:
26 return
27 else:
28 T = getcursor();
29 D = {'Font': 'Times-Roman'}
30 S2 = [D]
31 S = fi.readlines()
32 for X in S:
33 Y = X[0:len(X)-1]
34 D = {'Text': Y}
35 S2.append(D)
36 S2.append('Return')
37 h1 = newlabel(T[0], T[1], S2)
38 return h1
40 def prompttext():
41 filepopup('Enter filename to import:', 'gettext')
43 bind('Control_G', 'prompttext')
44 newbutton('Edit', 'Get Text (^G)', 'prompttext')
46 #-----------------------------------------------------------