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$ 
  5  #* $Id$ 
  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 os, sys, logging 
 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(os.path.dirname(__file__), "selector.glade") 
 42   
43 -class WarningSc:
44 """ 45 Print a warning before starting the program and allows to change the working directory 46 """
47 - def __init__(self, directory, window="dialog-warning", manageGTK=True, callBack=None):
48 """ 49 Print a small dialog screen 50 51 @param callBack: method to be called with the directory chosen 52 @type callBack: method or function 53 """ 54 logging.debug("WarningSc.init") 55 self.directory = directory 56 self.window = window 57 self.manageGTK = manageGTK 58 self.quit = True 59 self.callBack = callBack 60 self.guiFiler = None 61 self.gui = gtk.glade.XML(unifiedglade, root=self.window) 62 self.gui.signal_connect('on_dialog_destroy', self.destroy) 63 self.gui.signal_connect('on_Select_clicked', self.filer) 64 self.gui.signal_connect('on_cancel_clicked', self.destroy) 65 self.gui.signal_connect('on_ok_clicked', self.continu) 66 self.gui.signal_connect('on_dirname_editing_done', self.continu) 67 self.gui.get_widget("dirname").set_text(directory) 68 69 if self.manageGTK: 70 gtk.main() 71 else: 72 while gtk.events_pending(): 73 gtk.main_iteration()
74
75 - def continu(self, *args):
76 """ 77 Just destroy the window and goes on .... 78 """ 79 logging.debug("WarningSc.continue") 80 self.directory = self.gui.get_widget("dirname").get_text().strip() 81 if self.manageGTK: 82 gtk.main_quit() 83 self.quit = False 84 self.gui.get_widget(self.window).destroy() 85 while gtk.events_pending(): 86 gtk.main_iteration() 87 if self.callBack is not None: 88 self.callBack(self.directory)
89
90 - def destroy(self, *args):
91 """ 92 Destroy clicked by user -> quit the program 93 """ 94 logging.debug("WarningSc.destroy called") 95 if self.manageGTK: 96 if self.quit: 97 sys.exit(0) 98 else: 99 self.gui.get_widget(self.window).destroy() 100 while gtk.events_pending(): 101 gtk.main_iteration()
102 103
104 - def filer(self, *args):
105 """ 106 Launch the filer GUI to choose the root directory 107 """ 108 logging.debug("WarningSc.dirchooser.filer called") 109 self.guiFiler = gtk.glade.XML(unifiedglade, root="filer") 110 self.guiFiler.get_widget("filer").set_current_folder(self.directory) 111 self.guiFiler.signal_connect('on_Open_clicked', self.filerSelect) 112 self.guiFiler.signal_connect('on_Cancel_clicked', self.filerDestroy)
113 114
115 - def filerSelect(self, *args):
116 """ 117 Close the filer GUI and update the data 118 """ 119 logging.debug("WarningSc.filerSelect called") 120 self.directory = self.guiFiler.get_widget("filer").get_current_folder() 121 self.gui.get_widget("dirname").set_text(self.directory) 122 self.guiFiler.get_widget("filer").destroy()
123
124 - def filerDestroy(self, *args):
125 """ 126 Close the filer GUI 127 """ 128 logging.debug("WarningSc.filerDestroy called") 129 self.guiFiler.get_widget("filer").destroy()
130
131 - def getDirectory(self):
132 """ 133 Return the directory chosen 134 """ 135 logging.debug("WarningSc.getDirectory") 136 self.directory = self.gui.get_widget("dirname").get_text().strip() 137 return self.directory
138