~ubuntu-branches/ubuntu/quantal/torchat/quantal

« back to all changes in this revision

Viewing changes to torchat.py

  • Committer: Bazaar Package Importer
  • Author(s): Ulises Vitulli
  • Date: 2011-04-16 23:35:04 UTC
  • Revision ID: james.westby@ubuntu.com-20110416233504-j4dulunjoc224vfp
Tags: upstream-0.9.9.534
ImportĀ upstreamĀ versionĀ 0.9.9.534

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: UTF-8 -*-
 
3
# vim: set sw=4 sts=4 expandtab:
 
4
 
 
5
##############################################################################
 
6
#                                                                            #
 
7
# Copyright (c) 2007-2010 Bernd Kreuss <prof7bit@gmail.com>                  #
 
8
#                                                                            #
 
9
# This program is licensed under the GNU General Public License V3,          #
 
10
# the full source code is included in the binary distribution.               #
 
11
#                                                                            #
 
12
# Included in the distribution are files from other open source projects:    #
 
13
# - TOR Onion Router (c) The Tor Project, 3-clause-BSD                       #
 
14
# - SocksiPy (c) Dan Haim, BSD Style License                                 #
 
15
# - Gajim buddy status icons (c) The Gajim Team, GNU GPL                     #
 
16
#                                                                            #
 
17
##############################################################################
 
18
 
 
19
import config
 
20
import wxversion
 
21
if config.isMac():
 
22
    if wxversion.checkInstalled('2.9'):
 
23
        wxversion.select('2.9') # For Mac it is tweaked and optimized with 2.9
 
24
    else:
 
25
        print "(1) wxPython-2.9 is not installed"
 
26
        
 
27
else:
 
28
    try:
 
29
        if wxversion.checkInstalled('2.8'):
 
30
            wxversion.select('2.8') # On MSW and GTK we stick with 2.8 for now
 
31
        else:
 
32
            print "(1) wxPython-2.8 is not installed"
 
33
        
 
34
    except:
 
35
        # continue anyways. 
 
36
        # in the pyinstaller binary wxversion can screw up and throw exceptions 
 
37
        # so we ignore the error and just use the wx that happens to be available.
 
38
        # TODO: Does this still happen since we now use checkInstalled()?
 
39
        print "(2) wxversion screwed up, this is harmless, ignoring it."
 
40
 
 
41
import wx
 
42
import os
 
43
import tc_client
 
44
import tc_gui
 
45
        
 
46
def main():
 
47
    print "(2) wxPython version %s" % wx.version()
 
48
    #create the mandatory wx application object
 
49
    if config.isMac():
 
50
        import tc_mac
 
51
        app = tc_mac.App(redirect=False)
 
52
    else:
 
53
        app = wx.App(redirect=False)
 
54
    
 
55
    #test for availability of our listening port
 
56
    interface = config.get("client", "listen_interface")
 
57
    port = config.getint("client", "listen_port")
 
58
    print "(1) opening TorChat listener on %s:%s" % (interface, port)
 
59
    listen_socket = tc_client.tryBindPort(interface, port)
 
60
    if not listen_socket:
 
61
        print "(1) %s:%s is already in use" % (interface, port)
 
62
        wx.MessageBox(tc_gui.lang.D_WARN_USED_PORT_MESSAGE % (interface, port),
 
63
                      tc_gui.lang.D_WARN_USED_PORT_TITLE)
 
64
        return
 
65
    else:
 
66
        print "(1) TorChat is listening on %s:%s" % (interface, port)
 
67
    
 
68
    #now continue with normal program startup 
 
69
    print "(1) start initializing main window"
 
70
    app.mw = tc_gui.MainWindow(listen_socket)
 
71
    app.SetTopWindow(app.mw)
 
72
    print "(1) main window initialized"
 
73
    print "(1) entering main loop"
 
74
    app.MainLoop()
 
75
 
 
76
if __name__ == "__main__":
 
77
    try:
 
78
        main()
 
79
    except KeyboardInterrupt:
 
80
        tc_client.stopPortableTor()