Package imagizer :: Module dirchooser |
[hide private]
[frames] | no frames]

# Source Code for Module imagizer.dirchooser

     1  #!/usr/bin/env python
     2  # -*- coding: UTF8 -*-
     3  #******************************************************************************\
     4  #* $Source: /srv/cvs/imagizer/doc/html/imagizer.dirchooser-pysrc.html,v $
     5  #* $Id: imagizer.dirchooser-pysrc.html,v 1.1 2010-04-28 19:44:10 jerome Exp $
     6  #*
     7  #* Copyright (C) 2006-2009,  Jérome Kieffer <kieffer@terre-adelie.org>
     8  #* Conception : Jérôme KIEFFER, Mickael Profeta & Isabelle Letard
     9  #* Licence GPL v2
    10  #* This program is free software; you can redistribute it and/or modify
    11  #* it under the terms of the GNU General Public License as published by
    12  #* the Free Software Foundation; either version 2 of the License, or
    13  #* (at your option) any later version.
    14  #*
    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  #*
    20  #* You should have received a copy of the GNU General Public License
    21  #* along with this program; if not, write to the Free Software
    22  #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    23  #*
    24  #*****************************************************************************/
    25
    26  """
    27  Library used by selector and the installer to select the working directories.
    28  """
    29
    30  import distutils.sysconfig, os, sys
    31
    32  try:
    33      import pygtk ; pygtk.require('2.0')
    34      import gtk, gtk.glade
    35  except:
    36          raise "Selector needs pygtk and glade-2 available from http://www.pygtk.org/"
    37
    38  from config import Config
    39  config = Config()
    40
    41  unifiedglade = os.path.join(distutils.sysconfig.get_python_lib(), "imagizer", "selector.glade")
    42
    43 -class WarningSc:
    44      """print a warning before starting the program and allows to chang the working directory"""
    45 -    def __init__(self, directory, window="dialog-warning"):
    46          self.directory = directory
    47          self.window = window
    48          self.quit = True
    49          self.xml = gtk.glade.XML(unifiedglade, root=self.window)
    50          self.xml.signal_connect('on_dialog_warning_destroy', self.destroy)
    51          self.xml.signal_connect('on_Select_clicked', self.filer)
    52          self.xml.signal_connect('on_cancel_clicked', self.destroy)
    53          self.xml.signal_connect('on_ok_clicked', self.continu)
    54          self.xml.signal_connect('on_dirname_editing_done', self.continu)
    55          while gtk.events_pending():gtk.main_iteration()
    56          self.xml.get_widget("dirname").set_text(directory)
    57          gtk.main()
    58
    59 -    def continu(self, *args):
    60          """just destroy the window and goes on ...."""
    61          self.directory = self.xml.get_widget("dirname").get_text().strip()
    62          gtk.main_quit()
    63          self.quit = False
    64          self.xml.get_widget(self.window).destroy()
    65          while gtk.events_pending():
    66              gtk.main_iteration()
    67
    68 -    def destroy(self, *args):
    69          """destroy clicked by user -> quit the program"""
    70          if self.quit:
    71              sys.exit(0)
    72
    73 -    def filer(self, *args):
    74          """Launch the filer GUI to choose the root directory"""
    75          self.xml2 = gtk.glade.XML(unifiedglade, root="filer")
    76          self.xml2.get_widget("filer").set_current_folder(self.directory)
    77          self.xml2.signal_connect('on_Open_clicked', self.filerselect)
    78          self.xml2.signal_connect('on_Cancel_clicked', self.filerdestroy)
    79
    80 -    def filerselect(self, *args):
    81          """Close the filer GUI and update the data"""
    82          self.directory = self.xml2.get_widget("filer").get_current_folder()
    83          self.xml.get_widget("dirname").set_text(self.directory)
    84          self.xml2.get_widget("filer").destroy()
    85
    86 -    def filerdestroy(self, *args):
    87          """Close the filer GUI"""
    88          self.xml2.get_widget("filer").destroy()
    89