Corrected a long-standing error in which ending text with a literal
[xcircuit.git] / lib / python / pagebbox.py
blobc7f9f80febd5a2b48b6f21bef339438effad3802
1 # pagebbox.py
2 #-----------------------------------------------------------
3 # Python script which creates a function "pagebbox(width, height)"
4 # that generates a bounding box of the specified width and height.
6 # Execute this script using menu option "File/Execute Script",
7 # if Python has been compiled in.
9 # Add key 'B' for popuppromt asking for page size. Add button to
10 # "Edit" menu for same. Add Ctrl-B and Ctrl-Shift-B for standard
11 # 8 1/2 x 11 and 11 x 17 page bounding boxes.
12 #-----------------------------------------------------------
14 def newbox(lx, ly, ux, uy):
15 h1=newelement("Polygon")
16 plist = [(lx, ly), (ux, ly), (ux, uy), (lx, uy)]
17 d = {"points": plist}
18 setattr(h1, d)
19 return h1
21 def pagebbox(w, h):
22 h1 = newbox(0, 0, w, h)
23 d = {"style": 512, "color": (255, 165, 0)}
24 setattr(h1, d)
25 return h1
27 def intbbox(s):
28 slist = s.split()
29 slen = len(slist)
30 if slen > 1:
31 w = eval(slist[0])
32 else:
33 w = 8.5
35 if slen == 3:
36 h = eval(slist[2])
37 elif slen == 2:
38 h = eval(slist[1])
39 else:
40 h = 11
42 # note to self: should look at coord style, set default for A4 size
43 # if style is CM, not INCHES.
45 p1 = getpage()
46 oscale = p1['output scale']
48 inchsc = 192
49 h1 = pagebbox(w * oscale * inchsc, h * oscale * inchsc)
50 return h1
52 def promptbbox():
53 popupprompt('Enter width x height:', 'intbbox')
55 def stdbbox():
56 intbbox("8.5 x 11")
58 def bigbbox():
59 intbbox("11 x 17")
61 bind('B', 'promptbbox')
62 bind('Control_b', 'stdbbox')
63 bind('Control_Shift_B', 'bigbbox')
65 newbutton('Edit', 'New BBox (B)', 'promptbbox')
66 # newtool('BBox', 'promptbbox', '', 'bounding box');
68 #-----------------------------------------------------------