Source

boa-constructor / About.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
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
#-----------------------------------------------------------------------------
# Name:        About.py
# Purpose:
#
# Author:      Riaan Booysen
#
# Created:     2000
# RCS-ID:      $Id$
# Copyright:   (c) 2000 - 2007
# Licence:     GPL
#-----------------------------------------------------------------------------

import sys, time, re, string
from thread import start_new_thread

import wx
import wx.html
import wx.lib.wxpTag

import __version__
import Preferences, Utils
from Utils import _

from ExternalLib import langlistctrl

translations = [
  (wx.LANGUAGE_AFRIKAANS, 'Riaan Booysen (riaan@e.co.za)'),
  (wx.LANGUAGE_CHINESE, 'Dylan Yang (otherrrr@gmail.com)'),
  (wx.LANGUAGE_FRENCH, 'Olivier Thiery (olivier.th@gmail.com)'),
  (wx.LANGUAGE_GERMAN, 'Werner F. Bruhin (werner.bruhin@free.fr), Jens Klein (jens@bluedynamics.com)'),
  (wx.LANGUAGE_ITALIAN, 'Michele Petrazzo (michele.petrazzo@unipex.it)'),
  (wx.LANGUAGE_PORTUGUESE_BRAZILIAN, 'Sergio Brant (sergiobrant@yahoo.com.br)'),
  (wx.LANGUAGE_SPANISH, 'Felix Medrano Sanz (xukosky@yahoo.es)'),
]

prog_update = re.compile('<<(?P<cnt>[0-9]+)/(?P<tot>[0-9]+)>>')

about_html = '''
<html>
<body bgcolor="#4488FF">
<center>
<table cellpadding="5" bgcolor="#FFFFFF" width="100%%">
  <tr>
    <td align="center"><br>
    <img src="%s"><br>
    <font color="#006600" size="+4"><b>Constructor</b></font><br><strong>v%s</strong>%s</td>
  </tr>
</table>
%s
</body>
</html>
'''

#  <param name="style" value="ALIGN_CENTER | CLIP_CHILDREN | ST_NO_AUTORESIZE">

progress_text = '''<p>
<wxp module="wx" class="StaticText">
  <param name="label" value="  ">
  <param name="id"    value="%d">
  <param name="size"  value="(352, 20)">
  <param name="style" value="wx.ALIGN_CENTER | wx.CLIP_CHILDREN | wx.ST_NO_AUTORESIZE">
</wxp>
<wxp module="wx" class="Window">
  <param name="id"    value="%d">
  <param name="size"  value="(352, 16)">
</wxp>'''


credits_html = '''
<html>
<body bgcolor="#4488FF">
<center>
<table bgcolor="#FFFFFF" width="100%%">
  <tr>
    <td align="center"><h3>Credits</h3><br>
    <br>
<b>The Boa Team</b><br>
<br>
Riaan Booysen (riaan@e.co.za)<p>
Werner F. Bruhin (werner.bruhin@free.fr)<br>
Shane Hathaway (shane@zope.com)<br>
Kevin Gill (kevin@telcotek.com)<br>
Robert Boulanger (robert@boulanger.de)<br>
Tim Hochberg (tim.hochberg@ieee.org)<br>
Kevin Light (klight@walkertechnical.com)<br>
Marius van Wyk (marius@e.co.za)<br>

<p>
<b>Translators</b><br>
<br>
%s
<p>
<b>Many thanks to</b><br>
<br>
Guido van Rossum and PythonLabs for Python<br>
<br>
wxPython (Robin Dunn) & wxWidgets (Julian Smart, Robert Roebling, Vadim Zeitlin, et al.)<br>
Neil Hodgson for Scintilla<br>
<br>
moduleparse.py borrows from pyclbrs.py - standard python library<br>
PythonInterpreter.py by Fredrik Lundh<br>
Mozilla, Delphi, WinCVS for iconic inspirations<br>
Cyclops, ndiff, reindent by Tim Peters<br>
Client.py, WebDAV, DateTime package and the Zope Book from Zope Corporation for Zope integration<br>
PyChecker by Neal Norwitz & Eric C. Newton<br>
py2exe by Thomas Heller<br>
Jeff Sasmor for wxStyledTextCtrl docs<br>
Hernan M. Foffani for ZopeShelf from which the Zope Book was converted<br>
Phil Dawes et al for the Bicycle Repair Man project, a Python refactoring package<br>
<p>
Mike Fletcher for reports, ideas and patches (MakePy dialog and much improved UML layout)<br>
<p>
Cedric Delfosse for maintaining the Debian package of Boa
<p>
<b>Boa interfaces with the following external applications, thanks to their authors</b><br>
Zope, CVS, SVN, SSH, SCP<br>
<p>
Last but not least, a very big thank you to <a href="TBS">Tangible Business Software</a> for partially
sponsoring my time on this project.<br>
<p>
<b>Boa Constructor is built on:</b><br>
<a href="Python"><img src="%s"></a>&nbsp;
<a href="wxPython"><img src="%s"></a>&nbsp;
<a href="wxWidgets"><img src="%s"></a><br>
<p>
<b>Boa Constructor is packaged for:</b><br>
<a href="Debian"><img src="%s"></a>&nbsp;
<a href="Gentoo"><img src="%s"></a>&nbsp;
<a href="FreeBSD"><img src="%s"></a>&nbsp;
<p>
<a href="Back">Back</a><br>
    </td>
  </tr>
</table>
</body>
</html>
'''

about_text = '''
<p>A <b>Python</b> IDE and <b>wxPython</b> GUI builder
</p>
<p><a href="Boa">http://boa-constructor.sourceforge.net</a><br></u>
&copy;1999-2007 <b>Riaan Booysen</b>. <a href="MailMe">riaan@e.co.za</a><br>
<a href="Credits">Credits</a>
</p>
<p><font size=-1 color="#000077">Python %s</font><br>
<font size=-1 color="#000077">wx.Python %s: %s, <img src="%s">&nbsp;%s, %s</font></p>
<hr>
<wxp module="wx" class="Button">
  <param name="label" value="OK">
  <param name="id"    value="ID_OK">
</wxp>
</center>
<br>
<p>
<center>
<font size=-1><i>for <font color="#AA0000"><b>Bonnie</b></font></i></font>
</center>
</p>
'''

wx.FileSystem.AddHandler(wx.MemoryFSHandler())

def addImagesToFS():
    PNG = wx.BITMAP_TYPE_PNG
    for name, path, type in [
        ('Boa.jpg', 'Images/Shared/Boa.jpg', wx.BITMAP_TYPE_JPEG),
        ('PythonPowered.png', 'Images/Shared/PythonPowered.png', PNG),
        ('wxPyButton.png', 'Images/Shared/wxPyButton.png', PNG),
        ('wxWidgetsButton.png', 'Images/Shared/wxWidgetsButton.png', PNG),
        ('Debian.png', 'Images/Shared/Debian.png', PNG),
        ('Gentoo.png', 'Images/Shared/Gentoo.png', PNG),
        ('FreeBSD.png', 'Images/Shared/FreeBSD.png', PNG),
        ]:
        if name not in addImagesToFS.addedImages:
            wx.MemoryFSHandler.AddFile(name, Preferences.IS.load(path), type)
            addImagesToFS.addedImages.append(name)

    for lid, _tr in translations:
        li = wx.Locale.GetLanguageInfo(lid)
        name = 'flag-%s'%li.CanonicalName
        if name not in addImagesToFS.addedImages:
            bmp = langlistctrl.GetLanguageFlag(lid)
            wx.MemoryFSHandler.AddFile(name, bmp, wx.BITMAP_TYPE_PNG)
            addImagesToFS.addedImages.append(name)

    
addImagesToFS.addedImages = []

def createSplash(parent, modTot, fileTot):
    return AboutBoxSplash(parent, modTot, fileTot, extraStyle=wx.html.HW_SCROLLBAR_NEVER)

def createNormal(parent):
    return AboutBox(parent)

wxID_ABOUTBOX = wx.NewId()

class AboutBoxMixin:
    border = 7
    def __init__(self, parent, modTot=0, fileTot=0, extraStyle=0):
        self._init_ctrls(parent)
        
        addImagesToFS()

        self.moduleTotal = modTot
        self.fileTotal = fileTot

        self.blackback = wx.Window(self, -1, pos=(0, 0),
              size=self.GetClientSize(), style=wx.CLIP_CHILDREN)
        self.blackback.SetBackgroundColour(wx.BLACK)

        self.html = Utils.wxUrlClickHtmlWindow(self.blackback, -1, 
              style=wx.CLIP_CHILDREN | wx.html.HW_NO_SELECTION | extraStyle)
        Utils.EVT_HTML_URL_CLICK(self.html, self.OnLinkClick)
        self.setPage()
        self.blackback.SetAutoLayout(True)
        lc = wx.LayoutConstraints()
        lc.top.SameAs(self.blackback, wx.Top, self.border)
        lc.left.SameAs(self.blackback, wx.Left, self.border)
        lc.bottom.SameAs(self.blackback, wx.Bottom, self.border)
        lc.right.SameAs(self.blackback, wx.Right, self.border)
        self.html.SetConstraints(lc)
        self.blackback.Layout()
        self.Center(wx.BOTH)
        self.SetAcceleratorTable(wx.AcceleratorTable([(0, wx.WXK_ESCAPE, wx.ID_OK)]))

    def gotoInternetUrl(self, url):
        try:
            import webbrowser
        except ImportError:
            wx.MessageBox('Please point your browser at: %s' % url)
        else:
            webbrowser.open(url)

    def OnLinkClick(self, event):
        clicked = event.linkinfo[0]
        if clicked == 'Credits':
            translators = []
            for lid, name in translations:
                li = wx.Locale.GetLanguageInfo(lid)
                translators.append('<img src="memory:flag-%s">&nbsp;%s - %s<br>'%(
                      li.CanonicalName, li.Description, name))
            translators = ''.join(translators)          

            self.html.SetPage(credits_html % (translators, 
                                              'memory:PythonPowered.png',
                                              'memory:wxPyButton.png', 
                                              'memory:wxWidgetsButton.png',
                                              'memory:Debian.png',
                                              'memory:Gentoo.png',
                                              'memory:FreeBSD.png',
                                             ))
        elif clicked == 'Back':
            self.setPage()
            #self.html.HistoryBack()
        elif clicked == 'Python':
            self.gotoInternetUrl('http://www.python.org')
        elif clicked == 'wxPython':
            self.gotoInternetUrl('http://wxpython.org')
        elif clicked == 'wxWidgets':
            self.gotoInternetUrl('http://www.wxwidgets.org')
        elif clicked == 'Debian':
            self.gotoInternetUrl(
               'http://packages.debian.org/unstable/devel/boa-constructor.html')
        elif clicked == 'Gentoo':
            self.gotoInternetUrl(
               'http://www.gentoo.org/dyn/pkgs/dev-util/boa-constructor.xml')
        elif clicked == 'FreeBSD':
            self.gotoInternetUrl(
               'http://www.freebsd.org/ports/python.html#boaconstructor-0.2.3')
        elif clicked == 'Boa':
            self.gotoInternetUrl('http://boa-constructor.sourceforge.net')
        elif clicked == 'TBS':
            self.gotoInternetUrl('http://www.tbs.co.za')
        elif clicked == 'MailMe':
            self.gotoInternetUrl('mailto:riaan@e.co.za')


class AboutBox(AboutBoxMixin, wx.Dialog):
    def _init_ctrls(self, prnt):
        wx.Dialog.__init__(self, size=wx.Size(410, 570), pos=(-1, -1),
              id=wxID_ABOUTBOX, title=_('About Boa Constructor'), parent=prnt,
              name='AboutBox', style=wx.DEFAULT_DIALOG_STYLE)
        
        try:
            if 'Language.png' not in addImagesToFS.addedImages:
                wx.MemoryFSHandler.AddFile('Language.png', 
                 langlistctrl.GetLanguageFlag(wx.GetApp().locale.GetLanguage()), 
                 wx.BITMAP_TYPE_PNG)
                addImagesToFS.addedImages.append('Language.png')
        except Exception, err:
            pass

    def setPage(self):
        sysLangName = wx.GetApp().locale.GetSysName()
        self.html.SetPage((about_html % (
              'memory:Boa.jpg', __version__.version,
              '', about_text % (sys.version, wx.VERSION_STRING, 
                ', '.join(wx.PlatformInfo), 'memory:Language.png', sysLangName,
                sys.getdefaultencoding()))))

DefAboutBox = AboutBox

class AboutBoxSplash(AboutBoxMixin, wx.Frame):
    progressBorder = 1
    fileOpeningFactor = 10
    def _init_ctrls(self, prnt):
        wx.Frame.__init__(self, size=wx.Size(418, 320), pos=(-1, -1),
              id=wxID_ABOUTBOX, title='Boa Constructor', parent=prnt,
              name='AboutBoxSplash', style=wx.SIMPLE_BORDER)
        self.progressId = wx.NewId()
        self.gaugePId = wx.NewId()
        self.SetBackgroundColour(wx.Colour(0x44, 0x88, 0xFF))#wxColour(0x99, 0xcc, 0xff))

    def setPage(self):
        self.html.SetPage(about_html % ('memory:Boa.jpg',
          __version__.version, progress_text % (self.progressId, self.gaugePId), ''))

        self.initCtrlNames()

    def initCtrlNames(self):
        self.label = self.FindWindowById(self.progressId)
        self.label.SetBackgroundColour(wx.WHITE)
        parentWidth = self.label.GetParent().GetClientSize().x
        self.label.SetSize((parentWidth - 40, self.label.GetSize().y))

        gaugePrnt = self.FindWindowById(self.gaugePId)
        gaugePrnt.SetBackgroundColour(wx.BLACK)#wx.Colour(0x99, 0xcc, 0xff))
        gaugeSze = gaugePrnt.GetClientSize()
        self.gauge = wx.Gauge(gaugePrnt, -1,
              range=self.moduleTotal+self.fileTotal*self.fileOpeningFactor,
              style=wx.GA_HORIZONTAL|wx.GA_SMOOTH,
              pos=(self.progressBorder, self.progressBorder),
              size=(gaugeSze.x - 2 * self.progressBorder,
                    gaugeSze.y - 2 * self.progressBorder))
        self.gauge.SetBackgroundColour(wx.Colour(0xff, 0x33, 0x00))
        # secret early quit option
        self.gauge.Bind(wx.EVT_LEFT_DOWN, self.OnGaugeDClick)
        self._gaugeClicks = 0
        
        # route all printing thru the text on the splash screen
        sys.stdout = StaticTextPF(self.label)
        start_new_thread(self.monitorModuleCount, ())

        EVT_MOD_CNT_UPD(self, self.OnUpdateProgress)

    def monitorModuleCount(self):
        self._live = True
        lastCnt = 0
        if self and sys and len(sys.modules) >= self.moduleTotal:
            wx.PostEvent(self, ModCntUpdateEvent(self.moduleTotal, 'importing'))
        else:
            while self and self._live and sys and len(sys.modules) < self.moduleTotal:
                mc = len(sys.modules)
                if mc > lastCnt:
                    lastCnt = mc
                    wx.PostEvent(self, ModCntUpdateEvent(mc, 'importing'))
                time.sleep(0.125)

    def Destroy(self):
        self._live = False
        self.gauge = None

        if sys:
            sys.stdout = sys.__stdout__
        wx.Frame.Destroy(self)

    def OnUpdateProgress(self, event):
        self._live = event.tpe == 'importing' and self._live
        if self.gauge:
            cnt = event.cnt
            if event.tpe == 'opening':
                cnt = cnt * self.fileOpeningFactor + self.moduleTotal
            self.gauge.SetValue(min(self.gauge.GetRange(), cnt))
        self.Update()

    def OnGaugeDClick(self, event):
        if event.GetPosition().x <10:
            self._gaugeClicks += 1
            if self._gaugeClicks >= 5:
                print 
                print 'Received early abort...'
                sys.exit()

class StaticTextPF(Utils.PseudoFile):
    def write(self, s):
        if not wx.Thread_IsMain():
            locker = wx.MutexGuiLocker()

        res = prog_update.search(s)
        if res:
            cnt = int(res.group('cnt'))
            wx.PostEvent(self.output.GetGrandParent().GetParent(),
                  ModCntUpdateEvent(cnt, 'opening'))
            s = s[:res.start()]

        ss = string.strip(s)
        if ss:
            self.output.SetLabel(ss)

        if sys:
##            frame = sys._getframe()
##            try:
##                d = 0
##                while frame.f_back:
##                    frame = frame.f_back
##                    d += 1
##            except AttributeError:
##                pass
##            s = '  '*d + s
##            
            try:
                sys.__stdout__.write(s)#+':'+sys.path[-1])
            except UnicodeEncodeError:
                s = s.encode(sys.getdefaultencoding(), 'replace')
                sys.__stdout__.write(s)
            
        wx.Yield()

wxEVT_MOD_CNT_UPD = wx.NewId()
EVT_MOD_CNT_UPD = wx.PyEventBinder(wxEVT_MOD_CNT_UPD)

class ModCntUpdateEvent(wx.PyEvent):
    def __init__(self, cnt, tpe):
        wx.PyEvent.__init__(self)
        self.SetEventType(wxEVT_MOD_CNT_UPD)
        self.cnt = cnt
        self.tpe = tpe

if __name__ == '__main__':

    app = wx.PySimpleApp()
    wx.InitAllImageHandlers()

    #dialog
    #frame = createNormal(None)
    #frame.ShowModal()

    #frame
    def updlbl(frame):
        frame.label.SetLabel('Testing')
        frame.label.SetLabel('Testing 1')
        frame.label.SetLabel('Testing 2')
        frame.label.SetLabel('Testing 3')
        
    frame = createSplash(None, 0, 0)
    frame.Show()
    wx.CallAfter(updlbl, frame)

    app.MainLoop()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.