1#!/usr/bin/env python
2
3
4#############################################################################
5##
6## Copyright (C) 2013 Riverbank Computing Limited.
7## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
8## All rights reserved.
9##
10## This file is part of the examples of PyQt.
11##
12## $QT_BEGIN_LICENSE:BSD$
13## You may use this file under the terms of the BSD license as follows:
14##
15## "Redistribution and use in source and binary forms, with or without
16## modification, are permitted provided that the following conditions are
17## met:
18##   * Redistributions of source code must retain the above copyright
19##     notice, this list of conditions and the following disclaimer.
20##   * Redistributions in binary form must reproduce the above copyright
21##     notice, this list of conditions and the following disclaimer in
22##     the documentation and/or other materials provided with the
23##     distribution.
24##   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
25##     the names of its contributors may be used to endorse or promote
26##     products derived from this software without specific prior written
27##     permission.
28##
29## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
40## $QT_END_LICENSE$
41##
42#############################################################################
43
44
45from PyQt5.QtCore import QFileInfo
46from PyQt5.QtWidgets import (QApplication, QCheckBox, QDialog,
47        QDialogButtonBox, QFrame, QGroupBox, QLabel, QLineEdit, QListWidget,
48        QTabWidget, QVBoxLayout, QWidget)
49
50
51class TabDialog(QDialog):
52    def __init__(self, fileName, parent=None):
53        super(TabDialog, self).__init__(parent)
54
55        fileInfo = QFileInfo(fileName)
56
57        tabWidget = QTabWidget()
58        tabWidget.addTab(GeneralTab(fileInfo), "General")
59        tabWidget.addTab(PermissionsTab(fileInfo), "Permissions")
60        tabWidget.addTab(ApplicationsTab(fileInfo), "Applications")
61
62        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
63
64        buttonBox.accepted.connect(self.accept)
65        buttonBox.rejected.connect(self.reject)
66
67        mainLayout = QVBoxLayout()
68        mainLayout.addWidget(tabWidget)
69        mainLayout.addWidget(buttonBox)
70        self.setLayout(mainLayout)
71
72        self.setWindowTitle("Tab Dialog")
73
74
75class GeneralTab(QWidget):
76    def __init__(self, fileInfo, parent=None):
77        super(GeneralTab, self).__init__(parent)
78
79        fileNameLabel = QLabel("File Name:")
80        fileNameEdit = QLineEdit(fileInfo.fileName())
81
82        pathLabel = QLabel("Path:")
83        pathValueLabel = QLabel(fileInfo.absoluteFilePath())
84        pathValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
85
86        sizeLabel = QLabel("Size:")
87        size = fileInfo.size() // 1024
88        sizeValueLabel = QLabel("%d K" % size)
89        sizeValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
90
91        lastReadLabel = QLabel("Last Read:")
92        lastReadValueLabel = QLabel(fileInfo.lastRead().toString())
93        lastReadValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
94
95        lastModLabel = QLabel("Last Modified:")
96        lastModValueLabel = QLabel(fileInfo.lastModified().toString())
97        lastModValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
98
99        mainLayout = QVBoxLayout()
100        mainLayout.addWidget(fileNameLabel)
101        mainLayout.addWidget(fileNameEdit)
102        mainLayout.addWidget(pathLabel)
103        mainLayout.addWidget(pathValueLabel)
104        mainLayout.addWidget(sizeLabel)
105        mainLayout.addWidget(sizeValueLabel)
106        mainLayout.addWidget(lastReadLabel)
107        mainLayout.addWidget(lastReadValueLabel)
108        mainLayout.addWidget(lastModLabel)
109        mainLayout.addWidget(lastModValueLabel)
110        mainLayout.addStretch(1)
111        self.setLayout(mainLayout)
112
113
114class PermissionsTab(QWidget):
115    def __init__(self, fileInfo, parent=None):
116        super(PermissionsTab, self).__init__(parent)
117
118        permissionsGroup = QGroupBox("Permissions")
119
120        readable = QCheckBox("Readable")
121        if fileInfo.isReadable():
122            readable.setChecked(True)
123
124        writable = QCheckBox("Writable")
125        if fileInfo.isWritable():
126            writable.setChecked(True)
127
128        executable = QCheckBox("Executable")
129        if fileInfo.isExecutable():
130            executable.setChecked(True)
131
132        ownerGroup = QGroupBox("Ownership")
133
134        ownerLabel = QLabel("Owner")
135        ownerValueLabel = QLabel(fileInfo.owner())
136        ownerValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
137
138        groupLabel = QLabel("Group")
139        groupValueLabel = QLabel(fileInfo.group())
140        groupValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
141
142        permissionsLayout = QVBoxLayout()
143        permissionsLayout.addWidget(readable)
144        permissionsLayout.addWidget(writable)
145        permissionsLayout.addWidget(executable)
146        permissionsGroup.setLayout(permissionsLayout)
147
148        ownerLayout = QVBoxLayout()
149        ownerLayout.addWidget(ownerLabel)
150        ownerLayout.addWidget(ownerValueLabel)
151        ownerLayout.addWidget(groupLabel)
152        ownerLayout.addWidget(groupValueLabel)
153        ownerGroup.setLayout(ownerLayout)
154
155        mainLayout = QVBoxLayout()
156        mainLayout.addWidget(permissionsGroup)
157        mainLayout.addWidget(ownerGroup)
158        mainLayout.addStretch(1)
159        self.setLayout(mainLayout)
160
161
162class ApplicationsTab(QWidget):
163    def __init__(self, fileInfo, parent=None):
164        super(ApplicationsTab, self).__init__(parent)
165
166        topLabel = QLabel("Open with:")
167
168        applicationsListBox = QListWidget()
169        applications = []
170
171        for i in range(1, 31):
172            applications.append("Application %d" % i)
173
174        applicationsListBox.insertItems(0, applications)
175
176        alwaysCheckBox = QCheckBox()
177
178        if fileInfo.suffix():
179            alwaysCheckBox = QCheckBox("Always use this application to open "
180                    "files with the extension '%s'" % fileInfo.suffix())
181        else:
182            alwaysCheckBox = QCheckBox("Always use this application to open "
183                    "this type of file")
184
185        layout = QVBoxLayout()
186        layout.addWidget(topLabel)
187        layout.addWidget(applicationsListBox)
188        layout.addWidget(alwaysCheckBox)
189        self.setLayout(layout)
190
191
192if __name__ == '__main__':
193
194    import sys
195
196    app = QApplication(sys.argv)
197
198    if len(sys.argv) >= 2:
199        fileName = sys.argv[1]
200    else:
201        fileName = "."
202
203    tabdialog = TabDialog(fileName)
204    tabdialog.show()
205    sys.exit(app.exec_())
206