示例#1
0
class HDFViewWindow(gui.SlabWindow, UiClass):
    def __init__(self, fname=None):
        gui.SlabWindow.__init__(self, HDFViewThread)
        self.setupSlabWindow(autoparam=True)
        self.auto_register_gui()

        self.register_param(self.datasets_treeWidget, "dataset")
        self.register_param(self.datapath_lineEdit, "datapath")

        # Setup Plots -- Could be eliminated if QtDesigner plugins were setup
        self.toolbar = Qt.QToolBar()
        self.addToolBar(self.toolbar)
        self.image_widget = ImageWidget(show_xsection=True, show_ysection=True)
        self.image_widget.add_toolbar(self.toolbar)
        self.image_widget.register_all_image_tools()
        self.image_plot = self.image_widget.plot
        self.image_plot_layout.addWidget(self.image_widget)
        self.gui["image_plot"] = self.image_plot
        
        self.line_widget = CurveWidget()
        self.gui["line_plot"] = self.line_plot = self.line_widget.plot #CurvePlot()
        self.line_plot_layout.addWidget(self.line_plot)
        self.line_widget.register_all_image_tools()

        # Context Menu actions
        self.set_x_action = Qt.QAction("Set as x data", self)
        self.clear_x_action = Qt.QAction("Clear x data", self)
        self.datasets_treeWidget.customContextMenuRequested.connect(
            lambda point: self.msg("menu requested"))
        self.datasets_treeWidget.customContextMenuRequested.connect(
            self.datasets_context_menu)

        # Connect launchers
        self.datapath_browse_pushButton.clicked.connect(self.select_datapath)
        self.register_script("set_datapath", self.datapath_lineEdit)
        self.register_script("load_file", self.datafiles_listWidget)
        self.register_script("load_dset", self.datasets_treeWidget)
        self.register_script("set_x_data", self.set_x_action)
        self.register_script("clear_x_data", self.clear_x_action)

        # Syntax Highlighting
        self.highlight = syntax.PythonHighlighter(self.script_textEdit.document())


        # Setup Prompt
        """
        message = "The currently loaded file is stored as 'f'"
        self.shell = InternalShell(self, message=message)
        self.shell.set_font(Qt.QFont("Consolas"))
        self.shell_dockWidget.setWidget(self.shell)
        self.gui["shell"] = self.shell
        """

        self.start_thread()

        if fname is not None:
            self.shell.exit_interpreter()
            directory = os.path.dirname(fname)
            nameitem = namedtuple('pseudoitem', ('filename',))(fname)
            self.msg(fname)
            self.set_param("datapath", directory)
            self.start_script("set_datapath")
            self.start_script("load_file", nameitem)
        
    def closeEvent(self, event):
        self.shell.exit_interpreter()
        event.accept()

    def select_datapath(self):
        path = str(Qt.QFileDialog.getExistingDirectory(
                    self, 'Open Datapath',self.params["datapath"]))
        if path:
            self.params["datapath"] = path
            self.emit(Qt.SIGNAL("RunOnDataThread"), "set_datapath")

    def datasets_context_menu(self, point):
        menu = Qt.QMenu()
        menu.addAction(self.set_x_action)
        menu.addAction(self.clear_x_action)
        menu.exec_(self.datasets_treeWidget.mapToGlobal(point))
示例#2
0
class CentralWidget(QSplitter):
    def __init__(self, parent, toolbar):
        QSplitter.__init__(self, parent)
        self.setContentsMargins(10, 10, 10, 10)
        self.setOrientation(Qt.Vertical)
        
        imagelistwithproperties = ImageListWithProperties(self)
        self.addWidget(imagelistwithproperties)
        self.imagelist = imagelistwithproperties.imagelist
        self.connect(self.imagelist, SIGNAL("currentRowChanged(int)"),
                     self.current_item_changed)
        self.connect(self.imagelist, SIGNAL("itemSelectionChanged()"),
                     self.selection_changed)
        self.properties = imagelistwithproperties.properties
        self.connect(self.properties, SIGNAL("apply_button_clicked()"),
                     self.properties_changed)
        
        self.imagewidget = ImageWidget(self)
        self.connect(self.imagewidget.plot, SIG_LUT_CHANGED,
                     self.lut_range_changed)
        self.item = None # image item
        
        self.imagewidget.add_toolbar(toolbar, "default")
        self.imagewidget.register_all_image_tools()
        
        self.addWidget(self.imagewidget)

        self.images = [] # List of ImageParam instances
        self.lut_ranges = [] # List of LUT ranges

        self.setStretchFactor(0, 0)
        self.setStretchFactor(1, 1)
        self.setHandleWidth(10)
        self.setSizes([1, 2])
        
    def refresh_list(self):
        self.imagelist.clear()
        self.imagelist.addItems([image.title for image in self.images])
        
    def selection_changed(self):
        """Image list: selection changed"""
        row = self.imagelist.currentRow()
        self.properties.setDisabled(row == -1)
        
    def current_item_changed(self, row):
        """Image list: current image changed"""
        image, lut_range = self.images[row], self.lut_ranges[row]
        self.show_data(image.data, lut_range)
        update_dataset(self.properties.dataset, image)
        self.properties.get()
        
    def lut_range_changed(self):
        row = self.imagelist.currentRow()
        self.lut_ranges[row] = self.item.get_lut_range()
        
    def show_data(self, data, lut_range=None):
        plot = self.imagewidget.plot
        if self.item is not None:
            self.item.set_data(data)
            if lut_range is None:
                lut_range = self.item.get_lut_range()
            self.imagewidget.set_contrast_range(*lut_range)
            self.imagewidget.update_cross_sections()
        else:
            self.item = make.image(data)
            plot.add_item(self.item, z=0)
        plot.replot()
        
    def properties_changed(self):
        """The properties 'Apply' button was clicked: updating image"""
        row = self.imagelist.currentRow()
        image = self.images[row]
        update_dataset(image, self.properties.dataset)
        self.refresh_list()
        self.show_data(image.data)
    
    def add_image(self, image):
        self.images.append(image)
        self.lut_ranges.append(None)
        self.refresh_list()
        self.imagelist.setCurrentRow(len(self.images)-1)
        plot = self.imagewidget.plot
        plot.do_autoscale()
    
    def add_image_from_file(self, filename):
        image = ImageParam()
        image.title = to_text_string(filename)
        image.data = io.imread(filename, to_grayscale=True)
        image.height, image.width = image.data.shape
        self.add_image(image)
示例#3
0
class PlotItem(qt.QWidget):
    def __init__(self,
                 ident,
                 rank,
                 accum,
                 plotkwargs,
                 trace=None,
                 xpts=[],
                 ypts=[]):
        qt.QWidget.__init__(self)
        qt.QVBoxLayout(self)
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(5, 0, 5, 0)

        self.toolbar = toolbar = qt.QToolBar()
        self.layout().addWidget(toolbar)

        self.ident = ident
        self.rank = rank
        self.accum = accum
        self.xpts = xpts
        self.ypts = ypts
        self.update_count = 0
        self.collapsed = False

        autoscale_gui_default = True
        if self.rank == 1:
            self.plot_widget = CurveWidget(title=ident)
            self.plot_widget.add_toolbar(toolbar)
            self.plot_widget.register_all_curve_tools()
            try:
                vmin, vmax = plotkwargs.pop('xlimit')
                self.plot_widget.plot.set_axis_limits(2, vmin, vmax)
                autoscale_gui_default = False
            except:
                pass
            try:
                vmin, vmax = plotkwargs.pop('ylimit')
                self.plot_widget.plot.set_axis_limits(0, vmin, vmax)
                autoscale_gui_default = False
            except:
                pass
            try:
                title = plotkwargs.pop('title')
                self.plot_widget.set_title(title)
            except:
                pass
            try:
                background = plotkwargs.pop('background')
                self.plot_widget.plot.grid.gridparam.background = background
                self.plot_widget.plot.grid.update_params()
            except:
                pass

        elif self.rank == 2:
            self.plot_widget = ImageWidget(title=ident,
                                           lock_aspect_ratio=False)
            self.plot_widget.add_toolbar(toolbar)
            self.plot_widget.register_all_image_tools()
        else:
            raise ValueError
        self.items = {}
        self.add_item(trace, plotkwargs)
        self.layout().addWidget(self.plot_widget)

        self.buttons_widget = buttons = qt.QWidget()
        qt.QHBoxLayout(buttons)
        self.hide_button = qt.QPushButton('Hide')
        self.hide_button.clicked.connect(self.collapse)
        self.show_button = qt.QPushButton('Show ' + ident)
        self.show_button.clicked.connect(self.expand)
        self.show_button.hide()
        self.remove_button = qt.QPushButton('Remove')
        self.zoom_button = qt.QPushButton('Zoom')
        self.autoscale_check = qt.QCheckBox('autoscale')
        #print autoscale_gui_default,"<== is this true?"
        self.autoscale_check.setChecked(autoscale_gui_default)
        buttons.layout().addWidget(self.hide_button)
        buttons.layout().addWidget(self.remove_button)
        buttons.layout().addWidget(self.zoom_button)
        buttons.layout().addWidget(self.autoscale_check)
        self.layout().addWidget(buttons)
        self.layout().addWidget(self.show_button)

    def add_item(self, trace, plotkwargs={}):
        if trace in self.items:
            self.plot_widget.plot.del_item(self.items[trace])
        if self.rank == 1:
            try:
                self.items[trace] = make.curve([], [], **plotkwargs)
            except:
                raise
        elif self.rank == 2:
            if 'interpolation' not in plotkwargs:
                plotkwargs['interpolation'] = 'nearest'
            self.items[trace] = make.image(np.array([[0]]), **plotkwargs)
        else:
            raise ValueError
        self.plot_widget.plot.add_item(self.items[trace])

    def collapse(self):
        self.collapsed = True
        self.toolbar.hide()
        self.plot_widget.hide()
        self.buttons_widget.hide()
        self.show_button.show()

    def expand(self):
        self.collaped = False
        self.toolbar.show()
        self.plot_widget.show()
        self.buttons_widget.show()
        self.show_button.hide()
示例#4
0
class PlotItem(qt.QWidget):
    def __init__(self, ident, rank, accum, plotkwargs, trace=None, xpts=[], ypts=[]):
        qt.QWidget.__init__(self)
        qt.QVBoxLayout(self)
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(5,0,5,0)
        
        self.toolbar = toolbar = qt.QToolBar()
        self.layout().addWidget(toolbar)
        
        self.ident = ident
        self.rank = rank
        self.accum = accum
        self.xpts = xpts
        self.ypts = ypts
        self.update_count = 0
        self.collapsed = False
        
        autoscale_gui_default=True
        if self.rank == 1:
            self.plot_widget = CurveWidget(title=ident)
            self.plot_widget.add_toolbar(toolbar)
            self.plot_widget.register_all_curve_tools()
            try: 
                vmin,vmax=plotkwargs.pop('xlimit')
                self.plot_widget.plot.set_axis_limits(2,vmin,vmax)
                autoscale_gui_default=False
            except:
                pass
            try: 
                vmin,vmax=plotkwargs.pop('ylimit')
                self.plot_widget.plot.set_axis_limits(0,vmin,vmax)
                autoscale_gui_default=False
            except:
                pass
            try: 
                title=plotkwargs.pop('title')
                self.plot_widget.set_title(title)
            except:
                pass
            try:
                background=plotkwargs.pop('background')
                self.plot_widget.plot.grid.gridparam.background = background                
                self.plot_widget.plot.grid.update_params()
            except:
                pass
                

        elif self.rank == 2:
            self.plot_widget = ImageWidget(title=ident, lock_aspect_ratio=False)
            self.plot_widget.add_toolbar(toolbar)
            self.plot_widget.register_all_image_tools()
        else:
            raise ValueError
        self.items = {}
        self.add_item(trace, plotkwargs)
        self.layout().addWidget(self.plot_widget)

        self.buttons_widget = buttons = qt.QWidget()
        qt.QHBoxLayout(buttons)
        self.hide_button = qt.QPushButton('Hide')
        self.hide_button.clicked.connect(self.collapse)        
        self.show_button = qt.QPushButton('Show ' + ident)
        self.show_button.clicked.connect(self.expand)
        self.show_button.hide()
        self.remove_button = qt.QPushButton('Remove')
        self.zoom_button = qt.QPushButton('Zoom')
        self.autoscale_check = qt.QCheckBox('autoscale')
        #print autoscale_gui_default,"<== is this true?"
        self.autoscale_check.setChecked(autoscale_gui_default)
        buttons.layout().addWidget(self.hide_button)
        buttons.layout().addWidget(self.remove_button)
        buttons.layout().addWidget(self.zoom_button)
        buttons.layout().addWidget(self.autoscale_check)
        self.layout().addWidget(buttons)
        self.layout().addWidget(self.show_button)
    
    def add_item(self, trace, plotkwargs={}):
        if trace in self.items:
            self.plot_widget.plot.del_item(self.items[trace])
        if self.rank == 1:
            try:
                self.items[trace] = make.curve([], [], **plotkwargs)
            except:
                raise
        elif self.rank == 2:
            if 'interpolation' not in plotkwargs:
                plotkwargs['interpolation'] = 'nearest'
            self.items[trace] = make.image(np.array([[0]]), **plotkwargs)
        else:
            raise ValueError
        self.plot_widget.plot.add_item(self.items[trace])

    def collapse(self):
        self.collapsed = True
        self.toolbar.hide()
        self.plot_widget.hide()
        self.buttons_widget.hide()
        self.show_button.show()
        
    def expand(self):
        self.collaped = False
        self.toolbar.show()
        self.plot_widget.show()
        self.buttons_widget.show()
        self.show_button.hide()
示例#5
0
class CentralWidget(QSplitter):
    def __init__(self, parent, toolbar):
        QSplitter.__init__(self, parent)
        self.setContentsMargins(10, 10, 10, 10)
        self.setOrientation(Qt.Vertical)

        imagelistwithproperties = ImageListWithProperties(self)
        self.addWidget(imagelistwithproperties)
        self.imagelist = imagelistwithproperties.imagelist
        self.imagelist.currentRowChanged.connect(self.current_item_changed)
        self.imagelist.itemSelectionChanged.connect(self.selection_changed)
        self.properties = imagelistwithproperties.properties
        self.properties.SIG_APPLY_BUTTON_CLICKED.connect(
            self.properties_changed)

        self.imagewidget = ImageWidget(self)
        self.imagewidget.plot.SIG_LUT_CHANGED.connect(self.lut_range_changed)
        self.item = None  # image item

        self.imagewidget.add_toolbar(toolbar, "default")
        self.imagewidget.register_all_image_tools()

        self.addWidget(self.imagewidget)

        self.images = []  # List of ImageParam instances
        self.lut_ranges = []  # List of LUT ranges

        self.setStretchFactor(0, 0)
        self.setStretchFactor(1, 1)
        self.setHandleWidth(10)
        self.setSizes([1, 2])

    def refresh_list(self):
        self.imagelist.clear()
        self.imagelist.addItems([image.title for image in self.images])

    def selection_changed(self):
        """Image list: selection changed"""
        row = self.imagelist.currentRow()
        self.properties.setDisabled(row == -1)

    def current_item_changed(self, row):
        """Image list: current image changed"""
        image, lut_range = self.images[row], self.lut_ranges[row]
        self.show_data(image.data, lut_range)
        update_dataset(self.properties.dataset, image)
        self.properties.get()

    def lut_range_changed(self):
        row = self.imagelist.currentRow()
        self.lut_ranges[row] = self.item.get_lut_range()

    def show_data(self, data, lut_range=None):
        plot = self.imagewidget.plot
        if self.item is not None:
            self.item.set_data(data)
            if lut_range is None:
                lut_range = self.item.get_lut_range()
            self.imagewidget.set_contrast_range(*lut_range)
            self.imagewidget.update_cross_sections()
        else:
            self.item = make.image(data)
            plot.add_item(self.item, z=0)
        plot.replot()

    def properties_changed(self):
        """The properties 'Apply' button was clicked: updating image"""
        row = self.imagelist.currentRow()
        image = self.images[row]
        update_dataset(image, self.properties.dataset)
        self.refresh_list()
        self.show_data(image.data)

    def add_image(self, image):
        self.images.append(image)
        self.lut_ranges.append(None)
        self.refresh_list()
        self.imagelist.setCurrentRow(len(self.images) - 1)
        plot = self.imagewidget.plot
        plot.do_autoscale()

    def add_image_from_file(self, filename):
        image = ImageParam()
        image.title = to_text_string(filename)
        image.data = io.imread(filename, to_grayscale=True)
        image.height, image.width = image.data.shape
        self.add_image(image)