home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / SoftwareProperties / dialog_add.py < prev    next >
Encoding:
Python Source  |  2006-08-24  |  2.4 KB  |  73 lines

  1. # dialog_add.py.in - dialog to add a new repository
  2. #  
  3. #  Copyright (c) 2004-2005 Canonical
  4. #                2005 Michiel Sikkes
  5. #              
  6. #  Authors: 
  7. #       Michael Vogt <mvo@debian.org>
  8. #       Michiel Sikkes <michiels@gnome.org>
  9. #       Sebastian Heinlein <glatzor@ubuntu.com>
  10. #
  11. #  This program is free software; you can redistribute it and/or 
  12. #  modify it under the terms of the GNU General Public License as 
  13. #  published by the Free Software Foundation; either version 2 of the
  14. #  License, or (at your option) any later version.
  15. #  This program is distributed in the hope that it will be useful,
  16. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #  GNU General Public License for more details.
  19. #  You should have received a copy of the GNU General Public License
  20. #  along with this program; if not, write to the Free Software
  21. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  22. #  USA
  23.  
  24. import os
  25. import gobject
  26. import gtk
  27. import gtk.glade
  28. from gettext import gettext as _
  29.  
  30. import UpdateManager.Common.aptsources as aptsources
  31.  
  32. class dialog_add:
  33.   def __init__(self, parent, sourceslist, datadir):
  34.     """
  35.     Initialize the dialog that allows to add a new source entering the
  36.     raw apt line
  37.     """
  38.     self.sourceslist = sourceslist
  39.     self.parent = parent
  40.     self.datadir = datadir
  41.     # gtk stuff
  42.     self.gladexml = gtk.glade.XML("%s/glade/SoftwarePropertiesDialogs.glade" %\
  43.                                   datadir)
  44.     self.dialog = self.gladexml.get_widget("dialog_add_custom")
  45.     self.dialog.set_transient_for(self.parent)
  46.     self.entry = self.gladexml.get_widget("entry_source_line")
  47.     self.button_add = self.gladexml.get_widget("button_add_source")
  48.     self.entry.connect("changed", self.check_line)
  49.  
  50.   def run(self):
  51.     res = self.dialog.run()
  52.     self.dialog.hide()
  53.     if res == gtk.RESPONSE_OK:
  54.         line = self.entry.get_text() + "\n"
  55.     else:
  56.         line = None
  57.     return line
  58.  
  59.   def check_line(self, *args):
  60.     """
  61.     Check for a valid apt line and set the sensitiveness of the
  62.     button 'add' accordingly
  63.     """
  64.     line = self.entry.get_text() + "\n"
  65.     source_entry = aptsources.SourceEntry(line)
  66.     if source_entry.invalid == True or source_entry.disabled == True:
  67.         self.button_add.set_sensitive(False)
  68.     else:
  69.         self.button_add.set_sensitive(True)
  70.  
  71.