oskusalerma / blyte

Screenplay writing program

This URL has Read+Write access

blyte / config.py
ade68370 » oskusalerma 2003-11-15 Initial import. 1 # see fileformat.txt for more detailed information about the various
2 # defines found here.
3
d6c8025c » oskusalerma 2003-11-15 Implement file open / save ... 4 from error import *
33929cc0 » oskusalerma 2004-07-15 Add misc.isUnix / isWindows... 5 import misc
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 6 import mypickle
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 7 import pml
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 8 import screenplay
b0065668 » oskusalerma 2004-07-04 Allow other font sizes besi... 9 import util
10
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 11 import copy
34826d74 » oskusalerma 2003-11-26 Add support for multiple op... 12 from wxPython.wx import *
d6c8025c » oskusalerma 2003-11-15 Implement file open / save ... 13
ade68370 » oskusalerma 2003-11-15 Initial import. 14 # mapping from character to linebreak
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 15 _char2lb = {
16 '>' : screenplay.LB_SPACE,
17 '+' : screenplay.LB_SPACE2,
18 '&' : screenplay.LB_NONE,
19 '|' : screenplay.LB_FORCED,
20 '.' : screenplay.LB_LAST
ade68370 » oskusalerma 2003-11-15 Initial import. 21 }
22
83ff6b62 » oskusalerma 2004-07-21 Add copying selection to ex... 23 # reverse to above
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 24 _lb2char = {}
83ff6b62 » oskusalerma 2004-07-21 Add copying selection to ex... 25
26 # what string each linebreak type should be mapped to.
27 _lb2str = {
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 28 screenplay.LB_SPACE : " ",
29 screenplay.LB_SPACE2 : " ",
30 screenplay.LB_NONE : "",
31 screenplay.LB_FORCED : "\n",
32 screenplay.LB_LAST : "\n"
83ff6b62 » oskusalerma 2004-07-21 Add copying selection to ex... 33 }
ade68370 » oskusalerma 2003-11-15 Initial import. 34
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 35 # contains a TypeInfo for each element type
36 _ti = []
ade68370 » oskusalerma 2003-11-15 Initial import. 37
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 38 # mapping from character to TypeInfo
39 _char2ti = {}
40
41 # mapping from line type to TypeInfo
42 _lt2ti = {}
43
44 # mapping from element name to TypeInfo
45 _name2ti = {}
ade68370 » oskusalerma 2003-11-15 Initial import. 46
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 47 # page break indicators. do not change these values as they're saved to
48 # the config file.
0770ec04 » oskusalerma 2004-05-01 Add almost fully working pa... 49 PBI_NONE = 0
50 PBI_REAL = 1
51 PBI_REAL_AND_UNADJ = 2
52
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 53 # for range checking above value
54 PBI_FIRST, PBI_LAST = PBI_NONE, PBI_REAL_AND_UNADJ
55
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 56 # constants for identifying PDFFontInfos
57 PDF_FONT_NORMAL = "Normal"
58 PDF_FONT_BOLD = "Bold"
59 PDF_FONT_ITALIC = "Italic"
60 PDF_FONT_BOLD_ITALIC = "Bold-Italic"
83ff6b62 » oskusalerma 2004-07-21 Add copying selection to ex... 61
62 # construct reverse lookup tables
63
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 64 for k, v in _char2lb.items():
65 _lb2char[v] = k
83ff6b62 » oskusalerma 2004-07-21 Add copying selection to ex... 66
d3bda29f » oskusalerma 2004-07-29 Small fixes for things foun... 67 del k, v
83ff6b62 » oskusalerma 2004-07-21 Add copying selection to ex... 68
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 69 # non-changing information about an element type
70 class TypeInfo:
71 def __init__(self, lt, char, name):
72
73 # line type, e.g. screenplay.ACTION
74 self.lt = lt
75
76 # character used in saved scripts, e.g. "."
77 self.char = char
78
79 # textual name, e.g. "Action"
80 self.name = name
81
82 # text type
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 83 class TextType:
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 84 cvars = None
85
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 86 def __init__(self):
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 87 if not self.__class__.cvars:
88 v = self.__class__.cvars = mypickle.Vars()
89
90 v.addBool("isCaps", False, "AllCaps")
91 v.addBool("isBold", False, "Bold")
92 v.addBool("isItalic", False, "Italic")
93 v.addBool("isUnderlined", False, "Underlined")
94
95 self.__class__.cvars.setDefaults(self)
96
97 def save(self, prefix):
98 return self.cvars.save(prefix, self)
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 99
12993695 » oskusalerma 2004-08-01 Add support for loading con... 100 def load(self, vals, prefix):
101 self.cvars.load(vals, prefix, self)
102
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 103 # script-specific information about an element type
ade68370 » oskusalerma 2003-11-15 Initial import. 104 class Type:
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 105 cvars = None
106
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 107 def __init__(self, lt):
108
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 109 # line type
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 110 self.lt = lt
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 111
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 112 # pointer to TypeInfo
113 self.ti = lt2ti(lt)
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 114
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 115 # text types, one for screen and one for export
116 self.screen = TextType()
117 self.export = TextType()
390d096d » oskusalerma 2004-08-29 Don't try to auto-generate ... 118
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 119 if not self.__class__.cvars:
120 v = self.__class__.cvars = mypickle.Vars()
ade68370 » oskusalerma 2003-11-15 Initial import. 121
0c5215b7 » oskusalerma 2004-08-21 Add intra-line spacing supp... 122 # these two are how much empty space to insert a) before the
123 # element b) between the element's lines, in units of line /
124 # 10.
125 v.addInt("beforeSpacing", 0, "BeforeSpacing", 0, 50)
126 v.addInt("intraSpacing", 0, "IntraSpacing", 0, 20)
127
12993695 » oskusalerma 2004-08-01 Add support for loading con... 128 v.addInt("indent", 0, "Indent", 0, 80)
129 v.addInt("width", 5, "Width", 5, 80)
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 130
12993695 » oskusalerma 2004-08-01 Add support for loading con... 131 v.makeDicts()
132
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 133 self.__class__.cvars.setDefaults(self)
134
135 def save(self, prefix):
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 136 prefix += "%s/" % self.ti.name
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 137
138 s = self.cvars.save(prefix, self)
139 s += self.screen.save(prefix + "Screen/")
140 s += self.export.save(prefix + "Export/")
141
142 return s
d299871b » oskusalerma 2004-05-11 Support per-element style d... 143
12993695 » oskusalerma 2004-08-01 Add support for loading con... 144 def load(self, vals, prefix):
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 145 prefix += "%s/" % self.ti.name
12993695 » oskusalerma 2004-08-01 Add support for loading con... 146
147 self.cvars.load(vals, prefix, self)
148 self.screen.load(vals, prefix + "Screen/")
149 self.export.load(vals, prefix + "Export/")
150
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 151 # global information about an element type
152 class TypeGlobal:
153 cvars = None
154
155 def __init__(self, lt):
156
157 # line type
158 self.lt = lt
159
160 # pointer to TypeInfo
161 self.ti = lt2ti(lt)
162
163 if not self.__class__.cvars:
164 v = self.__class__.cvars = mypickle.Vars()
165
166 # what type of element to insert when user presses enter or tab.
167 v.addElemName("newTypeEnter", screenplay.ACTION, "NewTypeEnter")
168 v.addElemName("newTypeTab", screenplay.ACTION, "NewTypeTab")
169
170 # what element to switch to when user hits tab / shift-tab.
171 v.addElemName("nextTypeTab", screenplay.ACTION, "NextTypeTab")
172 v.addElemName("prevTypeTab", screenplay.ACTION, "PrevTypeTab")
173
174 v.makeDicts()
175
176 self.__class__.cvars.setDefaults(self)
177
178 def save(self, prefix):
179 prefix += "%s/" % self.ti.name
180
181 return self.cvars.save(prefix, self)
182
183 def load(self, vals, prefix):
184 prefix += "%s/" % self.ti.name
185
186 self.cvars.load(vals, prefix, self)
187
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 188 # command (an action in the main program)
189 class Command:
190 cvars = None
191
192 def __init__(self, name, desc, defKeys = [], isMovement = False,
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 193 isFixed = False, isMenu = False):
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 194 # name, e.g. "MoveLeft"
195 self.name = name
196
197 # textual description
198 self.desc = desc
199
200 # default keys (list of serialized util.Key objects (ints))
201 self.defKeys = defKeys
202
203 # is this a movement command
204 self.isMovement = isMovement
205
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 206 # some commands & their keys (Tab, Enter, Quit, etc) are fixed and
207 # can't be changed
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 208 self.isFixed = isFixed
209
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 210 # is this a menu item
211 self.isMenu = isMenu
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 212
213 if not self.__class__.cvars:
214 v = self.__class__.cvars = mypickle.Vars()
215
216 v.addList("keys", [], "Keys",
217 mypickle.IntVar("", 0, "", 0, 9223372036854775808L))
218
219 v.makeDicts()
220
221 # this is not actually needed but let's keep it for consistency
222 self.__class__.cvars.setDefaults(self)
223
224 self.keys = copy.deepcopy(self.defKeys)
225
226 def save(self, prefix):
227 if self.isFixed:
228 return ""
229
230 prefix += "%s/" % self.name
231
232 if len(self.keys) > 0:
233 return self.cvars.save(prefix, self)
234 else:
235 self.keys.append(0)
236 s = self.cvars.save(prefix, self)
237 self.keys = []
238
239 return s
240
241 def load(self, vals, prefix):
242 if self.isFixed:
243 return
244
245 prefix += "%s/" % self.name
246
247 tmp = copy.deepcopy(self.keys)
248 self.cvars.load(vals, prefix, self)
249
250 if len(self.keys) == 0:
251 # we have a new command in the program not found in the old
252 # config file
253 self.keys = tmp
254 elif self.keys[0] == 0:
255 self.keys = []
256
257 # weed out invalid bindings
258 tmp2 = self.keys
259 self.keys = []
260
261 for k in tmp2:
262 k2 = util.Key.fromInt(k)
263 if not k2.isValidInputChar():
264 self.keys.append(k)
265
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 266 # information about one screen font
267 class FontInfo:
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 268 def __init__(self):
269 self.font = None
270
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 271 # font width and height
272 self.fx = 1
273 self.fy = 1
274
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 275 # information about one PDF font
276 class PDFFontInfo:
277 cvars = None
278
9dcfcaba » oskusalerma 2006-04-03 Disallow more characters fr... 279 # list of characters not allowed in pdfNames
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 280 invalidChars = None
281
282 def __init__(self, name, style):
283 # our name for the font (one of the PDF_FONT_* constants)
284 self.name = name
285
286 # 2 lowest bits of pml.TextOp.flags
287 self.style = style
288
289 if not self.__class__.cvars:
290 v = self.__class__.cvars = mypickle.Vars()
291
292 # name to use in generated PDF file (CourierNew, MyFontBold,
293 # etc.). if empty, use the default PDF Courier font.
294 v.addStrLatin1("pdfName", "", "Name")
295
296 # filename for the font to embed, or empty meaning don't
297 # embed.
298 v.addStrUnicode("filename", u"", "Filename")
299
300 v.makeDicts()
301
302 tmp = ""
303
304 for i in range(256):
9dcfcaba » oskusalerma 2006-04-03 Disallow more characters fr... 305 # the OpenType font specification 1.4, of all places,
306 # contains the most detailed discussion of characters
307 # allowed in Postscript font names, in the section on
308 # 'name' tables, describing name ID 6 (=Postscript name).
309 if (i <= 32) or (i >= 127) or chr(i) in (
310 "[", "]", "(", ")", "{", "}", "<", ">", "/", "%"):
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 311 tmp += chr(i)
312
313 self.__class__.invalidChars = tmp
314
315 self.__class__.cvars.setDefaults(self)
316
317 def save(self, prefix):
318 prefix += "%s/" % self.name
319
320 return self.cvars.save(prefix, self)
321
322 def load(self, vals, prefix):
323 prefix += "%s/" % self.name
324
325 self.cvars.load(vals, prefix, self)
326
327 # fix up invalid values.
328 def refresh(self):
329 self.pdfName = util.deleteChars(self.pdfName, self.invalidChars)
330
340546ae » oskusalerma 2006-04-02 To avoid confused users not... 331 # to avoid confused users not understanding why their embedded
332 # font isn't working, put in an arbitrary font name if needed
333 if self.filename and not self.pdfName:
334 self.pdfName = "SampleFontName"
335
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 336 # per-script config, each script has its own one of these.
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 337 class Config:
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 338 cvars = None
339
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 340 def __init__(self):
ade68370 » oskusalerma 2003-11-15 Initial import. 341
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 342 if not self.__class__.cvars:
343 self.setupVars()
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 344
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 345 self.__class__.cvars.setDefaults(self)
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 346
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 347 # type configs, key = line type, value = Type
348 self.types = { }
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 349
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 350 # element types
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 351 t = Type(screenplay.SCENE)
0c5215b7 » oskusalerma 2004-08-21 Add intra-line spacing supp... 352 t.beforeSpacing = 10
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 353 t.indent = 0
354 t.width = 60
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 355 t.screen.isCaps = True
356 t.screen.isBold = True
357 t.export.isCaps = True
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 358 self.types[t.lt] = t
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 359
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 360 t = Type(screenplay.ACTION)
0c5215b7 » oskusalerma 2004-08-21 Add intra-line spacing supp... 361 t.beforeSpacing = 10
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 362 t.indent = 0
363 t.width = 60
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 364 self.types[t.lt] = t
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 365
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 366 t = Type(screenplay.CHARACTER)
0c5215b7 » oskusalerma 2004-08-21 Add intra-line spacing supp... 367 t.beforeSpacing = 10
5c63be4f » oskusalerma 2004-07-17 Config: 368 t.indent = 22
369 t.width = 38
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 370 t.screen.isCaps = True
371 t.export.isCaps = True
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 372 self.types[t.lt] = t
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 373
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 374 t = Type(screenplay.DIALOGUE)
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 375 t.indent = 10
376 t.width = 35
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 377 self.types[t.lt] = t
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 378
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 379 t = Type(screenplay.PAREN)
5c63be4f » oskusalerma 2004-07-17 Config: 380 t.indent = 16
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 381 t.width = 25
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 382 self.types[t.lt] = t
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 383
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 384 t = Type(screenplay.TRANSITION)
0c5215b7 » oskusalerma 2004-08-21 Add intra-line spacing supp... 385 t.beforeSpacing = 10
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 386 t.indent = 45
387 t.width = 20
388 t.screen.isCaps = True
389 t.export.isCaps = True
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 390 self.types[t.lt] = t
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 391
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 392 t = Type(screenplay.SHOT)
0c5215b7 » oskusalerma 2004-08-21 Add intra-line spacing supp... 393 t.beforeSpacing = 10
fe74da1e » oskusalerma 2004-06-06 Add 'Shot' element type. 394 t.indent = 0
395 t.width = 60
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 396 t.screen.isCaps = True
397 t.export.isCaps = True
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 398 self.types[t.lt] = t
fe74da1e » oskusalerma 2004-06-06 Add 'Shot' element type. 399
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 400 t = Type(screenplay.NOTE)
0c5215b7 » oskusalerma 2004-08-21 Add intra-line spacing supp... 401 t.beforeSpacing = 10
2d097c02 » oskusalerma 2004-06-07 Add 'Script Note' element t... 402 t.indent = 5
403 t.width = 55
37400210 » oskusalerma 2004-07-05 Add separate configuration ... 404 t.screen.isItalic = True
405 t.export.isItalic = True
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 406 self.types[t.lt] = t
2d097c02 » oskusalerma 2004-06-07 Add 'Script Note' element t... 407
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 408 # pdf font configs, key = PDF_FONT_*, value = PdfFontInfo
409 self.pdfFonts = { }
410
411 for name, style in (
412 (PDF_FONT_NORMAL, pml.COURIER),
413 (PDF_FONT_BOLD, pml.COURIER | pml.BOLD),
414 (PDF_FONT_ITALIC, pml.COURIER | pml.ITALIC),
415 (PDF_FONT_BOLD_ITALIC, pml.COURIER | pml.BOLD | pml.ITALIC)):
416 self.pdfFonts[name] = PDFFontInfo(name, style)
417
0770ec04 » oskusalerma 2004-05-01 Add almost fully working pa... 418 self.recalc()
419
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 420 def setupVars(self):
421 v = self.__class__.cvars = mypickle.Vars()
422
423 # font size used for PDF generation, in points
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 424 v.addInt("fontSize", 12, "FontSize", 4, 72)
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 425
426 # margins
427 v.addFloat("marginBottom", 25.4, "Margin/Bottom", 0.0, 900.0)
428 v.addFloat("marginLeft", 38.1, "Margin/Left", 0.0, 900.0)
429 v.addFloat("marginRight", 25.4, "Margin/Right", 0.0, 900.0)
430 v.addFloat("marginTop", 12.7, "Margin/Top", 0.0, 900.0)
431
432 # paper size
433 v.addFloat("paperHeight", 297.0, "Paper/Height", 100.0, 1000.0)
434 v.addFloat("paperWidth", 210.0, "Paper/Width", 50.0, 1000.0)
435
436 # leave at least this many action lines on the end of a page
437 v.addInt("pbActionLines", 2, "PageBreakActionLines", 1, 30)
438
439 # leave at least this many dialogue lines on the end of a page
440 v.addInt("pbDialogueLines", 2, "PageBreakDialogueLines", 1, 30)
441
eeef37af » oskusalerma 2004-09-14 Add scene continueds. 442 # whether scene continueds are enabled
443 v.addBool("sceneContinueds", True, "SceneContinueds")
444
4ee133e1 » oskusalerma 2006-01-04 Add support for opening scr... 445 # scene continued text indent width
3bca976a » oskusalerma 2005-08-15 Make the horizontal positio... 446 v.addInt("sceneContinuedIndent", 45, "SceneContinuedIndent", -20, 80)
447
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 448 # whether to include scene numbers
449 v.addBool("pdfShowSceneNumbers", False, "ShowSceneNumbers")
450
850f035f » oskusalerma 2005-09-24 PDF generation: Add support... 451 # whether to include PDF TOC
452 v.addBool("pdfIncludeTOC", True, "IncludeTOC")
453
454 # whether to show PDF TOC by default
455 v.addBool("pdfShowTOC", True, "ShowTOC")
456
457 # whether to open PDF document on current page
458 v.addBool("pdfOpenOnCurrentPage", True, "OpenOnCurrentPage")
459
caddf9e1 » oskusalerma 2005-12-23 Add an option to omit Note ... 460 # whether to remove Note elements in PDF output
461 v.addBool("pdfRemoveNotes", False, "RemoveNotes")
462
aae01ff5 » oskusalerma 2005-12-23 Add option for drawing rect... 463 # whether to draw rectangles around the outlines of Note elements
464 v.addBool("pdfOutlineNotes", True, "OutlineNotes")
465
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 466 # whether to draw rectangle showing margins
467 v.addBool("pdfShowMargins", False, "ShowMargins")
468
469 # whether to show line numbers next to each line
470 v.addBool("pdfShowLineNumbers", False, "ShowLineNumbers")
471
4ee133e1 » oskusalerma 2006-01-04 Add support for opening scr... 472 # cursor position, line
473 v.addInt("cursorLine", 0, "Cursor/Line", 0, 1000000)
474
475 # cursor position, column
476 v.addInt("cursorColumn", 0, "Cursor/Column", 0, 1000000)
477
fbde17fb » oskusalerma 2005-08-20 Make the (MORE) etc. texts ... 478 # various strings we add to the script
4f76a937 » oskusalerma 2006-03-04 Add Str(Latin1|Unicode|Bina... 479 v.addStrLatin1("strMore", "(MORE)", "String/MoreDialogue")
480 v.addStrLatin1("strContinuedPageEnd", "(CONTINUED)",
481 "String/ContinuedPageEnd")
482 v.addStrLatin1("strContinuedPageStart", "CONTINUED:",
483 "String/ContinuedPageStart")
484 v.addStrLatin1("strDialogueContinued", " (cont'd)",
485 "String/DialogueContinued")
fbde17fb » oskusalerma 2005-08-20 Make the (MORE) etc. texts ... 486
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 487 v.makeDicts()
488
489 # load config from string 's'. does not throw any exceptions, silently
490 # ignores any errors, and always leaves config in an ok state.
491 def load(self, s):
492 vals = self.cvars.makeVals(s)
493
494 self.cvars.load(vals, "", self)
495
105aaea0 » oskusalerma 2006-01-15 Revert accidentally committ... 496 for t in self.types.itervalues():
497 t.load(vals, "Element/")
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 498
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 499 for pf in self.pdfFonts.itervalues():
500 pf.load(vals, "Font/")
501
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 502 self.recalc()
503
504 # save config into a string and return that.
505 def save(self):
506 s = self.cvars.save("", self)
507
508 for t in self.types.itervalues():
509 s += t.save("Element/")
510
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 511 for pf in self.pdfFonts.itervalues():
512 s += pf.save("Font/")
513
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 514 return s
515
516 # fix up all invalid config values and recalculate all variables
517 # dependent on other variables.
518 #
519 # if doAll is False, enforces restrictions only on a per-variable
520 # basis, e.g. doesn't modify variable v2 based on v1's value. this is
521 # useful when user is interactively modifying v1, and it temporarily
522 # strays out of bounds (e.g. when deleting the old text in an entry
523 # box, thus getting the minimum value), which would then possibly
524 # modify the value of other variables which is not what we want.
525 def recalc(self, doAll = True):
526 for it in self.cvars.numeric.itervalues():
527 util.clampObj(self, it.name, it.minVal, it.maxVal)
528
529 for el in self.types.itervalues():
530 for it in el.cvars.numeric.itervalues():
531 util.clampObj(el, it.name, it.minVal, it.maxVal)
532
4f76a937 » oskusalerma 2006-03-04 Add Str(Latin1|Unicode|Bina... 533 for it in self.cvars.stringLatin1.itervalues():
fbde17fb » oskusalerma 2005-08-20 Make the (MORE) etc. texts ... 534 setattr(self, it.name, util.toInputStr(getattr(self, it.name)))
535
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 536 for pf in self.pdfFonts.itervalues():
537 pf.refresh()
538
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 539 # make sure usable space on the page isn't too small
540 if doAll and (self.marginTop + self.marginBottom) >= \
541 (self.paperHeight - 100.0):
542 self.marginTop = 0.0
543 self.marginBottom = 0.0
544
545 h = self.paperHeight - self.marginTop - self.marginBottom
546
547 # how many lines on a page
548 self.linesOnPage = int(h / util.getTextHeight(self.fontSize))
549
550 def getType(self, lt):
551 return self.types[lt]
552
5f5e4ebf » oskusalerma 2006-04-02 Add support for using arbit... 553 # get a PDFFontInfo object for the given font type (PDF_FONT_*)
554 def getPDFFont(self, fontType):
555 return self.pdfFonts[fontType]
556
557 # return a tuple of all the PDF font types
558 def getPDFFontIds(self):
559 return (PDF_FONT_NORMAL, PDF_FONT_BOLD, PDF_FONT_ITALIC,
560 PDF_FONT_BOLD_ITALIC)
561
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 562 # global config. there is only ever one of these active.
563 class ConfigGlobal:
564 cvars = None
565
566 def __init__(self):
567
568 if not self.__class__.cvars:
569 self.setupVars()
570
571 self.__class__.cvars.setDefaults(self)
572
573 # type configs, key = line type, value = TypeGlobal
574 self.types = { }
575
576 # element types
577 t = TypeGlobal(screenplay.SCENE)
578 t.newTypeEnter = screenplay.ACTION
579 t.newTypeTab = screenplay.CHARACTER
580 t.nextTypeTab = screenplay.ACTION
581 t.prevTypeTab = screenplay.TRANSITION
582 self.types[t.lt] = t
583
584 t = TypeGlobal(screenplay.ACTION)
585 t.newTypeEnter = screenplay.ACTION
586 t.newTypeTab = screenplay.CHARACTER
587 t.nextTypeTab = screenplay.CHARACTER
588 t.prevTypeTab = screenplay.CHARACTER
589 self.types[t.lt] = t
590
591 t = TypeGlobal(screenplay.CHARACTER)
592 t.newTypeEnter = screenplay.DIALOGUE
593 t.newTypeTab = screenplay.PAREN
594 t.nextTypeTab = screenplay.ACTION
595 t.prevTypeTab = screenplay.ACTION
596 self.types[t.lt] = t
597
598 t = TypeGlobal(screenplay.DIALOGUE)
599 t.newTypeEnter = screenplay.CHARACTER
600 t.newTypeTab = screenplay.ACTION
601 t.nextTypeTab = screenplay.PAREN
602 t.prevTypeTab = screenplay.ACTION
603 self.types[t.lt] = t
604
605 t = TypeGlobal(screenplay.PAREN)
606 t.newTypeEnter = screenplay.DIALOGUE
607 t.newTypeTab = screenplay.ACTION
608 t.nextTypeTab = screenplay.CHARACTER
609 t.prevTypeTab = screenplay.DIALOGUE
610 self.types[t.lt] = t
611
612 t = TypeGlobal(screenplay.TRANSITION)
613 t.newTypeEnter = screenplay.SCENE
614 t.newTypeTab = screenplay.TRANSITION
615 t.nextTypeTab = screenplay.SCENE
616 t.prevTypeTab = screenplay.CHARACTER
617 self.types[t.lt] = t
618
619 t = TypeGlobal(screenplay.SHOT)
620 t.newTypeEnter = screenplay.ACTION
621 t.newTypeTab = screenplay.CHARACTER
622 t.nextTypeTab = screenplay.ACTION
623 t.prevTypeTab = screenplay.SCENE
624 self.types[t.lt] = t
625
626 t = TypeGlobal(screenplay.NOTE)
627 t.newTypeEnter = screenplay.ACTION
628 t.newTypeTab = screenplay.CHARACTER
629 t.nextTypeTab = screenplay.ACTION
630 t.prevTypeTab = screenplay.CHARACTER
631 self.types[t.lt] = t
632
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 633 # keyboard commands
634 self.commands = [
635 Command("Abort", "Abort something, e.g. selection,"
636 " auto-completion, etc.", [WXK_ESCAPE], isFixed = True),
637
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 638 Command("About", "Show the about dialog.", isMenu = True),
639
b1035db5 » oskusalerma 2005-07-30 Move auto-completion from c... 640 Command("AutoCompletionDlg", "Open the auto-completion dialog.",
641 isMenu = True),
642
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 643 Command("ChangeToAction", "Change current element's style to"
644 " action.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 645 [util.Key(ord("A"), alt = True).toInt()]),
646
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 647 Command("ChangeToCharacter", "Change current element's style to"
648 " character.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 649 [util.Key(ord("C"), alt = True).toInt()]),
650
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 651 Command("ChangeToDialogue", "Change current element's style to"
652 " dialogue.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 653 [util.Key(ord("D"), alt = True).toInt()]),
654
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 655 Command("ChangeToNote", "Change current element's style to note.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 656 [util.Key(ord("N"), alt = True).toInt()]),
657
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 658 Command("ChangeToParenthetical", "Change current element's"
659 " style to parenthetical.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 660 [util.Key(ord("P"), alt = True).toInt()]),
661
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 662 Command("ChangeToScene", "Change current element's style to"
663 " scene.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 664 [util.Key(ord("S"), alt = True).toInt()]),
665
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 666 Command("ChangeToShot", "Change current element's style to"
667 " shot."),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 668
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 669 Command("ChangeToTransition", "Change current element's style to"
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 670 " transition.",
671 [util.Key(ord("T"), alt = True).toInt()]),
672
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 673 Command("CharacterMap", "Open the character map.",
674 isMenu = True),
675
676 Command("CloseScript", "Close the current script.",
677 isMenu = True),
678
679 Command("CompareScripts", "Compare two scripts.", isMenu = True),
680
681 Command("Copy", "Copy selected text to the internal clipboard.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 682 [util.Key(3, ctrl = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 683 isFixed = True, isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 684
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 685 Command("CopySystemCb", "Copy selected text to the system's"
686 " clipboard.", isMenu = True),
687
688 Command("Cut", "Cut selected text to internal clipboard.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 689 [util.Key(24, ctrl = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 690 isFixed = True, isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 691
692 Command("Delete", "Delete the character under the cursor,"
693 " or selected text.", [WXK_DELETE], isFixed = True),
694
695 Command("DeleteBackward", "Delete the character behind the"
696 " cursor.", [WXK_BACK], isFixed = True),
697
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 698 Command("DeleteElements", "Open the 'Delete elements' dialog.",
699 isMenu = True),
700
701 Command("ExportScript", "Export the current script.",
702 isMenu = True),
703
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 704 Command("FindAndReplaceDlg", "Open the 'Find & Replace' dialog.",
705 [util.Key(6, ctrl = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 706 isFixed = True, isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 707
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 708 Command("FindNextError", "Find next error in the current script.",
709 [util.Key(5, ctrl = True).toInt()], isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 710
711 Command("ForcedLineBreak", "Insert a forced line break.",
712 [util.Key(WXK_RETURN, ctrl = True).toInt(),
713 util.Key(WXK_RETURN, shift = True).toInt(),
714
715 # CTRL+Enter under wxMSW
716 util.Key(10, ctrl = True).toInt()],
717 isFixed = True),
718
6620ff8b » oskusalerma 2005-12-21 Add "Goto scene" command. 719 Command("GotoScene", "Goto to a given scene.",
720 [util.Key(ord("G"), alt = True).toInt()], isFixed = True,
721 isMenu = True),
722
061401d4 » oskusalerma 2005-12-21 Add "Goto page" command. 723 Command("GotoPage", "Goto to a given page.",
724 [util.Key(7, ctrl = True).toInt()], isFixed = True,
725 isMenu = True),
726
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 727 Command("HeadersDlg", "Open the headers dialog.", isMenu = True),
728
729 Command("HelpCommands", "Show list of commands and their key"
730 " bindings.", isMenu = True),
731
732 Command("HelpManual", "Open the manual.", isMenu = True),
733
734 Command("ImportScript", "Import a script.", isMenu = True),
735
736 Command("LoadSettings", "Load global settings.", isMenu = True),
737
738 Command("LoadScriptSettings", "Load script-specific settings.",
739 isMenu = True),
740
e106883e » oskusalerma 2005-07-28 Add locations.Locations and... 741 Command("LocationsDlg", "Open the locations dialog.",
742 isMenu = True),
743
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 744 Command("MoveDown", "Move down.", [WXK_DOWN], isMovement = True),
745
746 Command("MoveEndOfLine", "Move to the end of the line or"
747 " finish auto-completion.",
748 [WXK_END], isMovement = True),
749
750 Command("MoveEndOfScript", "Move to the end of the script.",
751 [util.Key(WXK_END, ctrl = True).toInt()],
752 isMovement = True),
753
754 Command("MoveLeft", "Move left.", [WXK_LEFT], isMovement = True),
755
756 Command("MovePageDown", "Move one page down.",
757 [WXK_NEXT, WXK_PAGEDOWN], isMovement = True),
758
759 Command("MovePageUp", "Move one page up.",
760 [WXK_PRIOR, WXK_PAGEUP], isMovement = True),
761
762 Command("MoveRight", "Move right.", [WXK_RIGHT],
763 isMovement = True),
764
765 Command("MoveSceneDown", "Move one scene down.",
766 [util.Key(WXK_DOWN, ctrl = True).toInt()],
767 isMovement = True),
768
769 Command("MoveSceneUp", "Move one scene up.",
770 [util.Key(WXK_UP, ctrl = True).toInt()],
771 isMovement = True),
772
773 Command("MoveStartOfLine", "Move to the start of the line.",
774 [WXK_HOME], isMovement = True),
775
776 Command("MoveStartOfScript", "Move to the start of the"
777 " script.",
778 [util.Key(WXK_HOME, ctrl = True).toInt()],
779 isMovement = True),
780
781 Command("MoveUp", "Move up.", [WXK_UP], isMovement = True),
782
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 783 Command("NameDatabase", "Open the character name database.",
784 isMenu = True),
785
786 Command("NewElement", "Create a new element.", [WXK_RETURN],
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 787 isFixed = True),
788
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 789 Command("NewScript", "Create a new script.", isMenu = True),
790
791 Command("OpenScript", "Open a script.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 792 [util.Key(15, ctrl = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 793 isFixed = True, isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 794
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 795 Command("Paginate", "Paginate current script.", isMenu = True),
796
797 Command("Paste", "Paste text from the internal clipboard.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 798 [util.Key(22, ctrl = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 799 isFixed = True, isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 800
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 801 Command("PasteSystemCb", "Paste text from the system's"
802 " clipboard.", isMenu = True),
803
804 Command("PrintScript", "Print current script.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 805 [util.Key(16, ctrl = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 806 isFixed = True, isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 807
808 Command("Quit", "Quit the program.",
809 [util.Key(17, ctrl = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 810 isFixed = True, isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 811
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 812 Command("ReportCharacter", "Generate character report.",
813 isMenu = True),
814
815 Command("ReportDialogueChart", "Generate dialogue chart report.",
816 isMenu = True),
5a428104 » oskusalerma 2005-07-24 Add preliminary support for... 817
818 Command("ReportLocation", "Generate location report.",
819 isMenu = True),
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 820
a6520ad8 » oskusalerma 2005-05-29 Add scene report generation... 821 Command("ReportScene", "Generate scene report.",
822 isMenu = True),
823
6ffc0c34 » oskusalerma 2005-07-31 Add script report. 824 Command("ReportScript", "Generate script report.",
825 isMenu = True),
826
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 827 Command("RevertScript", "Revert current script to the"
828 " version on disk.", isMenu = True),
829
830 Command("SaveScriptSettingsAs", "Save script-specific settings"
831 " to a new file.", isMenu = True),
832
833 Command("SaveSettingsAs", "Save global settings to a new file.",
834 isMenu = True),
835
836 Command("SaveScript", "Save the current script.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 837 [util.Key(19, ctrl = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 838 isFixed = True, isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 839
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 840 Command("SaveScriptAs", "Save the current script to a new file.",
841 isMenu = True),
842
58ef1bf9 » oskusalerma 2006-03-11 Add Script[Next|Prev] comma... 843 Command("ScriptNext", "Change to next open script.",
844 isMenu = True),
845
846 Command("ScriptPrev", "Change to previous open script.",
847 isMenu = True),
848
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 849 Command("ScriptSettings", "Change script-specific settings.",
850 isMenu = True),
851
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 852 Command("SelectScene", "Select the current scene.",
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 853 [util.Key(1, ctrl = True).toInt()], isMenu = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 854
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 855 Command("SetMark", "Set mark at current cursor position.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 856 [util.Key(WXK_SPACE, ctrl = True).toInt()]),
857
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 858 Command("Settings", "Change global settings.", isMenu = True),
093095d6 » oskusalerma 2005-10-04 Add spell checker. Fixes #22. 859
860 Command("SpellCheckerDlg","Spell check the script.",
861 [util.Key(WXK_F8).toInt()], isMenu = True),
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 862
093095d6 » oskusalerma 2005-10-04 Add spell checker. Fixes #22. 863 Command("SpellCheckerDictionaryDlg",
864 "Open the global spell checker dictionary dialog.",
865 isMenu = True),
866
867 Command("SpellCheckerScriptDictionaryDlg",
868 "Open the script-specific spell checker dictionary"
869 " dialog.",
870 isMenu = True),
871
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 872 Command("Tab", "Change current element to the next style or"
873 " create a new element.", [WXK_TAB], isFixed = True),
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 874
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 875 Command("TabPrev", "Change current element to the previous"
876 " style.",
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 877 [util.Key(WXK_TAB, shift = True).toInt()],
670ae40a » oskusalerma 2005-05-15 Add configurable keyboard c... 878 isFixed = True),
879
880 Command("TitlesDlg", "Open the titles dialog.", isMenu = True),
881
882 Command("ToggleShowFormatting", "Toggle 'Show formatting'"
883 " display.", isMenu = True),
884
885 Command("ViewModeDraft", "Change view mode to draft.",
886 isMenu = True),
887
888 Command("ViewModeLayout", "Change view mode to layout.",
889 isMenu = True),
890
891 Command("ViewModeOverviewLarge", "Change view mode to large"
892 " overview.", isMenu = True),
893
894 Command("ViewModeOverviewSmall", "Change view mode to small"
895 " overview.", isMenu = True),
896
897 Command("ViewModeSideBySide", "Change view mode to side by"
898 " side.", isMenu = True)
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 899 ]
900
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 901 self.recalc()
902
903 def setupVars(self):
904 v = self.__class__.cvars = mypickle.Vars()
905
906 # confirm non-undoable delete operations that would delete at
907 # least this many lines. (0 = disabled)
908 v.addInt("confirmDeletes", 2, "ConfirmDeletes", 0, 500)
909
910 # vertical distance between rows, in pixels
911 v.addInt("fontYdelta", 18, "FontYDelta", 4, 125)
912
913 # how many lines to scroll per mouse wheel event
914 v.addInt("mouseWheelLines", 4, "MouseWheelLines", 1, 50)
915
916 # interval in seconds between automatic pagination (0 = disabled)
917 v.addInt("paginateInterval", 1, "PaginateInterval", 0, 10)
918
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 919 # whether to check script for errors before export / print
920 v.addBool("checkOnExport", True, "CheckScriptForErrors")
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 921
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 922 # whether to auto-capitalize start of sentences
923 v.addBool("capitalize", True, "CapitalizeSentences")
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 924
6365f9d8 » oskusalerma 2006-01-01 Add support for auto-capita... 925 # whether to auto-capitalize i -> I
926 v.addBool("capitalizeI", True, "CapitalizeI")
927
4ee133e1 » oskusalerma 2006-01-04 Add support for opening scr... 928 # whether to open scripts on their last saved position
929 v.addBool("honorSavedPos", True, "OpenScriptOnSavedPos")
930
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 931 # page break indicators to show
932 v.addInt("pbi", PBI_REAL, "PageBreakIndicators", PBI_FIRST,
933 PBI_LAST)
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 934
e6d49ec3 » oskusalerma 2006-03-17 Look for several different ... 935 # PDF viewer program and args. defaults are empty since generating
936 # them is a complex process handled by findPDFViewer.
937 v.addStrUnicode("pdfViewerPath", u"", "PDF/ViewerPath")
938 v.addStrBinary("pdfViewerArgs", "", "PDF/ViewerArguments")
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 939
9e60aa6e » oskusalerma 2006-04-09 Add default fonts for wxGTK... 940 # fonts. real defaults are set in setDefaultFonts.
941 v.addStrBinary("fontNormal", "", "FontNormal")
942 v.addStrBinary("fontBold", "", "FontBold")
943 v.addStrBinary("fontItalic", "", "FontItalic")
944 v.addStrBinary("fontBoldItalic", "", "FontBoldItalic")
a9b5c8eb » oskusalerma 2004-07-29 Config: 945
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 946 # default script directory
e6d49ec3 » oskusalerma 2006-03-17 Look for several different ... 947 v.addStrUnicode("scriptDir", misc.progPath, "DefaultScriptDirectory")
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 948
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 949 # colors
950 v.addColor("text", 0, 0, 0, "TextFG", "Text foreground")
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 951 v.addColor("textHdr", 128, 128, 128, "TextHeadersFG",
952 "Text foreground (headers)")
953 v.addColor("textBg", 255, 255, 255, "TextBG", "Text background")
954 v.addColor("workspace", 204, 204, 204, "Workspace", "Workspace")
73b1212a » oskusalerma 2004-11-28 Final tweaks for beta2. 955 v.addColor("pageBorder", 0, 0, 0, "PageBorder", "Page border")
956 v.addColor("pageShadow", 128, 128, 128, "PageShadow", "Page shadow")
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 957 v.addColor("selected", 128, 192, 192, "Selected", "Selection")
958 v.addColor("search", 255, 127, 0, "SearchResult", "Search result")
959 v.addColor("cursor", 205, 0, 0, "Cursor", "Cursor")
960 v.addColor("autoCompFg", 0, 0, 0, "AutoCompletionFG",
961 "Auto-completion foreground")
962 v.addColor("autoCompBg", 249, 222, 99, "AutoCompletionBG",
963 "Auto-completion background")
964 v.addColor("note", 255, 255, 0, "ScriptNote", "Script note")
965 v.addColor("pagebreak", 128, 128, 128, "PageBreakLine",
966 "Page-break line")
967 v.addColor("pagebreakNoAdjust", 128, 128, 128,
968 "PageBreakNoAdjustLine",
969 "Page-break (original, not adjusted) line")
6272f219 » oskusalerma 2006-03-11 Use custom tab control. 970 v.addColor("tabFg", 0, 0, 0, "TabFG", "Tab foreground")
971 v.addColor("tabHighlight", 255, 255, 255, "TabHighlight",
972 "Tab highlight")
973 v.addColor("tabSelectedBg", 238, 238, 238, "TabSelectedBG",
974 "Tab background, selected")
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 975
12993695 » oskusalerma 2004-08-01 Add support for loading con... 976 v.makeDicts()
977
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 978 # load config from string 's'. does not throw any exceptions, silently
979 # ignores any errors, and always leaves config in an ok state.
980 def load(self, s):
d028c4df » oskusalerma 2004-08-02 Add mypickle.Vars.makeVals. 981 vals = self.cvars.makeVals(s)
12993695 » oskusalerma 2004-08-01 Add support for loading con... 982
983 self.cvars.load(vals, "", self)
984
985 for t in self.types.itervalues():
986 t.load(vals, "Element/")
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 987
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 988 for cmd in self.commands:
989 cmd.load(vals, "Command/")
990
12993695 » oskusalerma 2004-08-01 Add support for loading con... 991 self.recalc()
992
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 993 # save config into a string and return that.
994 def save(self):
995 s = self.cvars.save("", self)
996
997 for t in self.types.itervalues():
998 s += t.save("Element/")
999
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 1000 for cmd in self.commands:
1001 s += cmd.save("Command/")
1002
a15f9b73 » oskusalerma 2004-07-30 Add mypickle, finish up sav... 1003 return s
1004
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1005 # fix up all invalid config values.
1006 def recalc(self):
12993695 » oskusalerma 2004-08-01 Add support for loading con... 1007 for it in self.cvars.numeric.itervalues():
f9cf6e90 » oskusalerma 2004-07-29 Update config to have infor... 1008 util.clampObj(self, it.name, it.minVal, it.maxVal)
18ae6e8b » oskusalerma 2004-07-15 Add lots of infra-structure... 1009
e3c298a6 » oskusalerma 2004-07-07 Rename line type fields fro... 1010 def getType(self, lt):
1011 return self.types[lt]
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1012
d1d9b7ed » oskusalerma 2005-05-13 Add configurable keyboard c... 1013 # add SHIFT+Key alias for all keys bound to movement commands, so
1014 # selection-movement works.
1015 def addShiftKeys(self):
1016 for cmd in self.commands:
1017 if cmd.isMovement:
1018 nk = []
1019
1020 for key in cmd.keys:
1021 k = util.Key.fromInt(key)
1022 k.shift = True
1023 ki = k.toInt()
1024
1025 if ki not in cmd.keys:
1026 nk.append(ki)
1027
1028 cmd.keys.extend(nk)
1029
1030 # remove key (int) from given cmd
1031 def removeKey(self, cmd, key):
1032 cmd.keys.remove(key)
1033
1034 if cmd.isMovement:
1035 k = util.Key.fromInt(key)
1036 k.shift = True
1037 ki = k.toInt()
1038
1039 if ki in cmd.keys:
1040 cmd.keys.remove(ki)
1041
1042 # get textual description of conflicting keys, or None if no
1043 # conflicts.
1044 def getConflictingKeys(self):
1045 keys = {}
1046
1047 for cmd in self.commands:
1048 for key in cmd.keys:
1049 if key in keys:
1050 keys[key].append(cmd.name)
1051 else:
1052 keys[key] = [cmd.name]
1053
1054 s = ""
1055 for k, v in keys.iteritems():
1056 if len(v) > 1:
1057 s += "%s:" % util.Key.fromInt(k).toStr()
1058
1059 for cmd in v:
1060 s += " %s" % cmd
1061
1062 s += "\n"
1063
1064 if s == "":
1065 return None
1066 else:
1067 return s
1068
9e60aa6e » oskusalerma 2006-04-09 Add default fonts for wxGTK... 1069 # set default values that vary depending on platform, wxWidgets
1070 # version, etc. this is not at the end of __init__ because
1071 # non-interactive uses have no needs for these.
1072 def setDefaults(self):
1073 self.setDefaultFonts()
1074 self.findPDFViewer()
1075
1076 # set default fonts
1077 def setDefaultFonts(self):
1078 fn = ["", "", "", ""]
1079
1080 if misc.isUnix:
1081 if misc.wxIsUnicode:
1082 fn[0] = "Monospace 10"
1083 fn[1] = "Monospace Bold 10"
1084 fn[2] = "Monospace Italic 10"
1085 fn[3] = "Monospace Bold Italic 10"
1086 else:
1087 fn[0] = "0;-adobe-courier-medium-r-normal-*-*-140-*-*-m-*-iso8859-1"
1088 fn[1] = "0;-adobe-courier-bold-r-normal-*-*-140-*-*-m-*-iso8859-1"
1089 fn[2] = "0;-adobe-courier-medium-o-normal-*-*-140-*-*-m-*-iso8859-1"
1090 fn[3] = "0;-adobe-courier-bold-o-normal-*-*-140-*-*-m-*-iso8859-1"
1091
1092 elif misc.isWindows:
1093 fn[0] = "0;-13;0;0;0;400;0;0;0;0;3;2;1;49;Courier New"
1094 fn[1] = "0;-13;0;0;0;700;0;0;0;0;3;2;1;49;Courier New"
1095 fn[2] = "0;-13;0;0;0;400;255;0;0;0;3;2;1;49;Courier New"
1096 fn[3] = "0;-13;0;0;0;700;255;0;0;0;3;2;1;49;Courier New"
1097
1098 else:
1099 raise ConfigError("Unknown platform")
1100
1101 self.fontNormal = fn[0]
1102 self.fontBold = fn[1]
1103 self.fontItalic = fn[2]
1104 self.fontBoldItalic = fn[3]
1105
e6d49ec3 » oskusalerma 2006-03-17 Look for several different ... 1106 # set PDF viewer program to the best one found on the machine.
1107 def findPDFViewer(self):
1108 # list of programs to look for. each item is of the form (name,
1109 # args). if name is an absolute path only that exact location is
1110 # looked at, otherwise PATH is searched for the program (on
1111 # Windows, all paths are interpreted as absolute). args is the
1112 # list of arguments for the program.
1113 progs = []
1114
1115 if misc.isUnix:
1116 progs = [
1117 (u"/usr/local/Adobe/Acrobat7.0/bin/acroread", "-tempFile"),
ffdc878a » oskusalerma 2006-03-17 Add "acroread" to the list ... 1118 (u"acroread", "-tempFile"),
e6d49ec3 » oskusalerma 2006-03-17 Look for several different ... 1119 (u"xpdf", ""),
1120 (u"evince", ""),
1121 (u"gpdf", ""),
1122 (u"kpdf", ""),
1123 ]
1124 elif misc.isWindows:
1125 progs = [
1126 (ur"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe",
1127 ""),
1128 (ur"C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe",
1129 ""),
1130 (ur"C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe",
1131 ""),
1132 (ur"C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe",
1133 ""),
1134 ]
1135 else:
1136 pass
1137
1138 success = False
1139
1140 for name, args in progs:
1141 if misc.isWindows or (name[0] == u"/"):
1142 if util.fileExists(name):
1143 success = True
1144
1145 break
1146 else:
1147 name = util.findFileInPath(name)
1148
1149 if name:
1150 success = True
1151
1152 break
1153
1154 if success:
1155 self.pdfViewerPath = name
1156 self.pdfViewerArgs = args
1157
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1158 # config stuff that are wxwindows objects, so can't be in normal
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1159 # ConfigGlobal (deepcopy dies)
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1160 class ConfigGui:
1161
1162 # constants
1163 constantsInited = False
1164 bluePen = None
1165 redColor = None
1166 blackColor = None
1167
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1168 def __init__(self, cfgGl):
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1169
1170 if not ConfigGui.constantsInited:
1171 ConfigGui.bluePen = wxPen(wxColour(0, 0, 255))
1172 ConfigGui.redColor = wxColour(255, 0, 0)
1173 ConfigGui.blackColor = wxColour(0, 0, 0)
1174
1175 ConfigGui.constantsInited = True
f881ea46 » oskusalerma 2004-09-18 Add MyColor class, store th... 1176
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1177 # convert cfgGl.MyColor -> cfgGui.wxColour
1178 for it in cfgGl.cvars.color.itervalues():
1179 c = getattr(cfgGl, it.name)
f881ea46 » oskusalerma 2004-09-18 Add MyColor class, store th... 1180 tmp = wxColour(c.r, c.g, c.b)
1181 setattr(self, it.name, tmp)
1182
1183 self.textPen = wxPen(self.textColor)
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 1184 self.textHdrPen = wxPen(self.textHdrColor)
0770ec04 » oskusalerma 2004-05-01 Add almost fully working pa... 1185
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 1186 self.workspaceBrush = wxBrush(self.workspaceColor)
1187 self.workspacePen = wxPen(self.workspaceColor)
1188
1189 self.textBgBrush = wxBrush(self.textBgColor)
1190 self.textBgPen = wxPen(self.textBgColor)
1191
1192 self.pageBorderPen = wxPen(self.pageBorderColor)
1193 self.pageShadowPen = wxPen(self.pageShadowColor)
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1194
f881ea46 » oskusalerma 2004-09-18 Add MyColor class, store th... 1195 self.selectedBrush = wxBrush(self.selectedColor)
1196 self.selectedPen = wxPen(self.selectedColor)
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1197
f881ea46 » oskusalerma 2004-09-18 Add MyColor class, store th... 1198 self.searchBrush = wxBrush(self.searchColor)
1199 self.searchPen = wxPen(self.searchColor)
b56ac5f3 » oskusalerma 2004-04-12 Add implementation of Find. 1200
f881ea46 » oskusalerma 2004-09-18 Add MyColor class, store th... 1201 self.cursorBrush = wxBrush(self.cursorColor)
1202 self.cursorPen = wxPen(self.cursorColor)
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1203
f881ea46 » oskusalerma 2004-09-18 Add MyColor class, store th... 1204 self.noteBrush = wxBrush(self.noteColor)
1205 self.notePen = wxPen(self.noteColor)
2d097c02 » oskusalerma 2004-06-07 Add 'Script Note' element t... 1206
f881ea46 » oskusalerma 2004-09-18 Add MyColor class, store th... 1207 self.autoCompPen = wxPen(self.autoCompFgColor)
1208 self.autoCompBrush = wxBrush(self.autoCompBgColor)
1209 self.autoCompRevPen = wxPen(self.autoCompBgColor)
1210 self.autoCompRevBrush = wxBrush(self.autoCompFgColor)
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1211
f881ea46 » oskusalerma 2004-09-18 Add MyColor class, store th... 1212 self.pagebreakPen = wxPen(self.pagebreakColor)
1213 self.pagebreakNoAdjustPen = wxPen(self.pagebreakNoAdjustColor,
0770ec04 » oskusalerma 2004-05-01 Add almost fully working pa... 1214 style = wxDOT)
81d311f1 » oskusalerma 2004-02-28 Move GUI config objects out... 1215
6272f219 » oskusalerma 2006-03-11 Use custom tab control. 1216 self.tabFgPen = wxPen(self.tabFgColor)
1217 self.tabHighlightPen = wxPen(self.tabHighlightColor)
1218
1219 self.tabSelectedBgBrush = wxBrush(self.tabSelectedBgColor)
1220 self.tabSelectedBgPen = wxPen(self.tabSelectedBgColor)
1221
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 1222 # a 4-item list of FontInfo objects, indexed by the two lowest
1223 # bits of pml.TextOp.flags.
1224 self.fonts = []
ca50783f » oskusalerma 2004-11-07 Fix broken "Disable auto-pa... 1225
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 1226 for fname in ["fontNormal", "fontBold", "fontItalic",
1227 "fontBoldItalic"]:
1228 fi = FontInfo()
0762524f » oskusalerma 2004-08-02 Specify ISO-8859-1 as encod... 1229
9e60aa6e » oskusalerma 2006-04-09 Add default fonts for wxGTK... 1230 s = getattr(cfgGl, fname)
1231
1232 # evil users can set the font name to empty by modifying the
1233 # config file, and some wxWidgets ports crash hard when trying
1234 # to create a font from an empty string, so we must guard
1235 # against that.
1236 if s:
1237 nfi = wxNativeFontInfo()
1238 nfi.FromString(s)
1239 nfi.SetEncoding(wxFONTENCODING_ISO8859_1)
1240
1241 fi.font = wxFontFromNativeInfo(nfi)
1242
1243 # likewise, evil users can set the font name to "z" or
1244 # something equally silly, resulting in an
1245 # invalid/non-existent font. on wxGTK2 and wxMSW we can
1246 # detect this by checking the point size of the font.
1247 # wxGTK1 chooses some weird chinese font and I can't find
1248 # a way to detect that, but it's irrelevant since we'll
1249 # rip out support for it in a few months.
1250 if fi.font.GetPointSize() == 0:
1251 fi.font = None
1252
1253 # if either of the above failures happened, create a dummy
1254 # font and use it. this sucks but is preferable to crashing or
1255 # displaying an empty screen.
1256 if not fi.font:
1257 fi.font = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL,
1258 encoding = wxFONTENCODING_ISO8859_1)
1259 setattr(cfgGl, fname, fi.font.GetNativeFontInfo().ToString())
390d096d » oskusalerma 2004-08-29 Don't try to auto-generate ... 1260
22e1d66f » oskusalerma 2005-02-06 Use a single wxMemoryDC for... 1261 fx, fy = util.getTextExtent(fi.font, "O")
390d096d » oskusalerma 2004-08-29 Don't try to auto-generate ... 1262
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 1263 fi.fx = max(1, fx)
1264 fi.fy = max(1, fy)
390d096d » oskusalerma 2004-08-29 Don't try to auto-generate ... 1265
b10aa441 » oskusalerma 2004-11-28 Add 'Layout' view mode. 1266 self.fonts.append(fi)
390d096d » oskusalerma 2004-08-29 Don't try to auto-generate ... 1267
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1268 # TextType -> FontInfo
1269 def tt2fi(self, tt):
1270 return self.fonts[tt.isBold | (tt.isItalic << 1)]
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 1271
fe1416d2 » oskusalerma 2004-06-02 Screenplay file format: 1272 def _conv(dict, key, raiseException = True):
ade68370 » oskusalerma 2003-11-15 Initial import. 1273 val = dict.get(key)
fe1416d2 » oskusalerma 2004-06-02 Screenplay file format: 1274 if (val == None) and raiseException:
eae62fb2 » oskusalerma 2004-02-22 Make a real Config class ou... 1275 raise ConfigError("key '%s' not found from '%s'" % (key, dict))
ade68370 » oskusalerma 2003-11-15 Initial import. 1276
1277 return val
1278
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1279 # get TypeInfos
1280 def getTIs():
1281 return _ti
ade68370 » oskusalerma 2003-11-15 Initial import. 1282
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1283 def char2lb(char, raiseException = True):
1284 return _conv(_char2lb, char, raiseException)
1285
1286 def lb2char(lb):
1287 return _conv(_lb2char, lb)
ade68370 » oskusalerma 2003-11-15 Initial import. 1288
83ff6b62 » oskusalerma 2004-07-21 Add copying selection to ex... 1289 def lb2str(lb):
1290 return _conv(_lb2str, lb)
1291
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1292 def char2lt(char, raiseException = True):
1293 ti = _conv(_char2ti, char, raiseException)
1294
1295 if ti:
1296 return ti.lt
1297 else:
1298 return None
1299
1300 def lt2char(lt):
1301 return _conv(_lt2ti, lt).char
1302
1303 def name2ti(name, raiseException = True):
1304 return _conv(_name2ti, name, raiseException)
1305
1306 def lt2ti(lt):
1307 return _conv(_lt2ti, lt)
1308
1309 def _init():
1310
1311 for lt, char, name in (
1312 (screenplay.SCENE, "\\", "Scene"),
1313 (screenplay.ACTION, ".", "Action"),
1314 (screenplay.CHARACTER, "_", "Character"),
1315 (screenplay.DIALOGUE, ":", "Dialogue"),
1316 (screenplay.PAREN, "(", "Parenthetical"),
1317 (screenplay.TRANSITION, "/", "Transition"),
1318 (screenplay.SHOT, "=", "Shot"),
1319 (screenplay.NOTE, "%", "Note")
1320 ):
1321
1322 ti = TypeInfo(lt, char, name)
1323
1324 _ti.append(ti)
1325 _lt2ti[lt] = ti
1326 _char2ti[char] = ti
1327 _name2ti[name] = ti
ade68370 » oskusalerma 2003-11-15 Initial import. 1328
777ede12 » oskusalerma 2005-04-03 Merge per-script branch (r3... 1329 _init()