Пример #1
0
 def __init__(self, *args):
     KApplication.__init__(self)
     cfg = BaseConfig()
     self.cfg = cfg
     dirs = KStandardDirs()
     self.tmpdir = str(dirs.findResourceDir('tmp', '/'))
     self.datadir = str(dirs.findResourceDir('data', '/'))
     self.socketdir = str(dirs.findResourceDir('socket', '/'))
     dsn = {}
     self.cfg.setGroup('database')
     dsn['user'] = self.cfg.readEntry('dbuser')
     dsn['dbname'] = self.cfg.readEntry('dbname')
     dsn['passwd'] = self.cfg.readEntry('dbpass')
     self.cfg.setGroup('pgpool')
     self.pgpool = None
     usepgpool = self.cfg.readEntry('usepgpool')
     if usepgpool != 'false':
         print 'using pgpool'
         self.pgpool = PgPool(self.cfg, self.tmpdir, self.datadir)
         if not os.path.isfile(self.pgpool.pidfile):
             self.pgpool.run()
         else:
             self.pgpool = None
         dsn['host'] = 'localhost'
         dsn['port'] = self.cfg.readEntry('port')
     else:
         self.cfg.setGroup('database')
         dsn['host'] = self.cfg.readEntry('dbhost')
         dsn['port'] = self.cfg.readEntry('dbport')
     self.db = BaseDatabase(dsn, 'Konsultant', self)
     self.db.app = self
     self.connect(self, SIGNAL('aboutToQuit()'), self.quit)
Пример #2
0
 def __init__(self):
     KApplication.__init__(self)
     self.set_config()
     self.conn = None
     dirs = KStandardDirs()
     self.tmpdir = str(dirs.findResourceDir('tmp', '/'))
     self.datadir = str(dirs.findResourceDir('data', '/'))
     # I probably don't need the socket dir
     self.socketdir = str(dirs.findResourceDir('socket', '/'))
Пример #3
0
 def __init__(self, *args):
     KApplication.__init__(self)
     self.cfg = PaellaConfig()
     self.conn = PaellaConnection(self.cfg)
     self.db = BaseDatabase(self.conn, 'paelladb', None)
     dirs = KStandardDirs()
     self.tmpdir = str(dirs.findResourceDir('tmp', '/'))
     self.datadir = str(dirs.findResourceDir('data', '/'))
     self.socketdir = str(dirs.findResourceDir('socket', '/'))
     dsn = {}
Пример #4
0
 def __init__(self, *args):
     KApplication.__init__(self)
     self.cfg = PaellaConfig()
     self.conn = PaellaConnection(self.cfg)
     self.db = BaseDatabase(self.conn, 'paelladb', None)
     dirs = KStandardDirs()
     self.tmpdir = str(dirs.findResourceDir('tmp', '/'))
     self.datadir = str(dirs.findResourceDir('data', '/'))
     self.socketdir = str(dirs.findResourceDir('socket', '/'))
     dsn = {}
Пример #5
0
 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, 'dosbox-pykde')
     self.datadir = os.path.join(self.datadir_parent, 'dosbox-pykde')
     # 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)
Пример #6
0
    def __init__(self, *args):
        apply(KSystemTray.__init__, (self, ) + args)
        ''' comarInterface instance '''
        self.comarInterface = comarInterface(self.winId())
        ''' wirelessInterface instance '''
        self.wirelessInterface = wirelessInterface()
        ''' dcopInterface instance'''
        self.dcopInterface = dcopInterface(self.wirelessInterface)
        ''' Add /usr/share/PyWireless to KStandardDirs '''
        self.KStandardDirs = KStandardDirs()
        self.KStandardDirs.addResourceDir('icon', '/usr/share/PyWireless')
        ''' Create tray icon Loader '''
        self.icons = KIconLoader('PyWireless', self.KStandardDirs)
        ''' Timer event triggered every 3 second
            Until i found a way to use inotify or libfam '''
        self.time = QTimer(self)
        self.connect(self.time, SIGNAL('timeout()'), self.timeoutSlot)
        self.time.start(3000)

        self.connect(app, SIGNAL("shutDown()"), self.slotQuit)
        ''' Popup Menu '''
        connectionsMenu = KPopupMenu(self.contextMenu())
        ''' list all connections into Connections menu '''
        for entry in self.comarInterface.listConnections():
            if self.comarInterface.isActive(entry):
                id = connectionsMenu.insertItem(
                    QIconSet(
                        self.icons.loadIcon('wireless-online', KIcon.Desktop,
                                            16)), entry)
            else:
                id = connectionsMenu.insertItem(
                    QIconSet(
                        self.icons.loadIcon('wireless-offline', KIcon.Desktop,
                                            16)), entry)
        self.connect(connectionsMenu, SIGNAL("activated(int)"),
                     self.switchConnection)

        self.contextMenu().insertItem(_('Wireless Connections Profiles'),
                                      connectionsMenu)
        # FIXME: Use net-kga
        self.contextMenu().insertItem(_('Create New Wireless Connection'))

        self.show()
 def _setup_standard_directories(self):
     self._std_dirs = KStandardDirs()
     self.tmpdir_parent = path(str(self._std_dirs.findResourceDir("tmp", "/")))
     self.datadir_parent = path(str(self._std_dirs.findResourceDir("data", "/")))
     self.tmpdir = self.tmpdir_parent / "dosbox-pykde"
     self.datadir = self.datadir_parent / "dosbox-pykde"
     # we need this in dosbox object (for now)
     self.main_config_dir = self.datadir
     if not self.datadir.exists():
         self.datadir.mkdir()
Пример #8
0
class MainApplication(KApplication):
    def __init__(self):
        KApplication.__init__(self)
        # in case something needs done before quitting
        self.connect(self, SIGNAL('aboutToQuit()'), self.quit)
        self._setup_standard_directories()
        #self._generate_data_directories()
        dbfile = os.path.join(self.datadir, 'guests.db')
        self.conn = Connection(dbname=dbfile, autocommit=True,
                               encoding='ascii')
        self.guests = Guests(self.conn)
        
        
    # 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 = path(str(self._std_dirs.findResourceDir('tmp', '/')))
        self.datadir_parent = path(str(self._std_dirs.findResourceDir('data', '/')))
        self.tmpdir = self.tmpdir_parent / 'utguests'
        self.datadir = self.datadir_parent / 'utguests'
        # 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)
Пример #9
0
class MainApplication(KApplication):
    def __init__(self):
        KApplication.__init__(self)
        # in case something needs done before quitting
        self.connect(self, SIGNAL('aboutToQuit()'), self.quit)
        # place dcop object here
        self.dcop = DosboxHandler()
        self._setup_standard_directories()
        self._generate_data_directories()
        self.mainconfigfilename = os.path.join(self.datadir, 'dosbox-pykde.conf')
        if os.path.isfile(self.mainconfigfilename):
            self.generate_default_config()
            self.generate_main_objects()
            
            
    def generate_default_config(self):
        default_dbox_cfilename = os.path.join(self.datadir, 'dosbox.conf.default')
        # generate default config files if not already present
        # this would be a good time to use a wizard to setup config options
        generate_default_config(self.mainconfigfilename)
        generate_default_dosbox_config(default_dbox_cfilename)
        self.load_main_config()

    def generate_main_objects(self):
        # setup objects
        self.game_datahandler = self.make_new_datahandler()
        self.game_fileshandler = self.make_new_fileshandler()
        self.dosbox = self.make_new_dosbox_object()
        
    # we call self._generate_data_directories() in this method
    # because changes to the config may affect these options
    # and the corresponding application attributes
    def load_main_config(self):
        self.myconfig = MyConfig()
        self.myconfig.read([self.mainconfigfilename])
        self._generate_archive_directories()
        
    def update_main_config(self, configobj):
        cfile = StringIO()
        configobj.write(cfile)
        cfile.seek(0)
        self.myconfig.readfp(cfile)
        self.save_main_config(self.mainconfigfilename)
        self.load_main_config()

    def save_main_config(self, filename=None):
        if filename is None:
            filename = self.mainconfigfilename
        cfile = file(filename, 'w')
        self.myconfig.write(cfile)
        cfile.close()
        
    def make_new_datahandler(self):
        return GameDataHandler(self)

    def make_new_fileshandler(self):
        return GameFilesHandler(self)

    def make_new_dosbox_object(self):
        return Dosbox(self)

    
    # 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, 'dosbox-pykde')
        self.datadir = os.path.join(self.datadir_parent, 'dosbox-pykde')
        # 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)
        
    def _generate_data_directories(self):
        directories = {}.fromkeys(['games', 'configs', 'screenshots', 'capture', 'profiles'])
        for dir_key in directories:
            path = os.path.join(self.datadir, dir_key)
            directories[dir_key] = path
            if not os.path.exists(path):
                os.mkdir(path)
        self.data_directories = directories

    # this method sets attributes for the main directories
    # used in the application.
    # it also creates the directories if they aren't already there
    # except for the main_dosbox_path
    # I should probably use a yes/no dialog before actually creating the
    # directories.
    def _generate_archive_directories(self):
        cfg = self.myconfig
        installed_archives_path = cfg.get('filemanagement', 'installed_archives_path')
        extras_archives_path = cfg.get('filemanagement', 'extras_archives_path')
        makepaths(installed_archives_path, extras_archives_path)
        self.installed_archives_path = installed_archives_path
        self.extras_archives_path = extras_archives_path
        self.main_dosbox_path = cfg.get('dosbox', 'main_dosbox_path')

    # 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)
Пример #10
0
class SystemTray(KSystemTray):
    def __init__(self, *args):
        apply(KSystemTray.__init__, (self, ) + args)
        ''' comarInterface instance '''
        self.comarInterface = comarInterface(self.winId())
        ''' wirelessInterface instance '''
        self.wirelessInterface = wirelessInterface()
        ''' dcopInterface instance'''
        self.dcopInterface = dcopInterface(self.wirelessInterface)
        ''' Add /usr/share/PyWireless to KStandardDirs '''
        self.KStandardDirs = KStandardDirs()
        self.KStandardDirs.addResourceDir('icon', '/usr/share/PyWireless')
        ''' Create tray icon Loader '''
        self.icons = KIconLoader('PyWireless', self.KStandardDirs)
        ''' Timer event triggered every 3 second
            Until i found a way to use inotify or libfam '''
        self.time = QTimer(self)
        self.connect(self.time, SIGNAL('timeout()'), self.timeoutSlot)
        self.time.start(3000)

        self.connect(app, SIGNAL("shutDown()"), self.slotQuit)
        ''' Popup Menu '''
        connectionsMenu = KPopupMenu(self.contextMenu())
        ''' list all connections into Connections menu '''
        for entry in self.comarInterface.listConnections():
            if self.comarInterface.isActive(entry):
                id = connectionsMenu.insertItem(
                    QIconSet(
                        self.icons.loadIcon('wireless-online', KIcon.Desktop,
                                            16)), entry)
            else:
                id = connectionsMenu.insertItem(
                    QIconSet(
                        self.icons.loadIcon('wireless-offline', KIcon.Desktop,
                                            16)), entry)
        self.connect(connectionsMenu, SIGNAL("activated(int)"),
                     self.switchConnection)

        self.contextMenu().insertItem(_('Wireless Connections Profiles'),
                                      connectionsMenu)
        # FIXME: Use net-kga
        self.contextMenu().insertItem(_('Create New Wireless Connection'))

        self.show()

    def switchConnection(self, int):
        connection = self.contextMenu().text(int)

        if self.comarInterface.isActive(connection):
            ''' if selected is active then down it '''
            self.comarInterface.deactivateConnection(connection)
            self.contextMenu().changeItem(
                int,
                QIconSet(
                    self.icons.loadIcon('wireless-offline', KIcon.Desktop,
                                        16)),
                self.contextMenu().text(int))
        else:
            ''' if selected is not active then first down active one, up selected one '''
            self.comarInterface.deactivateConnection(
                self.comarInterface.activeConnection())
            self.comarInterface.activateConnection(connection)
            self.contextMenu().changeItem(
                int,
                QIconSet(
                    self.icons.loadIcon('wireless-online', KIcon.Desktop, 16)),
                self.contextMenu().text(int))

    def slotQuit(self):
        self.deleteLater()
        app.quit()

    def timeoutSlot(self):
        interfaceName = self.wirelessInterface.returnInterfaceName()
        interfaceESSID = self.wirelessInterface.returnESSID()
        interfaceMode = self.wirelessInterface.returnMode()
        linkStatus = self.wirelessInterface.returnLinkStatus()
        noiseStatus = self.wirelessInterface.returnNoiseStatus()
        signalStatus = self.wirelessInterface.returnSignalStatus()
        bitRate = self.wirelessInterface.returnBitrate()
        received = self.wirelessInterface.returnReceived()
        transferred = self.wirelessInterface.returnTransferred()
        status = self.wirelessInterface.returnInterfaceStatus()
        ''' Tray icon name '''
        if int(status):
            index = int(linkStatus) / 20
            iconName = 'pywireless_' + str(index)
            ''' Tooltip '''
            toolTip = _('''<center><img align="center" src="/usr/share/PyWireless/%s.png"></center>
            <center>
            <table border="0" bgcolor="#000000" cellspacing="1" cellpadding="1">
            <tr>
                <td colspan="2" bgcolor="#04CC1A"><center><b>Monitoring:</b> [ %s ]</b></center></td>
            <tr>
                <td bgcolor="#CCCCCC"><b>ESSID:</b></td>
                <td bgcolor="#CCCCCC"><center>%s</center></td>
            </tr>
            <tr>
                <td bgcolor="#EEEEEE"><b>Link Quality:</b></td>
                    <td bgcolor="#EEEEEE"><center>%d</center></td>
            </tr>
            <tr>
                <td bgcolor="#CCCCCC"><b>Bitrate:</b></td>
                <td bgcolor="#CCCCCC"><center>%s</center></td>
            </tr>
            <tr>
               <td bgcolor="#EEEEEE"><b>Mode:</b></td>
                <td bgcolor="#EEEEEE"><center>%s</center></td>
            </tr>
            <tr>
                <td bgcolor="#CCCCCC"><b>Noise Level:</b></td>
                <td bgcolor="#CCCCCC"><center>%d dBm</center></td>
            </tr>
            <tr>
                <td bgcolor="#EEEEEE"><b>Signal Level:</b></td>
                <td bgcolor="#EEEEEE"><center>%d dBm</center></td>
            </tr>
            <tr>
                <td bgcolor="#CCCCCC"><b>Received:</b></td>
                <td bgcolor="#CCCCCC"><center>%s</center></td>
            </tr>
            <tr>
                <td bgcolor="#EEEEEE"><b>Transferred:</b></td>
                <td bgcolor="#EEEEEE"><center>%s</center></td>
            </tr>
            </table>
            </center>
            ''') % (iconName, interfaceName, interfaceESSID, \
                    linkStatus, bitRate, interfaceMode, \
                    noiseStatus, signalStatus, received, transferred)
        else:
            iconName = 'pywireless'
            toolTip = _(
                '''<center><img align="center" src="/usr/share/PyWireless/%s.png"></center>
            <center>
            <table border="0" bgcolor="#000000" cellspacing="1" cellpadding="1">
            <tr>
                <td colspan="2" bgcolor="#DD0500"><center>[ %s ] <b>is powered off</b></center></td>
            tr>
            </table>
            </center>''') % (iconName, interfaceName)

        QToolTip.add(self, toolTip)
        self.setPixmap(self.icons.loadIcon(iconName, KIcon.Desktop, 22))
class MainApplication(KApplication):
    def __init__(self):
        KApplication.__init__(self)
        # in case something needs done before quitting
        self.connect(self, SIGNAL("aboutToQuit()"), self.quit)
        # place dcop object here
        self.dcop = DosboxHandler()
        self._setup_standard_directories()
        self._generate_data_directories()
        self.mainconfigfilename = os.path.join(self.datadir, "dosbox-pykde.conf")
        if os.path.isfile(self.mainconfigfilename):
            self.generate_default_config()
            self.generate_main_objects()

    def setMainWidget(self, win):
        self.mainwindow = win
        KApplication.setMainWidget(self, win)

    def generate_default_config(self):
        default_dbox_cfilename = os.path.join(self.datadir, "dosbox.conf.default")
        # generate default config files if not already present
        # this would be a good time to use a wizard to setup config options
        generate_default_config(self.mainconfigfilename)
        generate_default_dosbox_config(default_dbox_cfilename)
        self.load_main_config()

    def generate_main_objects(self):
        # setup objects
        self.upgrade_to_db_required = False
        self._dbfile = self.datadir / "main.db"
        if not self._dbfile.exists():
            print "no database file exists."
            # test for xml files
            gdh = GameDataHandlerCompat(self)
            games = gdh.get_game_names()
            if games:
                self.upgrade_to_db_required = True
        self.conn = Connection(self._dbfile)
        # self.game_datahandler = self.make_new_datahandler()
        self.game_datahandler = GameDataBaseCompat(self.conn)
        self.game_datahandler.set_screenshots_path(self.data_directories["screenshots"])
        self.game_fileshandler = self.make_new_fileshandler()
        self.dosbox = self.make_new_dosbox_object()

    def convert_all_xml_to_db(self):
        gdh = GameDataHandlerCompat(self)
        games = gdh.get_game_names()
        for game in games:
            print "converting", game
            gamedata = gdh.get_game_data(game)
            installed = gdh.get_installed_files(game)
            self.game_datahandler.add_new_game(gamedata, installed)

    # we call self._generate_data_directories() in this method
    # because changes to the config may affect these options
    # and the corresponding application attributes
    def load_main_config(self):
        self.myconfig = MyConfig()
        self.myconfig.read([self.mainconfigfilename])
        self._generate_archive_directories()

    def update_main_config(self, configobj):
        cfile = StringIO()
        configobj.write(cfile)
        cfile.seek(0)
        self.myconfig.readfp(cfile)
        self.save_main_config(self.mainconfigfilename)
        self.load_main_config()

    def save_main_config(self, filename=None):
        if filename is None:
            filename = self.mainconfigfilename
        cfile = file(filename, "w")
        self.myconfig.write(cfile)
        cfile.close()

    def make_new_datahandler(self):
        return GameDataHandler(self)

    def make_new_fileshandler(self):
        return GameFilesHandler(self)

    def make_new_dosbox_object(self):
        return Dosbox(self)

    # 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 = path(str(self._std_dirs.findResourceDir("tmp", "/")))
        self.datadir_parent = path(str(self._std_dirs.findResourceDir("data", "/")))
        self.tmpdir = self.tmpdir_parent / "dosbox-pykde"
        self.datadir = self.datadir_parent / "dosbox-pykde"
        # we need this in dosbox object (for now)
        self.main_config_dir = self.datadir
        if not self.datadir.exists():
            self.datadir.mkdir()

    def _generate_data_directories(self):
        directories = {}.fromkeys(["games", "configs", "screenshots", "capture", "profiles", "cache"])
        for dir_key in directories:
            newdir = self.datadir / dir_key
            directories[dir_key] = newdir
            if not newdir.exists():
                try:
                    newdir.mkdir()
                except OSError, inst:
                    # print inst, dir(inst), inst.errno
                    if inst.errno != 17:
                        raise OSError(inst)
        self.data_directories = directories
Пример #12
0
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')