Reformat with Black
No functional changes.
This commit is contained in:
@@ -30,31 +30,39 @@ class MenuItem:
|
||||
text_size_small = 10
|
||||
|
||||
DEFAULT_ICONS = {
|
||||
'FOLDER': os.path.join(library_icons_path, 'folder.png'),
|
||||
'SPINNER': os.path.join(library_icons_path, 'spinner.png'),
|
||||
'ERROR': os.path.join(library_icons_path, 'error.png'),
|
||||
"FOLDER": os.path.join(library_icons_path, "folder.png"),
|
||||
"SPINNER": os.path.join(library_icons_path, "spinner.png"),
|
||||
"ERROR": os.path.join(library_icons_path, "error.png"),
|
||||
}
|
||||
|
||||
FOLDER_NODE_TYPES = {'group_texture', 'group_hdri',
|
||||
nodes.UpNode.NODE_TYPE, nodes.ProjectNode.NODE_TYPE}
|
||||
SUPPORTED_NODE_TYPES = {'texture', 'hdri'}.union(FOLDER_NODE_TYPES)
|
||||
FOLDER_NODE_TYPES = {
|
||||
"group_texture",
|
||||
"group_hdri",
|
||||
nodes.UpNode.NODE_TYPE,
|
||||
nodes.ProjectNode.NODE_TYPE,
|
||||
}
|
||||
SUPPORTED_NODE_TYPES = {"texture", "hdri"}.union(FOLDER_NODE_TYPES)
|
||||
|
||||
def __init__(self, node, file_desc, thumb_path: str, label_text):
|
||||
self.log = logging.getLogger('%s.MenuItem' % __name__)
|
||||
if node['node_type'] not in self.SUPPORTED_NODE_TYPES:
|
||||
self.log.info('Invalid node type in node: %s', node)
|
||||
raise TypeError('Node of type %r not supported; supported are %r.' % (
|
||||
node['node_type'], self.SUPPORTED_NODE_TYPES))
|
||||
self.log = logging.getLogger("%s.MenuItem" % __name__)
|
||||
if node["node_type"] not in self.SUPPORTED_NODE_TYPES:
|
||||
self.log.info("Invalid node type in node: %s", node)
|
||||
raise TypeError(
|
||||
"Node of type %r not supported; supported are %r."
|
||||
% (node["node_type"], self.SUPPORTED_NODE_TYPES)
|
||||
)
|
||||
|
||||
assert isinstance(node, pillarsdk.Node), 'wrong type for node: %r' % type(node)
|
||||
assert isinstance(node['_id'], str), 'wrong type for node["_id"]: %r' % type(node['_id'])
|
||||
assert isinstance(node, pillarsdk.Node), "wrong type for node: %r" % type(node)
|
||||
assert isinstance(node["_id"], str), 'wrong type for node["_id"]: %r' % type(
|
||||
node["_id"]
|
||||
)
|
||||
self.node = node # pillarsdk.Node, contains 'node_type' key to indicate type
|
||||
self.file_desc = file_desc # pillarsdk.File object, or None if a 'folder' node.
|
||||
self.label_text = label_text
|
||||
self.small_text = self._small_text_from_node()
|
||||
self._thumb_path = ''
|
||||
self._thumb_path = ""
|
||||
self.icon = None
|
||||
self._is_folder = node['node_type'] in self.FOLDER_NODE_TYPES
|
||||
self._is_folder = node["node_type"] in self.FOLDER_NODE_TYPES
|
||||
self._is_spinning = False
|
||||
|
||||
# Determine sorting order.
|
||||
@@ -75,21 +83,21 @@ class MenuItem:
|
||||
"""Return the components of the texture (i.e. which map types are available)."""
|
||||
|
||||
if not self.node:
|
||||
return ''
|
||||
return ""
|
||||
|
||||
try:
|
||||
node_files = self.node.properties.files
|
||||
except AttributeError:
|
||||
# Happens for nodes that don't have .properties.files.
|
||||
return ''
|
||||
return ""
|
||||
if not node_files:
|
||||
return ''
|
||||
return ""
|
||||
|
||||
map_types = {f.map_type for f in node_files if f.map_type}
|
||||
map_types.discard('color') # all textures have colour
|
||||
map_types.discard("color") # all textures have colour
|
||||
if not map_types:
|
||||
return ''
|
||||
return ', '.join(sorted(map_types))
|
||||
return ""
|
||||
return ", ".join(sorted(map_types))
|
||||
|
||||
def sort_key(self):
|
||||
"""Key for sorting lists of MenuItems."""
|
||||
@@ -101,7 +109,7 @@ class MenuItem:
|
||||
|
||||
@thumb_path.setter
|
||||
def thumb_path(self, new_thumb_path: str):
|
||||
self._is_spinning = new_thumb_path == 'SPINNER'
|
||||
self._is_spinning = new_thumb_path == "SPINNER"
|
||||
|
||||
self._thumb_path = self.DEFAULT_ICONS.get(new_thumb_path, new_thumb_path)
|
||||
if self._thumb_path:
|
||||
@@ -111,20 +119,22 @@ class MenuItem:
|
||||
|
||||
@property
|
||||
def node_uuid(self) -> str:
|
||||
return self.node['_id']
|
||||
return self.node["_id"]
|
||||
|
||||
def represents(self, node) -> bool:
|
||||
"""Returns True iff this MenuItem represents the given node."""
|
||||
|
||||
node_uuid = node['_id']
|
||||
node_uuid = node["_id"]
|
||||
return self.node_uuid == node_uuid
|
||||
|
||||
def update(self, node, file_desc, thumb_path: str, label_text=None):
|
||||
# We can get updated information about our Node, but a MenuItem should
|
||||
# always represent one node, and it shouldn't be shared between nodes.
|
||||
if self.node_uuid != node['_id']:
|
||||
raise ValueError("Don't change the node ID this MenuItem reflects, "
|
||||
"just create a new one.")
|
||||
if self.node_uuid != node["_id"]:
|
||||
raise ValueError(
|
||||
"Don't change the node ID this MenuItem reflects, "
|
||||
"just create a new one."
|
||||
)
|
||||
self.node = node
|
||||
self.file_desc = file_desc # pillarsdk.File object, or None if a 'folder' node.
|
||||
self.thumb_path = thumb_path
|
||||
@@ -132,8 +142,8 @@ class MenuItem:
|
||||
if label_text is not None:
|
||||
self.label_text = label_text
|
||||
|
||||
if thumb_path == 'ERROR':
|
||||
self.small_text = 'This open is broken'
|
||||
if thumb_path == "ERROR":
|
||||
self.small_text = "This open is broken"
|
||||
else:
|
||||
self.small_text = self._small_text_from_node()
|
||||
|
||||
@@ -165,7 +175,7 @@ class MenuItem:
|
||||
texture = self.icon
|
||||
if texture:
|
||||
err = draw.load_texture(texture)
|
||||
assert not err, 'OpenGL error: %i' % err
|
||||
assert not err, "OpenGL error: %i" % err
|
||||
|
||||
# ------ TEXTURE ---------#
|
||||
if texture:
|
||||
@@ -185,8 +195,15 @@ class MenuItem:
|
||||
text_x = self.x + self.icon_margin_x + ICON_WIDTH + self.text_margin_x
|
||||
text_y = self.y + ICON_HEIGHT * 0.5 - 0.25 * self.text_size
|
||||
draw.text((text_x, text_y), self.label_text, fsize=self.text_size)
|
||||
draw.text((text_x, self.y + 0.5 * self.text_size_small), self.small_text,
|
||||
fsize=self.text_size_small, rgba=(1.0, 1.0, 1.0, 0.5))
|
||||
draw.text(
|
||||
(text_x, self.y + 0.5 * self.text_size_small),
|
||||
self.small_text,
|
||||
fsize=self.text_size_small,
|
||||
rgba=(1.0, 1.0, 1.0, 0.5),
|
||||
)
|
||||
|
||||
def hits(self, mouse_x: int, mouse_y: int) -> bool:
|
||||
return self.x < mouse_x < self.x + self.width and self.y < mouse_y < self.y + self.height
|
||||
return (
|
||||
self.x < mouse_x < self.x + self.width
|
||||
and self.y < mouse_y < self.y + self.height
|
||||
)
|
||||
|
Reference in New Issue
Block a user