# # This file is part of Documancer (http://documancer.sf.net) # # Copyright (C) 2003-2005 Vaclav Slavik # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: app.py,v 1.17 2005/02/06 10:16:18 vaclavslavik Exp $ # # wxPython application # import sys from wxPython.wx import * from MainFrame import MainFrame import utils, book, server, providers, indexer, cache from gettext import gettext as _ class UICallback_wx: def __init__(self, mainFrame): self.mainFrame = mainFrame self.busyCnt = 0 def error(self, msg): wxCallAfter(wxLogError, (msg)) def errorPrompt(self, msg): wxCallAfter(wxLogError, (msg)) def showBusyIndicator(self): self.busyCnt += 1 def hideBusyIndicator(self): self.busyCnt -= 1 if self.busyCnt == 0: if self.mainFrame != None: wxCallAfter(self.mainFrame.statusbar.SetStatusText, ('')) def setBusyText(self, text): if self.mainFrame != None: wxCallAfter(self.mainFrame.statusbar.SetStatusText, (text)) class ExceptionsWindow(wxPyOnDemandOutputWindow): """This class shows exceptions in a window _and_ writes them to stderr.""" def __init__(self): import sys self.err = sys.stderr wxPyOnDemandOutputWindow.__init__(self) def write(self, text): wxPyOnDemandOutputWindow.write(self, text) self.err.write(text.encode('utf-8')) class DocumancerApp(wxApp): def __init__(self): self.outputWindowClass = ExceptionsWindow doRedirect = (sys.platform == 'win32') wxApp.__init__(self, redirect=doRedirect) def OnInit(self): self.instanceChecker = wxPreSingleInstanceChecker() if self.instanceChecker.Create('documancer-%s' % wxGetUserId(), utils.getConfigDir()): if self.instanceChecker.IsAnotherRunning(): wxMessageBox(_("""\ Another Documancer instance is already running, exiting."""), _("Documancer Error"), wxOK | wxICON_ERROR) return 0 else: wxLogWarning(_("Unable to detect if another instance is running")) book.loadBooks() server.runServer(inBackground=1) wxInitAllImageHandlers() main_frame = MainFrame(None, -1, "", name=_('Documancer')) utils.uiCallback = UICallback_wx(main_frame) self.SetTopWindow(main_frame) main_frame.Show(1) main_frame.SetSize( (utils.config().ReadInt('/GuiState/MainFrame/width',500), utils.config().ReadInt('/GuiState/MainFrame/height',400))) cache.worker.start() return 1 def OnExit(self): busy = wxBusyInfo(_('Closing Documancer, please wait...')) book.saveBooks() providers.shutdown() cache.shutdown() indexer.shutdown() # must be after cache! self.instanceChecker = None # end of class DocumancerApp def run(): app = DocumancerApp() app.MainLoop() if __name__ == '__main__': run()