summaryrefslogtreecommitdiffstats
path: root/iw/language_support_gui.py
blob: 066eb77927796ff86db4933758d2526785ea94f6 (plain)
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
#
# langauge_support_gui.py: dialog for selection of which languages to support.
#
# Copyright 2001-2002 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import checklist
import gtk
import gui
from iw_gui import *
from flags import flags
from rhpl.translate import _, N_

from gui import setupTreeViewFixupIdleHandler

class LanguageSupportWindow (InstallWindow):
    windowTitle = _("Additional Language Support")
    htmlTag = "langsupport"
    
    def getNext (self):
        self.supportedLangs = []

        for row in range(self.maxrows):
            if self.languageList.get_active(row) == 1:
                selected = self.languageList.get_text (row, 1)
                self.supportedLangs.append (selected)

        self.defaultLang = self.combo.entry.get_text()
        self.langs.setSupported (self.supportedLangs)
        self.langs.setDefault (self.defaultLang)

        return None

    def toggled_language(self, data, row):
#        row = int(row)
#        lang = self.languageList.get_text(row, 1)
# 	 val = self.languageList.get_active(row)
#
	# may be too slow to redo everytime they select/deselect a lang
	# but worth trying since its simple
	self.rebuild_combo_box()
	

    def rebuild_combo_box(self):
        list = []

	for row in range(self.maxrows):
	    if self.languageList.get_active(row) == 1:
		selected = self.languageList.get_text (row, 1)
		list.append (selected)
	
	if len(list) == 0:
	    list = [""]
	    self.ics.setNextEnabled (gtk.FALSE)
	else:
	    self.ics.setNextEnabled (gtk.TRUE)

        self.defaultLang = self.combo.entry.get_text()
	self.combo.set_popdown_strings(list)

	if self.defaultLang in list:
	    index = list.index(self.defaultLang)
	    self.combo.list.select_item(index)
	else:
	    self.combo.list.select_item(0)
	    self.defaultLang = list[0]

    def select_all (self, data):
        self.ics.setNextEnabled (gtk.TRUE)
        for row in range(self.maxrows):
            self.languageList.set_active(row, gtk.TRUE)

	self.rebuild_combo_box()

    def select_default (self, data):
        self.ics.setNextEnabled (gtk.TRUE)
        for row in range(self.maxrows):
	    deflang = self.combo.entry.get_text()

	    if self.languageList.get_text(row, 1) == deflang:
		self.languageList.set_active(row, gtk.TRUE)
	    else:
		self.languageList.set_active(row, gtk.FALSE)

	self.rebuild_combo_box()

    def reset (self, data):
        self.ics.setNextEnabled (gtk.TRUE)
	list = []

        for row in range(self.maxrows):
            item = self.languageList.get_text (row, 1)

	    if item in self.origLangs:
                self.languageList.set_active(row, gtk.TRUE)
                list.append (item)
            else:
                self.languageList.set_active(row, gtk.FALSE)                

	self.defaultLang = self.oldDefaultLang
	self.combo.set_popdown_strings(list)

	self.combo.list.select_item(list.index(self.defaultLang))

    def setCurrent(self, currentDefault, recenter=1):
        parent = None

        store = self.languageList.get_model()
        row = 0

        # iterate over the list looking for the default locale
        while (row < self.languageList.num_rows):
            if self.languageList.get_text(row, 1) == currentDefault:
                path = store.get_path(store.get_iter((row,)))
                col = self.languageList.get_column(0)
                self.languageList.set_cursor(path, col, gtk.FALSE)
                self.languageList.scroll_to_cell(path, col, gtk.TRUE, 0.5, 0.5)
                break
            row = row + 1

    # LanguageSupportWindow tag="langsupport"
    def getScreen (self, langs):
	self.langs = langs
        self.languages = self.langs.getAllSupported ()
        self.supportedLangs = self.langs.getSupported()
	self.origLangs = []
        for i in self.supportedLangs:
            self.origLangs.append(i)
            
	self.defaultLang = self.langs.getDefault()
	self.oldDefaultLang = self.defaultLang

        # first time we hit this point in install this is not initialized
        if self.origLangs == []:
            self.origLangs.append(self.defaultLang)
        
        vbox = gtk.VBox (gtk.FALSE, 10)
        hbox = gtk.HBox (gtk.FALSE)
        
        self.combo = gtk.Combo ()

        label = gui.MnemonicLabel(_("Select the _default language for the system:   "))
        label.set_mnemonic_widget(self.combo.entry)
        hbox.pack_start (label, gtk.FALSE, 20)

        hbox.pack_start (self.combo, gtk.FALSE, 20)
        vbox.pack_start (hbox, gtk.FALSE, 50)

        sep = gtk.HSeparator ()
        vbox.pack_start (sep, gtk.FALSE, 15)

	label = gui.MnemonicLabel(_("Select _additional languages to install "
				    "on the system:"))
        
        label.set_alignment (0.0, 0.5)
        label.set_line_wrap (gtk.TRUE)
        label.set_size_request(400, -1)
        vbox.pack_start (label, gtk.FALSE)
        
        hbox = gtk.HBox (gtk.FALSE)

        # langs we want to support
        self.languageList = checklist.CheckList(1)
        label.set_mnemonic_widget(self.languageList)

        self.maxrows = 0
        list = []
        comboCurr = 0
	firstItem = 0
        sel = 0

        for locale in self.languages:
	    if locale == self.defaultLang or (locale in self.supportedLangs):
		self.languageList.append_row((locale, ""), gtk.TRUE)
		list.append(locale)

		if locale == self.defaultLang:
		    firstItem = self.maxrows
		    sel = comboCurr
		else:
		    comboCurr = comboCurr + 1
	    else:
		self.languageList.append_row((locale, ""), gtk.FALSE)

            self.maxrows = self.maxrows + 1

        self.setCurrent(self.defaultLang)
            
        self.combo.set_popdown_strings (list)
        self.combo.list.select_item(sel)
        self.combo.entry.set_property("editable", gtk.FALSE)

        sw = gtk.ScrolledWindow ()
        sw.set_border_width (5)
        sw.set_policy (gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        sw.add (self.languageList)
        sw.set_shadow_type(gtk.SHADOW_IN)

        vbox2 = gtk.VBox (gtk.FALSE, 12)

        all_button = gtk.Button (_("_Select All"))
        all_button.set_size_request(160, -1)
        all_button.connect ('clicked', self.select_all)
        a1 = gtk.Alignment (0.5, 0.5)
        a1.add (all_button)

        default_button = gtk.Button (_("Select Default _Only"))
        default_button.set_size_request(160, -1)
        default_button.connect ('clicked', self.select_default)
        a2 = gtk.Alignment (0.5, 0.5)
        a2.add (default_button)

        reset_button = gtk.Button (_("Rese_t"))
        reset_button.set_size_request(160, -1)
        reset_button.connect ('clicked', self.reset)
        a3 = gtk.Alignment (0.5, 0.5)
        a3.add (reset_button)

        vbox2.pack_start (a1, gtk.FALSE, 10)
        vbox2.pack_start (a2, gtk.FALSE)
        vbox2.pack_start (a3, gtk.FALSE)
        hbox.pack_start (sw, gtk.TRUE, 10)
        hbox.pack_start (vbox2, gtk.FALSE, 10)
        vbox.pack_start (hbox, gtk.TRUE)

        # default button
#        alignment = gtk.Alignment (0.0, 0.0)
#        button = gtk.Button (_("Select as default"))
#        alignment.add (button)

	# connect CB for when they change selected langs
        self.languageList.checkboxrenderer.connect("toggled",
					       self.toggled_language)

	store = self.languageList.get_model()

	setupTreeViewFixupIdleHandler(self.languageList, store)


        return vbox