Exemple #1
0
 def accept(self):
     self.exporter.includeSched = (
         self.frm.includeSched.isChecked())
     self.exporter.includeMedia = (
         self.frm.includeMedia.isChecked())
     self.exporter.includeTags = (
         self.frm.includeTags.isChecked())
     if not self.frm.deck.currentIndex():
         self.exporter.did = None
     else:
         name = self.decks[self.frm.deck.currentIndex()]
         self.exporter.did = self.col.decks.id(name)
     if (self.isApkg and self.exporter.includeSched and not
         self.exporter.did):
         verbatim = True
         # it's a verbatim apkg export, so place on desktop instead of
         # choosing file
         file = os.path.join(QDesktopServices.storageLocation(
             QDesktopServices.DesktopLocation), "collection.apkg")
         if os.path.exists(file):
             if not askUser(
                 _("%s already exists on your desktop. Overwrite it?")%
                 "collection.apkg"):
                 return
     else:
         verbatim = False
         # Get deck name and remove invalid filename characters
         deck_name = self.decks[self.frm.deck.currentIndex()]
         deck_name = re.sub('[\\\\/?<>:*|"^]', '_', deck_name)
         filename = os.path.join(aqt.mw.pm.base,
                                 u'{0}{1}'.format(deck_name, self.exporter.ext))
         while 1:
             file = getSaveFile(self, _("Export"), "export",
                                self.exporter.key, self.exporter.ext,
                                fname=filename)
             if not file:
                 return
             if checkInvalidFilename(os.path.basename(file), dirsep=False):
                 continue
             break
     self.hide()
     if file:
         self.mw.progress.start(immediate=True)
         try:
             f = open(file, "wb")
             f.close()
         except (OSError, IOError), e:
             showWarning(_("Couldn't save file: %s") % unicode(e))
         else:
             os.unlink(file)
             self.exporter.exportInto(file)
             if verbatim:
                 msg = _("A file called collection.apkg was saved on your desktop.")
                 period = 5000
             else:
                 period = 3000
                 msg = ngettext("%d card exported.", "%d cards exported.", \
                             self.exporter.count) % self.exporter.count
             tooltip(msg, period=period)
         finally:
def onExportList(browser):
    # big reach!
    if not browser.form.tableView.selectionModel().hasSelection():
        showWarning("Please select 1 or more rows", browser, help="")
        return
    path = getSaveFile(browser, _("Export Browser List"), "exportcsv", _("Cards as CSV"), '.csv', 'exportcsv.csv')
    if not path:
        return
    file = open(path, "wb")
    writer = csv.writer(file, dialect='excel')

    for rowIndex in browser.form.tableView.selectionModel().selectedRows():
        #wasn't sure if I could modify the "Index" objects we get back from
        #  the selection model. Since the columnData function only accesses
        #  the row() and column() functions, seemed safer to create new
        #  instances.
        row = rowIndex.row()
        rowdata = []
        for column in range(browser.model.columnCount(0)):
            index = RowAndColumn(row, column)
            #let the browser model's columnData function do all the hard work
            answer = escapeText(browser.model.columnData(index))
            rowdata.append(answer.encode('utf8'))
        writer.writerow(rowdata)
    file.close()
Exemple #3
0
 def accept(self):
     file = getSaveFile(
         self, _("Export"), "export",
         self.exporter.key, self.exporter.ext)
     self.hide()
     if file:
         self.exporter.includeSched = (
             self.frm.includeSched.isChecked())
         self.exporter.includeMedia = (
             self.frm.includeMedia.isChecked())
         self.exporter.includeTags = (
             self.frm.includeTags.isChecked())
         if not self.frm.deck.currentIndex():
             self.exporter.did = None
         else:
             name = self.decks[self.frm.deck.currentIndex()]
             self.exporter.did = self.col.decks.id(name)
         self.mw.progress.start(immediate=True)
         try:
             f = open(file, "wb")
             f.close()
         except (OSError, IOError), e:
             showWarning(_("Couldn't save file: %s") % unicode(e))
         else:
             os.unlink(file)
             self.exporter.exportInto(file)
             tooltip(_("%d exported.") % self.exporter.count)
         finally:
Exemple #4
0
 def _imagePath(self):
     name = time.strftime("-%Y-%m-%[email protected]%H-%M-%S.pdf",
                          time.localtime(time.time()))
     name = "anki-"+_("stats")+name
     file = getSaveFile(self, title=_("Save PDF"),
                        dir_description="stats",
                        key="stats",
                        ext=".pdf",
                        fname=name)
     return file
Exemple #5
0
 def accept(self):
     self.exporter.includeSched = (
         self.frm.includeSched.isChecked())
     self.exporter.includeMedia = (
         self.frm.includeMedia.isChecked())
     self.exporter.includeTags = (
         self.frm.includeTags.isChecked())
     if not self.frm.deck.currentIndex():
         self.exporter.did = None
     else:
         name = self.decks[self.frm.deck.currentIndex()]
         self.exporter.did = self.col.decks.id(name)
     if (self.isApkg and self.exporter.includeSched and not
         self.exporter.did):
         verbatim = True
         # it's a verbatim apkg export, so place on desktop instead of
         # choosing file
         file = os.path.join(QDesktopServices.storageLocation(
             QDesktopServices.DesktopLocation), "collection.apkg")
         if os.path.exists(file):
             if not askUser(
                 _("%s already exists on your desktop. Overwrite it?")%
                 "collection.apkg"):
                 return
     else:
         verbatim = False
         file = getSaveFile(
             self, _("Export"), "export",
             self.exporter.key, self.exporter.ext)
         if not file:
             return
     self.hide()
     if file:
         self.mw.progress.start(immediate=True)
         try:
             f = open(file, "wb")
             f.close()
         except (OSError, IOError), e:
             showWarning(_("Couldn't save file: %s") % unicode(e))
         else:
             os.unlink(file)
             self.exporter.exportInto(file)
             if verbatim:
                 msg = _("A file called collection.apkg was saved on your desktop.")
                 period = 5000
             else:
                 period = 3000
                 msg = ngettext("%d card exported.", "%d cards exported.", \
                             self.exporter.count) % self.exporter.count
             tooltip(msg, period=period)
         finally:
Exemple #6
0
 def accept(self):
     file = getSaveFile(
         self, _("Choose file to export to"), "export",
         self.exporter.key, self.exporter.ext)
     self.hide()
     if file:
         self.exporter.includeSched = (
             self.frm.includeSched.isChecked())
         self.exporter.includeTags = (
             self.frm.includeTags.isChecked())
         if not self.frm.deck.currentIndex():
             self.exporter.did = None
         else:
             name = self.decks[self.frm.deck.currentIndex()]
             self.exporter.did = self.col.decks.id(name)
         self.mw.progress.start(immediate=True)
         self.exporter.exportInto(file)
         self.mw.progress.finish()
         tooltip(_("%d exported.") % self.exporter.count)
     QDialog.accept(self)
Exemple #7
0
    def accept(self):
        self.exporter.includeSched = (
            self.frm.includeSched.isChecked())
        self.exporter.includeMedia = (
            self.frm.includeMedia.isChecked())
        self.exporter.includeTags = (
            self.frm.includeTags.isChecked())
        self.exporter.includeHTML = (
            self.frm.includeHTML.isChecked())
        if not self.frm.deck.currentIndex():
            self.exporter.did = None
        else:
            name = self.decks[self.frm.deck.currentIndex()]
            self.exporter.did = self.col.decks.id(name)
        if self.isVerbatim:
            name = time.strftime("-%Y-%m-%[email protected]%H-%M-%S",
                                 time.localtime(time.time()))
            deck_name = _("collection")+name
        else:
            # Get deck name and remove invalid filename characters
            deck_name = self.decks[self.frm.deck.currentIndex()]
            deck_name = re.sub('[\\\\/?<>:*|"^]', '_', deck_name)

        if not self.isVerbatim and self.isApkg and self.exporter.includeSched and self.col.schedVer() == 2:
            showInfo("Please switch to the regular scheduler before exporting a single deck .apkg with scheduling.")
            return

        filename = '{0}{1}'.format(deck_name, self.exporter.ext)
        while 1:
            file = getSaveFile(self, _("Export"), "export",
                               self.exporter.key, self.exporter.ext,
                               fname=filename)
            if not file:
                return
            if checkInvalidFilename(os.path.basename(file), dirsep=False):
                continue
            break
        self.hide()
        if file:
            self.mw.progress.start(immediate=True)
            try:
                f = open(file, "wb")
                f.close()
            except (OSError, IOError) as e:
                showWarning(_("Couldn't save file: %s") % str(e))
            else:
                os.unlink(file)
                exportedMedia = lambda cnt: self.mw.progress.update(
                        label=ngettext("Exported %d media file",
                                       "Exported %d media files", cnt) % cnt
                        )
                addHook("exportedMediaFiles", exportedMedia)
                self.exporter.exportInto(file)
                remHook("exportedMediaFiles", exportedMedia)
                period = 3000
                if self.isVerbatim:
                    msg = _("Collection exported.")
                else:
                    if self.isTextNote:
                        msg = ngettext("%d note exported.", "%d notes exported.",
                                    self.exporter.count) % self.exporter.count
                    else:
                        msg = ngettext("%d card exported.", "%d cards exported.",
                                    self.exporter.count) % self.exporter.count
                tooltip(msg, period=period)
            finally:
                self.mw.progress.finish()
        QDialog.accept(self)
Exemple #8
0
 def accept(self):
     self.exporter.includeSched = (
         self.frm.includeSched.isChecked())
     self.exporter.includeMedia = (
         self.frm.includeMedia.isChecked())
     self.exporter.includeTags = (
         self.frm.includeTags.isChecked())
     if not self.frm.deck.currentIndex():
         self.exporter.did = None
     else:
         name = self.decks[self.frm.deck.currentIndex()]
         self.exporter.did = self.col.decks.id(name)
     if (self.isApkg and self.exporter.includeSched and not
         self.exporter.did):
         verbatim = True
         # it's a verbatim apkg export, so place on desktop instead of
         # choosing file; use homedir if no desktop
         usingHomedir = False
         file = os.path.join(QStandardPaths.writableLocation(
             QStandardPaths.DesktopLocation), "collection.apkg")
         if not os.path.exists(os.path.dirname(file)):
             usingHomedir = True
             file = os.path.join(QStandardPaths.writableLocation(
                 QStandardPaths.HomeLocation), "collection.apkg")
         if os.path.exists(file):
             if usingHomedir:
                 question = _("%s already exists in your home directory. Overwrite it?")
             else:
                 question = _("%s already exists on your desktop. Overwrite it?")
             if not askUser(question % "collection.apkg"):
                 return
     else:
         verbatim = False
         # Get deck name and remove invalid filename characters
         deck_name = self.decks[self.frm.deck.currentIndex()]
         deck_name = re.sub('[\\\\/?<>:*|"^]', '_', deck_name)
         filename = '{0}{1}'.format(deck_name, self.exporter.ext)
         while 1:
             file = getSaveFile(self, _("Export"), "export",
                                self.exporter.key, self.exporter.ext,
                                fname=filename)
             if not file:
                 return
             if checkInvalidFilename(os.path.basename(file), dirsep=False):
                 continue
             break
     self.hide()
     if file:
         self.mw.progress.start(immediate=True)
         try:
             f = open(file, "wb")
             f.close()
         except (OSError, IOError) as e:
             showWarning(_("Couldn't save file: %s") % str(e))
         else:
             os.unlink(file)
             exportedMedia = lambda cnt: self.mw.progress.update(
                     label=ngettext("Exported %d media file",
                                    "Exported %d media files", cnt) % cnt
                     )
             addHook("exportedMediaFiles", exportedMedia)
             self.exporter.exportInto(file)
             remHook("exportedMediaFiles", exportedMedia)
             if verbatim:
                 if usingHomedir:
                     msg = _("A file called %s was saved in your home directory.")
                 else:
                     msg = _("A file called %s was saved on your desktop.")
                 msg = msg % "collection.apkg"
                 period = 5000
             else:
                 period = 3000
                 if self.isTextNote:
                     msg = ngettext("%d note exported.", "%d notes exported.",
                                 self.exporter.count) % self.exporter.count
                 else:
                     msg = ngettext("%d card exported.", "%d cards exported.",
                                 self.exporter.count) % self.exporter.count
             tooltip(msg, period=period)
         finally:
             self.mw.progress.finish()
     QDialog.accept(self)