-
Notifications
You must be signed in to change notification settings - Fork 2
/
wikitree-tools.py
119 lines (93 loc) · 3.75 KB
/
wikitree-tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
import Tix
import ScrolledText
import os
import wt_lint
import ConfigParser
class WikiTreeApp(Tix.Frame):
def __init__(self, master=None):
Tix.Frame.__init__(self, master)
self.conf = ConfigParser.ConfigParser()
self.conf.add_section('Common')
self.conf.add_section('Lint')
self.conf.read((os.path.expanduser('~/.wikitree-tools.cfg'),))
self.pack(expand=1,fill='both')
self.createWidgets()
self.master.title('WikiTree tools')
def saveConfig(self):
self.conf.write(open(os.path.expanduser('~/.wikitree-tools.cfg'),'w'))
def createWidgets(self):
self.infile_entry = Tix.FileEntry(self)
self.infile_entry['dialogtype'] = 'tixExFileSelectDialog'
self.infile_entry['label'] = 'GEDCOM:'
self.infile_entry.pack(side='top',fill='x',expand=1)
self.infile = Tix.StringVar()
self.infile_entry['variable'] = self.infile
self.infile_entry['command'] = self.inputChanged
if self.conf.has_option('Common','input'):
self.infile.set(self.conf.get('Common','input'))
self.createLintWidgets()
self.output = ScrolledText.ScrolledText(self)
self.output['state'] = 'disabled'
self.output.pack(side='bottom',fill='both',expand=1)
def printOutput(self, data='', lf=True):
self.output['state'] = 'normal'
self.output.insert('end',data)
if lf:
self.output.insert('end','\n')
self.output.see('end')
self.output['state'] = 'disabled'
def createLintWidgets(self):
lf = Tix.LabelFrame(self)
lf['label'] = 'Lint'
lf.pack(side='top',fill='both',expand=1)
oe = Tix.FileEntry(lf)
oe['dialogtype'] = 'tixExFileSelectDialog'
oe['label'] = 'Lint output: (.html)'
oe.pack(side='top',fill='x',expand=1)
self.lint_output = Tix.StringVar()
oe['variable'] = self.lint_output
oe['command'] = self.lintOutputChanged
if self.conf.has_option('Lint','output'):
self.lint_output.set(self.conf.get('Lint','output'))
ma = Tix.LabelEntry(lf)
ma['label'] = 'Maximum age:'
self.max_age = Tix.DoubleVar()
ma.entry['textvariable'] = self.max_age
self.max_age.set(0.0)
ma.pack(side='top')
opts = Tix.Select(lf,allowzero=True)
opts['label'] = 'Options'
opts.add('birth',text='birth')
opts.add('death',text='death')
opts.pack(side='top',expand=1)
self.lint_options = Tix.StringVar()
opts['variable'] = self.lint_options
lb = Tix.Button(lf)
lb['text'] = 'Run Lint'
lb['command'] = self.runLint
lb.pack(side='right')
def inputChanged(self,value):
if os.path.exists(value):
self.conf.set('Common','input',value)
self.saveConfig()
def lintOutputChanged(self,value):
self.conf.set('Lint','output',value)
self.saveConfig()
def runLint(self):
self.printOutput('Running wt_lint: '+self.infile.get())
opts = []
if self.max_age.get() > 0:
opts.append('maxage='+str(self.max_age.get()))
print self.lint_options.get()
for o in self.lint_options.get()[1:-1].split(','):
if o:
opts.append(o[1:-1])
if self.lint_output.get():
opts.append('output='+self.lint_output.get())
if not os.path.exists(self.infile.get()):
self.printOutput('Missing GEDCOM file?')
else:
wt_lint.lint(self.infile.get(),opts,self.printOutput)
self.printOutput('wt_lint done')
WikiTreeApp(Tix.Tk()).mainloop()