Skip to content

Commit

Permalink
Open images from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
rbreu committed May 26, 2024
1 parent 95b024e commit 6e3bc35
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Added
* Added a setting to choose the default arrange method on importing
images in batch.
(Settings -> Settings -> Images & Items -> Default Arrange Method).
* Added the ability to open image files from command line. If the
first command line arg is a bee file, it will be opened and all
further files will be ignored, as previously. If the first argument
isn't a bee file, all files will be treated as images and inserted
as if opened with "Insert -> Images".

Fixed
-----
Expand Down
10 changes: 7 additions & 3 deletions beeref/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
parser = argparse.ArgumentParser(
description=f'{constants.APPNAME_FULL} {constants.VERSION}')
parser.add_argument(
'filename',
nargs='?',
'filenames',
nargs='*',
default=None,
help='Bee file to open')
help=('Bee file or images to open. '
'If the first file is a bee file, it will be opened and all '
'further files will be ignored. If the first argument isn\'t a '
'bee file, all files will be treated as images and inserted as '
'if opened with "Insert -> Images".'))
parser.add_argument(
'--settings-dir',
help='settings directory to use instead of default location')
Expand Down
11 changes: 8 additions & 3 deletions beeref/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ def __init__(self, app, parent=None):
self.control_target = self
self.init_main_controls(main_window=parent)

# Load file given via command line
if commandline_args.filename:
self.open_from_file(commandline_args.filename)
# Load files given via command line
if commandline_args.filenames:
fn = commandline_args.filenames[0]
if os.path.splitext(fn)[1] == '.bee':
self.open_from_file(fn)
else:
self.do_insert_images(commandline_args.filenames)

self.update_window_title()

@property
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def reset_beeref_actions():
def commandline_args():
config_patcher = patch('beeref.view.commandline_args')
config_mock = config_patcher.start()
config_mock.filename = None
config_mock.filenames = []
yield config_mock
config_patcher.stop()

Expand Down
17 changes: 13 additions & 4 deletions tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_inits_menu(qapp):


@patch('beeref.view.BeeGraphicsView.open_from_file')
def test_init_without_filename(open_file_mock, qapp, commandline_args):
commandline_args.filename = None
def test_init_without_filenames(open_file_mock, qapp, commandline_args):
commandline_args.filenames = None
parent = QtWidgets.QMainWindow()
view = BeeGraphicsView(qapp, parent)
open_file_mock.assert_not_called()
Expand All @@ -34,14 +34,23 @@ def test_init_without_filename(open_file_mock, qapp, commandline_args):


@patch('beeref.view.BeeGraphicsView.open_from_file')
def test_init_with_filename(open_file_mock, qapp, commandline_args):
commandline_args.filename = 'test.bee'
def test_init_with_filenames_beefile(open_file_mock, qapp, commandline_args):
commandline_args.filenames = ['test.bee']
parent = QtWidgets.QMainWindow()
view = BeeGraphicsView(qapp, parent)
open_file_mock.assert_called_once_with('test.bee')
del view


@patch('beeref.view.BeeGraphicsView.do_insert_images')
def test_init_with_filenames_images(insert_img_mock, qapp, commandline_args):
commandline_args.filenames = ['/foo/bar.png', '/foo/baz.jpg']
parent = QtWidgets.QMainWindow()
view = BeeGraphicsView(qapp, parent)
insert_img_mock.assert_called_once_with(['/foo/bar.png', '/foo/baz.jpg'])
del view


@patch('beeref.widgets.welcome_overlay.WelcomeOverlay.hide')
def test_on_scene_changed_when_items(hide_mock, view):
item = BeePixmapItem(QtGui.QImage())
Expand Down

0 comments on commit 6e3bc35

Please sign in to comment.