[go: up one dir, main page]

Menu

[1e9e3f]: / main.py  Maximize  Restore  History

Download this file

725 lines (562 with data), 30.5 kB

  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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# This script is no longer executable, use launch.py
# -*- coding: utf-8 -*-
# System modules
import wx, os, shutil, subprocess, webbrowser, tarfile
from urllib2 import URLError, HTTPError
# Local modules
import dbr, wiz_bin
from dbr import Logger, DebugEnabled, GT
from dbr.constants import VERSION, VERSION_STRING, HOMEPAGE, \
ID_BUILD, ID_CHANGELOG, ID_MAN, ID_CONTROL, ID_COPYRIGHT, ID_DEPENDS,\
ID_GREETING, ID_FILES, ID_SCRIPTS, ID_MENU, ID_ZIP_NONE,\
ID_ZIP_GZ, ID_ZIP_BZ2, ID_ZIP_XZ, compression_formats
from dbr.config import GetDefaultConfigValue, WriteConfig
# Pages
ID_Dialogs = wx.NewId()
# Debian Policy Manual IDs
ID_DPM = wx.NewId()
ID_DPMCtrl = wx.NewId()
ID_DPMLog = wx.NewId()
ID_UPM = wx.NewId()
ID_Lintian = wx.NewId()
ID_QBUILD = wx.NewId()
ID_UPDATE = wx.NewId()
default_title = _(u'Debreate - Debian Package Builder')
class MainWindow(wx.Frame):
def __init__(self, pos, size):
wx.Frame.__init__(self, None, wx.ID_ANY, default_title, pos, size)
self.workingdir = None
self.SetMinSize((640,400))
# ----- Set Titlebar Icon
self.main_icon = wx.Icon(u'{}/bitmaps/debreate64.png'.format(dbr.application_path), wx.BITMAP_TYPE_PNG)
self.SetIcon(self.main_icon)
# If window is maximized this will store last window size and position for next session
wx.EVT_MAXIMIZE(self, self.OnMaximize)
# ----- Status Bar
self.stat_bar = wx.StatusBar(self, -1)
self.SetStatusBar(self.stat_bar)
# ***** Menu Bar ***** #
# ----- File Menu
self.menu_file = wx.Menu()
# Quick Build
self.QuickBuild = wx.MenuItem(self.menu_file, ID_QBUILD,
_(u'Quick Build'), _(u'Build a package from an existing build tree'))
self.QuickBuild.SetBitmap(wx.Bitmap(u'{}/bitmaps/clock16.png'.format(dbr.application_path)))
self.menu_file.Append(wx.ID_NEW, help=_(u'Start a new project'))
self.menu_file.Append(wx.ID_OPEN, help=_(u'Open a previously saved project'))
self.menu_file.Append(wx.ID_SAVE, help=_(u'Save current project'))
self.menu_file.Append(wx.ID_SAVEAS, help=_(u'Save current project with a new filename'))
self.menu_file.AppendSeparator()
self.menu_file.AppendItem(self.QuickBuild)
self.menu_file.AppendSeparator()
self.menu_file.Append(wx.ID_EXIT)
wx.EVT_MENU(self, wx.ID_NEW, self.OnNewProject)
wx.EVT_MENU(self, wx.ID_OPEN, self.OnOpenProject)
# Debugging
if DebugEnabled():
wx.EVT_MENU(self, wx.ID_SAVE, self.SaveProject)
else:
wx.EVT_MENU(self, wx.ID_SAVE, self.OnSaveProjectDeprecated)
wx.EVT_MENU(self, wx.ID_SAVEAS, self.OnSaveProjectDeprecated)
wx.EVT_MENU(self, ID_QBUILD, self.OnQuickBuild)
wx.EVT_MENU(self, wx.ID_EXIT, self.OnQuit)
wx.EVT_CLOSE(self, self.OnQuit) #custom close event shows a dialog box to confirm quit
# ----- Page Menu
self.menu_page = wx.Menu()
self.p_info = wx.MenuItem(self.menu_page, ID_GREETING, _(u'Information'),
_(u'Go to Information section'), kind=wx.ITEM_RADIO)
self.p_ctrl = wx.MenuItem(self.menu_page, ID_CONTROL, _(u'Control'),
_(u'Go to Control section'), kind=wx.ITEM_RADIO)
self.p_deps = wx.MenuItem(self.menu_page, ID_DEPENDS, _(u'Dependencies'),
_(u'Go to Dependencies section'), kind=wx.ITEM_RADIO)
self.p_files = wx.MenuItem(self.menu_page, ID_FILES, _(u'Files'),
_(u'Go to Files section'), kind=wx.ITEM_RADIO)
if DebugEnabled():
# FIXME: Add to Gettext locale files
self.p_man = wx.MenuItem(self.menu_page, ID_MAN, _(u'Manpages'),
_(u'Go to Manpages section'), kind=wx.ITEM_RADIO)
self.p_scripts = wx.MenuItem(self.menu_page, ID_SCRIPTS, _(u'Scripts'),
_(u'Go to Scripts section'), kind=wx.ITEM_RADIO)
self.p_clog = wx.MenuItem(self.menu_page, ID_CHANGELOG, _(u'Changelog'),
_(u'Go to Changelog section'), kind=wx.ITEM_RADIO)
self.p_cpright = wx.MenuItem(self.menu_page, ID_COPYRIGHT, _(u'Copyright'),
_(u'Go to Copyright section'), kind=wx.ITEM_RADIO)
self.p_menu = wx.MenuItem(self.menu_page, ID_MENU, _(u'Menu Launcher'),
_(u'Go to Menu Launcher section'), kind=wx.ITEM_RADIO)
self.p_build = wx.MenuItem(self.menu_page, ID_BUILD, _(u'Build'),
_(u'Go to Build section'), kind=wx.ITEM_RADIO)
self.menu_page.AppendItem(self.p_info)
self.menu_page.AppendItem(self.p_ctrl)
self.menu_page.AppendItem(self.p_deps)
self.menu_page.AppendItem(self.p_files)
if DebugEnabled():
self.menu_page.AppendItem(self.p_man)
self.menu_page.AppendItem(self.p_scripts)
self.menu_page.AppendItem(self.p_clog)
self.menu_page.AppendItem(self.p_cpright)
self.menu_page.AppendItem(self.p_menu)
self.menu_page.AppendItem(self.p_build)
# ----- Options Menu
self.menu_opt = wx.Menu()
# Dialogs options
self.cust_dias = wx.MenuItem(self.menu_opt, ID_Dialogs, _(u'Use Custom Dialogs'),
_(u'Use System or Custom Save/Open Dialogs'), kind=wx.ITEM_CHECK)
# Project compression options
# FIXME: Need custom IDs
self.menu_compression = wx.Menu()
opt_compression_uncompressed = wx.MenuItem(self.menu_compression, ID_ZIP_NONE,
GT(u'Uncompressed'), kind=wx.ITEM_RADIO)
opt_compression_gz = wx.MenuItem(self.menu_compression, ID_ZIP_GZ,
GT(u'Gzip'), kind=wx.ITEM_RADIO)
opt_compression_bz2 = wx.MenuItem(self.menu_compression, ID_ZIP_BZ2,
GT(u'Bzip2'), kind=wx.ITEM_RADIO)
opt_compression_xz = wx.MenuItem(self.menu_compression, ID_ZIP_XZ,
GT(u'XZ'), kind=wx.ITEM_RADIO)
compression_opts = (
opt_compression_uncompressed,
opt_compression_gz,
opt_compression_bz2,
opt_compression_xz,
)
for OPT in compression_opts:
self.menu_compression.AppendItem(OPT)
# FIXME: Re-enable when ready
self.menu_compression.Enable(ID_ZIP_XZ, False)
# Default compression
self.menu_compression.Check(ID_ZIP_BZ2, True)
self.menu_opt.AppendItem(self.cust_dias)
self.menu_opt.AppendSubMenu(self.menu_compression, GT(u'Project Compression'),
GT(u'Set the compression type for project save output'))
# ----- Help Menu
self.menu_help = wx.Menu()
# ----- Version update
self.version_check = wx.MenuItem(self.menu_help, ID_UPDATE, _(u'Check for Update'))
self.menu_help.AppendItem(self.version_check)
self.menu_help.AppendSeparator()
wx.EVT_MENU(self, ID_UPDATE, self.OnCheckUpdate)
# Menu with links to the Debian Policy Manual webpages
self.Policy = wx.Menu()
globe = wx.Bitmap(u'{}/bitmaps/globe16.png'.format(dbr.application_path))
self.DPM = wx.MenuItem(self.Policy, ID_DPM, _(u'Debian Policy Manual'), u'http://www.debian.org/doc/debian-policy')
self.DPM.SetBitmap(globe)
self.DPMCtrl = wx.MenuItem(self.Policy, ID_DPMCtrl, _(u'Control Files'), u'http://www.debian.org/doc/debian-policy/ch-controlfields.html')
self.DPMCtrl.SetBitmap(globe)
self.DPMLog = wx.MenuItem(self.Policy, ID_DPMLog, _(u'Changelog'), u'http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog')
self.DPMLog.SetBitmap(globe)
self.UPM = wx.MenuItem(self.Policy, ID_UPM, _(u'Ubuntu Policy Manual'), u'http://people.canonical.com/~cjwatson/ubuntu-policy/policy.html/')
self.UPM.SetBitmap(globe)
self.DebFrmSrc = wx.MenuItem(self.Policy, 222, _(u'Building debs from Source'), u'http://www.quietearth.us/articles/2006/08/16/Building-deb-package-from-source') # This is here only temporarily for reference
self.DebFrmSrc.SetBitmap(globe)
self.LintianTags = wx.MenuItem(self.Policy, ID_Lintian, _(u'Lintian Tags Explanation'), u'http://lintian.debian.org/tags-all.html')
self.LintianTags.SetBitmap(globe)
self.Policy.AppendItem(self.DPM)
self.Policy.AppendItem(self.DPMCtrl)
self.Policy.AppendItem(self.DPMLog)
self.Policy.AppendItem(self.UPM)
self.Policy.AppendItem(self.DebFrmSrc)
self.Policy.AppendItem(self.LintianTags)
self.references = {
ID_DPM: u'http://www.debian.org/doc/debian-policy',
ID_DPMCtrl: u'http://www.debian.org/doc/debian-policy/ch-controlfields.html',
ID_DPMLog: u'http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog',
ID_UPM: u'http://people.canonical.com/~cjwatson/ubuntu-policy/policy.html/',
222: u'http://www.quietearth.us/articles/2006/08/16/Building-deb-package-from-source',
ID_Lintian: u'http://lintian.debian.org/tags-all.html'
}
for R_ID in self.references:
wx.EVT_MENU(self, R_ID, self.OpenPolicyManual)
self.Help = wx.MenuItem(self.menu_help, wx.ID_HELP, _(u'Help'), _(u'Open a usage document'))
self.About = wx.MenuItem(self.menu_help, wx.ID_ABOUT, _(u'About'), _(u'About Debreate'))
self.menu_help.AppendMenu(-1, _(u'Reference'), self.Policy)
self.menu_help.AppendSeparator()
self.menu_help.AppendItem(self.Help)
self.menu_help.AppendItem(self.About)
wx.EVT_MENU(self, wx.ID_HELP, self.OnHelp)
wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
self.menubar = wx.MenuBar()
self.SetMenuBar(self.menubar)
self.menubar.Insert(0, self.menu_file, _(u'File'))
self.menubar.Insert(1, self.menu_page, _(u'Page'))
self.menubar.Insert(2, self.menu_opt, _(u'Options'))
self.menubar.Insert(3, self.menu_help, _(u'Help'))
# FIXME: QuickBuild broken
self.QuickBuild.SetText(u'Quick Build (Broken)')
self.QuickBuild.Enable(False)
# ***** END MENUBAR ***** #
self.wizard = dbr.Wizard(self) # Binary
self.page_info = wiz_bin.PageGreeting(self.wizard)
self.page_info.SetInfo()
self.page_control = wiz_bin.PageControl(self.wizard)
self.page_depends = wiz_bin.PageDepends(self.wizard)
self.page_files = wiz_bin.PageFiles(self.wizard)
if DebugEnabled():
self.page_man = wiz_bin.PageMan(self.wizard)
self.page_scripts = wiz_bin.PageScripts(self.wizard)
self.page_clog = wiz_bin.PageChangelog(self.wizard)
self.page_cpright = wiz_bin.PageCopyright(self.wizard)
self.page_menu = wiz_bin.PageMenu(self.wizard)
self.page_build = wiz_bin.PageBuild(self.wizard)
self.all_pages = (
self.page_control, self.page_depends, self.page_files, self.page_scripts,
self.page_clog, self.page_cpright, self.page_menu, self.page_build
)
self.bin_pages = [
self.page_info, self.page_control, self.page_depends, self.page_files, self.page_scripts,
self.page_clog, self.page_cpright, self.page_menu, self.page_build
]
if DebugEnabled():
self.bin_pages.insert(4, self.page_man)
self.wizard.SetPages(self.bin_pages)
self.pages = {self.p_info: self.page_info, self.p_ctrl: self.page_control, self.p_deps: self.page_depends,
self.p_files: self.page_files, self.p_scripts: self.page_scripts, self.p_clog: self.page_clog,
self.p_cpright: self.page_cpright, self.p_menu: self.page_menu, self.p_build: self.page_build}
if DebugEnabled():
self.pages[self.p_man] = self.page_man
for p in self.pages:
wx.EVT_MENU(self, p.GetId(), self.GoToPage)
# ----- Layout
self.main_sizer = wx.BoxSizer(wx.VERTICAL)
self.main_sizer.Add(self.wizard, 1, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(self.main_sizer)
self.Layout()
# Saving
# First item is name of saved file displayed in title
# Second item is actual path to project file
self.saved_project = wx.EmptyString
## Sets working directory for file open/save dialogs
#
# FIXME: Unused?
# \param target
# \b \e unicode|str : Target directory
def SetWorkingDirectory(self, target):
if target != None:
self.workingdir = target
else:
self.workingdir = GetDefaultConfigValue(u'workingdir')
if not os.path.isdir(self.workingdir):
Logger.Warning(__name__, _(u'Working directory set to "{}" which is not an actual directory'.format(self.workingdir)))
def OnMaximize(self, event):
# FIXME: ???
print(u'Maximized')
### ***** Check for New Version ***** ###
def OnCheckUpdate(self, event):
wx.SafeYield()
current = dbr.GetCurrentVersion()
if type (current) == URLError or type(current) == HTTPError:
current = unicode(current)
wx.MessageDialog(self, current, _(u'Error'), wx.OK|wx.ICON_ERROR).ShowModal()
elif (current > VERSION):
current = u'{}.{}.{}'.format(current[0], current[1], current[2])
l1 = _(u'Version %s is available!').decode(u'utf-8') % (current)
l2 = _(u'Would you like to go to Debreate\'s website?').decode(u'utf-8')
update = wx.MessageDialog(self, u'{}\n\n{}'.format(l1, l2), _(u'Debreate'), wx.YES_NO|wx.ICON_INFORMATION).ShowModal()
if (update == wx.ID_YES):
wx.LaunchDefaultBrowser(HOMEPAGE)
elif (current < VERSION):
wx.MessageDialog(self, _(u'This is a development version, no updates available'),
_(u'Debreate'), wx.OK|wx.ICON_INFORMATION).ShowModal()
else:
wx.MessageDialog(self, _(u'Debreate is up to date!'), _(u'Debreate'), wx.OK|wx.ICON_INFORMATION).ShowModal()
### ***** Menu Handlers ***** ###
def OnNewProject(self, event):
dia = wx.MessageDialog(self, _(u'You will lose any unsaved information\n\nContinue?'),
_(u'Start New Project'), wx.YES_NO|wx.NO_DEFAULT)
if dia.ShowModal() == wx.ID_YES:
self.NewProject()
#self.SetMode(None)
def NewProject(self):
for page in self.all_pages:
page.ResetAllFields()
self.SetTitle(default_title)
# Reset the saved project field so we know that a project file doesn't exists
self.saved_project = wx.EmptyString
def OnOpenProject(self, event):
cont = False
dbp = u'|*.dbp'
d = _(u'Debreate project files')
if self.cust_dias.IsChecked():
dia = dbr.OpenFile(self, _(u'Open Debreate Project'))
dia.SetFilter(u'{}{}'.format(d, dbp))
if dia.DisplayModal():
cont = True
else:
dia = wx.FileDialog(self, _(u'Open Debreate Project'), os.getcwd(), u'', u'{}{}'.format(d, dbp), wx.FD_CHANGE_DIR)
if dia.ShowModal() == wx.ID_OK:
cont = True
if cont:
# Get the path and set the saved project
self.saved_project = dia.GetPath()
p_open = open(self.saved_project, u'r')
p_text = p_open.read()
p_open.close()
filename = os.path.split(self.saved_project)[1]
self.OpenProject(p_text, filename)
def OpenProject(self, data, filename):
def ProjectError():
wx.MessageDialog(self, _(u'Not a valid Debreate project'), _(u'Error'),
style=wx.OK|wx.ICON_ERROR).ShowModal()
if data == wx.EmptyString:
ProjectError()
return
lines = data.split(u'\n')
app = lines[0].split(u'-')[0].split(u'[')[1]
#ver = lines[0].split(u'-')[1].split(u']')[0]
if app != u'DEBREATE':
ProjectError()
return
# Set title to show open project
#self.SetTitle(u'Debreate - %s' % filename)
# *** Get Control Data *** #
control_data = data.split(u'<<CTRL>>\n')[1].split(u'\n<</CTRL>>')[0]
depends_data = self.page_control.SetFieldData(control_data)
self.page_depends.SetFieldData(depends_data)
# *** Get Files Data *** #
files_data = data.split(u'<<FILES>>\n')[1].split(u'\n<</FILES>>')[0]
self.page_files.SetFieldData(files_data)
# *** Get Scripts Data *** #
scripts_data = data.split(u'<<SCRIPTS>>\n')[1].split(u'\n<</SCRIPTS>>')[0]
self.page_scripts.SetFieldData(scripts_data)
# *** Get Changelog Data *** #
clog_data = data.split(u'<<CHANGELOG>>\n')[1].split(u'\n<</CHANGELOG>>')[0]
self.page_clog.SetChangelog(clog_data)
# *** Get Copyright Data *** #
try:
cpright_data = data.split(u'<<COPYRIGHT>>\n')[1].split(u'\n<</COPYRIGHT')[0]
self.page_cpright.SetCopyright(cpright_data)
except IndexError:
pass
# *** Get Menu Data *** #
menu_data = data.split(u'<<MENU>>\n')[1].split(u'\n<</MENU>>')[0]
self.page_menu.SetFieldData(menu_data)
# Get Build Data
build_data = data.split(u'<<BUILD>>\n')[1].split(u'\n<</BUILD')[0]#.split(u'\n')
self.page_build.SetFieldData(build_data)
## Shows a quit dialog & exits the application
#
# If user confirms quit, closes main window & exits.
def OnQuit(self, event):
confirm = wx.MessageDialog(self, _(u'You will lose any unsaved information'), _(u'Quit?'),
wx.OK|wx.CANCEL|wx.ICON_QUESTION)
if confirm.ShowModal() == wx.ID_OK: # Show a dialog to confirm quit
confirm.Destroy()
maximized = self.IsMaximized()
# Get window attributes and save to config file
if maximized: # Save default window settings if maximized
WriteConfig(u'size', GetDefaultConfigValue(u'size'))
WriteConfig(u'position', GetDefaultConfigValue(u'position'))
WriteConfig(u'center', GetDefaultConfigValue(u'center'))
WriteConfig(u'maximize', True)
else:
WriteConfig(u'size', (self.GetSize()[0], self.GetSize()[1]))
WriteConfig(u'position', (self.GetPosition()[0], self.GetPosition()[1]))
WriteConfig(u'center', False)
WriteConfig(u'maximize', False)
WriteConfig(u'workingdir', os.getcwd())
WriteConfig(u'dialogs', self.cust_dias.IsChecked())
self.Destroy()
else:
confirm.Destroy()
# ----- Page Menu
def GoToPage(self, event):
for p in self.pages:
if p.IsChecked():
PAGE_ID = p.GetId()
self.wizard.ShowPage(PAGE_ID)
# ----- Help Menu
def OpenPolicyManual(self, event):
EVENT_ID = event.GetId() # Get the id for the webpage link we are opening
webbrowser.open(self.references[EVENT_ID])
def OnAbout(self, event):
'''Opens a dialog box with information about the program'''
about = dbr.AboutDialog(self, -1, _(u'About'))
about.SetGraphic(u'{}/bitmaps/debreate64.png'.format(dbr.application_path))
about.SetVersion(VERSION_STRING)
about.SetAuthor(u'Jordan Irwin')
about.SetDescription(_(u'A package builder for Debian based systems'))
about.AddDeveloper(u'Jordan Irwin', u'antumdeluge@gmail.com')
about.AddPackager(u'Jordan Irwin', u'antumdeluge@gmail.com')
about.AddTranslator(_(u'Karim Oulad Chalha'), u'herr.linux88@gmail.com', u'ar_MA', )
about.AddTranslator(_(u'Jordan Irwin'), u'antumdeluge@gmail.com', u'es')
about.AddTranslator(_(u'Philippe Dalet'), u'philippe.dalet@ac-toulouse.fr', u'fr_FR')
about.SetChangelog()
about.SetLicense()
about.ShowModal()
about.Destroy()
def OnHelp(self, event):
if dbr.DebugEnabled():
dbr.HelpDialog(self).ShowModal()
else:
# First tries to open pdf help file. If fails tries to open html help file. If fails opens debreate usage webpage
wx.Yield()
status = subprocess.call([u'xdg-open', u'{}/docs/usage.pdf'.format(dbr.application_path)])
if status:
wx.Yield()
status = subprocess.call([u'xdg-open', u'{}/docs/usage'.format(dbr.application_path)])
if status:
wx.Yield()
webbrowser.open(u'http://debreate.sourceforge.net/usage')
# *** SAVING *** #
def IsSaved(self):
title = self.GetTitle()
if title[-1] == u'*':
return False
else:
return True
def IsNewProject(self):
title = self.GetTitle()
if title == default_title:
return True
else:
return False
def SetSavedStatus(self, status):
if status: # If status is changing to unsaved this is True
title = self.GetTitle()
if self.IsSaved() and title != default_title:
self.SetTitle(u'{}*'.format(title))
# FIXME: New format unused. Currently still using OnSaveProjectDeprecated
def SaveProject(self, event):
# TODO: Add strings to GetText output
Logger.Debug(__name__, _(u'Saving in new project format'))
title = _(u'Save Debreate Project')
suffix = dbr.PROJECT_FILENAME_SUFFIX
# Set Displayed description & filename filter for dialog
dbp = u'|*.{}'.format(suffix)
description = _(u'Debreate project files')
ext_filter = u'{} (.{}){}'.format(description, suffix, dbp)
file_save = dbr.GetFileSaveDialog(self, title,
ext_filter, suffix)
if dbr.ShowDialog(self, file_save):
self.saved_project = file_save.GetPath()
working_path = os.path.dirname(self.saved_project)
output_filename = os.path.basename(self.saved_project)
temp_path = u'{}_temp'.format(self.saved_project)
Logger.Debug(
__name__,
u'Save project\n\tWorking path: {}\n\tFilename: {}\n\tTemp directory: {}'.format(working_path,
output_filename, temp_path)
)
if os.path.exists(temp_path):
if wx.MessageDialog(self, GT(u'Temp directory already exists.\nOverwrite?'), GT(u'Warning'),
wx.YES_NO|wx.YES_DEFAULT|wx.ICON_EXCLAMATION).ShowModal() == wx.ID_YES:
Logger.Debug(__name__, u'Overwriting temp directory: {}'.format(temp_path))
shutil.rmtree(temp_path)
else:
Logger.Debug(__name__, u'Not Overwriting temp directory: {}'.format(temp_path))
return 0
os.makedirs(temp_path)
export_pages = (
self.page_control,
self.page_files,
self.page_scripts,
self.page_clog,
self.page_cpright,
self.page_menu,
self.page_build,
)
self.wizard.ExportPages(export_pages, temp_path)
file_list = []
for PATH, DIRS, FILES in os.walk(temp_path):
for F in FILES:
file_list.append(F)
if DebugEnabled():
print(u'DEBUG:')
print(u'Output archive: {}.dbpz'.format(output_filename))
print(u'Temp directory: {}'.format(temp_path))
print(u'Working directory: {}'.format(working_path))
print(u'File list: {}'.format(file_list))
z_format = None
for Z in self.menu_compression.GetMenuItems():
Z_ID = Z.GetId()
if self.menu_compression.IsChecked(Z_ID):
z_format = compression_formats[Z_ID]
# Uncompressed tarball
if not z_format:
z_format = u'w'
else:
z_format = u'w:{}'.format(z_format)
Logger.Debug(__name__, u'Output compression: {}'.format(z_format))
p_archive = tarfile.open(u'{}.dbpz'.format(self.saved_project), z_format)
for F in file_list:
if DebugEnabled():
print(u'DEBUG: Adding file "{}/{}"'.format(temp_path, F))
p_archive.add(u'{}/{}'.format(temp_path, F), arcname=F)
p_archive.close()
#shutil.make_archive(temp_path, u'bztar', temp_path)
#debug_output = commands.getoutput(u'tar -cjf "{}/{}.dbpz" "{}"'.format(working_path, output_filename, temp_path))
#print(u'DEBUG: {}'.format(debug_output))
if os.path.isfile(u'{}.dbpz'.format(self.saved_project)):
#os.rename(u'{}.tar.bz2'.format(self.saved_project), u'{}.dbpz'.format(self.saved_project))
shutil.rmtree(temp_path)
return 0
def OnSaveProjectDeprecated(self, event):
EVENT_ID = event.GetId()
def SaveIt(path):
# Gather data from different pages
data = (self.page_control.GatherData(), self.page_files.GatherData(),
self.page_scripts.GatherData(), self.page_clog.GatherData(),
self.page_cpright.GatherData(), self.page_menu.GatherData(),
self.page_build.GatherData())
# Create a backup of the project
overwrite = False
if os.path.isfile(path):
backup = u'{}.backup'.format(path)
shutil.copy(path, backup)
overwrite = True
savefile = open(path, u'w')
# This try statement can be removed when unicode support is enabled
try:
savefile.write(u'[DEBREATE-{}]\n{}'.format(VERSION_STRING, u'\n'.join(data).encode(u'utf-8')))
savefile.close()
if overwrite:
os.remove(backup)
except UnicodeEncodeError:
serr = _(u'Save failed')
uni = _(u'Unfortunately Debreate does not support unicode yet. Remove any non-ASCII characters from your project.')
UniErr = wx.MessageDialog(self, u'{}\n\n{}'.format(serr, uni), _(u'Unicode Error'), style=wx.OK|wx.ICON_EXCLAMATION)
UniErr.ShowModal()
savefile.close()
if overwrite:
os.remove(path)
# Restore project backup
shutil.move(backup, path)
# Change the titlebar to show name of project file
#self.SetTitle(u'Debreate - %s' % os.path.split(path)[1])
def OnSaveAs():
dbp = u'|*.dbp'
d = _(u'Debreate project files')
cont = False
if self.cust_dias.IsChecked():
dia = dbr.SaveFile(self, _(u'Save Debreate Project'), u'dbp')
dia.SetFilter(u'{}{}'.format(d, dbp))
if dia.DisplayModal():
cont = True
filename = dia.GetFilename()
if filename.split(u'.')[-1] == u'dbp':
filename = u'.'.join(filename.split(u'.')[:-1])
self.saved_project = u'{}/{}.dbp'.format(dia.GetPath(), filename)
else:
dia = wx.FileDialog(self, _(u'Save Debreate Project'), os.getcwd(), u'', u'{}{}'.format(d, dbp),
wx.FD_SAVE|wx.FD_CHANGE_DIR|wx.FD_OVERWRITE_PROMPT)
if dia.ShowModal() == wx.ID_OK:
cont = True
filename = dia.GetFilename()
if filename.split(u'.')[-1] == u'dbp':
filename = u'.'.join(filename.split(u'.')[:-1])
self.saved_project = u'{}/{}.dbp'.format(os.path.split(dia.GetPath())[0], filename)
if cont:
SaveIt(self.saved_project)
if EVENT_ID == wx.ID_SAVE:
# Define what to do if save is pressed
# If project already exists, don't show dialog
if not self.IsSaved() or self.saved_project == wx.EmptyString or not os.path.isfile(self.saved_project):
OnSaveAs()
else:
SaveIt(self.saved_project)
else:
# If save as is press, show the save dialog
OnSaveAs()
def OnQuickBuild(self, event):
QB = wiz_bin.QuickBuild(self)
QB.ShowModal()
QB.Destroy()