Coverage for pyPhotoAlbum/mixins/operations/distribution_ops.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-20 12:55 +0000

1""" 

2Distribution operations mixin for pyPhotoAlbum 

3""" 

4 

5from pyPhotoAlbum.decorators import ribbon_action 

6from pyPhotoAlbum.alignment import AlignmentManager 

7from pyPhotoAlbum.commands import AlignElementsCommand 

8 

9 

10class DistributionOperationsMixin: 

11 """Mixin providing element distribution and spacing operations""" 

12 

13 def _get_selected_elements_list(self): 

14 """Get list of selected elements for distribution operations""" 

15 return list(self.gl_widget.selected_elements) if self.gl_widget.selected_elements else [] 

16 

17 def _execute_distribution(self, distribution_func, status_msg: str): 

18 """ 

19 Execute a distribution operation with common boilerplate. 

20 

21 Args: 

22 distribution_func: AlignmentManager method to call with elements 

23 status_msg: Status message format string (will receive element count) 

24 """ 

25 elements = self._get_selected_elements_list() 

26 if not self.require_selection(min_count=3): # type: ignore[attr-defined] 

27 return 

28 

29 changes = distribution_func(elements) 

30 if changes: 

31 cmd = AlignElementsCommand(changes) 

32 self.project.history.execute(cmd) # type: ignore[attr-defined] 

33 self.update_view() # type: ignore[attr-defined] 

34 self.show_status(status_msg.format(len(elements)), 2000) # type: ignore[attr-defined] 

35 

36 @ribbon_action( 

37 label="Distribute H", 

38 tooltip="Distribute selected elements evenly horizontally", 

39 tab="Arrange", 

40 group="Distribute", 

41 requires_selection=True, 

42 min_selection=3, 

43 ) 

44 def distribute_horizontally(self): 

45 """Distribute selected elements evenly horizontally""" 

46 self._execute_distribution(AlignmentManager.distribute_horizontally, "Distributed {} elements horizontally") 

47 

48 @ribbon_action( 

49 label="Distribute V", 

50 tooltip="Distribute selected elements evenly vertically", 

51 tab="Arrange", 

52 group="Distribute", 

53 requires_selection=True, 

54 min_selection=3, 

55 ) 

56 def distribute_vertically(self): 

57 """Distribute selected elements evenly vertically""" 

58 self._execute_distribution(AlignmentManager.distribute_vertically, "Distributed {} elements vertically") 

59 

60 @ribbon_action( 

61 label="Space H", 

62 tooltip="Space selected elements equally horizontally", 

63 tab="Arrange", 

64 group="Distribute", 

65 requires_selection=True, 

66 min_selection=3, 

67 ) 

68 def space_horizontally(self): 

69 """Space selected elements equally horizontally""" 

70 self._execute_distribution(AlignmentManager.space_horizontally, "Spaced {} elements horizontally") 

71 

72 @ribbon_action( 

73 label="Space V", 

74 tooltip="Space selected elements equally vertically", 

75 tab="Arrange", 

76 group="Distribute", 

77 requires_selection=True, 

78 min_selection=3, 

79 ) 

80 def space_vertically(self): 

81 """Space selected elements equally vertically""" 

82 self._execute_distribution(AlignmentManager.space_vertically, "Spaced {} elements vertically")