Skip to content

Commit bc2673c

Browse files
committed
Change strategy for default plot widget size
1 parent 6c7ea6d commit bc2673c

17 files changed

Lines changed: 42 additions & 17 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
💥 New features / Enhancements:
66

77
* Added support for color theme change at execution (relies on guidata V3.6)
8+
* Changed strategy for default plot widget size:
9+
* No default size is applied to the plot widget anymore (before, the default size was 800x600 pixels)
10+
* Added parameter `size` to `PlotDialog`, `PlotWindow` classes, and `make.dialog`, `make.window` functions to set the initial size of the plot widget
811

912
🛠️ Bug fixes:
1013

plotpy/builder/plot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def dialog(
143143
wintitle: str = "PlotPy",
144144
icon: str = "plotpy.svg",
145145
edit: bool = False,
146+
size: tuple[int, int] | None = None,
146147
title: str | None = None,
147148
xlabel: str | tuple[str, str] | None = None,
148149
ylabel: str | tuple[str, str] | None = None,
@@ -178,6 +179,7 @@ def dialog(
178179
wintitle: The window title
179180
icon: The window icon
180181
edit: If True, the plot is editable
182+
size: The window size
181183
title: The plot title
182184
xlabel: (bottom axis title, top axis title) or bottom axis title only
183185
ylabel: (left axis title, right axis title) or left axis title only
@@ -236,6 +238,7 @@ def dialog(
236238
title=wintitle,
237239
icon=icon,
238240
edit=edit,
241+
size=size,
239242
)
240243

241244
def window(
@@ -246,6 +249,7 @@ def window(
246249
auto_tools: bool = True,
247250
wintitle: str = "PlotPy",
248251
icon: str = "plotpy.svg",
252+
size: tuple[int, int] | None = None,
249253
title: str | None = None,
250254
xlabel: str | tuple[str, str] | None = None,
251255
ylabel: str | tuple[str, str] | None = None,
@@ -280,6 +284,7 @@ def window(
280284
If False, the user must register the tools manually.
281285
wintitle: The window title
282286
icon: The window icon
287+
size: The window size
283288
title: The plot title
284289
xlabel: (bottom axis title, top axis title) or bottom axis title only
285290
ylabel: (left axis title, right axis title) or left axis title only
@@ -337,6 +342,7 @@ def window(
337342
auto_tools=auto_tools,
338343
title=wintitle,
339344
icon=icon,
345+
size=size,
340346
)
341347

342348
def gridparam(

plotpy/plot/plotwidget.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,14 @@ def configure_manager(
366366

367367

368368
def set_widget_title_icon(
369-
widget: QWidget, title: str, icon: QG.QIcon, resize: tuple[int, int] | None = None
369+
widget: QWidget, title: str, icon: QG.QIcon, size: tuple[int, int] | None = None
370370
) -> None:
371371
"""Setups the widget title and icon
372372
373373
Args:
374374
title: The window title
375375
icon: The window icon
376-
resize: The window size (width, height). Defaults to None (no resize)
376+
size: The window size (width, height). Defaults to None (no resize)
377377
"""
378378
win32_fix_title_bar_background(widget)
379379
widget.setWindowTitle(title)
@@ -382,8 +382,8 @@ def set_widget_title_icon(
382382
if icon is not None:
383383
widget.setWindowIcon(icon)
384384
widget.setMinimumSize(320, 240)
385-
if resize is not None:
386-
widget.resize(*resize)
385+
if size is not None:
386+
widget.resize(*size)
387387

388388

389389
def add_widget_to_grid_layout(
@@ -535,6 +535,7 @@ class PlotDialog(QW.QDialog, AbstractPlotDialogWindow, metaclass=PlotDialogMeta)
535535
title: The window title
536536
icon: The window icon
537537
edit: If True, the plot is editable
538+
size: The window size (width, height). Defaults to None (no resize)
538539
"""
539540

540541
def __init__(
@@ -547,9 +548,10 @@ def __init__(
547548
title: str = "PlotPy",
548549
icon: str = "plotpy.svg",
549550
edit: bool = False,
551+
size: tuple[int, int] | None = None,
550552
) -> None:
551553
super().__init__(parent)
552-
set_widget_title_icon(self, title, icon, resize=(640, 480))
554+
set_widget_title_icon(self, title, icon, size)
553555
self.edit = edit
554556
self.button_box = None
555557
self.button_layout = None
@@ -692,6 +694,7 @@ class PlotWindow(QW.QMainWindow, AbstractPlotDialogWindow, metaclass=PlotWindowM
692694
If False, the user must register the tools manually.
693695
title: The window title
694696
icon: The window icon
697+
size: The window size (width, height). Defaults to None (no resize)
695698
"""
696699

697700
def __init__(
@@ -703,9 +706,10 @@ def __init__(
703706
auto_tools: bool = True,
704707
title: str = "PlotPy",
705708
icon: str = "plotpy.svg",
709+
size: tuple[int, int] | None = None,
706710
) -> None:
707711
super().__init__(parent)
708-
set_widget_title_icon(self, title, icon, resize=(640, 480))
712+
set_widget_title_icon(self, title, icon, size)
709713
self.plot_layout = QW.QGridLayout()
710714
self.plot_widget: PlotWidget = None
711715
self.manager: PlotManager = None
@@ -897,6 +901,7 @@ class SyncPlotWindow(QW.QMainWindow):
897901
If False, the user must register the tools manually.
898902
title: The window title
899903
icon: The window icon
904+
size: The window size (width, height). Defaults to None (no resize)
900905
901906
Usage: first, create a window, then add plots to it, then call the
902907
:py:meth:`.SyncPlotWindow.finalize_configuration` method to add panels and
@@ -920,9 +925,10 @@ def __init__(
920925
auto_tools: bool = True,
921926
title: str = "PlotPy",
922927
icon: str = "plotpy.svg",
928+
size: tuple[int, int] | None = None,
923929
) -> None:
924930
super().__init__(parent)
925-
set_widget_title_icon(self, title, icon)
931+
set_widget_title_icon(self, title, icon, size)
926932
self.manager = PlotManager(None)
927933
self.manager.set_main(self)
928934
self.subplotwidget = SubplotWidget(self.manager, parent=self, options=options)

plotpy/tests/benchmarks/test_bigimages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616

1717
def imshow():
18-
win = make.dialog(toolbar=True, title="Displaying 10 big images test")
18+
win = make.dialog(
19+
toolbar=True, title="Displaying 10 big images test", size=(800, 600)
20+
)
1921
plot = win.manager.get_plot()
2022
for i in range(10):
2123
plot.add_item(make.image(compute_image(i)))

plotpy/tests/features/test_contrast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def __create_dialog_with_contrast(item):
3030
wintitle="Contrast test",
3131
show_contrast=True,
3232
type="image",
33+
size=(600, 600),
3334
)
3435
plot = win.get_plot()
3536
plot.add_item(item)
3637
plot.set_active_item(item)
3738
item.unselect()
38-
win.resize(600, 600)
3939
win.show()
4040
return win
4141

plotpy/tests/features/test_dicom_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_dicom_image():
3030
wintitle="DICOM I/O test",
3131
show_contrast=True,
3232
type="image",
33+
size=(600, 700),
3334
)
3435
filename = get_path("mr-brain.dcm")
3536
image = make.image(filename=filename, title="DICOM img", colormap="gray")
@@ -38,7 +39,6 @@ def test_dicom_image():
3839
plot.select_item(image)
3940
contrast = win.manager.get_contrast_panel()
4041
contrast.histogram.eliminate_outliers(54.0)
41-
win.resize(600, 700)
4242

4343

4444
if __name__ == "__main__":

plotpy/tests/features/test_imagefilter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def imshow(x, y, data, filter_area, yreverse=True):
2727
ylabel="y (cm)",
2828
yreverse=yreverse,
2929
type="image",
30+
size=(800, 600),
3031
)
3132
image = make.xyimage(x, y, data)
3233
plot = win.manager.get_plot()

plotpy/tests/features/test_imagesuperp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def create_window():
2424
wintitle="Image superposition test",
2525
gridparam=gridparam,
2626
type="image",
27+
size=(800, 600),
2728
)
2829
for toolklass in (RectangleTool, EllipseTool, FreeFormTool, PlaceAxesTool):
2930
win.manager.add_tool(toolklass)

plotpy/tests/tools/test_cross_section.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def create_window():
2222
show_xsection=True,
2323
show_ysection=True,
2424
type="image",
25+
size=(640, 600),
2526
)
26-
win.resize(640, 600)
2727
return win
2828

2929

plotpy/tests/tools/test_customize_shape_tool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def create_window():
4343
wintitle="All image and plot tools test",
4444
gridparam=gridparam,
4545
type="image",
46+
size=(800, 600),
4647
)
4748
for toolklass in (
4849
RectangleTool,

0 commit comments

Comments
 (0)