File: import_dlg.py

package info (click to toggle)
mnemosyne 1.2.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,804 kB
  • ctags: 497
  • sloc: python: 9,546; makefile: 41
file content (95 lines) | stat: -rw-r--r-- 3,142 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
##############################################################################
#
# Widget to import items <Peter.Bienstman@UGent.be>
#
##############################################################################

from qt import *

from mnemosyne.core import *
from import_frm import *
from message_boxes import *



##############################################################################
#
# ImportDlg
#
##############################################################################

class ImportDlg(ImportFrm):

    ##########################################################################
    #
    # __init__
    #
    ##########################################################################

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        
        ImportFrm.__init__(self,parent,name,modal,fl)

        for fformat in get_importable_file_formats():
            self.fileformats.insertItem(fformat.name)

        self.fileformats.setCurrentText(get_config("import_format"))

        self.categories.insertItem(self.trUtf8("<default>"))

        names = [cat.name for cat in get_categories()]
        names.sort()
        for name in names:
            if name != self.trUtf8("<default>"):
                self.categories.insertItem(name)

        self.reset_box.setChecked(get_config("reset_learning_data_import"))
        
        self.connect(self.browse_button, SIGNAL("clicked()"), self.browse)
        self.connect(self.ok_button,     SIGNAL("clicked()"), self.apply)

    ##########################################################################
    #
    # browse
    #
    ##########################################################################

    def browse(self):

        fformat = get_file_format_from_name(
                      unicode(self.fileformats.currentText()))

        out = unicode(QFileDialog.getOpenFileName(
              expand_path(get_config("import_dir")),
              self.trUtf8("All Files (*);;").append(QString(fformat.filter)),
              self, None, self.trUtf8("Import"), fformat.filter))
       
        if out != "":
            self.filename.setText(out)
            
    ##########################################################################
    #
    # apply
    #
    #   Don't rebuild the revision queue here, as the scheduled item have
    #   already been added to it during import.
    #
    ##########################################################################

    def apply(self):

        fname = unicode(self.filename.text())
        fformat_name = unicode(self.fileformats.currentText())
        cat_name = unicode(self.categories.currentText())
        reset_learning_data = self.reset_box.isChecked()

        try:
            import_file(fname, fformat_name, cat_name, reset_learning_data)
        except MnemosyneError, e:
            messagebox_errors(self, e) # Needs to be caught at this level.

        set_config("import_dir", contract_path(os.path.dirname(fname)))
        set_config("import_format", fformat_name)
        set_config("reset_learning_data_import", reset_learning_data)
        
        self.close()