def getDbDir(self, settingskey):
     """Get the directory for storing user database files.
     Return None if cancelled.
     """
     dir0 = self.settings.getSetting(settingskey)
     dbpath = getDirectory(_("Database Folder"), dir0)
     if not dbpath: return None
     self.settings.setSetting(settingskey, dbpath)
     return dbpath
示例#2
0
 def getDbDir(self, settingskey):
     """Get the directory for storing user database files.
     Return None if cancelled.
     """
     dir0 = self.settings.getSetting(settingskey)
     dbpath = getDirectory(_("Database Folder"), dir0)
     if not dbpath: return None
     self.settings.setSetting(settingskey, dbpath)
     return dbpath
示例#3
0
 def slot_replacePix(self, arg):
     """Replace the all images by the contents of a supplied folder.
     """
     sdir = getDirectory(_("Image Folder"))
     if not sdir:
         return
     # Perform a save operation, but instead of getting the images
     # from the (old) source file, get them from sdir.
     if isinstance(sdir, unicode):
         sdir = sdir.encode('utf8')
     self.save(imageX=sdir)
    def slot_dump(self, arg):
        """Generate a backup file (sqlite database).
        """
        # Get destination directory:
        dir0 = self.settings.getSetting("destDir")
        dbpath = getDirectory(_("Destination Folder"), dir0)
        if not dbpath: return
        self.settings.setSetting("destDir", dbpath)

        # Do the dump
        backup = Dump(self.master, dbpath)
        if not backup.filepath: return

        guimessage = argSub(_("New backup file '%1' opened, now write in the data"),
                (backup.filepath,))
        guiReport(_("Create Backup File"), backup, guimessage)
示例#5
0
    def slot_dump(self, arg):
        """Generate a backup file (sqlite database).
        """
        # Get destination directory:
        dir0 = self.settings.getSetting("destDir")
        dbpath = getDirectory(_("Destination Folder"), dir0)
        if not dbpath: return
        self.settings.setSetting("destDir", dbpath)

        # Do the dump
        backup = Dump(self.master, dbpath)
        if not backup.filepath: return

        guimessage = argSub(
            _("New backup file '%1' opened, now write in the data"),
            (backup.filepath, ))
        guiReport(_("Create Backup File"), backup, guimessage)
示例#6
0
def recreate(dbm, filepath, user, gui):
    """Recreate the user database, taking master update lock
    into consideration. NOTE that this 'lock' is not 100%
    effective, but it is a simple method which I hope will be
    adequate for the envisaged application.
    """
    dir = os.path.dirname(filepath)
    while True:
        udt = getudtime(dbm)
        if not mUnstable(dbm):
            break
        gui.report(_("Master database is in unstable state.\n  Waiting ..."))
        sleep(10)

    # Dump the master database to the selected file
    while True:
        dump = Dump(dbm, dir, user)
        if dump.filepath:
            break
        warning(_("Couldn't create database file in folder %1,"
                " select new folder"), (dir,))
        dir = getDirectory(dir)
        if not dir:
            if confirmationDialog(_("Abandon?"),
                    _("User database not regenerated,"
                    " do you really want to abandon this operation?"), False):
                break

    if dump.filepath:
        dump.run(gui)

    fp = dump.filepath
    dump = None
    if fp:
        # Check master database hasn't been updated
        if (udt == getudtime(dbm)):
            gui.report(_("\nSUCCESS! - User database regenerated"))
        else:
            gui.report(_("Master has been updated,"
                    " need to repeat...\n"))
            recreate(dbm, filepath, user, gui)
    else:
        gui.report(_("\nFAILED! Couldn't regenerate user database.\n"
                " --- Please contact administrator!"))
示例#7
0
    def restoreConfigFile(self, db):
        """Get a parent directory for the creation of a data file.
        The file to be created may not exist already.
        Returns the file-name if successful, otherwise 'None'.
        """
        # put up directory dialog, starting one up from dir0
        dir = getDirectory(_("Parent Folder"))
        if not dir: return None
        datapath = os.path.join(dir, self.dbname + '.zip')
        if os.path.exists(datapath):
            message(_("'%1' already exists"), (datapath, ))
            return None
        dest = CfgZip(datapath, True)  # open for writing
        if not dest.isOpen():
            message(_("Couldn't open '%s' for writing") % datapath)
            return None

        for path, data in db.getAllData():
            dest.addFile(path, data)
        dest.close()
        message(_("Configuration saved to '%s'") % datapath)
        return datapath
    def restoreConfigFile(self, db):
        """Get a parent directory for the creation of a data file.
        The file to be created may not exist already.
        Returns the file-name if successful, otherwise 'None'.
        """
        # put up directory dialog, starting one up from dir0
        dir = getDirectory(_("Parent Folder"))
        if not dir: return None
        datapath = os.path.join(dir, self.dbname + '.zip')
        if os.path.exists(datapath):
            message(_("'%1' already exists"), (datapath,))
            return None
        dest = CfgZip(datapath, True)   # open for writing
        if not dest.isOpen():
            message(_("Couldn't open '%s' for writing") % datapath)
            return None

        for path, data in db.getAllData():
            dest.addFile(path, data)
        dest.close()
        message(_("Configuration saved to '%s'") % datapath)
        return datapath
示例#9
0
 def init(self, lastDir):
     # Get the directory containing the files
     self.idir = getDirectory(_("Folder: csv-files"), lastDir)
     if isinstance(self.idir, unicode):
         self.idir = self.idir.encode('utf8')
     return self.idir
示例#10
0
    def slot_print(self, arg):
        pupilList = self.db.classObject.orderedPupilList
        # individual, singlepage or multipage?
        pageType = self.gui.pageType()

        #   -- if multi, shrunk?
        shrink = self.gui.isShrink()

        #   -- if multi, landscape?
        landscape = self.gui.isLandscape()

        #   -- if reverse order printing?
        reverse = self.gui.isReverse()

        # Printer or pdf output?
        pdf = self.gui.isPdf()
        if pdf:
            # pdf needs a folder
            oldDir = self.gui.settings.getSetting("pdfDir")
            dir = getDirectory(_("pdf: folder for class folders"),
                    oldDir)
            if not dir: return
            self.gui.settings.setSetting("pdfDir", dir)
            # Check that the class folder exists
            cdir = os.path.join(dir, self.db.classObject.classTag)
            if not os.path.isdir(cdir):
                os.mkdir(cdir)

        loopCnt = len(pupilList)
        if reverse:             # pupil list index
            i = loopCnt - 1
        else:
            i = 0
        while (loopCnt > 0):
            pupilId = pupilList[i][1]
            if self.gui.isPupilChecked(i):
                self.message(_("Printing report for %1"),
                        (pupilList[i][0],))

                layout = LayoutReport(self.db, pupilId)

                if pdf:
                    # Generate a file name based on pupil id and
                    # page type
                    fileName = os.path.join(cdir, u"%s_%s.pdf" %
                            (pupilId, pageType))
                    self.message(u"  --> %s" % fileName)
                else:
                    fileName = None

                pages = self.gui.getPages()

                if (pageType == "multi"):
                    n = 2       # Only 2*A4 on A3 supported at the moment
                else:
                    n = 1

                printer = Printer(n, shrink, landscape, fileName)

                if reverse:
                    pages.reverse()

                first = True    # to control 'newPage'

                for p in pages: # or sheets

                    if p[1]:
                        page = p[0]

                        if not first:
                            printer.newPage()


                        if (pageType == "all"):
                            self.message(_("  --- page %s") % page)
                            pplist = [(page, 0)]
                        else:
                            self.message(_("  --- sheet %s") % page)
                            pplist = self.sheetSides[page]

                        for pageName, pos in pplist:
                            # find corresponding Page object
                            try:
                                ip = self.pages.index(pageName)
                            except:
                                error(_("No page with name '%1'"),
                                         (pageName,))
                            printer.render(layout.pages[ip].gScene, pos)

                        first = False

                printer.end()

            if reverse:
                i -= 1
            else:
                i += 1

            loopCnt -= 1

        self.message(_(" *** DONE ***"))
示例#11
0
 def init(self, lastDir):
     # Get the directory containing the files
     self.idir = getDirectory(_("Folder: csv-files"), lastDir)
     if isinstance(self.idir, unicode):
         self.idir = self.idir.encode('utf8')
     return self.idir