home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / softwareproperties / gtk / DialogEdit.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  3.7 KB  |  106 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import gobject
  6. import gtk
  7. import gtk.glade as gtk
  8. from aptsources.sourceslist import SourceEntry
  9.  
  10. class DialogEdit:
  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/dialogs.glade'):
  16.             self.gladexml = gtk.glade.XML('../data/dialogs.glade')
  17.         else:
  18.             self.gladexml = gtk.glade.XML('%s/glade/dialogs.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.         source_entry = SourceEntry(line)
  55.         if source_entry.invalid == True:
  56.             self.button_edit_ok.set_sensitive(False)
  57.         else:
  58.             self.button_edit_ok.set_sensitive(True)
  59.  
  60.     
  61.     def get_line(self):
  62.         '''Collect all values from the entries and create an apt line'''
  63.         combo_type = self.gladexml.get_widget('combobox_type')
  64.         if self.source_entry.disabled == True:
  65.             line = '#'
  66.         else:
  67.             line = ''
  68.         if combo_type.get_active() == 0:
  69.             line = '%sdeb' % line
  70.         else:
  71.             line = '%sdeb-src' % line
  72.         entry = self.gladexml.get_widget('entry_uri')
  73.         text = entry.get_text()
  74.         if len(text) < 1 and text.find(' ') != -1 or text.find('#') != -1:
  75.             return False
  76.         line = line + ' ' + entry.get_text()
  77.         entry = self.gladexml.get_widget('entry_dist')
  78.         text = entry.get_text()
  79.         if len(text) < 1 and text.find(' ') != -1 or text.find('#') != -1:
  80.             return False
  81.         line = line + ' ' + entry.get_text()
  82.         entry = self.gladexml.get_widget('entry_comps')
  83.         text = entry.get_text()
  84.         if text.find('#') != -1:
  85.             return False
  86.         entry = self.gladexml.get_widget('entry_comment')
  87.         if entry.get_text() != '':
  88.             line = line + ' #' + entry.get_text() + '\n'
  89.         else:
  90.             line = line + '\n'
  91.         return line
  92.  
  93.     
  94.     def run(self):
  95.         res = self.main.run()
  96.         if res == gtk.RESPONSE_OK:
  97.             line = self.get_line()
  98.             index = self.sourceslist.list.index(self.source_entry)
  99.             file = self.sourceslist.list[index].file
  100.             self.sourceslist.list[index] = SourceEntry(line, file)
  101.         
  102.         self.main.hide()
  103.         return res
  104.  
  105.  
  106.