########################################################################
#
#  Copyright (C) 2009, CZ.NIC, z.s.p.o.
# 
#  This file is part of dnstester.
#
#  dnstester is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  dnstester is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
########################################################################

import gtk

import messages
import lang

class LangCombo:

    def __init__(self, combo, items):
        self.combo = combo
        self.items = items
        self.fill()

    def clear(self):
        for c in range(len(self.items)):
            self.combo.remove_text(0)

    def fill(self):
        for msg in self.items:
            self.combo.append_text(lang.get_string(msg))

    def refill(self, items=None):

        if items != None:
            pos = 0
        else:
            pos = self.combo.get_active()

        self.clear()

        if items != None:
            self.items = items

        self.fill()
        self.combo.set_active(pos)

        self.combo.set_sensitive(self.items != None and len(self.items) != 0)

    def get_active_item_tag(self):
        pos = self.combo.get_active()
        if pos == -1: 
            return ''
        else:
            return self.items[self.combo.get_active()]

    def set_active(self, pos):
        self.combo.set_active(pos)

