mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Open images from command line
This commit is contained in:
parent
95b024ee42
commit
6e3bc35f74
5 changed files with 34 additions and 11 deletions
|
|
@ -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
|
||||
-----
|
||||
|
|
|
|||
|
|
@ -29,10 +29,14 @@ logger = logging.getLogger(__name__)
|
|||
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')
|
||||
|
|
|
|||
|
|
@ -82,9 +82,14 @@ class BeeGraphicsView(MainControlsMixin,
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Reference in a new issue