Project

Profile

Help

Feature #140 ยป wx_ctrl_phoenix.py

Vincent Le Goff, 12/01/2018 07:43 PM

 
1
# Copyright Max Kolosov 2009-2013 pyirrlicht@gmail.com
2
# http://pybass.sf.net
3
# BSD license
4

    
5
import sys
6

    
7
import pybass
8
try:
9
        import pybassmidi
10
except:
11
        pybassmidi = None
12
from io import StringIO
13

    
14
try:
15
        from exe import wx
16
except:
17
        import wx
18
from wx.lib.ticker import Ticker
19

    
20
def print_error():
21
        exc, err, traceback = sys.exc_info()
22
        print('%s %s ERROR ON LINE %d %s\n' % (exc, traceback.tb_frame.f_code.co_filename, traceback.tb_lineno, err))
23
        del exc, err, traceback
24

    
25
class memory_stream:
26
        def __init__(self, data, name = 'memory_stream'):
27
                self.name = name
28
                self.current_position = 0
29
                self.data = data
30
                self.end_position = len(self.data) - 1
31
                self.decode_length = 0
32
                self.seconds = 0
33
        def read(self, size = 1024):
34
                result = ''
35
                if self.current_position is not self.end_position and size > 0:
36
                        last_index = self.current_position + size
37
                        if last_index > self.end_position:
38
                                last_index = self.end_position
39
                        result = self.data[self.current_position : last_index]
40
                        self.current_position = last_index
41
                return result
42
        def write(self, value = ''):
43
                self.data += value
44
        def seek(self, position, whence = 0):
45
                if whence is 0:
46
                        if position <= self.end_position:
47
                                self.current_position = position
48
                elif whence is 1:
49
                        if position + self.current_position <= self.end_position:
50
                                self.current_position += position
51
                elif whence is 2:
52
                        if position < 0:
53
                                position *= -1
54
                        if self.end_position - position > 0:
55
                                self.current_position = self.end_position - position
56
        def tell(self):
57
                return self.current_position
58
        def isatty(self):
59
                return 1
60
        def flush(self):
61
                pass
62
        def is_eof(self):
63
                return self.current_position == self.end_position
64

    
65
class slider_ctrl(wx.Slider):
66
        def __init__(self, *args, **kwargs):
67
                self.timer_interval = 500
68
                self.player_ctrl = args[0]
69
                wx.Slider.__init__(self, *args, **kwargs)
70
                self.timer = wx.Timer(self)
71
                self.Bind(wx.EVT_LEFT_DOWN, self.event_left_down)
72
                self.Bind(wx.EVT_LEFT_UP, self.event_left_up)
73
                self.Bind(wx.EVT_TIMER, self.event_timer)
74
        def __del__(self):
75
                if hasattr(self, 'timer'):
76
                        self.timer.Stop()
77
        def timer_start(self):
78
                if not self.timer.IsRunning():
79
                        self.timer.Start(self.timer_interval)
80
        def timer_stop(self):
81
                if self.timer.IsRunning():
82
                        self.timer.Stop()
83
        def event_timer(self, event):
84
                if self.player_ctrl.method_get_position() < self.player_ctrl.method_get_length() - 1:
85
                        self.SetValue(self.player_ctrl.method_get_position())
86
                else:
87
                        self.player_ctrl.method_stop_audio()
88
        def event_left_down(self, event):
89
                self.timer_stop()
90
                event.Skip()
91
        def event_left_up(self, event):
92
                self.player_ctrl.method_set_position(self.GetValue())
93
                self.timer_start()
94
                event.Skip()
95

    
96
class player_ctrl(wx.Panel):
97
        def __init__(self, *args, **kwargs):
98

    
99
                self.stream = kwargs.pop('stream', None)
100
                self.name_stream = kwargs.pop('name_stream', 'memory_stream')
101
                self.bass_handle = 0
102
                self.sound_font = 0
103

    
104
                result = pybass.BASS_Init(-1, 44100, 0, 0, 0)
105
                if not result:
106
                        bass_error_code = pybass.BASS_ErrorGetCode()
107
                        if bass_error_code != pybass.BASS_ERROR_ALREADY:
108
                                self.slider.Enable(False)
109
                                self.btn_play.Enable(False)
110
                                self.btn_stop.Enable(False)
111
                                print('BASS_Init error %s' % pybass.get_error_description(bass_error_code))
112
                self.plugins = {}
113
                self.plugins['aac'] = (pybass.BASS_PluginLoad(b'bass_aac.dll', 0), '|AAC|*.aac')
114
                self.plugins['ac3'] = (pybass.BASS_PluginLoad(b'bass_ac3.dll', 0), '|AC3|*.ac3')
115
                self.plugins['aix'] = (pybass.BASS_PluginLoad(b'bass_aix.dll', 0), '|AIX|*.aix')
116
                self.plugins['ape'] = (pybass.BASS_PluginLoad(b'bass_ape.dll', 0), '|APE|*.ape')
117
                self.plugins['mpc'] = (pybass.BASS_PluginLoad(b'bass_mpc.dll', 0), '|MPC|*.mpc')
118
                self.plugins['ofr'] = (pybass.BASS_PluginLoad(b'bass_ofr.dll', 0), '|OFR|*.ofr')
119
                self.plugins['spx'] = (pybass.BASS_PluginLoad(b'bass_spx.dll', 0), '|SPX|*.spx')
120
                self.plugins['tta'] = (pybass.BASS_PluginLoad(b'bass_tta.dll', 0), '|TTA|*.tta')
121
                self.plugins['cda'] = (pybass.BASS_PluginLoad(b'basscd.dll', 0), '|CDA|*.cda')
122
                self.plugins['flac'] = (pybass.BASS_PluginLoad(b'bassflac.dll', 0), '|FLAC|*.flac')
123
                self.plugins['wma'] = (pybass.BASS_PluginLoad(b'basswma.dll', 0), '|WMA, WMV|*.wma;*.wmv')
124
                if pybassmidi:
125
                        sound_font_file_name = 'CT4MGM.SF2'
126
                        self.sound_font = pybassmidi.BASS_MIDI_FontInit(sound_font_file_name, 0)
127
                        if self.sound_font == 0:
128
                                print('BASS_MIDI_FontInit error %s (sound font file must be %s)' % (pybass.get_error_description(pybass.BASS_ErrorGetCode()), sound_font_file_name))
129
                        else:
130
                                self.plugins['midi'] = (pybass.BASS_PluginLoad('bassmidi.dll', 0), '|MID|*.mid')
131
                else:
132
                        print('pybassmidi module not accessible')
133

    
134
                wx.Panel.__init__(self, *args, **kwargs)
135

    
136
                sizer_h = wx.BoxSizer(wx.HORIZONTAL)
137

    
138
                self.btn_play = wx.Button(self, wx.ID_ANY, _('Play'), style = wx.NO_BORDER)
139
                self.btn_play.SetToolTip(_('Play media data'))
140
                self.Bind(wx.EVT_BUTTON, self.event_play, self.btn_play)
141
                sizer_h.Add(self.btn_play)
142

    
143
                self.btn_stop = wx.Button(self, wx.ID_ANY, _('Stop'), style = wx.NO_BORDER)
144
                self.Bind(wx.EVT_BUTTON, self.event_stop, self.btn_stop)
145
                sizer_h.Add(self.btn_stop)
146

    
147
                self.btn_open = wx.Button(self, wx.ID_OPEN, _('Open'), style = wx.NO_BORDER)
148
                self.Bind(wx.EVT_BUTTON, self.event_open, self.btn_open)
149
                sizer_h.Add(self.btn_open)
150

    
151
                sizer_v = wx.BoxSizer(wx.VERTICAL)
152

    
153
                self.status_line = Ticker(self, fgcolor = '#000062', bgcolor = '#7F7F8F', start = False, ppf = 1, fps = 50, direction = 'ltr')
154
                sizer_v.Add(self.status_line, 0, wx.EXPAND)
155

    
156
                self.slider = slider_ctrl(self, wx.ID_ANY, 0, 0, 1)
157
                sizer_v.Add(self.slider, 0, wx.EXPAND)
158

    
159
                sizer_v.Add(sizer_h)
160

    
161
                self.SetSizer(sizer_v)
162
                self.SetAutoLayout(True)
163

    
164
                self.volume_slider = wx.Slider(self, wx.ID_ANY, pybass.BASS_GetVolume() * 100, 0, 100)
165
                self.Bind(wx.EVT_SCROLL, self.event_volume_slider, self.volume_slider)
166
                sizer_h.Add(self.volume_slider, 0, wx.EXPAND)
167

    
168
                self.method_check_controls()
169

    
170
        def method_load_file(self):
171
                import os
172
                wildcard = 'music sounds (MO3, IT, XM, S3M, MTM, MOD, UMX)|*.mo3;*.it;*.xm;*.s3m;*.mtm;*.mod;*.umx'
173
                wildcard += '|stream sounds (MP3, MP2, MP1, OGG, WAV, AIFF)|*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aiff'
174
                for plugin in self.plugins.values():
175
                        if plugin[0] > 0:
176
                                wildcard += plugin[1]
177
                wildcard += '|All files (*.*)|*.*'
178
                dlg = wx.FileDialog(self, message = _('Choose a file'), defaultDir = os.getcwd(),  defaultFile = '', wildcard = wildcard, style = wx.FD_OPEN|wx.FD_CHANGE_DIR)
179
                if dlg.ShowModal() == wx.ID_OK:
180
                        self.name_stream = file_name = dlg.GetPath()
181
                        if os.path.isfile(file_name):
182
                                flags = 0
183
                                if isinstance(file_name, str):                #flags |= pybass.BASS_UNICODE
184
                                        try:
185
                                            pybass.BASS_CHANNELINFO._fields_.remove(('filename', pybass.ctypes.c_char_p))
186
                                        except:
187
                                                pass
188
                                        else:
189
                                                pybass.BASS_CHANNELINFO._fields_.append(('filename', pybass.ctypes.c_wchar_p))
190
                                error_msg = 'BASS_StreamCreateFile error %s'
191
                                new_bass_handle = 0
192
                                if dlg.GetFilterIndex() == 0:#BASS_CTYPE_MUSIC_MOD
193
                                        flags |= pybass.BASS_MUSIC_PRESCAN
194
                                        new_bass_handle = pybass.BASS_MusicLoad(False, file_name.encode(), 0, 0, flags, 0)
195
                                        error_msg = 'BASS_MusicLoad error %s'
196
                                else:#other sound types
197
                                        new_bass_handle = pybass.BASS_StreamCreateFile(False, file_name.encode(), 0, 0, flags)
198
                                if new_bass_handle == 0:
199
                                        print(error_msg % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
200
                                else:
201
                                        self.method_stop_audio()
202
                                        self.bass_handle = new_bass_handle
203
                                        self.stream = None
204
                                        self.method_slider_set_range()
205
                                        self.method_check_controls()
206

    
207
        def method_load_wav_file(self):
208
                import os
209
                wildcard = 'wav (*.wav)|*.wav|All files (*.*)|*.*'
210
                dlg = wx.FileDialog(self, message = _('Choose a file'), defaultDir = os.getcwd(),  defaultFile = '', wildcard = wildcard, style = wx.OPEN|wx.CHANGE_DIR)
211
                if dlg.ShowModal() == wx.ID_OK:
212
                        self.name_stream = file_name = dlg.GetPath()
213
                        if os.path.isfile(file_name):
214
                                flags = 0
215
                                #if isinstance(file_name, unicode):
216
                                #        flags |= pybass.BASS_UNICODE
217
                                #        try:
218
                                #                pybass.BASS_CHANNELINFO._fields_.remove(('filename', pybass.ctypes.c_char_p))
219
                                #        except:
220
                                #                pass
221
                                #        else:
222
                                #                pybass.BASS_CHANNELINFO._fields_.append(('filename', pybass.ctypes.c_wchar_p))
223
                                def stream_callback(handle, buffer, length, user):
224
                                        b = pybass.ctypes.cast(buffer, pybass.ctypes.c_char_p)
225
                                        pybass.ctypes.memset(b, 0, length)
226
                                        data = pybass.ctypes.c_char_p(self.stream.read(length))
227
                                        pybass.ctypes.memmove(b, data, length)
228
                                        if self.stream.is_eof():
229
                                                length |= pybass.BASS_STREAMPROC_END
230
                                                self.stream.current_position = 0
231
                                        return length
232
                                self.stream_callback = stream_callback
233
                                self.user_func = pybass.STREAMPROC(self.stream_callback)
234
                                self.stream = memory_stream(open(file_name, 'rb').read(), file_name)
235
                                new_bass_handle = pybass.BASS_StreamCreate(44100, 2, flags, self.user_func, 0)
236
                                if new_bass_handle == 0:
237
                                        print('BASS_StreamCreate error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
238
                                else:
239
                                        self.method_stop_audio()
240
                                        self.bass_handle = new_bass_handle
241
                                        self.stream = None
242
                                        self.method_slider_set_range()
243
                                        self.method_check_controls()
244

    
245
        def method_load_data(self, stream, name_stream = 'memory_stream'):
246
                if stream is not None:
247
                        if isinstance(stream, (str, list, tuple, buffer)):
248
                                self.stream = memory_stream(stream, name_stream)
249
                        else:
250
                                self.stream = stream
251
                        if isinstance(self.stream, memory_stream):
252
                                system = pybass.STREAMFILE_BUFFER
253
                                flags = 0
254
                                def callback_close(user):
255
                                        self.stream.current_position = 0
256
                                self.callback_close = callback_close
257
                                def callback_length(user):
258
                                        return len(self.stream.data)
259
                                self.callback_length = callback_length
260
                                def callback_read(buffer, length, user):
261
                                        b = pybass.ctypes.cast(buffer, pybass.ctypes.c_char_p)
262
                                        pybass.ctypes.memset(b, 0, length)
263
                                        data = pybass.ctypes.c_char_p(self.stream.read(length))
264
                                        pybass.ctypes.memmove(b, data, length)
265
                                        return length
266
                                self.callback_read = callback_read
267
                                def callback_seek(offset, user):
268
                                        self.stream.seek(offset)
269
                                        return True
270
                                self.callback_seek = callback_seek
271
                                self.bass_file_procs = pybass.BASS_FILEPROCS()
272
                                self.bass_file_procs.close = pybass.FILECLOSEPROC(self.callback_close)
273
                                self.bass_file_procs.length = pybass.FILELENPROC(self.callback_length)
274
                                self.bass_file_procs.read = pybass.FILEREADPROC(self.callback_read)
275
                                self.bass_file_procs.seek = pybass.FILESEEKPROC(self.callback_seek)
276
                                new_bass_handle = pybass.BASS_StreamCreateFileUser(system, flags, self.bass_file_procs, id(self.stream.data))
277
                                if new_bass_handle == 0:
278
                                        print('BASS_StreamCreateFileUser error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
279
                                else:
280
                                        self.method_stop_audio()
281
                                        self.bass_handle = new_bass_handle
282
                                        channel_info = self.method_get_channel_info()
283
                                        if channel_info.ctype == pybass.BASS_CTYPE_STREAM_OGG:
284
                                                import pyogginfo
285
                                                ogg_info = pyogginfo.VorbisStreamInfo()
286
                                                stream = pyogginfo.SimpleDemultiplexer(ogg_info)
287
                                                if isinstance(self.stream.data, str):
288
                                                        stream.process(self.stream.data)
289
                                                else:
290
                                                        stream.process(str(self.stream.data))
291
                                                self.stream.decode_length = ogg_info.lastPosition
292
                                                self.stream.seconds = ogg_info.stop
293
                                                try:
294
                                                        for key, value in ogg_info.comments.comments:
295
                                                                if key == 'TITLE':
296
                                                                        if value.strip() > '':
297
                                                                                self.stream.name = value
298
                                                except:
299
                                                        pass
300
                                        self.method_slider_set_range()
301
                                        self.method_check_controls()
302

    
303
        def method_get_channel_info(self):
304
                channel_info = pybass.BASS_CHANNELINFO()
305
                if not pybass.BASS_ChannelGetInfo(self.bass_handle, channel_info):
306
                        print('BASS_ChannelGetInfo error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
307
                return channel_info
308

    
309
        def method_get_state(self):
310
                return pybass.BASS_ChannelIsActive(self.bass_handle)
311

    
312
        def method_get_length(self):
313
                result = pybass.BASS_ChannelGetLength(self.bass_handle, pybass.BASS_POS_BYTE)
314
                if result <= 0 and isinstance(self.stream, memory_stream):
315
                        result = self.stream.decode_length
316
                return result
317

    
318
        def method_get_position(self):
319
                return pybass.BASS_ChannelGetPosition(self.bass_handle, pybass.BASS_POS_BYTE)
320

    
321
        def method_set_position(self, value):
322
                if not pybass.BASS_ChannelSetPosition(self.bass_handle, value, pybass.BASS_POS_BYTE):
323
                        print('BASS_ChannelSetPosition error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
324

    
325
        def method_slider_set_range(self):
326
                self.slider.SetRange(0, self.method_get_length())
327

    
328
        def method_check_controls(self):
329
                if self.bass_handle:
330
                        self.slider.Enable(True)
331
                        self.btn_play.Enable(True)
332
                        if self.method_get_state() == pybass.BASS_ACTIVE_STOPPED:
333
                                self.btn_stop.Enable(False)
334
                        else:
335
                                self.btn_stop.Enable(True)
336
                        test = ''
337
                        if hasattr(self.stream, 'name'):
338
                                text = self.stream.name + ' (' + pybass.seconds_to_string(self.stream.seconds) + ')'
339
                        else:
340
                                #~ channel_info = self.method_get_channel_info()
341
                                #~ text = channel_info.filename
342
                                text = self.name_stream + ' (' + pybass.stream_length_as_hms(self.bass_handle) + ')'
343
                        self.status_line.SetText(text)
344
                        if self.status_line.GetText() != '':
345
                                self.status_line.Start()
346
                else:
347
                        self.slider.Enable(False)
348
                        self.btn_play.Enable(False)
349
                        self.btn_stop.Enable(False)
350
                        if self.status_line.GetText() == '':
351
                                if self.status_line.IsTicking():
352
                                        self.status_line.Stop()
353

    
354
        def method_is_end(self):
355
                return self.method_get_state() == pybass.BASS_ACTIVE_STOPPED and self.method_get_position() == 0
356

    
357
        def method_play(self):
358
                if self.bass_handle:
359
                        if self.method_get_state() in (pybass.BASS_ACTIVE_STOPPED, pybass.BASS_ACTIVE_PAUSED):
360
                                if not pybass.BASS_ChannelPlay(self.bass_handle, False):
361
                                        print('BASS_ChannelPlay error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
362
                                else:
363
                                        self.slider.timer_start()
364
                                        self.btn_play.SetLabel(_('Pause'))
365
                                        self.btn_stop.Enable(True)
366
                        else:
367
                                if not pybass.BASS_ChannelPause(self.bass_handle):
368
                                        print('BASS_ChannelPause error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
369
                                else:
370
                                        self.slider.timer_stop()
371
                                        self.btn_play.SetLabel(_('Unpause'))
372

    
373
        def event_volume_slider(self, event):
374
                pybass.BASS_SetVolume(event.GetPosition() / 100.0)
375

    
376
        def event_play(self, event):
377
                self.method_play()
378

    
379
        def event_open(self, event):
380
                self.method_load_file()
381

    
382
        def event_stop(self, event):
383
                self.method_stop_audio()
384

    
385
        def method_stop_audio(self):
386
                self.method_stop_audio_stream()
387
                self.btn_play.SetLabel(_('Play'))
388
                self.slider.SetValue(0)
389
                self.btn_stop.Enable(False)
390

    
391
        def method_stop_audio_stream(self):
392
                self.slider.timer_stop()
393
                if self.bass_handle:
394
                        if not pybass.BASS_ChannelStop(self.bass_handle):
395
                                print('BASS_ChannelStop error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
396
                        else:
397
                                self.method_set_position(0)
398

    
399
        def method_free_handle(self):
400
                if self.bass_handle:
401
                        channel_info = self.method_get_channel_info()
402
                        if channel_info.ctype >= pybass.BASS_CTYPE_MUSIC_MOD:
403
                                if not pybass.BASS_MusicFree(self.bass_handle):
404
                                        print('BASS_MusicFree error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
405
                                else:
406
                                        self.bass_handle = 0
407
                        elif channel_info.ctype >= pybass.BASS_CTYPE_STREAM:
408
                                if not pybass.BASS_StreamFree(self.bass_handle):
409
                                        print('BASS_StreamFree error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
410
                                else:
411
                                        self.bass_handle = 0
412

    
413
        def method_reset(self):
414
                self.method_free_handle()
415
                self.status_line.SetText('')
416
                self.method_check_controls()
417

    
418
        def __del__(self):
419
                self.method_free_handle()
420
                if self.sound_font != 0 and pybassmidi:
421
                        if pybassmidi.BASS_MIDI_FontFree(self.sound_font):
422
                                print('BASS_MIDI_FontFree error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
423
                for plugin in self.plugins.values():
424
                        if plugin[0] > 0:
425
                                if pybass.BASS_PluginFree(plugin[0]):
426
                                        print('BASS_PluginFree error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
427

    
428

    
429
if __name__ == "__main__":
430
        import os, gettext
431
        from locale import getdefaultlocale, setlocale, LC_ALL
432
        from wx.lib.agw.aui import AuiManager, AuiPaneInfo, AuiToolBar, AUI_TB_DEFAULT_STYLE, AUI_TB_OVERFLOW
433
        from wx.html import HtmlHelpController
434
        setlocale(LC_ALL, '')
435

    
436
        class log_ctrl(wx.TextCtrl):
437
                def __init__(self, *args, **kwargs):
438
                        self.file_name = kwargs.pop('file_name', 'log.txt')
439
                        self.main_frame = kwargs.pop('main_frame', None)
440
                        self.add_to_file = kwargs.pop('add_to_file', False)
441
                        if self.main_frame is None:
442
                                self.main_frame = args[0]
443
                        super(log_ctrl, self).__init__(*args, **kwargs)
444
                def __write__(self, content):
445
                        self.WriteText(content)
446
                def show_control(self, ctrl_name = 'log_ctrl'):
447
                        if self.main_frame is not None:
448
                                if hasattr(self.main_frame,'aui_manager'):
449
                                        self.main_frame.show_aui_pane_info(ctrl_name)
450
                        self.SetInsertionPointEnd()
451
                        if self.add_to_file: self.flush()
452
                def write(self, content):
453
                        self.show_control()
454
                        self.__write__(content)
455
                def writelines(self, l):
456
                        self.show_control()
457
                        map(self.__write__, l)
458
                def flush(self):
459
                        self.SaveFile(self.file_name)
460

    
461
        class main_frame(wx.Frame):
462
                def __init__(self, *args, **kwargs):
463
                        print("b0")
464
                        self.app = kwargs.pop('app', None)
465
                        wx.Frame.__init__(self, *args, **kwargs)
466
                        # =============== Logging Text Control ================
467
                        print("b1")
468
                        self.log_ctrl = log_ctrl(self, style = wx.TE_MULTILINE, add_to_file = True)
469
                        #sys.stdout = self.log_ctrl
470
                        #sys.stderr = self.log_ctrl
471
                        print("b2")
472
                        self.log = wx.LogTextCtrl(self.log_ctrl)
473
                        self.log.SetLogLevel(wx.LOG_Error)
474
                        #~ wx.Log_SetActiveTarget(self.log)
475
                        # =============== player Control ================
476
                        self.player = player_ctrl(self)
477
                        # =============== StatusBar ================
478
                        statusbar = self.CreateStatusBar(2)
479
                        statusbar.SetStatusWidths([-1, -1])
480
                        statusbar.SetStatusText(_('Welcome into application!'), 0)
481
                        print("b3")
482
                        # =============== AuiManager ================
483
                        self.aui_manager = AuiManager()
484
                        self.aui_manager.SetManagedWindow(self)
485
                        self.aui_manager.AddPane(self.player, AuiPaneInfo().Name('player').CenterPane())
486
                        self.aui_manager.AddPane(self.log_ctrl, AuiPaneInfo().Name('log_ctrl').Bottom().Layer(0).BestSize((100, 100)).Hide())
487
                        print("b4")
488
                        if self.log_ctrl.GetValue() != '':
489
                                self.aui_manager.GetPane('log_ctrl').Show()
490
                        self.aui_manager.Update()
491
                def DoUpdate(self):
492
                        self.aui_manager.Update()
493
                def show_aui_pane_info(self, name):
494
                        if not self.aui_manager.GetPane(name).IsShown():
495
                                self.aui_manager.GetPane(name).Show()
496
                        self.aui_manager.Update()
497
                def show_hide_aui_pane_info(self, name):
498
                        if self.aui_manager.GetPane(name).IsShown():
499
                                self.aui_manager.GetPane(name).Hide()
500
                        else:
501
                                self.aui_manager.GetPane(name).Show()
502
                        self.aui_manager.Update()
503

    
504
        #~ class application(wx.PySimpleApp):
505
        class application(wx.App):
506
                app_version = '0.4'
507
                app_path = os.getcwd()
508
                app_name = os.path.basename(sys.argv[0].split('.')[0])
509
                help_file = app_path + '/' + app_name + '.htb'
510
                settings_name = app_path + '/' + app_name + '.cfg'
511
                def start(self):
512
                        result = True
513
                        print(5)
514
                        self.help_file = self.app_name + '.htb'
515
                        #SETUP LANGUAGE
516
                        lang_catalog = getdefaultlocale()[0]
517
                        list_trans = []
518
                        current_trans = -1
519
                        i = 0
520
                        print(6)
521
                        if os.path.exists('lang/%s'%lang_catalog):
522
                                for dir_name in os.listdir('lang'):
523
                                        if os.path.exists('lang/%s/%s.mo'%(dir_name, self.app_name)):
524
                                                if dir_name == lang_catalog:
525
                                                        current_trans = i
526
                                                        self.help_file = 'lang/' + dir_name + '/'+ self.help_file
527
                                                list_trans.append(gettext.GNUTranslations(open('lang/%s/%s.mo'%(dir_name, self.app_name), 'rb')))
528
                                                i += 1
529
                                if len(list_trans) > 0:
530
                                        try:
531
                                                list_trans[current_trans].install()
532
                                        except:
533
                                                print_error()
534
                        print(7)
535
                        if current_trans == -1:
536
                                trans = gettext.NullTranslations()
537
                                trans.install()
538
                        # SETUP WX LANGUAGE TRANSLATION TO OS DEFAULT LANGUAGE
539
                        # WX DIRECTORY MUST BE TO CONTAIN LANG DIRECTORY
540
                        self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)
541
                        print(8)
542
                        # CHECK EXISTS INSTANCE
543
                        name_user = wx.GetUserId()
544
                        name_instance = self.app_name + '::'
545
                        self.instance_checker = wx.SingleInstanceChecker(name_instance + name_user)
546
                        print(9)
547
                        if self.instance_checker.IsAnotherRunning():
548
                                wx.MessageBox(_('Software is already running.'), _('Warning'))
549
                                return False
550
                        # CREATE HTML HELP CONTROLLER
551
                        #~ wx.FileSystem.AddHandler(wx.ZipFSHandler())
552
                        self.help_controller = HtmlHelpController()
553
                        print(10)
554
                        if os.path.exists(self.help_file):
555
                                self.help_controller.AddBook(self.help_file)
556
                        #ABOUT APPLICATION
557
                        self.developers = [_('Maxim Kolosov')]
558
                        self.copyright = _('(C) 2013 Max Kolosov')
559
                        self.web_site = ('http://pybass.sf.net', _('Home page'))
560
                        self.email = ('mailto:pyirrlicht@gmail.com', _('email for feedback'))
561
                        self.license = _('BSD license')
562
                        self.about_description = _('wxPython bass music player.')
563
                        #CREATE MAIN FRAME
564
                        print(11)
565
                        self.main_frame = main_frame(None, wx.ID_ANY, self.app_name, app = self)
566
                        print(12)
567
                        self.SetTopWindow(self.main_frame)
568
                        print(13)
569
                        self.main_frame.Show()
570
                        print(14)
571
                        return result
572

    
573
                def OnExit(self):
574
                        try:
575
                                del self.instance_checker
576
                        except:
577
                                print_error()
578

    
579
        print(1)
580
        app = application(0)
581
        print(2)
582
        if app.start():
583
                print(3)
584
                app.MainLoop()
585
        else:
586
                print(4)
587
                app.OnExit()
    (1-1/1)