forked from krathjen/studiolibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfolderitem.py
More file actions
89 lines (65 loc) · 2.56 KB
/
folderitem.py
File metadata and controls
89 lines (65 loc) · 2.56 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This library is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, either
# version 3 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
import os
import studiolibrary
import studioqt
from studioqt import QtWidgets
class FolderItem(studiolibrary.LibraryItem):
RegisterOrder = 100
EnableNestedItems = True
DisplayInSidebar = True
MenuName = "Folder"
MenuOrder = 1
MenuIconPath = studiolibrary.resource().get("icons/folder.png")
ThumbnailPath = studiolibrary.resource().get("icons/folder_item.png")
@classmethod
def match(cls, path):
"""
Return True if the given path is supported by the item.
:type path: str
:rtype: bool
"""
if os.path.isdir(path):
return True
@classmethod
def showCreateWidget(cls, libraryWidget):
"""
Show the dialog for creating a new folder.
:rtype: None
"""
path = libraryWidget.selectedFolderPath() or libraryWidget.path()
name, button = studioqt.MessageBox.input(
libraryWidget,
"Create folder",
"Create a new folder with the name:",
)
name = name.strip()
if name and button == QtWidgets.QDialogButtonBox.Ok:
path = os.path.join(path, name)
item = cls(path, libraryWidget=libraryWidget)
item.save()
def createItemData(self):
"""Overriding this method to force the item type to Folder"""
itemData = super(FolderItem, self).createItemData()
itemData['type'] = "Folder"
return itemData
def doubleClicked(self):
"""Overriding this method to show the items contained in the folder."""
self.libraryWidget().selectFolderPath(self.path())
def save(self, *args, **kwargs):
"""
Create a new folder on disc at the given path.
:rtype: str
"""
super(FolderItem, self).save(*args, **kwargs)
if self.libraryWidget():
self.libraryWidget().selectFolderPath(self.path())
studiolibrary.registerItem(FolderItem)