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_edit.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  3.4 KB  |  107 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import os
  5. import gobject
  6. import gtk
  7. import gtk.glade as gtk
  8. import UpdateManager.Common.aptsources as aptsources
  9.  
  10. class dialog_edit:
  11.     
  12.     def __init__(self, parent, sourceslist, source_entry, datadir):
  13.         self.sourceslist = sourceslist
  14.         self.source_entry = source_entry
  15.         if os.path.exists('../data/SoftwarePropertiesDialogs.glade'):
  16.             self.gladexml = gtk.glade.XML('../data/SoftwarePropertiesDialogs.glade')
  17.         else:
  18.             self.gladexml = gtk.glade.XML('%s/glade/SoftwarePropertiesDialogs.glade' % datadir)
  19.         self.main = self.gladexml.get_widget('dialog_edit')
  20.         self.main.set_transient_for(parent)
  21.         self.button_edit_ok = self.gladexml.get_widget('button_edit_ok')
  22.         combo_type = self.gladexml.get_widget('combobox_type')
  23.         if source_entry.type == 'deb':
  24.             combo_type.set_active(0)
  25.         elif source_entry.type == 'deb-src':
  26.             combo_type.set_active(1)
  27.         else:
  28.             print "Error, unknown source type: '%s'" % source_enrty.type
  29.         entry = self.gladexml.get_widget('entry_uri')
  30.         entry.set_text(source_entry.uri)
  31.         entry = self.gladexml.get_widget('entry_dist')
  32.         entry.set_text(source_entry.dist)
  33.         entry = self.gladexml.get_widget('entry_comps')
  34.         comps = ''
  35.         for c in source_entry.comps:
  36.             if len(comps) > 0:
  37.                 comps = comps + ' ' + c
  38.                 continue
  39.             comps = c
  40.         
  41.         entry.set_text(comps)
  42.         entry = self.gladexml.get_widget('entry_comment')
  43.         entry.set_text(source_entry.comment)
  44.         self.gladexml.signal_connect('on_entry_source_line_changed', self.check_line)
  45.  
  46.     
  47.     def check_line(self, *args):
  48.         """Check for a valid apt line and set the sensitiveness of the
  49.        button 'add' accordingly"""
  50.         line = self.get_line()
  51.         if line == False:
  52.             self.button_edit_ok.set_sensitive(False)
  53.             return None
  54.         
  55.         source_entry = aptsources.SourceEntry(line)
  56.         if source_entry.invalid == True or source_entry.disabled == True:
  57.             self.button_edit_ok.set_sensitive(False)
  58.         else:
  59.             self.button_edit_ok.set_sensitive(True)
  60.  
  61.     
  62.     def get_line(self):
  63.         '''Collect all values from the entries and create an apt line'''
  64.         combo_type = self.gladexml.get_widget('combobox_type')
  65.         if combo_type.get_active() == 0:
  66.             line = 'deb'
  67.         else:
  68.             line = 'deb-src'
  69.         entry = self.gladexml.get_widget('entry_uri')
  70.         text = entry.get_text()
  71.         if len(text) < 1 and text.find(' ') != -1 or text.find('#') != -1:
  72.             return False
  73.         
  74.         line = line + ' ' + entry.get_text()
  75.         entry = self.gladexml.get_widget('entry_dist')
  76.         text = entry.get_text()
  77.         if len(text) < 1 and text.find(' ') != -1 or text.find('#') != -1:
  78.             return False
  79.         
  80.         line = line + ' ' + entry.get_text()
  81.         entry = self.gladexml.get_widget('entry_comps')
  82.         text = entry.get_text()
  83.         if len(text) < 1 or text.find('#') != -1:
  84.             return False
  85.         
  86.         line = line + ' ' + entry.get_text()
  87.         entry = self.gladexml.get_widget('entry_comment')
  88.         if entry.get_text() != '':
  89.             line = line + ' #' + entry.get_text() + '\n'
  90.         else:
  91.             line = line + '\n'
  92.         return line
  93.  
  94.     
  95.     def run(self):
  96.         res = self.main.run()
  97.         if res == gtk.RESPONSE_OK:
  98.             line = self.get_line()
  99.             index = self.sourceslist.list.index(self.source_entry)
  100.             file = self.sourceslist.list[index].file
  101.             self.sourceslist.list[index] = aptsources.SourceEntry(line, file)
  102.         
  103.         self.main.hide()
  104.         return res
  105.  
  106.  
  107.