Skip to content

Commit a32b186

Browse files
committedMar 20, 2023
itemtree: Rename _Item to Item
1 parent e6b0cd7 commit a32b186

File tree

5 files changed

+53
-53
lines changed

5 files changed

+53
-53
lines changed
 

‎export_layers/exporter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class LayerExporter(object):
6969
Setting this to `False` allows e.g. the export procedure to export multiple
7070
layers at once instead of each layer individually.
7171
72-
* `current_item` (read-only) - An `itemtree._Item` instance currently being
72+
* `current_item` (read-only) - An `itemtree.Item` instance currently being
7373
processed.
7474
7575
* `current_raw_item` - Raw item (`gimp.Layer`) currently being processed.
@@ -84,10 +84,10 @@ class LayerExporter(object):
8484
8585
* `process_names` (read-only) - See `export()`.
8686
87-
* `tagged_items` - Dictionary of (tag name, `itemtree._Item`) pairs containing
87+
* `tagged_items` - Dictionary of (tag name, `itemtree.Item`) pairs containing
8888
tagged items.
8989
90-
* `inserted_tagged_items` - Dictionary of (tag name, `itemtree._Item`) pairs
90+
* `inserted_tagged_items` - Dictionary of (tag name, `itemtree.Item`) pairs
9191
containing tagged items currently inserted in `current_image`.
9292
9393
* `invoker` - `pygimplib.invoker.Invoker` instance to

‎export_layers/gui/preview_name.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(
8484

8585
self.is_filtering = False
8686

87-
# key: `_Item.raw.ID` or (`_Item.raw.ID`, 'folder') instance
87+
# key: `Item.raw.ID` or (`Item.raw.ID`, 'folder') instance
8888
# value: `gtk.TreeIter` instance
8989
self._tree_iters = collections.defaultdict(pg.utils.return_none_func)
9090

‎export_layers/pygimplib/itemtree.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ItemTree(future.utils.with_metaclass(abc.ABCMeta, object)):
4242
4343
* `VectorTree` for vectors (paths).
4444
45-
Each item in the tree is an `_Item` instance. Each item contains `gimp.Item`
45+
Each item in the tree is an `Item` instance. Each item contains `gimp.Item`
4646
attributes and additional derived attributes.
4747
4848
Items can be directly accessed via their ID or name. Both ID and name are
@@ -62,7 +62,7 @@ class ItemTree(future.utils.with_metaclass(abc.ABCMeta, object)):
6262
6363
* `name` (read-only) - Optional name of the item tree. The name is currently
6464
used as an identifier of the persistent source for tags in items. See
65-
`_Item.tags` for more information.
65+
`Item.tags` for more information.
6666
6767
* `is_filtered` - If `True`, ignore items that do not match the filter
6868
(`ObjectFilter`) in this object when iterating.
@@ -86,14 +86,14 @@ def __init__(
8686
self.filter = pgobjectfilter.ObjectFilter(self._filter_match_type)
8787

8888
# Contains all items in the item tree (including item groups).
89-
# key: `_Item.raw.ID` or (`_Item.raw.ID`, `FOLDER_KEY`) in case of folders
90-
# value: `_Item` instance
89+
# key: `Item.raw.ID` or (`Item.raw.ID`, `FOLDER_KEY`) in case of folders
90+
# value: `Item` instance
9191
self._itemtree = collections.OrderedDict()
9292

9393
# key:
94-
# `_Item.orig_name` (derived from `_Item.raw.name`)
95-
# or (`_Item.raw.ID`, `FOLDER_KEY`) in case of folders
96-
# value: `_Item` instance
94+
# `Item.orig_name` (derived from `Item.raw.name`)
95+
# or (`Item.raw.ID`, `FOLDER_KEY`) in case of folders
96+
# value: `Item` instance
9797
self._itemtree_names = {}
9898

9999
self._build_tree()
@@ -107,10 +107,10 @@ def name(self):
107107
return self._name
108108

109109
def __getitem__(self, id_or_name):
110-
"""Returns an `_Item` object by its ID or original name.
110+
"""Returns an `Item` object by its ID or original name.
111111
112-
An item's ID is the `_Item.raw.ID` attribute. An item's original name is the
113-
`_Item.orig_name` attribute.
112+
An item's ID is the `Item.raw.ID` attribute. An item's original name is the
113+
`Item.orig_name` attribute.
114114
115115
To access an item group as a folder, pass a tuple `(ID or name, 'folder')`.
116116
For example:
@@ -123,9 +123,9 @@ def __getitem__(self, id_or_name):
123123
return self._itemtree_names[id_or_name]
124124

125125
def __contains__(self, id_or_name):
126-
"""Returns `True` if an `_Item` object is in the item tree, regardless of
127-
filters. Return `False` otherwise. The `_Item` object is specified by its
128-
`_Item.raw.ID` attribute or its `orig_name` attribute.
126+
"""Returns `True` if an `Item` object is in the item tree, regardless of
127+
filters. Return `False` otherwise. The `Item` object is specified by its
128+
`Item.raw.ID` attribute or its `orig_name` attribute.
129129
"""
130130
return id_or_name in self._itemtree or id_or_name in self._itemtree_names
131131

@@ -148,7 +148,7 @@ def __iter__(self):
148148
149149
Yields:
150150
151-
* `item` - The current `_Item` object.
151+
* `item` - The current `Item` object.
152152
"""
153153
return self.iter(with_folders=False, with_empty_groups=False)
154154

@@ -169,7 +169,7 @@ def iter(self, with_folders=True, with_empty_groups=False, filtered=True):
169169
170170
Yields:
171171
172-
* `item` - The current `_Item` object.
172+
* `item` - The current `Item` object.
173173
"""
174174
for item in self._itemtree.values():
175175
should_yield_item = True
@@ -196,7 +196,7 @@ def iter_all(self):
196196
197197
Yields:
198198
199-
* `item` - The current `_Item` object.
199+
* `item` - The current `Item` object.
200200
"""
201201
for item in self._itemtree.values():
202202
yield item
@@ -258,10 +258,10 @@ def _build_tree(self):
258258
child_items = []
259259
for raw_item in self._get_children_from_image(self._image):
260260
if self._is_group(raw_item):
261-
child_items.append(_Item(raw_item, TYPE_FOLDER, [], [], None, None, self._name))
262-
child_items.append(_Item(raw_item, TYPE_GROUP, [], [], None, None, self._name))
261+
child_items.append(Item(raw_item, TYPE_FOLDER, [], [], None, None, self._name))
262+
child_items.append(Item(raw_item, TYPE_GROUP, [], [], None, None, self._name))
263263
else:
264-
child_items.append(_Item(raw_item, TYPE_ITEM, [], [], None, None, self._name))
264+
child_items.append(Item(raw_item, TYPE_ITEM, [], [], None, None, self._name))
265265

266266
item_tree = child_items
267267
item_list = []
@@ -281,14 +281,14 @@ def _build_tree(self):
281281
for raw_item in self._get_children_from_raw_item(item.raw):
282282
if self._is_group(raw_item):
283283
child_items.append(
284-
_Item(raw_item, TYPE_FOLDER, parents_for_child, [], None, None, self._name))
284+
Item(raw_item, TYPE_FOLDER, parents_for_child, [], None, None, self._name))
285285
child_items.append(
286-
_Item(raw_item, TYPE_GROUP, parents_for_child, [], None, None, self._name))
286+
Item(raw_item, TYPE_GROUP, parents_for_child, [], None, None, self._name))
287287
else:
288288
child_items.append(
289-
_Item(raw_item, TYPE_ITEM, parents_for_child, [], None, None, self._name))
289+
Item(raw_item, TYPE_ITEM, parents_for_child, [], None, None, self._name))
290290

291-
# We break the convention here and access a private attribute from `_Item`.
291+
# We break the convention here and access a private attribute from `Item`.
292292
item._orig_children = child_items
293293
item.children = child_items
294294

@@ -299,7 +299,7 @@ def _build_tree(self):
299299
self._itemtree_names[item.orig_name] = item
300300

301301
for i in range(1, len(item_list) - 1):
302-
# We break the convention here and access private attributes from `_Item`.
302+
# We break the convention here and access private attributes from `Item`.
303303
item_list[i]._prev_item = item_list[i - 1]
304304
item_list[i]._next_item = item_list[i + 1]
305305

@@ -351,7 +351,7 @@ def _get_children_from_image(self, image):
351351

352352

353353
@future.utils.python_2_unicode_compatible
354-
class _Item(object):
354+
class Item(object):
355355
"""Wrapper for a `gimp.Item` object containing additional attributes.
356356
357357
Note that the attributes will not be up to date if changes were made to the
@@ -364,29 +364,29 @@ class _Item(object):
364364
* `type` (read-only) - Item type - one of the following:
365365
* `TYPE_ITEM` - regular item
366366
* `TYPE_GROUP` - item group (item whose raw `gimp.Item` is a group with
367-
children; this `_Item` has no children and acts as a regular item)
367+
children; this `Item` has no children and acts as a regular item)
368368
* `TYPE_FOLDER` - item containing children (raw item is a group with
369369
children)
370370
371-
* `parents` - List of `_Item` parents for this item, sorted from the topmost
371+
* `parents` - List of `Item` parents for this item, sorted from the topmost
372372
parent to the bottommost (immediate) parent.
373373
374-
* `children` - List of `_Item` children for this item.
374+
* `children` - List of `Item` children for this item.
375375
376376
* `depth` (read-only) - Integer indicating the depth of the item in the item
377377
tree. 0 means the item is at the top level. The greater the depth, the lower
378378
the item is in the item tree.
379379
380-
* `parent` (read-only) - Immediate `_Item` parent of this object.
380+
* `parent` (read-only) - Immediate `Item` parent of this object.
381381
If this object has no parent, return `None`.
382382
383383
* `name` - Item name as a string, initially equal to `orig_name`. Modify this
384384
attribute instead of `gimp.Item.name` to avoid modifying the original item.
385385
386-
* `prev` - Previous `_Item` in the `ItemTree`, or `None` if there is no
386+
* `prev` - Previous `Item` in the `ItemTree`, or `None` if there is no
387387
previous item.
388388
389-
* `next` - Next `_Item` in the `ItemTree`, or `None` if there is no next item.
389+
* `next` - Next `Item` in the `ItemTree`, or `None` if there is no next item.
390390
391391
* `tags` - Set of arbitrary strings attached to the item. Tags can be used for
392392
a variety of purposes, such as special handling of items with specific tags.
@@ -395,7 +395,7 @@ class _Item(object):
395395
`tags_source_name` attribute.
396396
397397
* `orig_name` (read-only) - Original `gimp.Item.name` as a string. This
398-
attribute may be used to access `_Item`s in `ItemTree`.
398+
attribute may be used to access `Item`s in `ItemTree`.
399399
400400
* `orig_parents` (read-only) - Initial `parents` of this item.
401401

‎export_layers/pygimplib/tests/test_itemtree.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,20 @@ def setUp(self):
258258
self.GROUP = pgitemtree.TYPE_GROUP
259259
self.FOLDER = pgitemtree.TYPE_FOLDER
260260

261-
self.item = pgitemtree._Item(
261+
self.item = pgitemtree.Item(
262262
stubs_gimp.LayerStub('main-background.jpg'), self.ITEM)
263263

264264
def test_str(self):
265-
self.assertEqual(str(self.item), '<_Item "main-background.jpg">')
265+
self.assertEqual(str(self.item), '<Item "main-background.jpg">')
266266

267267
self.item.name = 'main-background'
268268

269-
self.assertEqual(str(self.item), '<_Item "main-background.jpg">')
269+
self.assertEqual(str(self.item), '<Item "main-background.jpg">')
270270

271271
def test_repr(self):
272272
self.assertEqual(
273273
repr(self.item),
274-
'<pygimplib.itemtree._Item "main-background.jpg {}" at {}>'.format(
274+
'<pygimplib.itemtree.Item "main-background.jpg {}" at {}>'.format(
275275
type(self.item.raw),
276276
hex(id(self.item)).rstrip('L'),
277277
),
@@ -356,7 +356,7 @@ def test_initial_tags(self):
356356
layer.parasite_attach(
357357
stubs_gimp.ParasiteStub(item_tags_source_name, 0, pickle.dumps(set(['background']))))
358358

359-
item = pgitemtree._Item(layer, self.ITEM, tags_source_name=item_tags_source_name)
359+
item = pgitemtree.Item(layer, self.ITEM, tags_source_name=item_tags_source_name)
360360
self.assertIn('background', item.tags)
361361

362362
@mock.patch(
@@ -369,7 +369,7 @@ def test_initial_tags_with_invalid_data(self):
369369
layer.parasite_attach(
370370
stubs_gimp.ParasiteStub(item_tags_source_name, 0, 'invalid_data'))
371371

372-
item = pgitemtree._Item(layer, self.ITEM, tags_source_name=item_tags_source_name)
372+
item = pgitemtree.Item(layer, self.ITEM, tags_source_name=item_tags_source_name)
373373
self.assertFalse(item.tags)
374374

375375
@mock.patch(
@@ -383,7 +383,7 @@ def test_initial_tags_for_item_as_folder(self):
383383
layer.parasite_attach(
384384
stubs_gimp.ParasiteStub(folder_tags_source_name, 0, pickle.dumps(set(['background']))))
385385

386-
item = pgitemtree._Item(layer, self.FOLDER, tags_source_name=item_tags_source_name)
386+
item = pgitemtree.Item(layer, self.FOLDER, tags_source_name=item_tags_source_name)
387387
self.assertEqual(item.tags_source_name, folder_tags_source_name)
388388
self.assertIn('background', item.tags)
389389

@@ -398,6 +398,6 @@ def test_initial_tags_for_item_as_folder_unrecognized_source_name(self):
398398
layer.parasite_attach(
399399
stubs_gimp.ParasiteStub(item_tags_source_name, 0, pickle.dumps(set(['background']))))
400400

401-
item = pgitemtree._Item(layer, self.FOLDER, tags_source_name=item_tags_source_name)
401+
item = pgitemtree.Item(layer, self.FOLDER, tags_source_name=item_tags_source_name)
402402
self.assertEqual(item.tags_source_name, folder_tags_source_name)
403403
self.assertNotIn('background', item.tags)

‎export_layers/uniquifier.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,35 @@
1010

1111

1212
class ItemUniquifier(object):
13-
"""Class renaming `pygimplib.ItemTree._Item` instances to be unique under the
13+
"""Class renaming `pygimplib.ItemTree.Item` instances to be unique under the
1414
same parent.
1515
"""
1616

1717
def __init__(self, generator=None):
1818
self.generator = generator
1919

20-
# key: `_Item` instance (parent) or None (item tree root)
21-
# value: set of `_Item` instances
20+
# key: `Item` instance (parent) or None (item tree root)
21+
# value: set of `Item` instances
2222
self._uniquified_items = {}
2323

24-
# key: `_Item` instance (parent) or None (item tree root)
25-
# value: set of `_Item.name` strings
24+
# key: `Item` instance (parent) or None (item tree root)
25+
# value: set of `Item.name` strings
2626
self._uniquified_item_names = {}
2727

2828
def uniquify(self, item, position=None):
29-
"""Renames the `_Item` instance by making it unique among all other `_Item`
30-
instances under the same parent `_Item`.
29+
"""Renames the `Item` instance by making it unique among all other `Item`
30+
instances under the same parent `Item`.
3131
3232
To achieve uniquification, a substring in the form of `' (<number>)'` is
3333
inserted at the end of the item names.
3434
35-
Calling the method with the same `_Item` instance will have no effect as
35+
Calling the method with the same `Item` instance will have no effect as
3636
that instance will be marked as visited. Call `reset()` to clear cache of
3737
items that were passed to this function.
3838
3939
Parameters:
4040
41-
* `item` - `_Item` instance whose `name` attribute will be uniquified.
41+
* `item` - `Item` instance whose `name` attribute will be uniquified.
4242
4343
* `position` - Position (index) where a unique substring is inserted into
4444
the item's name. If `None`, insert the substring at the end of the name

0 commit comments

Comments
 (0)
Please sign in to comment.