File: dlg_settings.py

package info (click to toggle)
torchat 0.9.9.550-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 772 kB
  • sloc: python: 5,527; makefile: 45; sh: 5
file content (116 lines) | stat: -rw-r--r-- 5,545 bytes parent folder | download | duplicates (3)
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
##############################################################################
#                                                                            #
# Copyright (c) 2007-2010 Bernd Kreuss <prof7bit@gmail.com>                  #
#                                                                            #
# This program is licensed under the GNU General Public License V3,          #
# the full source code is included in the binary distribution.               #
#                                                                            #
# Included in the distribution are files from other open source projects:    #
# - TOR Onion Router (c) The Tor Project, 3-clause-BSD                       #
# - SocksiPy (c) Dan Haim, BSD Style License                                 #
# - Gajim buddy status icons (c) The Gajim Team, GNU GPL                     #
#                                                                            #
##############################################################################

# This is the settings dialog

import wx
import dlg
import config
import tc_client
import translations
lang = translations.lang_en


class Dialog(wx.Dialog):
    def __init__(self, main_window):
        wx.Dialog.__init__(self, main_window, wx.ID_ANY, lang.DSET_TITLE)
        self.mw = main_window
        
        #1 outer panel and vertical sizer
        self.outer_panel = wx.Panel(self)
        outer_sizer = wx.BoxSizer(wx.VERTICAL)
        self.outer_panel.SetSizer(outer_sizer)

        #1.1 the notebook on the top
        self.notebook = wx.Notebook(self.outer_panel)
        outer_sizer.Add(self.notebook, 1, wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5)
        
        #1.2 the button_sizer at the bottom
        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
        outer_sizer.Add(button_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, border=5)
        
        #1.2.1 cancel button
        btn_cancel = wx.Button(self.outer_panel, wx.ID_CANCEL, lang.BTN_CANCEL)
        button_sizer.Add(btn_cancel)
        
        #1.2.2 ok button
        btn_ok = wx.Button(self.outer_panel, wx.ID_OK, lang.BTN_OK)
        button_sizer.Add(btn_ok, 0, wx.LEFT, 5)
        
        #2 the button bindings
        btn_ok.Bind(wx.EVT_BUTTON, self.onOk)
        btn_cancel.Bind(wx.EVT_BUTTON, self.onCancel)
        
        #3 now we create the notebook tabs
        #3.1 network
        self.p1 = dlg.Panel(self.notebook)
        self.notebook.AddPage(self.p1, lang.DSET_NET_TITLE)

        self.s_tor_portable = dlg.Separator(self.p1, "Tor portable")
        dlg.Text(self.p1, lang.DSET_NET_TOR_ADDRESS, ("tor_portable", "tor_server"), True)
        dlg.Text(self.p1, lang.DSET_NET_TOR_SOCKS, ("tor_portable", "tor_server_socks_port"))
        dlg.Text(self.p1, lang.DSET_NET_TOR_CONTROL, ("tor_portable", "tor_server_control_port"))
        self.s_tor = dlg.Separator(self.p1, "Tor")
        dlg.Text(self.p1, lang.DSET_NET_TOR_ADDRESS, ("tor", "tor_server"), True)
        dlg.Text(self.p1, lang.DSET_NET_TOR_SOCKS, ("tor", "tor_server_socks_port"))
        dlg.Text(self.p1, lang.DSET_NET_TOR_CONTROL, ("tor", "tor_server_control_port"))
        dlg.Text(self.p1, lang.DSET_NET_OWN_HOSTNAME, ("client", "own_hostname"), True)
        dlg.Separator(self.p1, "Client")
        dlg.Text(self.p1, lang.DSET_NET_LISTEN_INTERFACE, ("client", "listen_interface"), True)
        dlg.Text(self.p1, lang.DSET_NET_LISTEN_PORT, ("client", "listen_port"))
        self.p1.fit()
        
        portable = (tc_client.TOR_CONFIG == "tor_portable")
        if portable:
            self.s_tor.setEnabled(False)
        else:
            self.s_tor_portable.setEnabled(False)
        
        #3.2 user interface
        self.p2 = dlg.Panel(self.notebook)
        self.notebook.AddPage(self.p2, lang.DSET_GUI_TITLE)

        self.lang = dlg.Text(self.p2, lang.DSET_GUI_LANGUAGE, ("gui", "language"))
        self.lang_old = self.lang.getValue()
        dlg.Check(self.p2, lang.DSET_GUI_OPEN_MAIN_HIDDEN, ("gui", "open_main_window_hidden"))
        dlg.Check(self.p2, lang.DSET_GUI_OPEN_CHAT_HIDDEN, ("gui", "open_chat_window_hidden"))
        dlg.Check(self.p2, lang.DSET_GUI_NOTIFICATION_POPUP, ("gui", "notification_popup"))
        dlg.Text(self.p2, lang.DSET_GUI_NOTIFICATION_METHOD, ("gui", "notification_method"))
        dlg.Check(self.p2, lang.DSET_GUI_FLASH_WINDOW, ("gui", "notification_flash_window"))
        
        #3.3 misc options
        self.p3 = dlg.Panel(self.notebook)
        self.notebook.AddPage(self.p3, lang.DSET_MISC_TITLE)
        self.chk_tmp = dlg.Check(self.p3, lang.DSET_MISC_TEMP_IN_DATA, ("files", "temp_files_in_data_dir"))
        self.dir_tmp = dlg.Dir(self.p3, lang.DSET_MISC_TEMP_CUSTOM_DIR, ("files", "temp_files_custom_dir"))
        self.dir_tmp.setEnabled(not self.chk_tmp.getValue())
        self.chk_tmp.wx_ctrl.Bind(wx.EVT_CHECKBOX, self.onChkTmp)
        
        #4 fit the sizers
        outer_sizer.Fit(self)
        
    def onChkTmp(self, evt):
        self.dir_tmp.setEnabled(not self.chk_tmp.getValue())
        
    def onCancel(self, evt):
        evt.Skip() #let the frame now process the Cancel event
        
    def onOk(self, evt):
        self.p1.saveAllData()
        self.p2.saveAllData()
        self.p3.saveAllData()
        if self.lang.getValue() != self.lang_old:
            config.importLanguage()
        evt.Skip() #let the frame now process the Ok event