Skip to content

Commit 7e3e89a

Browse files
committed
add ui.dialogs module
1 parent 79e3e9d commit 7e3e89a

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

src/slice/ui/__init__.py

Whitespace-only changes.

src/slice/ui/dialogs.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# This file is part of Slice.
2+
#
3+
# Slice is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation, either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# Slice is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with Slice. If not, see <https://www.gnu.org/licenses/>.
15+
16+
from PyQt5.QtCore import QDir, Qt
17+
from PyQt5.QtGui import QImage, QPixmap
18+
from PyQt5.QtWidgets import (
19+
QDialog,
20+
QDialogButtonBox,
21+
QFileDialog,
22+
QLabel,
23+
QMessageBox,
24+
QTextBrowser,
25+
QVBoxLayout,
26+
)
27+
28+
from ..imageresources import *
29+
30+
31+
class SliceOpenFileDialog(QFileDialog):
32+
def __init__(self):
33+
QFileDialog.__init__(self)
34+
self.file_path = None
35+
self.root_directory = QDir.homePath()
36+
37+
self.setWindowTitle("Open File")
38+
# options |= QFileDialog.DontUseNativeDialog
39+
40+
file_path, _ = self.getOpenFileName(
41+
self,
42+
"Open File",
43+
self.root_directory,
44+
"All Files (*);;ttf Files(*.ttf);;otf Files (*.otf)",
45+
options=self.Options(),
46+
)
47+
48+
if file_path:
49+
self.file_path = file_path
50+
51+
def get_file_path(self):
52+
return self.file_path
53+
54+
55+
class SliceSaveFileDialog(QFileDialog):
56+
def __init__(self, root_directory=None):
57+
QFileDialog.__init__(self)
58+
self.file_path = None
59+
self.root_directory = None
60+
61+
self.setWindowTitle("Save File")
62+
63+
if root_directory:
64+
self.root_directory = root_directory
65+
else:
66+
self.root_directory = QDir.homePath()
67+
68+
file_path, _ = self.getSaveFileName(
69+
self,
70+
"Save File",
71+
self.root_directory,
72+
"All Files (*);;ttf Files(*.ttf);;otf Files (*.otf)",
73+
options=self.Options(),
74+
)
75+
76+
if file_path:
77+
self.file_path = file_path
78+
79+
def get_file_path(self):
80+
return self.file_path
81+
82+
83+
class SliceAboutDialog(QDialog):
84+
def __init__(self, version):
85+
QDialog.__init__(self)
86+
87+
QBtn = QDialogButtonBox.Ok
88+
self.buttonBox = QDialogButtonBox(QBtn)
89+
self.buttonBox.accepted.connect(self.accept)
90+
self.buttonBox.rejected.connect(self.reject)
91+
92+
layout = QVBoxLayout()
93+
94+
title = QLabel("Slice")
95+
font = title.font()
96+
font.setPointSize(30)
97+
title.setFont(font)
98+
99+
layout.addWidget(title)
100+
101+
logoLabel = QLabel()
102+
qimage = QImage(":/img/slice-icon.svg")
103+
pixmap = QPixmap.fromImage(qimage)
104+
logoLabel.setPixmap(pixmap)
105+
logoLabel.setFixedHeight(60)
106+
logoLabel.setFixedWidth(75)
107+
108+
layout.addWidget(logoLabel)
109+
110+
layout.addWidget(QLabel(f"Version {version}"))
111+
layout.addWidget(QLabel("Copyright 2021 Christopher Simpkins"))
112+
licenseLink = QLabel(
113+
"<p><a href='https://github.com/source-foundry/Slice/blob/main/LICENSE'>GPLv3 License</a></p>"
114+
)
115+
licenseLink.setOpenExternalLinks(True)
116+
layout.addWidget(licenseLink)
117+
sourceLink = QLabel(
118+
"<p><a href='https://github.com/source-foundry/Slice'>Source</a></p>"
119+
)
120+
sourceLink.setOpenExternalLinks(True)
121+
layout.addWidget(sourceLink)
122+
layout.addWidget(QLabel("❤️ Built with these fine tools ❤️"))
123+
124+
attributionTextField = QTextBrowser()
125+
attributionTextField.setOpenExternalLinks(True)
126+
127+
attributionTextField.setHtml(
128+
"<ul>"
129+
"<li><p><a href='https://www.riverbankcomputing.com/software/pyqt/'>PyQt5</a> GUI framework</p></li>"
130+
"<li><p><a href='https://github.com/fonttools/fonttools'>fontTools</a> Python library</p></li>"
131+
"<li><p><a href='https://fonts.google.com/specimen/Monoton'>Monoton typeface</a> by Vernon Adams</p></li>"
132+
"</ul>"
133+
)
134+
attributionTextField.setMaximumHeight(100)
135+
layout.addWidget(attributionTextField)
136+
137+
for i in range(0, layout.count()):
138+
layout.itemAt(i).setAlignment(Qt.AlignHCenter)
139+
140+
layout.addWidget(self.buttonBox)
141+
142+
self.setLayout(layout)
143+
self.exec_()
144+
145+
146+
class SliceErrorDialog(QMessageBox):
147+
def __init__(self, inform_text, detailed_text=None):
148+
QMessageBox.__init__(self)
149+
self.setIcon(QMessageBox.Critical)
150+
self.setText("Error")
151+
self.setWindowTitle("Error")
152+
self.setInformativeText(f"{inform_text}")
153+
if detailed_text:
154+
self.setDetailedText(f"{detailed_text}")
155+
self.setStandardButtons(QMessageBox.Ok)
156+
self.exec_()

0 commit comments

Comments
 (0)