mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Add commandline options for loglevel and debug shapes
This commit is contained in:
parent
7bb8cd200d
commit
fea8d38d95
7 changed files with 68 additions and 14 deletions
|
|
@ -29,3 +29,7 @@ Run unittests with coverage report::
|
|||
If your browser doesn't open automatically, view ``htmlcov/index.html``.
|
||||
|
||||
Beeref files are sqlite databases, so they can be inspected with any sqlite browser.
|
||||
|
||||
For debugging options, run::
|
||||
|
||||
beeref --help
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import sys
|
|||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from beeref.config import commandline_args
|
||||
from beeref.view import BeeGraphicsView
|
||||
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ class BeeRefMainWindow(QtWidgets.QWidget):
|
|||
self.setLayout(layout)
|
||||
self.resize(500, 300)
|
||||
self.show()
|
||||
self.view = BeeGraphicsView(app, self, filename)
|
||||
self.view = BeeGraphicsView(app, self)
|
||||
layout.addWidget(self.view)
|
||||
|
||||
def __del__(self):
|
||||
|
|
@ -68,11 +69,9 @@ def handle_sigint(signum, frame):
|
|||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.basicConfig(level=getattr(logging, commandline_args.loglevel))
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
|
||||
filename = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
bee = BeeRefMainWindow(app, filename) # NOQA:F841
|
||||
bee = BeeRefMainWindow(app) # NOQA:F841
|
||||
|
||||
signal.signal(signal.SIGINT, handle_sigint)
|
||||
# Repeatedly run python-noop to give the interpreter time to
|
||||
|
|
|
|||
37
beeref/config.py
Normal file
37
beeref/config.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# This file is part of BeeRef.
|
||||
#
|
||||
# BeeRef is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BeeRef is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BeeRef. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='BeeRef referance image viewer')
|
||||
parser.add_argument(
|
||||
'filename',
|
||||
nargs='?',
|
||||
default=None,
|
||||
help='Bee file to open')
|
||||
parser.add_argument(
|
||||
'-l', '--loglevel',
|
||||
default='INFO',
|
||||
choices=list(logging._nameToLevel.keys()),
|
||||
help='log level for console output')
|
||||
parser.add_argument(
|
||||
'--draw-debug-shapes',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='draw debug shapes for bounding rects and interactable areas')
|
||||
|
||||
commandline_args = parser.parse_args()
|
||||
|
|
@ -24,6 +24,7 @@ from PyQt6.QtCore import Qt
|
|||
from PyQt6.QtWidgets import QGraphicsItem
|
||||
|
||||
from beeref import commands
|
||||
from beeref.config import commandline_args
|
||||
|
||||
|
||||
logger = logging.getLogger('BeeRef')
|
||||
|
|
@ -37,7 +38,6 @@ class BeePixmapItem(QtWidgets.QGraphicsPixmapItem):
|
|||
SELECT_HANDLE_SIZE = 15 # size of selection handles for scaling
|
||||
SELECT_RESIZE_SIZE = 20 # size of hover area for scaling
|
||||
SELECT_ROTATE_SIZE = 20 # size of hover area for rotating
|
||||
select_debug = False # Draw debug shapes
|
||||
|
||||
def __init__(self, image, filename=None):
|
||||
super().__init__(QtGui.QPixmap.fromImage(image))
|
||||
|
|
@ -52,6 +52,7 @@ class BeePixmapItem(QtWidgets.QGraphicsPixmapItem):
|
|||
|
||||
self.scale_active_corner = None
|
||||
self.viewport_scale = 1
|
||||
self.conf_debug_shapes = commandline_args.draw_debug_shapes
|
||||
|
||||
def __str__(self):
|
||||
return (f'Image "{self.filename}" '
|
||||
|
|
@ -141,7 +142,7 @@ class BeePixmapItem(QtWidgets.QGraphicsPixmapItem):
|
|||
def paint(self, painter, option, widget):
|
||||
painter.drawPixmap(0, 0, self.pixmap())
|
||||
|
||||
if self.select_debug:
|
||||
if self.conf_debug_shapes:
|
||||
self.draw_debug_shape(painter, self.boundingRect(), 0, 255, 0)
|
||||
self.draw_debug_shape(painter, self.shape(), 255, 0, 0)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
|
|||
from PyQt6.QtCore import Qt
|
||||
|
||||
from beeref import commands
|
||||
from beeref.config import commandline_args
|
||||
from beeref import fileio
|
||||
from beeref.gui import BeeProgressDialog, WelcomeOverlay
|
||||
from beeref.items import BeePixmapItem
|
||||
|
|
@ -29,7 +30,7 @@ logger = logging.getLogger('BeeRef')
|
|||
|
||||
class BeeGraphicsView(QtWidgets.QGraphicsView):
|
||||
|
||||
def __init__(self, app, parent=None, filename=None):
|
||||
def __init__(self, app, parent=None):
|
||||
super().__init__(parent)
|
||||
self.app = app
|
||||
self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(60, 60, 60)))
|
||||
|
|
@ -70,8 +71,8 @@ class BeeGraphicsView(QtWidgets.QGraphicsView):
|
|||
self.welcome_overlay = WelcomeOverlay(self)
|
||||
|
||||
# Load file given via command line
|
||||
if filename:
|
||||
self.open_from_file(filename)
|
||||
if commandline_args.filename:
|
||||
self.open_from_file(commandline_args.filename)
|
||||
|
||||
def on_scene_changed(self, region):
|
||||
if not self.scene.items():
|
||||
|
|
|
|||
|
|
@ -145,7 +145,8 @@ class BeePixmapItemPaintstuffTestCase(BeePixmapItemWithViewBaseTestCase):
|
|||
self.item.SELECT_ROTATE_SIZE = 100
|
||||
assert self.item.select_rotate_size == 25
|
||||
|
||||
def test_paint_when_not_selected(self):
|
||||
@patch('beeref.items.BeePixmapItem.draw_debug_shape')
|
||||
def test_paint_when_not_selected(self, debug_mock):
|
||||
painter = MagicMock()
|
||||
self.item.setSelected(False)
|
||||
self.item.pixmap = MagicMock(return_value='pixmap')
|
||||
|
|
@ -153,6 +154,7 @@ class BeePixmapItemPaintstuffTestCase(BeePixmapItemWithViewBaseTestCase):
|
|||
painter.drawPixmap.assert_called_once_with(0, 0, 'pixmap')
|
||||
painter.drawRect.assert_not_called()
|
||||
painter.drawPoint.assert_not_called()
|
||||
debug_mock.assert_not_called()
|
||||
|
||||
def test_paint_when_selected_single_selection(self):
|
||||
painter = MagicMock()
|
||||
|
|
@ -160,7 +162,7 @@ class BeePixmapItemPaintstuffTestCase(BeePixmapItemWithViewBaseTestCase):
|
|||
self.item.paint(painter, None, None)
|
||||
painter.drawPixmap.assert_called_once()
|
||||
painter.drawRect.assert_called_once()
|
||||
painter.drawPoint.assert_called()
|
||||
assert painter.drawPoint.call_count == 4
|
||||
|
||||
def test_paint_when_selected_multi_selection(self):
|
||||
item2 = BeePixmapItem(QtGui.QImage())
|
||||
|
|
@ -173,6 +175,14 @@ class BeePixmapItemPaintstuffTestCase(BeePixmapItemWithViewBaseTestCase):
|
|||
painter.drawRect.assert_called_once()
|
||||
painter.drawPoint.assert_not_called()
|
||||
|
||||
def test_paint_when_draw_debug_shapes(self):
|
||||
with patch('beeref.items.commandline_args') as args_mock:
|
||||
with patch('beeref.items.BeePixmapItem.draw_debug_shape') as m:
|
||||
args_mock.draw_debug_shapes = True
|
||||
item = BeePixmapItem(QtGui.QImage())
|
||||
item.paint(MagicMock(), None, None)
|
||||
m.assert_called()
|
||||
|
||||
def test_corners(self):
|
||||
assert set(self.item.corners) == set((
|
||||
(0, 0),
|
||||
|
|
|
|||
|
|
@ -13,5 +13,7 @@ class BeeGraphicsViewTestCase(BeeTestCase):
|
|||
|
||||
@patch('beeref.view.BeeGraphicsView.open_from_file')
|
||||
def test_init_with_filename(self, open_file_mock):
|
||||
BeeGraphicsView(self.app, filename='bee.png')
|
||||
open_file_mock.assert_called_once_with('bee.png')
|
||||
with patch('beeref.view.commandline_args') as args_mock:
|
||||
args_mock.filename = 'test.bee'
|
||||
BeeGraphicsView(self.app)
|
||||
open_file_mock.assert_called_once_with('test.bee')
|
||||
|
|
|
|||
Loading…
Reference in a new issue