def __init__(self): KApplication.__init__(self) # in case something needs done before quitting self.connect(self, SIGNAL('aboutToQuit()'), self.quit) self.dcop = ToolBoxDCOPInterface() self._setup_standard_directories() #self._generate_data_directories() dbfile = os.path.join(self.datadir, 'main.db') #self.conn = Connection(dbname=dbfile, autocommit=True, # encoding='ascii') #self.guests = Guests(self.conn) #self.db = EntityManager(self.conn) from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker self.engine = create_engine('sqlite:///%s' % dbfile) if not self.engine.table_names(): from newschema import metadata metadata.create_all(self.engine) self.DbSession = sessionmaker(bind=self.engine, autoflush=True, transactional=False) self.session = self.DbSession() self.db = EntityManager(self.session) self.urlhandler = MainUrlHandler(self) self.filehandler = BaseFileHandler(self) # setup the timer to handle background jobs self.timer = QTimer() # every five seconds self.timer.changeInterval(1000) self.connect(self.timer, SIGNAL('timeout()'), self._timer_done) self.main_window = None
class MainApplication(KApplication): def __init__(self): KApplication.__init__(self) # in case something needs done before quitting self.connect(self, SIGNAL('aboutToQuit()'), self.quit) self.dcop = ToolBoxDCOPInterface() self._setup_standard_directories() #self._generate_data_directories() dbfile = os.path.join(self.datadir, 'main.db') #self.conn = Connection(dbname=dbfile, autocommit=True, # encoding='ascii') #self.guests = Guests(self.conn) #self.db = EntityManager(self.conn) from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker self.engine = create_engine('sqlite:///%s' % dbfile) if not self.engine.table_names(): from newschema import metadata metadata.create_all(self.engine) self.DbSession = sessionmaker(bind=self.engine, autoflush=True, transactional=False) self.session = self.DbSession() self.db = EntityManager(self.session) self.urlhandler = MainUrlHandler(self) self.filehandler = BaseFileHandler(self) # setup the timer to handle background jobs self.timer = QTimer() # every five seconds self.timer.changeInterval(1000) self.connect(self.timer, SIGNAL('timeout()'), self._timer_done) self.main_window = None # this method sets up the directories used by the application # with respect to the KDE environment # currently the main config file is placed in self.datadir # changes in the file dialogs used in the application will # be stored in the config file in its proper location # when I am ready to deal with changes to that config file # that my code doesn't use, I will probably move the main # config file to the regular config location def _setup_standard_directories(self): self._std_dirs = KStandardDirs() self.tmpdir_parent = str(self._std_dirs.findResourceDir('tmp', '/')) self.datadir_parent = str(self._std_dirs.findResourceDir('data', '/')) self.tmpdir = os.path.join(self.tmpdir_parent, 'toolbox') self.datadir = os.path.join(self.datadir_parent, 'toolbox') # we need this in dosbox object (for now) self.main_config_dir = self.datadir if not os.path.exists(self.datadir): os.mkdir(self.datadir) # This method is currently useless, but may be useful later # if some house cleaning needs doing before quitting def quit(self): # house cleaning chores go here KApplication.quit(self) def _timer_done(self): self.urlhandler.scan_jobs() if self.urlhandler.completed_jobs(): self.urlhandler.handle_completed_jobs() self.emit(PYSIGNAL('UrlHandled'),(True,)) jobs = self.urlhandler.jobs if jobs: self.main_window.label.setText('toolbox: %d jobs running' % len(jobs)) else: self.main_window.label.setText('toolbox')