agateau / gwenview-importer

Proof of concept of a picture importer for Gwenview

This URL has Read+Write access

gwenview-importer / importdialog.py
100644 74 lines (54 sloc) 1.869 kb
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
import os
import time
 
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.kdecore import *
from PyKDE4.kdeui import *
 
from ui_importdialog import Ui_ImportDialog
 
 
class ImportDialog(KDialog):
    def __init__(self, dstUrl):
        KDialog.__init__(self)
 
        self.dstBaseUrl = KUrl(dstUrl)
        year = str(time.gmtime().tm_year)
        self.dstBaseUrl.addPath(year)
 
        # Destination
        widget = QWidget(self)
        self.ui = Ui_ImportDialog()
        self.ui.setupUi(widget)
        widget.layout().setMargin(0)
        self.setMainWidget(widget)
        self.showButtonSeparator(True)
        self.setButtonText(KDialog.Ok, i18n("Import"))
 
        self.initComboBox()
        self.ui.eventComboBox.clearEditText()
 
        QObject.connect(self.ui.eventComboBox, SIGNAL("editTextChanged(QString)"), \
            self.updateDstLabel)
 
        self.ui.eventComboBox.setFocus()
        font = self.ui.dstLabel.font()
        font.setItalic(True)
        self.ui.dstLabel.setFont(font)
        self.updateDstLabel()
 
 
    def initComboBox(self):
        dir = unicode(self.dstBaseUrl.path())
        if not os.path.exists(dir):
            return
        lst = QStringList()
        for file in os.listdir(dir):
            if os.path.isdir(os.path.join(dir, file)):
                lst.append(QString(file))
        lst.sort()
        self.ui.eventComboBox.addItems(lst)
 
 
    def sizeHint(self):
        sh = KDialog.sizeHint(self)
        sh.setWidth(400)
        return sh
 
 
    def updateDstLabel(self):
        url = self.dstUrl()
        text = i18n("Pictures will be imported in:\n%1", url.pathOrUrl())
        self.ui.dstLabel.setText(text)
        self.adjustSize()
 
 
    def dstUrl(self):
        url = KUrl(self.dstBaseUrl)
        url.addPath(self.ui.eventComboBox.currentText())
        return url
 
 
# vi: ts=4 sw=4 et