Subversion Repositories Scribus

Rev

Rev 540 | Rev 1048 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
540 subik 1
""" DESCRIPTION & USAGE:
2
This script needs Tkinter. It will create a GUI with an alphabetical list
3
of fonts using the names as they will be shown in Scribus. User can select
4
one or more fonts and create an example sheet(s) to print or create a PDF
5
from. It is heavily commented to make it easier for the user to adjust it
6
for his / her own needs.
222 Franz 7
 
540 subik 8
First release   : 30/12/2003
9
 
10
This release     : v0.6.1 (released 24th Feb 2004)
11
 
12
Copyright               : (C) 2003 - 2004 Steve Callcott
13
 
14
email                   : stotte@ntlworld.com
15
 
16
Latest releases : www.
17
 
18
Maintainer              : Steve Callcott 2003 - 2004
19
 
20
Feature requests and bug reports to stotte@ntlworld.com
21
For revision history see the ChangeLog file.
22
Bugs and future plans are listed in the TODO file.
23
See NEWS for new features since last version.
24
 
25
This program is free software; you can redistribute it and/or modify
26
it under the terms of the GNU General Public License as published by
27
the Free Software Foundation; either version 2 of the License, or
28
(at your option) any later version.
29
 
30
This program is distributed in the hope that it will be useful,
31
but WITHOUT ANY WARRANTY; without even the implied warranty of
32
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
GNU General Public License for more details.
34
 
35
You should have received a copy of the GNU General Public License
36
along with this program; if not, write to the Free Software
37
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38
"""
39
 
222 Franz 40
from Tkinter import *
41
from scribus import *
42
 
43
 
44
class BookStyle:
45
        pass
46
bookstyle = BookStyle()
47
 
48
 
49
class TocStyle:
50
        pass
51
tocstyle = TocStyle()
52
 
53
 
54
class Paper:
55
        pass
56
paper = Paper()
57
 
58
 
59
bookstyle.fixedfont = ""
60
bookstyle.propfont = ""
61
tocstyle.charsInRow = 75
62
 
63
 
64
def setFixedFont():
65
        fixed = (
66
        "Luxi Mono Regular",
67
        "Nimbus Mono L Regular"
68
        "Courier 10 Pitch Regular"
69
        "Courier New Regular"
70
        "Courier Regular"
71
        "Andale Mono Regular"
72
        "Larabiefont Regular"
73
        )
74
 
751 subik 75
        fontlist = getFontNames()
222 Franz 76
        found = 0
77
        for f in fixed:
78
                if found == 1:
79
                        break
80
                for i in fontlist:
81
                        if found == 0:
82
                                if f == i:
83
                                        bookstyle.fixedfont = f
84
                                        found = 1
85
                                        break
86
        if found == 0:
87
                print "Please install at least one of these fixed width fonts:"
88
                print fixed
89
 
90
 
91
def setPropFont():
92
        proportional = (
93
        "Nimbus Sans L Regular",
94
        "Luxi Sans Regular",
95
        "Bitstream Vera Sans",
96
        "Helvetica",
97
        "Arial Regular"
98
        )
99
 
751 subik 100
        fontlist = getFontNames()
222 Franz 101
        found = 0
102
        for p in proportional:
103
                if found == 1:
104
                        break
105
                for i in fontlist:
106
                        if found == 0:
107
                                if p == i:
108
                                        bookstyle.propfont = p
109
                                        found = 1
110
                                        break
111
        if found == 0:
112
                print "Please install at least one of these proportional fonts:"
113
                print proportional
114
 
115
 
116
def setPaperSize(paperSize):
117
        if paperSize == 1:                              # A4 - 595 x 842 Points
751 subik 118
                paper.size = PAPER_A4
222 Franz 119
                paper.width = 595
120
                paper.height = 842
121
                paper.tmargin = 60
122
                paper.bmargin = 50
123
                paper.lmargin = 50
124
                paper.rmargin = 50
125
                paper.binding = 16
126
                tocstyle.tocRows = 56
127
                paper.pagenumvoffset = 16
128
                paper.textwidth = paper.width - paper.lmargin - paper.rmargin - 2
129
                paper.lmarginOdd = paper.lmargin + paper.binding
130
                paper.rmarginEven = paper.rmargin + paper.binding
131
                paper.textheight = paper.height - paper.tmargin - paper.bmargin
132
                paper.margins = paper.lmargin, paper.rmargin, paper.tmargin, paper.bmargin
133
        if paperSize == 2:                              # US Letter - 612 x 792 Points
751 subik 134
                paper.size = PAPER_LETTER
222 Franz 135
                paper.width = 612
136
                paper.height = 792
137
                paper.tmargin = 27
138
                paper.bmargin = 45
139
                paper.lmargin = 50
140
                paper.rmargin = 50
141
                paper.binding = 18
142
                tocstyle.tocRows = 55
143
                paper.pagenumvoffset = 16
144
                paper.textwidth = paper.width - paper.lmargin - paper.rmargin - 2
145
                paper.lmarginOdd = paper.lmargin + paper.binding
146
                paper.rmarginEven = paper.rmargin + paper.binding
147
                paper.textheight = paper.height - paper.tmargin - paper.bmargin
148
                paper.margins = paper.lmargin, paper.rmargin, paper.tmargin, paper.bmargin
149
 
150
 
151
def setTextWidthForBinding(wantBindingOffset):
152
        # if we are adding a binding offset to the margins then we will have less width for our text.
153
        if wantBindingOffset == 1:
154
                paper.textwidth = paper.width - paper.lmargin - paper.rmargin - paper.binding - 2
155
        else:
156
                paper.textwidth = paper.width - paper.lmargin - paper.rmargin -2
157
 
158
 
159
def setPageGeometries():
160
        setPaperSize(app.paper.get())
161
        setTextWidthForBinding(app.wantBindingOffset.get())
162
 
163
 
164
def setOddEven(pageNum):
165
        # This function checks the number passed to it and sets left and right
540 subik 166
        # margins accordingly.Call it once after each new page is created.
222 Franz 167
        # Also it will return 1 if even and 0 if odd page.
168
        if pageNum % 2 == 0:
169
                isEvenPage = 1                                                                                  # Even side
170
        else:
171
                isEvenPage = 0                                                                                  # Odd side
172
 
173
        if app.wantBindingOffset.get() == 1:
174
                if isEvenPage == 1 and app.wantDoubleSided.get() == 1# Even (when double sided)
175
                        paper.leftSide = paper.lmargin + 1
176
                        paper.rightSide = paper.rmarginEven + 1
177
                else:                                                                                                   # Odd side
178
                        paper.leftSide = paper.lmarginOdd + 1
179
                        paper.rightSide = paper.rmargin + 1
180
        else:                                                                                                           # No binding
181
                paper.leftSide = paper.lmargin + 1
182
                paper.rightSide = paper.rmargin + 1
183
 
184
        return isEvenPage
185
 
186
 
187
def addSampleRow(font, fontsize, linespace, textstring, x, y, w, h, style, getSizeOnly):
188
        if getSizeOnly == 0:
751 subik 189
                f = createText(x, y, w, h)
190
                insertText(textstring, 0, f)
222 Franz 191
                if style == "l":
751 subik 192
                        setFont(bookstyle.propfont, f)
222 Franz 193
                else:
751 subik 194
                        setFont(font, f)
195
                setFontSize(fontsize, f)
196
                setLineSpacing(linespace, f)
197
                setTextAlignment(ALIGN_LEFT, f)
222 Franz 198
        return y + h + 1
199
 
200
 
201
def drawSampleBlock(fontname, x, y, w, getSizeOnly):
202
        startPos = y
203
 
204
        # An "l" as last parameter will result in that line being in a plain font.
205
        # Use \xBC etc to insert Hex ascii chars into the sample strings below.
206
 
207
        samples = (
208
        # Key: fontsize, linespace, textstring, height, style
209
        # comment out any sample lines below that you do not require...
210
        [16, 15, fontname + '\n', 23, "l"],
211
        [10.5, 12, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#?$*&\n", 18, ""],
212
        [6, 6, "This line is in 6 point\n", 13, ""],
213
        [8, 8, "This line is in 8 point\n", 16, ""],
214
        [10, 11, "This line is in 10 point\n", 19, ""],
215
        [12, 11, "This line is in 12 point\n", 21, ""],
216
        [16, 13, "This line is in 16 point\n", 26, ""],
217
        [20, 16, "This line is in 20 point\n", 31, ""],
218
        [32, 29, "This line is in 32 point\n", 49, ""]
219
        )
220
 
221
        for i in samples:
222
                # (note there is one extra point inserted by addSampleRow() for each row generated)...
223
                y = addSampleRow(fontname, i[0], i[1], i[2], x, y, w, i[3], i[4], getSizeOnly)
224
        y = y + 1
225
 
226
        if getSizeOnly == 0:
751 subik 227
                createLine(x, y, (w + x), y)
222 Franz 228
        else:
229
                y = y + 1       # if changing line above then check this, it should be exactly  the same as the line height
230
        y = y + 5
231
        return y - startPos
232
 
233
 
234
def addTocRow(fontname, pageNum, ypos, frame):
235
        dotline = ""
236
        dotquant = tocstyle.charsInRow - len(fontname) - len(str(pageNum)) + 1
237
        for i in range(dotquant):
238
                dotline = dotline + '.'
239
        oneline = fontname + dotline + str(pageNum) + "\n"
751 subik 240
        insertText(oneline, ypos, frame)
222 Franz 241
        ypos = ypos + len(oneline) + 0
242
        return ypos
243
 
244
 
245
def buildTocPageFrames():
246
        # first put a header on the empty page...
247
        textstring = "Table of Contents"
248
        ypos = paper.tmargin + 1
751 subik 249
        header = createText(paper.leftSide, ypos, paper.textwidth, 35)
250
        insertText(textstring, 0, header)
251
        setFont(bookstyle.propfont, header)
252
        setFontSize(24, header)
253
        setTextAlignment(ALIGN_CENTERED, header)
222 Franz 254
 
255
        # now create a text frame for the table of contents...
256
        ypos = ypos + 36
751 subik 257
        body = createText(paper.leftSide, ypos, paper.textwidth, paper.height - ypos - paper.bmargin - 1)
258
        setFont(bookstyle.fixedfont, body)
259
        setFontSize(10, body)
260
        setLineSpacing(12, body)
222 Franz 261
        return body
262
 
263
 
264
def addToc(tocList):
265
        rowCount = 0
266
        ypos = 0
267
        tocPageNum = 1
268
        tocPageCount = 1
269
 
751 subik 270
        newPage(tocPageNum)
222 Franz 271
        isEvenPage = setOddEven(tocPageNum)
272
        body = buildTocPageFrames()                             # create frames for new empty page
273
        if isEvenPage == 0:
751 subik 274
                setTextAlignment(ALIGN_RIGHT, body)
222 Franz 275
        else:
751 subik 276
                setTextAlignment(ALIGN_LEFT, body)
222 Franz 277
        for i in tocList:
278
                ypos = addTocRow(i[0], i[1], ypos, body)
279
                rowCount = rowCount + 1
280
                if rowCount > tocstyle.tocRows:         # Need to build a new TOC page (started from zero, not one)
281
                        tocPageNum = tocPageNum + 1
751 subik 282
                        newPage(tocPageNum)
222 Franz 283
                        isEvenPage = setOddEven(tocPageNum)
284
                        body = buildTocPageFrames()
285
                        if isEvenPage == 0:
751 subik 286
                                setTextAlignment(ALIGN_RIGHT, body)
222 Franz 287
                        else:
751 subik 288
                                setTextAlignment(ALIGN_LEFT, body)
222 Franz 289
                        rowCount = 0
290
                        ypos = 0
291
                        tocPageCount = tocPageCount + 1
292
        if app.wantDoubleSided.get() == 1:
293
                if tocPageCount % 2 != 0:                       # Odd page
294
                        tocPageNum = tocPageNum + 1
751 subik 295
                        newPage(tocPageNum)                             # Add an extra page if odd number
222 Franz 296
 
297
 
298
def addPageNum(pagenum):
299
        ypos = paper.height - paper.bmargin - paper.pagenumvoffset
751 subik 300
        footer = createText(paper.leftSide, ypos, paper.textwidth, 15)
301
        insertText("%s" % pagenum, 0, footer)
302
        setFont(bookstyle.propfont, footer)
303
        setFontSize(9, footer)
304
        setTextAlignment(ALIGN_CENTERED, footer)
305
        setLineSpacing(10, footer)
222 Franz 306
 
307
 
308
def useSelection(fontlist):
309
        tocList = []
310
        ypos = paper.tmargin + 1
311
        pageNum = 1
751 subik 312
        if newDoc(paper.size, paper.margins, PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT):
313
                setRedraw(0)                                            # Disable redrawing
222 Franz 314
                # We have a new page by default so set it up first...
315
                setOddEven(pageNum)
316
                if app.wantPageNum.get() == 1:
317
                        addPageNum(pageNum)
751 subik 318
                createLine(paper.leftSide, ypos, paper.leftSide + paper.textwidth, ypos)
222 Franz 319
                ypos = ypos + 5
320
                for i in fontlist:
321
                        # Test if fits...
322
                        blockHeight = drawSampleBlock(i, paper.leftSide, ypos, paper.textwidth, 1)
323
                        if ypos + blockHeight > paper.height - paper.bmargin - paper.pagenumvoffset:
324
                                # Not enough room so create a new page first...
751 subik 325
                                newPage(-1)
222 Franz 326
                                pageNum = pageNum + 1
327
                                setOddEven(pageNum)
328
                                ypos = paper.tmargin +1         # Reset y position back to top of page
329
                                if app.wantPageNum.get() == 1:
330
                                        addPageNum(pageNum)
751 subik 331
                                createLine(paper.leftSide, ypos, paper.leftSide + paper.textwidth, ypos)
222 Franz 332
                                ypos = ypos + 5
333
                        # Now place the actual sample block...
334
                        blockHeight = drawSampleBlock(i, paper.leftSide, ypos, paper.textwidth, 0)
335
                        ypos = ypos + blockHeight
336
                        tocList.append([i, pageNum])    # Add to TOC
337
                if app.wantToc.get() == 1:
338
                        addToc(tocList)                                 # Insert table of contents - (before page numbering)
751 subik 339
                gotoPage(1)
340
                setRedraw(1)                                            # Enable redraws again
222 Franz 341
        app.quit()
342
 
343
 
344
class Application(Frame):
345
        def __init__(self, master = None):
346
                Frame.__init__(self, master)
347
                self.pack(fill=BOTH, expand=1)
348
                self.grid_rowconfigure(0, weight=1)
349
                self.grid_columnconfigure(0, weight=1)
350
 
351
                # now start adding our widgets starting with the top frame...
352
                self.listbox_frame = Frame(self)
353
                self.listbox_frame.grid()
354
 
355
                # left hand listbox
356
                self.yScroll1 = Scrollbar(self.listbox_frame, orient=VERTICAL)
357
                self.yScroll1.grid(row=0, column=1, sticky=NS)
358
                self.xScroll1 = Scrollbar(self.listbox_frame, orient=HORIZONTAL)
359
                self.xScroll1.grid(row=1, column=0, sticky=EW)
360
 
361
                self.listbox1 = Listbox(self.listbox_frame,
362
                        xscrollcommand=self.xScroll1.set,
363
                        yscrollcommand=self.yScroll1.set,
364
                        selectmode=EXTENDED,
365
                        height=20, width=40)
366
                self.listbox1.grid(row=0, column=0, sticky=NSEW)
367
                self.xScroll1["command"] = self.listbox1.xview
368
                self.yScroll1["command"] = self.listbox1.yview
369
 
370
                def __lbox1Callback(event):
371
                        self.__listSelectionToRight()
372
                self.listbox1.bind("<Double-Button-1>", __lbox1Callback)
373
 
374
                def __lbox1ClickCallback(event):
375
                        self.listbox2.selection_clear(0,END)
376
                        self.__setUpDownActive(0, 0)    # Force a disable if in other box
377
                        if self.listbox1.size() > 0:
378
                                self.__setSelButtonsActive(0, 1)
379
                        else:
380
                                self.__setSelButtonsActive(0, 0)
381
                self.listbox1.bind("<Button-1>", __lbox1ClickCallback)
382
                self.listbox1.bind("<FocusIn>", __lbox1ClickCallback)
383
                self.listbox1.bind("<FocusOut>", __lbox1ClickCallback)
384
 
385
                # middle button frame
386
                self.midbutton_frame = Frame(self.listbox_frame)
387
                self.midbutton_frame.grid(row=0, column=2, sticky=NSEW)
388
 
389
                self.rsingleButton = Button(self.midbutton_frame, state='disabled', text=">", command=self.__rsingleButtonClick)
390
                self.rsingleButton.grid(row=0, column=0, padx=5, pady=5, sticky=EW)
391
                self.rdoubleButton = Button(self.midbutton_frame, text=">>", command=self.__rdoubleButtonClick)
392
                self.rdoubleButton.grid(row=1, column=0, padx=5, pady=5, sticky=EW)
393
 
394
                self.itemupButton = Button(self.midbutton_frame, state='disabled', text="Up", command=self.__itemupButtonClick)
395
                self.itemupButton.grid(row=2, column=0, padx=5, pady=5, sticky=EW)
396
                self.itemdownButton = Button(self.midbutton_frame, state='disabled', text="Down", command=self.__itemdownButtonClick)
397
                self.itemdownButton.grid(row=3, column=0, padx=5, pady=5, sticky=EW)
398
 
399
                self.lsingleButton = Button(self.midbutton_frame, state='disabled', text="<", command=self.__lsingleButtonClick)
400
                self.lsingleButton.grid(row=4, column=0, padx=5, pady=5, sticky=EW)
401
                self.ldoubleButton = Button(self.midbutton_frame, state='disabled', text="<<", command=self.__ldoubleButtonClick)
402
                self.ldoubleButton.grid(row=5, column=0, padx=5, pady=5, sticky=EW)
403
 
404
                # Right hand listbox
405
                self.yScroll2 = Scrollbar(self.listbox_frame, orient=VERTICAL)
406
                self.yScroll2.grid(row=0, column=4, sticky=NS)
407
                self.xScroll2 = Scrollbar(self.listbox_frame, orient=HORIZONTAL)
408
                self.xScroll2.grid(row=1, column=3, sticky=EW)
409
 
410
                self.listbox2 = Listbox(self.listbox_frame,
411
                        xscrollcommand=self.xScroll2.set,
412
                        yscrollcommand=self.yScroll2.set,
413
                        selectmode=EXTENDED,
414
                        height=20, width=40)
415
                self.listbox2.grid(row=0, column=3, sticky=NSEW)
416
                self.xScroll2["command"] = self.listbox2.xview
417
                self.yScroll2["command"] = self.listbox2.yview
418
 
419
                def __lbox2callback(event):
420
                        self.__listSelectionToLeft()
421
                        self.__testUpDownState()        # Really want to get at the listbox2 onchange event
422
                self.listbox2.bind("<Double-Button-1>", __lbox2callback)
423
 
424
                def __lbox2ClickCallback(event):
425
                        self.listbox1.selection_clear(0,END)
426
                        self.__testUpDownState()
427
                        if self.listbox2.size() > 0:
428
                                self.__setSelButtonsActive(1, 0)
429
                        else:
430
                                self.__setSelButtonsActive(0, 0)
431
                self.listbox2.bind("<Button-1>", __lbox2ClickCallback)
432
                self.listbox2.bind("<FocusIn>", __lbox2ClickCallback)
433
                self.listbox2.bind("<FocusOut>", __lbox2ClickCallback)
434
 
435
                def __lbox2ButtonUpCallback(event):
436
                        self.__testUpDownState()        # Catches a mouse drag highlight by testing on button release
437
                self.listbox2.bind("<ButtonRelease>", __lbox2ButtonUpCallback)
438
 
439
                # now draw the bottom controls frame...
440
                self.controls_frame = Frame(self)
441
                self.controls_frame.grid(row=1, column=0, sticky=EW)
442
 
443
                # now the paper size radio buttons...
444
                self.paper = IntVar()
445
                self.radiobutton_frame = Frame(self.controls_frame, bd=1, relief=RIDGE)
446
                self.radiobutton_frame.grid(row=0, column=0, padx=10, pady=2)
447
                self.a4papersizeSelect = Radiobutton(self.radiobutton_frame, text="A4", variable=self.paper, value=1, command=self.__a4paperButtonClick)
448
                self.a4papersizeSelect.grid(row=0, column=0, padx=0, sticky=W)
449
                self.uspapersizeSelect = Radiobutton(self.radiobutton_frame, text="US Letter", variable=self.paper, value=2, command=self.__uspaperButtonClick)
450
                self.uspapersizeSelect.grid(row=1, column=0, padx=0, sticky=W)
451
                self.a4papersizeSelect.select()
452
 
453
                # now the TOC and page number selection buttons...
454
                self.wantToc = IntVar()
455
                self.wantPageNum = IntVar()
456
                self.togglebutton_frame = Frame(self.controls_frame, bd=1, relief=RIDGE)
457
                self.togglebutton_frame.grid(row=0, column=1, padx=10, pady=2)
458
                self.pagenumSelect = Checkbutton(self.togglebutton_frame, text="want page numbers", variable=self.wantPageNum, offvalue=0, onvalue=1)
459
                self.pagenumSelect.grid(row=0, column=0, padx=0, sticky=W)
460
                self.tocSelect = Checkbutton(self.togglebutton_frame, text="Print TOC", variable=self.wantToc, offvalue=0, onvalue=1)
461
                self.tocSelect.grid(row=1, column=0, padx=0, sticky=W)
462
                self.pagenumSelect.select()
463
                self.tocSelect.select()
464
 
465
                # now the binding offset and double sided selection buttons...
466
                self.wantBindingOffset = IntVar()
467
                self.wantDoubleSided = IntVar()
468
                self.bindingbutton_frame = Frame(self.controls_frame, bd=1, relief=RIDGE)
469
                self.bindingbutton_frame.grid(row=0, column=2, padx=10, pady=2)
470
                self.bindingoffsetSelect = Checkbutton(self.bindingbutton_frame, text="Extra offset for binding", variable=self.wantBindingOffset, offvalue=0, onvalue=1, command=self.__bindingoffsetSelectButtonClick)
471
                self.bindingoffsetSelect.grid(row=0, column=0, sticky=W)
472
                self.doublesidedSelect = Checkbutton(self.bindingbutton_frame, text="Double sided pages", variable=self.wantDoubleSided, offvalue=0, onvalue=1)
473
                self.doublesidedSelect.grid(row=1, column=0, rowspan=2, sticky=W)
474
 
475
                # now the ok and cancel buttons...
476
                self.cancelButton = Button(self.controls_frame, text="Cancel", command=self.__cancelButtonClick)
477
                self.cancelButton.grid(row=0, column=3, padx=5)
478
                self.okButton = Button(self.controls_frame, text="OK", state='disabled', command=self.__okButtonClick)
479
 
480
                self.okButton.grid(row=0, column=4, padx=5)
481
 
482
                # now create the bottom status bar frame and contents...
483
                self.status_frame = Frame(self)
484
                self.status_frame.grid(row=2, column=0, sticky=E+W)
485
                self.status0 = Label(self.status_frame, bd=1, relief=SUNKEN, anchor=W)
486
                self.status0.pack(side=LEFT)
487
                self.status1 = Label(self.status_frame, bd=1, relief=SUNKEN, anchor=W)
488
                self.status1.pack(side=LEFT)
489
                self.status2 = Label(self.status_frame, bd=1, relief=SUNKEN, anchor=W)
490
                self.status2.pack(fill=X)
491
 
492
        def statusbarUpdate(self):
493
                available = self.listbox1.size()
494
                selected = self.listbox2.size()
495
                size = FloatType(selected)
496
                value = size / 3
497
                pages = IntType(value)                                  # Get whole part of number
498
                value = value - pages                                   # Remove whole number part
499
                if value > 0:                                                   # Test remainder
500
                        pages = pages + 1                               # Had remainder so add a page
501
                self.status0['text'] = "Fonts available: %s    " % (available + selected)
502
                self.status1['text'] = "Fonts selected: %s    " % selected
503
                self.status2['text'] = "Sheets required: %s    " % pages
504
 
505
        def __listSelectionToRight(self):
506
                toMoveRight = ListType(self.listbox1.curselection())
507
                self.listbox1.selection_clear(0,END)
508
                toMoveRight.reverse()   # reverse list so we delete from bottom of listbox first
509
                templist = []
510
                for i in toMoveRight:
511
                        templist.insert(0,self.listbox1.get(i)) # gets the actual strings (reverse again)
512
                        self.listbox1.delete(i)
513
                for j in templist:
514
                        self.listbox2.insert(END, j)
515
                self.__setButtonsState()
516
                self.__setSelButtonsActive(0, 0)
517
                self.statusbarUpdate()
518
 
519
        def __listSelectionToLeft(self):
520
                toMoveLeft = ListType(self.listbox2.curselection())
521
                toMoveLeft.reverse()
522
                self.listbox2.selection_clear(0,END)
523
                for i in toMoveLeft:
524
                        self.listbox1.insert(END, self.listbox2.get(i)) # Insert it at the end
525
                        self.listbox2.delete(i)
526
                fontlist = ListType(self.listbox1.get(0, END))          # Copy contents to a list type
527
                self.listbox1.delete(0, END)                                            # Remove all contents
528
                fontlist.sort()                                                                         # Use sort method of list
529
                for j in fontlist:
530
                        self.listbox1.insert(END, j)                                    # Replace with sorted version
531
                self.__setButtonsState()
532
                self.__setSelButtonsActive(0, 0)
533
                self.statusbarUpdate()
534
 
535
        def __listAllToRight(self):
536
                fontlist = self.listbox1.get(0, END)    # Get each font name into a list
537
                for i in fontlist:
538
                        self.listbox2.insert(END, i)            # Copy each one
539
                self.listbox1.delete(0, END)                    # All done so empty the left listbox
540
                self.__setButtonsState()
541
                self.__setSelButtonsActive(0, 0)
542
                self.statusbarUpdate()
543
 
544
        def __listAllToLeft(self):
545
                # This quick way just clears both sides and reloads left listbox in correct order from scratch
546
                self.listbox1.delete(0, END)
751 subik 547
                fontlist = getFontNames()
222 Franz 548
                fontlist.sort()
549
                for i in fontlist:
550
                        self.listbox1.insert(END, i)
551
                self.listbox2.delete(0, END)
552
                self.__setButtonsState()
553
                self.__setSelButtonsActive(0, 0)
554
                self.statusbarUpdate()
555
 
556
        def __setSelButtonsActive(self, selToRight, selToLeft):
557
                # The "selection" buttons are the ones with ">"  and "<"  on them
558
                if selToRight == 1:
559
                        self.lsingleButton['state'] = NORMAL
560
                else:
561
                        self.lsingleButton['state'] = DISABLED
562
                if selToLeft == 1:
563
                        self.rsingleButton['state'] = NORMAL
564
                else:
565
                        self.rsingleButton['state'] = DISABLED
566
 
567
        def __setAllButtonsActive(self, allToRight, allToLeft):
568
                # The "all" buttons are the ones with ">>"  and "<<"  on them
569
                if allToRight == 1:
570
                        self.rdoubleButton['state'] = NORMAL
571
                else:
572
                        self.rdoubleButton['state'] = DISABLED
573
                if allToLeft == 1:
574
                        self.ldoubleButton['state'] = NORMAL
575
                else:
576
                        self.ldoubleButton['state'] = DISABLED
577
 
578
        def __setButtonsState(self):
579
                if self.listbox2.size() > 0 and self.listbox1.size() > 0:
580
                        self.__setAllButtonsActive(1, 1)
581
                        self.okButton['state'] = NORMAL
582
                elif self.listbox2.size() == 0:
583
                        self.__setAllButtonsActive(1, 0)
584
                        self.okButton['state'] = DISABLED
585
                elif self.listbox1.size() == 0:
586
                        self.__setAllButtonsActive(0, 1)
587
                        self.okButton['state'] = NORMAL
588
 
589
        def __itemUp(self):
590
                # This function is intended to be used with one item selected
591
                selection = self.listbox2.curselection()        # Returns tuple, we only want one item
592
                indexid = IntType(selection[0])                         # Get the first in the list, convert to integer type
593
                if indexid > 0:
594
                        fontstring = self.listbox2.get(indexid)
595
                        self.listbox2.delete(indexid)
596
                        newpos = indexid - 1
597
                        self.listbox2.selection_clear(0, END)
598
                        self.listbox2.insert(newpos, fontstring)
599
                        self.listbox2.see(newpos - 10)                  # Scrolls listbox automatically into view if req.
600
                        self.listbox2.selection_set(newpos)
601
                        self.__testUpDownState()
602
 
603
        def __itemDown(self):
604
                # This function is intended to be used with one item selected
605
                limit = self.listbox2.size()
606
                selection = self.listbox2.curselection()
607
                indexid = IntType(selection[0])
608
                if indexid < limit - 1:
609
                        fontstring = self.listbox2.get(indexid)
610
                        self.listbox2.delete(indexid)
611
                        newpos = indexid + 1
612
                        self.listbox2.selection_clear(0, END)
613
                        self.listbox2.insert(newpos, fontstring)
614
                        self.listbox2.see(newpos + 10)
615
                        self.listbox2.selection_set(newpos)
616
                        self.__testUpDownState()
617
 
618
        def __setUpDownActive(self, up, down):
619
        # This function just sets the buttons active or inactive
620
        # See testUpDown() for actual evaluation
621
                if up == 1:
622
                        self.itemupButton['state'] = NORMAL
623
                else:
624
                        self.itemupButton['state'] = DISABLED
625
                if down == 1:
626
                        self.itemdownButton['state'] = NORMAL
627
                else:
628
                        self.itemdownButton['state'] = DISABLED
629
 
630
        def __testUpDownState(self):
631
                # Only ungray the up and down buttons when just a single item is
632
                # selected and then it should be up, down or both depending on its
633
                # position in the listbox. At all other times gray out both.
634
 
635
                # Get a count of how many items are currently selected...
636
                selection = list(self.listbox2.curselection())
637
                tcount = 0
638
                for sel in selection:
639
                        tcount = tcount + 1
640
 
641
                position = 0
642
                if tcount == 1:
643
                        position = IntType(selection[0])
644
 
645
                # If one selected and there is more than one item in the listbox then ok...
646
                if tcount == 1 and self.listbox2.size() > 1:
647
                        # Now test the position of the selected line...
648
                        if position > 0 and position < self.listbox2.size() - 1:    # Both
649
                                self.__setUpDownActive(1, 1)
650
                        # If not one less or lesser from the bottom (listbox.count-1?) then gray the down button.
651
                        elif position == self.listbox2.size() - 1:                                      # Up only
652
                                self.__setUpDownActive(1, 0)
653
                        # If not one or more from the top then gray up button.
654
                        elif position == 0:                                                                                     # Down only
655
                                self.__setUpDownActive(0, 1)
656
                else:
657
                        self.__setUpDownActive(0, 0)
658
 
659
        def quit(self):
660
                self.master.destroy()
661
 
662
        # create the button events...
663
        def __rsingleButtonClick(self):
664
                self.__listSelectionToRight()
665
 
666
        def __rdoubleButtonClick(self):
667
                self.__listAllToRight()
668
 
669
        def __lsingleButtonClick(self):
670
                self.__listSelectionToLeft()
671
                self.__testUpDownState()
672
 
673
        def __ldoubleButtonClick(self):
674
                self.__listAllToLeft()
675
                self.__testUpDownState()
676
 
677
        def __itemupButtonClick(self):
678
                self.__itemUp()
679
 
680
        def __itemdownButtonClick(self):
681
                self.__itemDown()
682
 
683
        def __cancelButtonClick(self):
684
                self.master.destroy()
685
 
686
        def __bindingoffsetSelectButtonClick(self):
687
                setPageGeometries()
688
 
689
        def __a4paperButtonClick(self):
690
                setPageGeometries()
691
 
692
        def __uspaperButtonClick(self):
693
                setPageGeometries()
694
 
695
        def __okButtonClick(event):
696
                useSelection(app.listbox2.get(0, END))
697
 
698
 
699
root = Tk()
700
app = Application(root)
701
app.master.resizable(0, 0)
702
app.master.title("(v0.6.1) Select fonts to use")
703
# get and set the initial paper size to match default radiobutton selection
704
setPageGeometries()
705
# now get a list of all the fonts...
751 subik 706
fontlist = getFontNames()
222 Franz 707
fontlist.sort()
708
# and put the list in the GUI listbox...
709
for i in fontlist:
710
        app.listbox1.insert(END, i)
711
setFixedFont()
712
setPropFont()
713
app.statusbarUpdate()
714
# now show the fonts list and wait for user to make a choice...
715
app.mainloop()
751 subik 716