Example #1
0
 def close(self):
     '''
     emits the signal 'closed'
     '''
     Dock.close(self)
     self._isclosed = True
     self.workspace.gui.undoRedo.displayClosed(self)
     self.closed.emit(self)
     self.widget.close()
Example #2
0
 def close(self):
     """
     emits the signal 'closed'
     """
     Dock.close(self)
     self._isclosed = True
     self.workspace.gui.undoRedo.displayClosed(self)
     self.closed.emit(self)
     self.widget.close()
Example #3
0
    def _reloadWidgetCls(self, widgetCls):
        data = None
        state = None
        toolbars = None
        if self.widget:
            data = self.widget.getData()
            state = self.widget.saveState()
            toolbars = self.widget.toolbars

        names = self.layerNames()
        self.widget = widgetCls(weakref.proxy(self), self.axes, data=data, names=names, toolbars=toolbars)
        if state:
            self.widget.restoreState(state)

        Dock.setWidget(self, self.widget)
Example #4
0
    def __setattr__(self, attr, value):
        """
        this method is to access display layers easily in the built-in python shell

        if attribute is 'l' or 'l0'...'l[layerNumber]':
            set all data of a certain data layer to [value]
        """
        if attr[0] == "l":
            a = attr[1:]
            if not a:
                # make sure that this display is updated through automation:
                self.tab.automation.checkWidgetIsActive(self.widget)

                nLayers = len(self.stack.childs)
                # CASE 'l'
                n = self.widget.getNLayers(value)
                #                 n = self._getNDataLayers(self.axes, value)
                #                 print nLayers, n,55555555555
                #                 if not n:
                # raise Exception("number of axes doesn't fit to data shape")

                if nLayers == n:
                    # print value
                    return self.widget.update(value)

                if nLayers != 0:
                    # remove old layers:
                    for i in range(nLayers):
                        self.removeLayer(i)
                if n > 1:
                    for layer in value:
                        self.addLayer(data=layer)
                else:
                    return self.addLayer(data=value)
            elif a.isdigit():
                # make sure that this display is updated through automation:
                self.tab.automation.checkWidgetIsActive(self.widget)

                nLayers = len(self.stack.childs)
                # CASE 'l0'...'l[n]'
                a = int(a)
                if a == nLayers:
                    # this index doesn't exist jet - so add a new layer
                    return self.addLayer(data=value)
                return self.widget.update(value, index=a)
        Dock.__setattr__(self, attr, value)
Example #5
0
    def __setattr__(self, attr, value):
        '''
        this method is to access display layers easily in the built-in python shell

        if attribute is 'l' or 'l0'...'l[layerNumber]':
            set all data of a certain data layer to [value]  
        '''
        if attr[0] == 'l':
            a = attr[1:]
            if not a:
                #make sure that this display is updated through automation:
                self.tab.automation.checkWidgetIsActive(self.widget)

                nLayers = len(self.stack.childs)
                # CASE 'l'
                n = self.widget.getNLayers(value)
                #                 n = self._getNDataLayers(self.axes, value)
                #                 print nLayers, n,55555555555
                #                 if not n:
                #                     raise Exception("number of axes doesn't fit to data shape")

                if nLayers == n:
                    #print value
                    return self.widget.update(value)

                if nLayers != 0:
                    #remove old layers:
                    for i in range(nLayers):
                        self.removeLayer(i)
                if n > 1:
                    for layer in value:
                        self.addLayer(data=layer)
                else:
                    return self.addLayer(data=value)
            elif a.isdigit():
                #make sure that this display is updated through automation:
                self.tab.automation.checkWidgetIsActive(self.widget)

                nLayers = len(self.stack.childs)
                # CASE 'l0'...'l[n]'
                a = int(a)
                if a == nLayers:
                    #this index doesn't exist jet - so add a new layer
                    return self.addLayer(data=value)
                return self.widget.update(value, index=a)
        Dock.__setattr__(self, attr, value)
Example #6
0
    def _reloadWidgetCls(self, widgetCls):
        data = None
        state = None
        toolbars = None
        if self.widget:
            data = self.widget.getData()
            state = self.widget.saveState()
            toolbars = self.widget.toolbars

        names = self.layerNames()
        self.widget = widgetCls(weakref.proxy(self),
                                self.axes,
                                data=data,
                                names=names,
                                toolbars=toolbars)
        if state:
            self.widget.restoreState(state)

        Dock.setWidget(self, self.widget)
Example #7
0
    def __getattr__(self, attr):
        """
        this method is to access display layers easily in the built-in python shell

        if attribute cannot be found:
        return data or data-layer if attribute = 'l' or 'l0'...'l[layerNumber]'
        """
        try:
            Dock.__getattr__(self, attr)
        except AttributeError:
            if attr[0] == "l":
                a = attr[1:]
                if a != "":
                    if not a.isdigit():
                        raise AttributeError("display %s doesn't has attribute %s" % (self.name(), attr))
                    a = int(a)
                    return self.widget.getData(a)
                return self.widget.getData()
            else:
                raise AttributeError("display %s doesn't has attribute %s" % (self.name(), attr))
Example #8
0
 def __getattr__(self, attr):
     '''
     this method is to access display layers easily in the built-in python shell
     
     if attribute cannot be found:
     return data or data-layer if attribute = 'l' or 'l0'...'l[layerNumber]'
     '''
     try:
         Dock.__getattr__(self, attr)
     except AttributeError:
         if attr[0] == 'l':
             a = attr[1:]
             if a != '':
                 if not a.isdigit():
                     raise AttributeError(
                         "display %s doesn't has attribute %s" %
                         (self.name(), attr))
                 a = int(a)
                 return self.widget.getData(a)
             return self.widget.getData()
         else:
             raise AttributeError("display %s doesn't has attribute %s" %
                                  (self.name(), attr))
Example #9
0
    def __init__(
        self,
        number,
        workspace,
        origin=None,
        index=None,
        names=None,
        title="",
        data=None,
        axes=None,
        info=None,
        changes=None,
        openfiles=True,
        docktitle=None,
    ):
        """
        ============   ===============================================
        Arguments      Description
        ============   ===============================================
        number         The display number, like 1,2...
        workspace      The workspace within the display is
        names          Path(s) of input files to open
        title          ... of the DisplayDock
        data           ... to display within the corresponding widget
        axes           Instance of AxesContainer with names and scales
                       for the axes scaling the data
        origin         The origin display
        index          The index of the origin layer
        info           informational text about the input
        changes        Additional changes done to the data
        openfiles      [True/False] whether to open the files
                       given in [filenames]
        ============   ===============================================
        """
        self.workspace = workspace
        self.number = number
        self.widget = None
        self._isclosed = False

        # GET VALUES FROM ORIGIN DISPLAY
        data, names, axes, title = self._extractInfoFromOrigin(origin, index, data, names, axes, title)
        if data is None and names is None and axes is None:
            raise Exception("either filenames, data or axes must be given")
        one_layer = False

        # FORMAT FILENAMES TO A LIST OF FILENAMES:
        if names is None:
            if data is not None:
                names = [None] * len(data)
            else:
                names = []
        elif isinstance(names, string_types):
            names = [names]
            one_layer = True
        if docktitle is None:
            docktitle = self._getDockTitle(title, number, names)
        # INIT SUPER CLASS
        Dock.__init__(self, docktitle)

        # SETUP FILE READER:
        self.reader = None
        if names and data is None:  # -->load input from file
            self.reader = getFileReader(names)
            self.reader = self.reader(weakref.proxy(self))
            # GET AXES FROM INPUT READER IF NOT DEFINED YET:
            if axes is None:
                axes = self.reader.axes
        # CREATE/FORMAT AXES IF INPUT GIVES AS DATA:
        if axes is None:
            axes = ["x", "y", "", "i", "j"][: data[0].ndim + 1]
        elif isinstance(axes, int):
            axes = ["x", "y", "", "i", "j"][:axes]

        self.stack = _StackParameter(self)

        # PARAMETERS:
        self.p = Parameter.create(name="", type="empty")

        # TAB DISPLAYING PREFERENCES AND INPUT INFORMATION:
        self.tab = _DisplayTab(self)
        # FILL PARAMETERS:
        self.pTitle = self.p.addChild({"name": "Title", "type": "str", "value": ""})
        self.pTitle.sigValueChanged.connect(self._setWidgetTitle)
        pSize = self.pTitle.addChild({"name": "Size", "type": "int", "value": 11})
        pSize.sigValueChanged.connect(lambda param, size: self.widget.setTitleSize(size))

        self.pTitleFromLayer = self.pTitle.addChild({"name": "From layer", "type": "bool", "value": False})
        self.pTitleFromLayer.sigValueChanged.connect(self._pTitleFromLayerChanged)

        self.pLimitLayers = self.p.addChild({"name": "Limit Layers", "type": "bool", "value": False})
        self.pLimitLayers.sigValueChanged.connect(self._pLimitLayersChanged)

        self.pMaxLayers = self.pLimitLayers.addChild(
            {"name": "Max. Layers", "type": "int", "value": 10, "visible": False, "limits": [1, 1e4]}
        )

        self.pMaxLayers.sigValueChanged.connect(self._limitLayers)

        # HANDLING THE INPUT LAYERS:
        self.p.addChild(self.stack)
        self.axes = AxesContainer(weakref.proxy(self), axes, weakref.proxy(self.stack))
        # ADD AXES PARAMETERS:
        self.p.addChild(self.axes.p)

        # LIST OF ALL FITTING DISPLAY FIGURES:
        #         widgetList = _DisplayFigureList(self)

        # UPDATE DATA FROM FILE USING SPECIFIED PREFERENCES:
        if self.reader:
            if self.reader.preferences:
                self.p.addChild(self.reader.preferences)

        # LIST OF ALL FITTING DISPLAY FIGURES:
        widgetList = _DisplayFigureList(self)
        if len(widgetList) > 1:
            # only show available widgets if
            # there are more than one:
            self.p.addChild(widgetList)

        # INIT WIDGET
        self.changeWidget(widgetList.getWidget())  # , data, names)

        # ADD DATA
        if len(names):
            if data is None and PathStr(names[0]).isfile():
                self.addFiles(names, openfiles)
            # TODO: what to do with mixed file/non file input?
            else:
                if one_layer:
                    self.addLayer(data, names[0], origin=origin)
                else:
                    self.addLayers(data, names, origin=origin)
Example #10
0
    def __init__(self, number, workspace, origin=None, index=None, 
                 names=None, title='', data=None, axes=None, info=None, 
                 changes=None, openfiles=True):
        '''
        ============   ===============================================
        Arguments      Description
        ============   ===============================================        
        number         The display number, like 1,2...
        workspace      The workspace within the display is
        names          Path(s) of input files to open
        title          ... of the DisplayDock
        data           ... to display within the corresponding widget
        axes           Instance of AxesContainer with names and scales
                       for the axes scaling the data
        origin         The origin display
        index          The index of the origin layer
        info           informational text about the input
        changes        Additional changes done to the data
        openfiles      [True/False] whether to open the files
                       given in [filenames]
        ============   ===============================================
        '''
        self.workspace = workspace  
        self.number = number

        self.widget = None

        self._isclosed = False

        #GET VALUES FROM ORIGIN DISPLAY
        data, names, axes, title = self._extractInfoFromOrigin(origin, index, 
                                                               data, names, axes, title)
        if data is None and names is None and axes is None:
            raise Exception('either filenames, data or axes must be given')
        one_layer = False
        
        #FORMAT FILENAMES TO A LIST OF FILENAMES:
        if names is None:
            if data is not None:
                names = [None]*len(data)
            else:
                names = []
        elif isinstance(names, basestring):
            names = [names]
            one_layer = True

        docktitle = self._getDockTitle(title, number,names)

        #INIT SUPER CLASS
        Dock.__init__(self, docktitle)

        #SETUP FILE READER:
        self.reader = None
        if names and data is None:#-->load input from file
            self.reader = getFileReader(names)
            self.reader = self.reader(weakref.proxy(self))
            #GET AXES FROM INPUT READER IF NOT DEFINED YET:
            if axes is None: 
                axes = self.reader.axes
        #CREATE/FORMAT AXES IF INPUT GIVES AS DATA:
        if axes is None: 
            axes = ['x', 'y', '', 'i','j'][:data[0].ndim+1]
        elif type(axes) == int:
            axes = ['x', 'y', '', 'i','j'][:axes]

        self.stack = _StackParameter(weakref.proxy(self))

        #PARAMETERS:
        self.p = Parameter.create(
                    name='', 
                    type='empty')

        #TAB DISPLAYING PREFERENCES AND INPUT INFORMATION:
        self.tab = _DisplayTab(weakref.proxy(self))
        #FILL PARAMETERS:
        self.pTitle = self.p.addChild({
                    'name':'Title',
                    'type':'str',
                    'value':''})
        self.pTitle.sigValueChanged.connect(self._setWidgetTitle)                        
        pSize = self.pTitle.addChild({
                    'name':'Size',
                    'type':'int',
                    'value':11})
        pSize.sigValueChanged.connect(lambda param, size: self.widget.setTitleSize(size))  

        self.pTitleFromLayer = self.pTitle.addChild({
                    'name':'From layer',
                    'type':'bool',
                    'value':False})
        self.pTitleFromLayer.sigValueChanged.connect(self._pTitleFromLayerChanged)  


        self.pLimitLayers = self.p.addChild({
                  'name':'Limit Layers',
                  'type':'bool',
                  'value':False})
        self.pLimitLayers.sigValueChanged.connect(self._pLimitLayersChanged)

        self.pMaxLayers = self.pLimitLayers.addChild({
                    'name':'Max. Layers',
                    'type':'int',
                    'value':10,
                    'visible':False,
                    'limits':[1,1e4]})
        
        self.pMaxLayers.sigValueChanged.connect(self._limitLayers)
 
        #HANDLING THE INPUT LAYERS:
        self.p.addChild(self.stack)
        self.axes = AxesContainer(weakref.proxy(self), axes, 
                                  weakref.proxy(self.stack))
        #ADD AXES PARAMETERS:
        self.p.addChild(self.axes.p)
        #LIST OF ALL FITTING DISPLAY FIGURES:
        widgetList = _DisplayFigureList(self)

        #UPDATE DATA FROM FILE USING SPECIFIED PREFERENCES: 
        #TODO: 'update' should only update file based data and no processed data
        if self.reader:
            pUpdate = Parameter.create(**{
                        'type':'action',
                        'name':'Update',
                        })
            if self.reader.preferences:
                pUpdate.addChild(self.reader.preferences)
            pUpdate.sigActivated.connect(self.updateInput)
            self.p.addChild(pUpdate)

        self.p.addChild(widgetList)
      
        #INIT WIDGET
        self.changeWidget(widgetList.getWidget())#, data, names)
        #ADD DATA
        if len(names):
            if data is None and PathStr(names[0]).isfile():
                self.addFiles(names, openfiles)
            #TODO: what to do with mixed file/non file input?
            else:
                if one_layer:
                    self.addLayer(data, names[0], origin=origin)
                else:
                    self.addLayers(data, names, origin=origin)
Example #11
0
    def __init__(self,
                 number,
                 workspace,
                 origin=None,
                 index=None,
                 names=None,
                 title='',
                 data=None,
                 axes=None,
                 info=None,
                 changes=None,
                 openfiles=True):
        '''
        ============   ===============================================
        Arguments      Description
        ============   ===============================================        
        number         The display number, like 1,2...
        workspace      The workspace within the display is
        names          Path(s) of input files to open
        title          ... of the DisplayDock
        data           ... to display within the corresponding widget
        axes           Instance of AxesContainer with names and scales
                       for the axes scaling the data
        origin         The origin display
        index          The index of the origin layer
        info           informational text about the input
        changes        Additional changes done to the data
        openfiles      [True/False] whether to open the files
                       given in [filenames]
        ============   ===============================================
        '''
        self.workspace = workspace
        self.number = number

        self.widget = None

        self._isclosed = False

        #GET VALUES FROM ORIGIN DISPLAY
        data, names, axes, title = self._extractInfoFromOrigin(
            origin, index, data, names, axes, title)
        if data is None and names is None and axes is None:
            raise Exception('either filenames, data or axes must be given')
        one_layer = False

        #FORMAT FILENAMES TO A LIST OF FILENAMES:
        if names is None:
            if data is not None:
                names = [None] * len(data)
            else:
                names = []
        elif isinstance(names, basestring):
            names = [names]
            one_layer = True

        docktitle = self._getDockTitle(title, number, names)

        #INIT SUPER CLASS
        Dock.__init__(self, docktitle)

        #SETUP FILE READER:
        self.reader = None
        if names and data is None:  #-->load input from file
            self.reader = getFileReader(names)
            self.reader = self.reader(weakref.proxy(self))
            #GET AXES FROM INPUT READER IF NOT DEFINED YET:
            if axes is None:
                axes = self.reader.axes
        #CREATE/FORMAT AXES IF INPUT GIVES AS DATA:
        if axes is None:
            axes = ['x', 'y', '', 'i', 'j'][:data[0].ndim + 1]
        elif type(axes) == int:
            axes = ['x', 'y', '', 'i', 'j'][:axes]

        self.stack = _StackParameter(self)

        #PARAMETERS:
        self.p = Parameter.create(name='', type='empty')

        #TAB DISPLAYING PREFERENCES AND INPUT INFORMATION:
        self.tab = _DisplayTab(self)
        #FILL PARAMETERS:
        self.pTitle = self.p.addChild({
            'name': 'Title',
            'type': 'str',
            'value': ''
        })
        self.pTitle.sigValueChanged.connect(self._setWidgetTitle)
        pSize = self.pTitle.addChild({
            'name': 'Size',
            'type': 'int',
            'value': 11
        })
        pSize.sigValueChanged.connect(
            lambda param, size: self.widget.setTitleSize(size))

        self.pTitleFromLayer = self.pTitle.addChild({
            'name': 'From layer',
            'type': 'bool',
            'value': False
        })
        self.pTitleFromLayer.sigValueChanged.connect(
            self._pTitleFromLayerChanged)

        self.pLimitLayers = self.p.addChild({
            'name': 'Limit Layers',
            'type': 'bool',
            'value': False
        })
        self.pLimitLayers.sigValueChanged.connect(self._pLimitLayersChanged)

        self.pMaxLayers = self.pLimitLayers.addChild({
            'name': 'Max. Layers',
            'type': 'int',
            'value': 10,
            'visible': False,
            'limits': [1, 1e4]
        })

        self.pMaxLayers.sigValueChanged.connect(self._limitLayers)

        #HANDLING THE INPUT LAYERS:
        self.p.addChild(self.stack)
        self.axes = AxesContainer(weakref.proxy(self), axes,
                                  weakref.proxy(self.stack))
        #ADD AXES PARAMETERS:
        self.p.addChild(self.axes.p)
        #LIST OF ALL FITTING DISPLAY FIGURES:
        widgetList = _DisplayFigureList(self)

        #UPDATE DATA FROM FILE USING SPECIFIED PREFERENCES:
        #TODO: 'update' should only update file based data and no processed data
        if self.reader:
            #             pUpdate = Parameter.create(**{
            #                         'type':'action',
            #                         'name':'Update',
            #                         })
            if self.reader.preferences:
                #                 pUpdate.addChild(self.reader.preferences)
                #             pUpdate.sigActivated.connect(self.updateInput)
                self.p.addChild(self.reader.preferences)

        self.p.addChild(widgetList)

        #INIT WIDGET
        self.changeWidget(widgetList.getWidget())  #, data, names)
        #ADD DATA
        if len(names):
            if data is None and PathStr(names[0]).isfile():
                self.addFiles(names, openfiles)
            #TODO: what to do with mixed file/non file input?
            else:
                if one_layer:
                    self.addLayer(data, names[0], origin=origin)
                else:
                    self.addLayers(data, names, origin=origin)