~ubuntu-branches/ubuntu/trusty/guiqwt/trusty

« back to all changes in this revision

Viewing changes to guiqwt/plot.py

  • Committer: Bazaar Package Importer
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2011-04-07 22:41:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110407224150-kkhppnq7rp2c8b3c
Tags: 2.1.0-1
* Imported Upstream version 2.1.0
* debian/patches/
  - 0001-features-01_bts614083.patch (delete)
  - 0001-feature-fix-the-documentation-build.patch (new)
* add and install the sift desktop file
* recommends python-dicom (Closes: #621421)
  thanks Junqian Gordon Xu for the report

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
 
107
107
from PyQt4.QtGui import (QDialogButtonBox, QVBoxLayout, QGridLayout, QToolBar,
108
108
                         QDialog, QHBoxLayout, QMenu, QActionGroup, QSplitter,
109
 
                         QSizePolicy, QApplication)
 
109
                         QSizePolicy, QApplication, QWidget, QMainWindow)
110
110
from PyQt4.QtCore import Qt, SIGNAL, SLOT
111
111
 
112
112
from guidata.configtools import get_icon
115
115
 
116
116
# Local imports
117
117
from guiqwt.config import _
118
 
from guiqwt.baseplot import EnhancedQwtPlot
 
118
from guiqwt.baseplot import BasePlot
119
119
from guiqwt.curve import CurvePlot, PlotItemList
120
120
from guiqwt.image import ImagePlot
121
 
from guiqwt.tools import (SelectTool, RectZoomTool, ColormapTool,
122
 
                          ReverseYAxisTool, BasePlotMenuTool, HelpTool,
123
 
                          ItemListTool, AntiAliasingTool, PrintTool,
 
121
from guiqwt.tools import (SelectTool, RectZoomTool, ColormapTool, HelpTool,
 
122
                          ReverseYAxisTool, BasePlotMenuTool, DeleteItemTool,
 
123
                          ItemListPanelTool, AntiAliasingTool, PrintTool,
124
124
                          DisplayCoordsTool, AxisScaleTool, SaveAsTool,
125
 
                          AspectRatioTool, ContrastTool, DummySeparatorTool,
126
 
                          XCrossSectionTool, YCrossSectionTool, SnapshotTool,
127
 
                          CrossSectionTool, AverageCrossSectionTool)
 
125
                          AspectRatioTool, ContrastPanelTool, XCSPanelTool,
 
126
                          YCSPanelTool, SnapshotTool, DummySeparatorTool,
 
127
                          CrossSectionTool, AverageCrossSectionTool,
 
128
                          ImageStatsTool)
128
129
from guiqwt.interfaces import IPlotManager
129
130
from guiqwt.signals import (SIG_ITEMS_CHANGED, SIG_ACTIVE_ITEM_CHANGED,
130
 
                            SIG_VISIBILITY_CHANGED)
 
131
                            SIG_VISIBILITY_CHANGED, SIG_PLOT_AXIS_CHANGED)
131
132
 
132
133
 
133
134
class DefaultPlotID(object):
144
145
 
145
146
    def __init__(self, main):
146
147
        self.main = main # The main parent widget
147
 
        self.plots = {} # maps ids to instances of EnhancedQwtPlot
 
148
        self.plots = {} # maps ids to instances of BasePlot
148
149
        self.panels = {} # Qt widgets that need to know about the plots
149
150
        self.tools = []
150
151
        self.toolbars = {}
152
153
        self.default_tool = None
153
154
        self.default_plot = None
154
155
        self.default_toolbar = None
 
156
        self.synchronized_plots = {}
155
157
        self.groups = {} # Action groups for grouping QActions
 
158
        # Keep track of the registration sequence (plots, panels, tools):
 
159
        self._first_tool_flag = True
156
160
 
157
161
    def add_plot(self, plot, plot_id=DefaultPlotID):
158
162
        """
171
175
        if plot_id is DefaultPlotID:
172
176
            plot_id = id(plot)
173
177
        assert plot_id not in self.plots
174
 
        assert isinstance(plot, EnhancedQwtPlot)
 
178
        assert isinstance(plot, BasePlot)
175
179
        assert not self.tools, "tools must be added after plots"
176
180
        assert not self.panels, "panels must be added after plots"
177
181
        self.plots[plot_id] = plot
178
182
        if len(self.plots) == 1:
179
183
            self.default_plot = plot
180
 
        plot.set_manager(self)
 
184
        plot.set_manager(self, id)
181
185
        # Connecting signals
182
186
        plot.connect(plot, SIG_ITEMS_CHANGED, self.update_tools_status)
183
187
        plot.connect(plot, SIG_ACTIVE_ITEM_CHANGED, self.update_tools_status)
 
188
        plot.connect(plot, SIG_PLOT_AXIS_CHANGED, self.plot_axis_changed)
184
189
        
185
190
    def set_default_plot(self, plot):
186
191
        """
211
216
        assert not self.tools, "tools must be added after panels"
212
217
        self.panels[panel.PANEL_ID] = panel
213
218
        panel.register_panel(self)
 
219
        
 
220
    def configure_panels(self):
 
221
        """
 
222
        Call all the registred panels 'configure_panel' methods to finalize the 
 
223
        object construction (this allows to use tools registered to the same 
 
224
        plot manager as the panel itself with breaking the registration 
 
225
        sequence: "add plots, then panels, then tools")
 
226
        """
 
227
        for panel_id in self.panels:
 
228
            panel = self.get_panel(panel_id)
 
229
            panel.configure_panel()
214
230
 
215
231
    def add_toolbar(self, toolbar, toolbar_id="default"):
216
232
        """
248
264
            2. add panels
249
265
            3. add tools
250
266
        """
 
267
        if self._first_tool_flag:
 
268
            # This is the very first tool to be added to this manager
 
269
            self._first_tool_flag = False
 
270
            self.configure_panels()
251
271
        tool = ToolKlass(self, *args, **kwargs)
252
272
        self.tools.append(tool)
253
273
        for plot in self.plots.values():
346
366
        """
347
367
        return self.main
348
368
 
 
369
    def set_main(self, main):
 
370
        self.main = main
 
371
 
349
372
    def get_panel(self, panel_id):
350
373
        """
351
374
        Return panel from its ID
427
450
        """
428
451
        return self.toolbars.get(toolbar_id, None)
429
452
 
430
 
    def get_context_menu(self, plot):
 
453
    def get_context_menu(self, plot=None):
431
454
        """
432
455
        Return widget context menu -- built using active tools
433
456
        """
 
457
        if plot is None:
 
458
            plot = self.get_plot()
434
459
        menu = QMenu(plot)
435
460
        self.update_tools_status(plot)
436
461
        for tool in self.tools:
437
462
            tool.setup_context_menu(menu, plot)
438
463
        return menu
439
464
        
440
 
    def update_tools_status(self, plot):
 
465
    def update_tools_status(self, plot=None):
441
466
        """
442
467
        Update tools for current plot
443
468
        """
 
469
        if plot is None:
 
470
            plot = self.get_plot()
444
471
        for tool in self.tools:
445
472
            tool.update_status(plot)
446
473
 
461
488
        self.set_default_tool(t)
462
489
        self.add_tool(RectZoomTool)
463
490
        self.add_tool(BasePlotMenuTool, "item")
 
491
        self.add_tool(DeleteItemTool)
 
492
        self.add_separator_tool()
464
493
        self.add_tool(BasePlotMenuTool, "grid")
465
494
        self.add_tool(BasePlotMenuTool, "axes")
466
495
        self.add_tool(DisplayCoordsTool)
467
496
        if self.get_itemlist_panel():
468
 
            self.add_tool(ItemListTool)
 
497
            self.add_tool(ItemListPanelTool)
469
498
 
470
499
    def register_curve_tools(self):
471
500
        """
494
523
        self.add_tool(ReverseYAxisTool)
495
524
        self.add_tool(AspectRatioTool)
496
525
        if self.get_contrast_panel():
497
 
            self.add_tool(ContrastTool)
 
526
            self.add_tool(ContrastPanelTool)
 
527
        self.add_tool(SnapshotTool)
 
528
        self.add_tool(ImageStatsTool)
498
529
        if self.get_xcs_panel() and self.get_ycs_panel():
499
 
            self.add_tool(XCrossSectionTool)
500
 
            self.add_tool(YCrossSectionTool)
 
530
            self.add_tool(XCSPanelTool)
 
531
            self.add_tool(YCSPanelTool)
501
532
            self.add_tool(CrossSectionTool)
502
533
            self.add_tool(AverageCrossSectionTool)
503
 
        self.add_tool(SnapshotTool)
504
534
        
505
535
    def register_other_tools(self):
506
536
        """
533
563
        self.register_curve_tools()
534
564
        self.add_separator_tool()
535
565
        self.register_other_tools()
 
566
        self.add_separator_tool()
536
567
        self.get_default_tool().activate()
537
 
    
 
568
        
538
569
    def register_all_image_tools(self):
539
570
        """
540
571
        Register standard, image-related and other tools
552
583
        self.register_image_tools()
553
584
        self.add_separator_tool()
554
585
        self.register_other_tools()
 
586
        self.add_separator_tool()
555
587
        self.get_default_tool().activate()
 
588
        
 
589
    def synchronize_axis(self, axis, plots):
 
590
        for plot_id in plots:
 
591
            synclist = self.synchronized_plots.setdefault(plot_id, [])
 
592
            for plot2_id in plots:
 
593
                if plot_id==plot2_id:
 
594
                    continue
 
595
                item = (axis,plot2_id)
 
596
                if item not in synclist:
 
597
                    synclist.append(item)
556
598
 
 
599
    def plot_axis_changed(self, plot):
 
600
        plot_id = plot.plot_id
 
601
        if plot_id not in self.synchronized_plots:
 
602
            return
 
603
        for (axis, other_plot_id) in self.synchronized_plots[plot_id]:
 
604
            scalediv = plot.axisScaleDiv(axis)
 
605
            map = plot.canvasMap(axis)
 
606
            other = self.get_plot(other_plot_id)
 
607
            lb = scalediv.lowerBound()
 
608
            ub = scalediv.upperBound()
 
609
            other.setAxisScale(axis, lb, ub)
 
610
            other.replot()
 
611
        
557
612
assert_interfaces_valid(PlotManager)
558
613
 
559
614
 
572
627
        qsplit.setStretchFactor(1, 1)
573
628
        qsplit.setSizes([1, 2])
574
629
 
 
630
class SubplotWidget(QSplitter):
 
631
    def __init__(self, parent=None, title=None, xlabel=None, ylabel=None,
 
632
                 section="plot", show_itemlist=False, gridparam=None):
 
633
        QSplitter.__init__(self, Qt.Horizontal, parent)
 
634
        
 
635
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
 
636
        
 
637
        self.plots = []
 
638
 
 
639
        parent = QWidget()
 
640
        self.plotlayout = QGridLayout()
 
641
        parent.setLayout(self.plotlayout)
 
642
        self.addWidget(parent)
 
643
 
 
644
        self.itemlist = PlotItemList(self)
 
645
        self.itemlist.setVisible(show_itemlist)
 
646
        self.addWidget(self.itemlist)
 
647
 
 
648
    def add_subplot(self, plot, i=0, j=0, plot_id=None):
 
649
        """Add a plot to the grid of plots"""
 
650
        self.plotlayout.addWidget(plot, i, j)
 
651
        self.plots.append(plot)
 
652
        if plot_id is None:
 
653
            plot_id = id(plot)
 
654
        self.manager.add_plot(plot, plot_id)
 
655
 
 
656
    def finalize(self):
 
657
        self.manager.add_panel(self.itemlist)
 
658
        configure_plot_splitter(self)
 
659
 
575
660
class BaseCurveWidget(QSplitter):
576
661
    """
577
662
    Construct a BaseCurveWidget object, which includes:
605
690
        * title: plot title
606
691
        * xlabel: (bottom axis title, top axis title) or bottom axis title only
607
692
        * ylabel: (left axis title, right axis title) or left axis title only
 
693
        * panels (optional): additionnal panels (list, tuple)
608
694
    """
609
695
    def __init__(self, parent=None, title=None, xlabel=None, ylabel=None,
610
 
                 section="plot", show_itemlist=False, gridparam=None):
 
696
                 section="plot", show_itemlist=False, gridparam=None,
 
697
                 panels=None):
611
698
        BaseCurveWidget.__init__(self, parent, title, xlabel, ylabel,
612
699
                                     section, show_itemlist, gridparam)
613
700
        PlotManager.__init__(self, main=self)
615
702
        # Configuring plot manager
616
703
        self.add_plot(self.plot)
617
704
        self.add_panel(self.itemlist)
618
 
        
619
 
class CurveDialog(QDialog, PlotManager):
620
 
    """
621
 
    Construct a CurveDialog object: plotting dialog box with integrated 
622
 
    plot manager
623
 
        * wintitle: window title
624
 
        * icon: window icon
625
 
        * edit: editable state
626
 
        * toolbar: show/hide toolbar
627
 
        * options: options sent to the :py:class:`guiqwt.curve.CurvePlot` object
628
 
          (dictionary)
629
 
        * parent: parent widget
630
 
    """
 
705
        if panels is not None:
 
706
            for panel in panels:
 
707
                self.add_panel(panel)
 
708
 
 
709
class CurveWidgetMixin(PlotManager):
631
710
    def __init__(self, wintitle="guiqwt plot", icon="guiqwt.png",
632
 
                 edit=False, toolbar=False, options=None, parent=None):
633
 
        QDialog.__init__(self, parent)
 
711
                 toolbar=False, options=None, panels=None):
634
712
        PlotManager.__init__(self, main=self)
635
713
 
636
 
        self.edit = edit
 
714
        self.plot_layout = QGridLayout()
 
715
        
 
716
        if options is None:
 
717
            options = {}
 
718
        self.plot_widget = None
 
719
        self.create_plot(options)
 
720
        
 
721
        if panels is not None:
 
722
            for panel in panels:
 
723
                self.add_panel(panel)
 
724
        
 
725
        self.toolbar = QToolBar(_("Tools"))
 
726
        if not toolbar:
 
727
            self.toolbar.hide()
 
728
 
 
729
        # Configuring widget layout
 
730
        self.setup_widget_properties(wintitle=wintitle, icon=icon)
 
731
        self.setup_widget_layout()
 
732
        
 
733
        # Configuring plot manager
 
734
        self.add_toolbar(self.toolbar, "default")
 
735
        self.register_tools()
 
736
        
 
737
    def setup_widget_layout(self):
 
738
        raise NotImplementedError
 
739
        
 
740
    def setup_widget_properties(self, wintitle, icon):
637
741
        self.setWindowTitle(wintitle)
638
742
        if isinstance(icon, basestring):
639
743
            icon = get_icon(icon)
640
744
        self.setWindowIcon(icon)
641
745
        self.setMinimumSize(320, 240)
642
746
        self.resize(640, 480)
 
747
 
 
748
    def register_tools(self):
 
749
        """
 
750
        Register the plotting dialog box tools: the base implementation 
 
751
        provides standard, curve-related and other tools - i.e. calling 
 
752
        this method is exactly the same as calling 
 
753
        :py:meth:`guiqwt.plot.CurveDialog.register_all_curve_tools`
 
754
        
 
755
        This method may be overriden to provide a fully customized set of tools
 
756
        """
 
757
        self.register_all_curve_tools()
 
758
 
 
759
    def create_plot(self, options):
 
760
        """
 
761
        Create the plotting widget (which is an instance of class 
 
762
        :py:class:`guiqwt.plot.BaseCurveWidget`), add it to the dialog box 
 
763
        main layout (:py:attr:`guiqwt.plot.CurveDialog.plot_layout`) and 
 
764
        then add the `item list` panel
 
765
 
 
766
        May be overriden to customize the plot layout 
 
767
        (:py:attr:`guiqwt.plot.CurveDialog.plot_layout`)
 
768
        """
 
769
        self.plot_widget = BaseCurveWidget(self, **options)
 
770
        self.plot_layout.addWidget(self.plot_widget, 0, 0)
 
771
        
 
772
        # Configuring plot manager
 
773
        self.add_plot(self.plot_widget.plot)
 
774
        self.add_panel(self.plot_widget.itemlist)
 
775
 
 
776
class CurveDialog(QDialog, CurveWidgetMixin):
 
777
    """
 
778
    Construct a CurveDialog object: plotting dialog box with integrated 
 
779
    plot manager
 
780
        * wintitle: window title
 
781
        * icon: window icon
 
782
        * edit: editable state
 
783
        * toolbar: show/hide toolbar
 
784
        * options: options sent to the :py:class:`guiqwt.curve.CurvePlot` object
 
785
          (dictionary)
 
786
        * parent: parent widget
 
787
        * panels (optional): additionnal panels (list, tuple)
 
788
    """
 
789
    def __init__(self, wintitle="guiqwt plot", icon="guiqwt.png", edit=False,
 
790
                 toolbar=False, options=None, parent=None, panels=None):
 
791
        QDialog.__init__(self, parent)
 
792
        self.edit = edit
 
793
        self.button_box = None
 
794
        CurveWidgetMixin.__init__(self, wintitle=wintitle, icon=icon, 
 
795
                                  toolbar=toolbar, options=options,
 
796
                                  panels=panels)
643
797
        self.setWindowFlags(Qt.Window)
644
798
        
645
 
        self.plot_layout = QGridLayout()
646
 
        
647
 
        if options is None:
648
 
            options = {}
649
 
            
650
 
        self.create_plot(options)
651
 
        
652
 
        self.vlayout = QVBoxLayout(self)
653
 
        
654
 
        self.toolbar = QToolBar(_("Tools"))
655
 
        if not toolbar:
656
 
            self.toolbar.hide()
657
 
        self.vlayout.addWidget(self.toolbar)
658
 
        
659
 
        self.setLayout(self.vlayout)
660
 
        self.vlayout.addLayout(self.plot_layout)
661
 
        
 
799
    def setup_widget_layout(self):
 
800
        vlayout = QVBoxLayout(self)
 
801
        vlayout.addWidget(self.toolbar)
 
802
        vlayout.addLayout(self.plot_layout)
 
803
        self.setLayout(vlayout)
662
804
        if self.edit:
663
805
            self.button_layout = QHBoxLayout()
664
806
            self.install_button_layout()
665
 
            self.vlayout.addLayout(self.button_layout)
666
 
        
667
 
        # Configuring plot manager
668
 
        self.add_toolbar(self.toolbar, "default")
669
 
        self.register_tools()
 
807
            vlayout.addLayout(self.button_layout)
670
808
        
671
809
    def install_button_layout(self):
672
810
        """
679
817
        self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
680
818
        self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
681
819
        self.button_layout.addWidget(bbox)
682
 
 
683
 
    def register_tools(self):
684
 
        """
685
 
        Register the plotting dialog box tools: the base implementation 
686
 
        provides standard, curve-related and other tools - i.e. calling 
687
 
        this method is exactly the same as calling 
688
 
        :py:meth:`guiqwt.plot.CurveDialog.register_all_curve_tools`
689
 
        
690
 
        This method may be overriden to provide a fully customized set of tools
691
 
        """
692
 
        self.register_all_curve_tools()
693
 
 
694
 
    def create_plot(self, options):
695
 
        """
696
 
        Create the plotting widget (which is an instance of class 
697
 
        :py:class:`guiqwt.plot.BaseCurveWidget`), add it to the dialog box 
698
 
        main layout (:py:attr:`guiqwt.plot.CurveDialog.plot_layout`) and 
699
 
        then add the `item list` panel
700
 
 
701
 
        May be overriden to customize the plot layout 
702
 
        (:py:attr:`guiqwt.plot.CurveDialog.plot_layout`)
703
 
        """
704
 
        widget = BaseCurveWidget(self, **options)
705
 
        self.plot_layout.addWidget(widget, 0, 0)
706
 
        
707
 
        # Configuring plot manager
708
 
        self.add_plot(widget.plot)
709
 
        self.add_panel(widget.itemlist)
 
820
        self.button_box = bbox
 
821
        
 
822
class CurveWindow(QMainWindow, CurveWidgetMixin):
 
823
    """
 
824
    Construct a CurveWindow object: plotting window with integrated plot manager
 
825
        * wintitle: window title
 
826
        * icon: window icon
 
827
        * toolbar: show/hide toolbar
 
828
        * options: options sent to the :py:class:`guiqwt.curve.CurvePlot` object
 
829
          (dictionary)
 
830
        * parent: parent widget
 
831
        * panels (optional): additionnal panels (list, tuple)
 
832
    """
 
833
    def __init__(self, wintitle="guiqwt plot", icon="guiqwt.png",
 
834
                 toolbar=False, options=None, parent=None, panels=None):
 
835
        QMainWindow.__init__(self, parent)
 
836
        CurveWidgetMixin.__init__(self, wintitle=wintitle, icon=icon, 
 
837
                                 toolbar=toolbar, options=options,
 
838
                                 panels=panels)
 
839
        
 
840
    def setup_widget_layout(self):
 
841
        self.addToolBar(self.toolbar)
 
842
        widget = QWidget()
 
843
        widget.setLayout(self.plot_layout)
 
844
        self.setCentralWidget(widget)
 
845
        
 
846
    def closeEvent(self, event):
 
847
        # Closing panels (necessary if at least one of these panels has no 
 
848
        # parent widget: otherwise, this panel will stay open after the main
 
849
        # window has been closed which is not the expected behavior)
 
850
        for panel in self.panels:
 
851
            self.get_panel(panel).close()
 
852
        QMainWindow.closeEvent(self, event)
710
853
 
711
854
 
712
855
#===============================================================================
746
889
                              gridparam=gridparam)
747
890
 
748
891
        from guiqwt.cross_section import YCrossSection
749
 
        self.ycsw = YCrossSection(self, position=ysection_pos)
 
892
        self.ycsw = YCrossSection(self, position=ysection_pos,
 
893
                                  xsection_pos=xsection_pos)
750
894
        self.ycsw.setVisible(show_ysection)
751
895
        
752
896
        from guiqwt.cross_section import XCrossSection
755
899
        
756
900
        self.connect(self.xcsw, SIG_VISIBILITY_CHANGED, self.xcsw_is_visible)
757
901
        
758
 
        xcsw_splitter = QSplitter(Qt.Vertical, self)
 
902
        self.xcsw_splitter = QSplitter(Qt.Vertical, self)
759
903
        if xsection_pos == "top":
760
 
            self.ycsw_spacer = self.ycsw.spacer1
761
 
            xcsw_splitter.addWidget(self.xcsw)
762
 
            xcsw_splitter.addWidget(self.plot)
 
904
            self.xcsw_splitter.addWidget(self.xcsw)
 
905
            self.xcsw_splitter.addWidget(self.plot)
763
906
        else:
764
 
            self.ycsw_spacer = self.ycsw.spacer2
765
 
            xcsw_splitter.addWidget(self.plot)
766
 
            xcsw_splitter.addWidget(self.xcsw)
767
 
        self.connect(xcsw_splitter, SIGNAL('splitterMoved(int,int)'),
 
907
            self.xcsw_splitter.addWidget(self.plot)
 
908
            self.xcsw_splitter.addWidget(self.xcsw)
 
909
        self.connect(self.xcsw_splitter, SIGNAL('splitterMoved(int,int)'),
768
910
                     lambda pos, index: self.adjust_ycsw_height())
769
911
        
770
 
        ycsw_splitter = QSplitter(Qt.Horizontal, self)
 
912
        self.ycsw_splitter = QSplitter(Qt.Horizontal, self)
771
913
        if ysection_pos == "left":
772
 
            ycsw_splitter.addWidget(self.ycsw)
773
 
            ycsw_splitter.addWidget(xcsw_splitter)
 
914
            self.ycsw_splitter.addWidget(self.ycsw)
 
915
            self.ycsw_splitter.addWidget(self.xcsw_splitter)
774
916
        else:
775
 
            ycsw_splitter.addWidget(xcsw_splitter)
776
 
            ycsw_splitter.addWidget(self.ycsw)
 
917
            self.ycsw_splitter.addWidget(self.xcsw_splitter)
 
918
            self.ycsw_splitter.addWidget(self.ycsw)
777
919
            
778
 
        configure_plot_splitter(xcsw_splitter,
 
920
        configure_plot_splitter(self.xcsw_splitter,
779
921
                                decreasing_size=xsection_pos == "bottom")
780
 
        configure_plot_splitter(ycsw_splitter,
 
922
        configure_plot_splitter(self.ycsw_splitter,
781
923
                                decreasing_size=ysection_pos == "right")
782
924
        
783
 
        self.sub_splitter.addWidget(ycsw_splitter)
 
925
        self.sub_splitter.addWidget(self.ycsw_splitter)
784
926
        
785
927
        self.itemlist = PlotItemList(self)
786
928
        self.itemlist.setVisible(show_itemlist)
798
940
    def adjust_ycsw_height(self, height=None):
799
941
        if height is None:
800
942
            height = self.xcsw.height()-self.ycsw.toolbar.height()
801
 
        self.ycsw_spacer.changeSize(0, height,
802
 
                                    QSizePolicy.Fixed, QSizePolicy.Fixed)
803
 
        self.ycsw.layout().invalidate()
 
943
        self.ycsw.adjust_height(height)
804
944
        if height:
805
945
            QApplication.processEvents()
806
946
        
829
969
          (string: "top", "bottom")
830
970
        * ysection_pos: y-axis cross section plot position 
831
971
          (string: "left", "right")
 
972
        * panels (optional): additionnal panels (list, tuple)
832
973
    """
833
974
    def __init__(self, parent=None, title="",
834
975
                 xlabel=("", ""), ylabel=("", ""), zlabel=None, yreverse=True,
835
976
                 colormap="jet", aspect_ratio=1.0, lock_aspect_ratio=True,
836
977
                 show_contrast=False, show_itemlist=False, show_xsection=False,
837
978
                 show_ysection=False, xsection_pos="top", ysection_pos="right",
838
 
                 gridparam=None):
 
979
                 gridparam=None, panels=None):
839
980
        BaseImageWidget.__init__(self, parent, title, xlabel, ylabel,
840
981
                 zlabel, yreverse, colormap, aspect_ratio, lock_aspect_ratio,
841
982
                 show_contrast, show_itemlist, show_xsection, show_ysection,
848
989
        self.add_panel(self.xcsw)
849
990
        self.add_panel(self.ycsw)
850
991
        self.add_panel(self.contrast)
851
 
 
852
 
class ImageDialog(CurveDialog):
853
 
    """
854
 
    Construct a ImageDialog object: plotting dialog box with integrated 
855
 
    plot manager
856
 
        * wintitle: window title
857
 
        * icon: window icon
858
 
        * edit: editable state
859
 
        * toolbar: show/hide toolbar
860
 
        * options: options sent to the :py:class:`guiqwt.image.ImagePlot` object
861
 
          (dictionary)
862
 
        * parent: parent widget
863
 
    """
864
 
    def __init__(self, wintitle="guiqwt imshow", icon="guiqwt.png",
865
 
                 edit=False, toolbar=False, options=None, parent=None):
866
 
        CurveDialog.__init__(self, wintitle=wintitle, icon=icon, edit=edit,
867
 
                                 toolbar=toolbar, options=options,
868
 
                                 parent=parent)
869
 
 
 
992
        if panels is not None:
 
993
            for panel in panels:
 
994
                self.add_panel(panel)
 
995
 
 
996
class ImageWidgetMixin(CurveWidgetMixin):
870
997
    def register_tools(self):
871
998
        """
872
999
        Register the plotting dialog box tools: the base implementation 
889
1016
        May be overriden to customize the plot layout 
890
1017
        (:py:attr:`guiqwt.plot.CurveDialog.plot_layout`)
891
1018
        """
892
 
        widget = BaseImageWidget(self, **options)
893
 
        self.plot_layout.addWidget(widget, row, column, rowspan, columnspan)
 
1019
        self.plot_widget = BaseImageWidget(self, **options)
 
1020
        self.plot_layout.addWidget(self.plot_widget,
 
1021
                                   row, column, rowspan, columnspan)
894
1022
        
895
1023
        # Configuring plot manager
896
 
        self.add_plot(widget.plot)
897
 
        self.add_panel(widget.itemlist)
898
 
        self.add_panel(widget.xcsw)
899
 
        self.add_panel(widget.ycsw)
900
 
        self.add_panel(widget.contrast)
 
1024
        self.add_plot(self.plot_widget.plot)
 
1025
        self.add_panel(self.plot_widget.itemlist)
 
1026
        self.add_panel(self.plot_widget.xcsw)
 
1027
        self.add_panel(self.plot_widget.ycsw)
 
1028
        self.add_panel(self.plot_widget.contrast)
 
1029
 
 
1030
class ImageDialog(CurveDialog, ImageWidgetMixin):
 
1031
    """
 
1032
    Construct a ImageDialog object: plotting dialog box with integrated 
 
1033
    plot manager
 
1034
        * wintitle: window title
 
1035
        * icon: window icon
 
1036
        * edit: editable state
 
1037
        * toolbar: show/hide toolbar
 
1038
        * options: options sent to the :py:class:`guiqwt.image.ImagePlot` object
 
1039
          (dictionary)
 
1040
        * parent: parent widget
 
1041
        * panels (optional): additionnal panels (list, tuple)
 
1042
    """
 
1043
    pass
 
1044
 
 
1045
class ImageWindow(CurveWindow, ImageWidgetMixin):
 
1046
    """
 
1047
    Construct a ImageWindow object: plotting window with integrated plot manager
 
1048
        * wintitle: window title
 
1049
        * icon: window icon
 
1050
        * toolbar: show/hide toolbar
 
1051
        * options: options sent to the :py:class:`guiqwt.image.ImagePlot` object
 
1052
          (dictionary)
 
1053
        * parent: parent widget
 
1054
        * panels (optional): additionnal panels (list, tuple)
 
1055
    """
 
1056
    pass
901
1057
 
902
1058
 
903
1059
#===============================================================================
916
1072
                 section="plot", show_itemlist=False, gridparam=None):
917
1073
        CurveWidget.__init__(self, parent, title, xlabel, ylabel, section,
918
1074
                             show_itemlist, gridparam)
 
1075
        self.manager = self
919
1076
        warnings.warn("For clarity's sake, the 'CurvePlotWidget' class has "
920
1077
                      "been renamed to 'CurveWidget' (this will raise an "
921
1078
                      "exception in future versions)", FutureWarning)
935
1092
                 edit=False, toolbar=False, options=None, parent=None):
936
1093
        CurveDialog.__init__(self, wintitle, icon, edit, toolbar, options,
937
1094
                             parent)
 
1095
        self.manager = self
938
1096
        warnings.warn("For clarity's sake, the 'CurvePlotDialog' class has "
939
1097
                      "been renamed to 'CurveDialog' (this will raise an "
940
1098
                      "exception in future versions)", FutureWarning)
968
1126
                             lock_aspect_ratio, show_contrast, show_itemlist,
969
1127
                             show_xsection, show_ysection, xsection_pos,
970
1128
                             ysection_pos, gridparam)
 
1129
        self.manager = self
971
1130
        warnings.warn("For clarity's sake, the 'ImagePlotWidget' class has "
972
1131
                      "been renamed to 'ImageWidget' (this will raise an "
973
1132
                      "exception in future versions)", FutureWarning)
987
1146
                 edit=False, toolbar=False, options=None, parent=None):
988
1147
        ImageDialog.__init__(self, wintitle, icon, edit, toolbar, options,
989
1148
                             parent)
 
1149
        self.manager = self
990
1150
        warnings.warn("For clarity's sake, the 'ImagePlotDialog' class has "
991
1151
                      "been renamed to 'ImageDialog' (this will raise an "
992
1152
                      "exception in future versions)", FutureWarning)