/
pyp_pres_panel.py
executable file
·269 lines (199 loc) · 8.18 KB
/
pyp_pres_panel.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import wx
import os, cPickle, pdb, subprocess
import persistent_panel
from rwkSingleFileChooser_v2 import rwkSingleFileChooser
import pyp_converter, rwkos
def_values = {'author':'Ryan Krauss','title':'My Title', \
'theme':'siue_Cambridge'}
themes = ['ryan_Warsaw', \
'siue_Cambridge', \
'AnnArbor', \
'Antibes', \
'Bergen', \
'Berkeley', \
'Berlin', \
'Boadilla', \
'CambridgeUS', \
'Copenhagen', \
'Darmstadt', \
'Dresden', \
'Frankfurt', \
'Goettingen', \
'Hannover', \
'Ilmenau', \
'JuanLesPins', \
'Luebeck', \
'Madrid', \
'Malmoe', \
'Marburg', \
'Montpellier', \
'PaloAlto', \
'Pittsburgh', \
'Rochester', \
'Singapore', \
'Szeged', \
'Warsaw']
go_button_id = wx.NewId()
launch_pdf_id = wx.NewId()
import rwkos
class main_panel(persistent_panel.Persistent_Panel):
def __init__(self, parent, *args, **kwds):
persistent_panel.Persistent_Panel.__init__(self, parent, \
*args, **kwds)
self.maindir = os.getcwd()
self.filechooser = rwkSingleFileChooser(self)
self.filechooser.filter = "PYP File (*.pyp)|*.pyp|All Files (*.*)|*.*"
self.author_label = wx.StaticText(self, -1, "Author")
self.author_box = wx.TextCtrl(self, -1, "")
self.title_label = wx.StaticText(self, -1, "Title")
self.title_box = wx.TextCtrl(self, -1, "")
self.theme_label = wx.StaticText(self, -1, "Beamer Theme")
self.theme_box = wx.ComboBox(self, -1, choices=themes)
self.draft_label = wx.StaticText(self, -1, "Draft")
self.draft_check = wx.CheckBox(self, -1)
self.go_button = wx.Button(self, go_button_id, "Go")
self.pdf_button = wx.Button(self, launch_pdf_id, "Open PDF")
self.only_one_label = wx.StaticText(self, -1, "Only One Slide")
self.only_one_check = wx.CheckBox(self, -1)
self.slide_num_label = wx.StaticText(self, -1, "Slide Number")
self.slide_num_box = wx.TextCtrl(self, -1, "-1")
only_one_sizer = wx.GridSizer(2,2)
TLR = wx.TOP|wx.LEFT|wx.RIGHT
BLR = wx.BOTTOM|wx.LEFT|wx.RIGHT
only_one_sizer.Add(self.only_one_label, 0, TLR, 5)
only_one_sizer.Add(self.slide_num_label, 0, TLR, 5)
only_one_sizer.Add(self.only_one_check, 0, BLR, 5)
only_one_sizer.Add(self.slide_num_box, 0, BLR, 5)
self.Bind(wx.EVT_BUTTON, self.On_Go_Button, self.go_button)
self.Bind(wx.EVT_BUTTON, self.Launch_PDF, self.pdf_button)
# Use a sizer to layout the controls, stacked vertically and with
# a 10 pixel border around each
##################
#
# Saving settings
#
##################
savesettingsname = 'pyp_pres_panel_settings.pkl'
self.settingspath = os.path.join(self.maindir, savesettingsname)
savekeys = ['path','author','title','theme','draft',\
'onlyone','slidenum']
getmethods = [self.filechooser.GetPath, \
self.author_box.GetValue, \
self.title_box.GetValue, \
self.theme_box.GetValue,\
self.draft_check.GetValue,
self.only_one_check.GetValue, \
self.slide_num_box.GetValue]
setmethods = [self.filechooser.SetPath, \
self.author_box.SetValue, \
self.title_box.SetValue, \
self.theme_box.SetValue, \
self.draft_check.SetValue, \
self.only_one_check.SetValue, \
self.slide_num_box.SetValue]
self.savedict = dict(zip(savekeys, getmethods))
self.loaddict = dict(zip(savekeys, setmethods))
self.LoadSettings(defaults=def_values)
self.Initialize()
#sizer and layout
grid_sizer = wx.FlexGridSizer(11, 1, 0, 0)
grid_sizer.Add(self.filechooser, 0, wx.ALL|wx.EXPAND, 5)
grid_sizer.Add(self.author_label, 0, wx.TOP|wx.LEFT|wx.RIGHT, 5)
grid_sizer.Add(self.author_box, 0, wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND, 5)
grid_sizer.Add(self.title_label, 0, wx.TOP|wx.LEFT|wx.RIGHT, 5)
grid_sizer.Add(self.title_box, 0, wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND, 5)
grid_sizer.Add(self.theme_label, 0, wx.TOP|wx.LEFT|wx.RIGHT, 5)
grid_sizer.Add(self.theme_box, 0, wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND, 5)
grid_sizer.Add(self.draft_label, 0, wx.TOP|wx.LEFT|wx.RIGHT, 5)
grid_sizer.Add(self.draft_check, 0, wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.EXPAND, 5)
grid_sizer.Add(only_one_sizer, 0, wx.ALL, 5)
grid_sizer.Add(self.go_button, 0, wx.ALL|wx.ALIGN_RIGHT, 5)
grid_sizer.Add(self.pdf_button, 0, wx.ALL|wx.ALIGN_RIGHT, 5)
grid_sizer.AddGrowableCol(0)
self.SetSizer(grid_sizer)
self.Layout()
def Initialize(self):
self.Build_PDF_Path()
def Build_PDF_Path(self):
path = self.Get_Path()
if path:
p_no_e, ext = os.path.splitext(path)
self.pdfpath = p_no_e+'.pdf'
def Get_Draft(self):
return self.draft_check.GetValue()
def Get_Author(self):
return self.author_box.GetValue()
def Get_Title(self):
return self.title_box.GetValue()
def Get_Theme(self):
return self.theme_box.GetValue()
def Get_Path(self):
return self.filechooser.GetPath()
def Get_Only_One_Ind(self):
if self.only_one_check.GetValue():
myind = int(self.slide_num_box.GetValue())
return [myind]
else:
return None
def Launch_PDF(self, event=0):
self.Build_PDF_Path()
path = rwkos.FindFullPath(self.pdfpath)
if rwkos.amiLinux():
pdfcmd = 'kpdf %s &'
cmd = pdfcmd % path
print(cmd)
os.system(cmd)
else:
pdfcmd = 'AcroRd32.exe %s'
cmd = pdfcmd % path
print(cmd)
subprocess.Popen(cmd)
def On_Go_Button(self, event):
draft = self.Get_Draft()
theme = self.Get_Theme()
title = self.Get_Title()
author = self.Get_Author()
path = self.Get_Path()
self.Build_PDF_Path()
slidenums = self.Get_Only_One_Ind()
path = rwkos.FindFullPath(path)
print('path='+path)
my_pres = pyp_converter.Beamer_pres(path, draft=draft, author=author, \
title=title, theme=theme)
my_pres.to_latex(slidenums=slidenums)
my_pres.save()
#if options.runlatex:
my_pres.run_latex()
pathout = my_pres.pathout
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title,
pos=(150, 150), size=(650, 500))
# Create the menubar
menuBar = wx.MenuBar()
# and a menu
menu = wx.Menu()
# add an item to the menu, using \tKeyName automatically
# creates an accelerator, the third param is some help text
# that will show up in the statusbar
menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit the application")
# bind the menu event to an event handler
self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
# and put the menu on the menubar
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
self.panel = main_panel(self)
def OnTimeToClose(self, event):
print('got OnTimeToClose event')
self.panel.SaveSettings()
self.Close()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, "PYP Presentation Generator")
self.SetTopWindow(frame)
#print "Print statements go to this stdout window by default."
frame.Show(True)
return True
if __name__ == "__main__":
app = MyApp(redirect=False)
app.MainLoop()