Skip to content

Commit ed86897

Browse files
committed
add ui.widgets module
1 parent 7e3e89a commit ed86897

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/slice/ui/widgets.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.QtWidgets import QLineEdit, QSizePolicy
17+
18+
19+
class DragDropLineEdit(QLineEdit):
20+
def __init__(self, parent, *args):
21+
QLineEdit.__init__(self, *args)
22+
# sets widget to accept drag and drop
23+
self.parent = parent
24+
self.setAcceptDrops(True)
25+
self.setClearButtonEnabled(True)
26+
self.setTextMargins(5, 5, 5, 5)
27+
self.setMinimumWidth(625)
28+
self.setMaximumWidth(2500)
29+
self.setMinimumHeight(35)
30+
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
31+
self.setPlaceholderText("Drop a variable font here or click the Open button")
32+
33+
def dragEnterEvent(self, e):
34+
# mime data types are defined in
35+
# https://www.tutorialspoint.com/pyqt5/pyqt5_drag_and_drop.htm
36+
if e.mimeData().hasText():
37+
e.accept()
38+
else:
39+
e.ignore()
40+
41+
def dropEvent(self, e):
42+
cleaned_text = self.clean_file_path(e.mimeData().text())
43+
# set the text entry area
44+
self.setText(cleaned_text)
45+
# call the parent method to load font on UI
46+
self.parent.load_font(cleaned_text)
47+
48+
def clean_file_path(self, text):
49+
return text.replace("file://", "")

0 commit comments

Comments
 (0)