mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Make arrange method for importing images configurable
This commit is contained in:
parent
2b9240693e
commit
95b024ee42
6 changed files with 53 additions and 4 deletions
|
|
@ -14,6 +14,9 @@ Added
|
|||
The confirmation dialog can be disalbed in:
|
||||
Settings -> Miscellaneous -> Confirm when closing an unsaved file
|
||||
* Add option to arrange by filename (Arrange -> Square (by filename))
|
||||
* Added a setting to choose the default arrange method on importing
|
||||
images in batch.
|
||||
(Settings -> Settings -> Images & Items -> Default Arrange Method).
|
||||
|
||||
Fixed
|
||||
-----
|
||||
|
|
|
|||
|
|
@ -122,6 +122,11 @@ class BeeSettings(QtCore.QSettings):
|
|||
'cast': int,
|
||||
'validate': lambda x: 0 <= x <= 200,
|
||||
},
|
||||
'Items/arrange_default': {
|
||||
'default': 'optimal',
|
||||
'validate': lambda x: x in (
|
||||
'optimal', 'horizontal', 'vertical', 'square'),
|
||||
},
|
||||
'Items/image_allocation_limit': {
|
||||
'default': 256,
|
||||
'cast': int,
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with BeeRef. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from queue import Queue
|
||||
from functools import partial
|
||||
import logging
|
||||
import math
|
||||
from queue import Queue
|
||||
|
||||
from PyQt6 import QtCore, QtWidgets, QtGui
|
||||
from PyQt6.QtCore import Qt
|
||||
|
|
@ -178,6 +179,17 @@ class BeeGraphicsScene(QtWidgets.QGraphicsScene):
|
|||
self.undo_stack.push(
|
||||
commands.NormalizeItems(items, scale_factors))
|
||||
|
||||
def arrange_default(self):
|
||||
default = self.settings.valueOrDefault('Items/arrange_default')
|
||||
MAPPING = {
|
||||
'optimal': self.arrange_optimal,
|
||||
'horizontal': self.arrange,
|
||||
'vertical': partial(self.arrange, vertical=True),
|
||||
'square': self.arrange_square,
|
||||
}
|
||||
|
||||
MAPPING[default]()
|
||||
|
||||
def arrange(self, vertical=False):
|
||||
"""Arrange items in a line (horizontally or vertically)."""
|
||||
|
||||
|
|
|
|||
|
|
@ -612,7 +612,7 @@ class BeeGraphicsView(MainControlsMixin,
|
|||
'Problem loading images',
|
||||
msg + IMG_LOADING_ERROR_MSG + errornames)
|
||||
self.scene.add_queued_items()
|
||||
self.scene.arrange_optimal()
|
||||
self.scene.arrange_default()
|
||||
self.undo_stack.endMacro()
|
||||
if new_scene:
|
||||
self.on_action_fit_scene()
|
||||
|
|
|
|||
|
|
@ -133,6 +133,19 @@ class SingleCheckboxGroup(GroupBase):
|
|||
return value == Qt.CheckState.Checked
|
||||
|
||||
|
||||
class ArrangeDefaultWidget(RadioGroup):
|
||||
TITLE = 'Default Arrange Method:'
|
||||
HELPTEXT = ('How images are arranged when inserted in batch')
|
||||
KEY = 'Items/arrange_default'
|
||||
OPTIONS = (
|
||||
('optimal', 'Optimal', 'Arrange Optimal'),
|
||||
('horizontal', 'Horizontal (by filename)',
|
||||
'Arrange Horizontal (by filename)'),
|
||||
('vertical', 'Vertical (by filename)',
|
||||
'Arrange Vertical (by filename)'),
|
||||
('square', 'Square (by filename)', 'Arrannge Square (by filename)'))
|
||||
|
||||
|
||||
class ImageStorageFormatWidget(RadioGroup):
|
||||
TITLE = 'Image Storage Format:'
|
||||
HELPTEXT = ('How images are stored inside bee files.'
|
||||
|
|
@ -191,8 +204,9 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||
items_layout = QtWidgets.QGridLayout()
|
||||
items.setLayout(items_layout)
|
||||
items_layout.addWidget(ImageStorageFormatWidget(), 0, 0)
|
||||
items_layout.addWidget(ArrangeGapWidget(), 0, 1)
|
||||
items_layout.addWidget(AllocationLimitWidget(), 1, 0)
|
||||
items_layout.addWidget(AllocationLimitWidget(), 0, 1)
|
||||
items_layout.addWidget(ArrangeGapWidget(), 1, 0)
|
||||
items_layout.addWidget(ArrangeDefaultWidget(), 1, 1)
|
||||
tabs.addTab(items, '&Images && Items')
|
||||
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import math
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
import pytest
|
||||
from pytest import approx
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
|
@ -249,6 +250,20 @@ def test_normalize_size_when_no_items(view):
|
|||
view.scene.cancel_crop_mode.assert_called_once_with()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('value,expected_func,expected_kwargs',
|
||||
[('optimal', 'arrange_optimal', {}),
|
||||
('horizontal', 'arrange', {}),
|
||||
('vertical', 'arrange', {'vertical': True}),
|
||||
('square', 'arrange_square', {})])
|
||||
def test_arrange_default(
|
||||
value, expected_func, expected_kwargs, settings, view):
|
||||
settings.setValue('Items/arrange_default', value)
|
||||
setattr(view.scene, expected_func, MagicMock())
|
||||
view.scene.arrange_default()
|
||||
getattr(view.scene, expected_func).assert_called_once_with(
|
||||
**expected_kwargs)
|
||||
|
||||
|
||||
def test_arrange_horizontal(view):
|
||||
item1 = BeePixmapItem(QtGui.QImage())
|
||||
item1.filename = 'foo.png'
|
||||
|
|
|
|||
Loading…
Reference in a new issue