def showCtfMicrographs(self, projectDirectory, ctfs):

        allMicrographs = []

        for i in range(len(ctfs)):
            fileName = ctfs[i]['ctfImage'].replace(':mrc', '')

            try:
                mrc = mrcfile.mmap(projectDirectory + fileName)
            except (FileNotFoundError, ValueError) as err:
                self.errorText.value = "Unable to load Micrograph: {0}".format(
                    err)
                self.errorText.layout = self.errorLayout
            else:
                #extract data, convert values to 0 - 255 int8 format
                formatted = (mrc.data[0] * 255 /
                             np.max(mrc.data)).astype('uint8')
                img = Image.fromarray(formatted)
                img.thumbnail(self.thumbNailSize)

                imagePng = self.convertToPNG(img)

                mrc.close()

            #Dynamically build the Ctf mrcs and buttons.
            img = widgets.Image(value=imagePng,
                                format='PNG',
                                width=self.thumbNailSize[0],
                                height=self.thumbNailSize[1])
            dataButton = widgets.Button(description='Data',
                                        disabled=False,
                                        button_style='',
                                        tooltip='Show data',
                                        icon='check')
            mrcButton = widgets.Button(description='Raw mrc',
                                       disabled=False,
                                       button_style='',
                                       tooltip='Show micrograph',
                                       icon='check')
            buttonOutput = widgets.Output(layout={'border': '2px solid black'})

            dataButton.add_traits(showData=traitlets.Any(buttonOutput))
            mrcButton.add_traits(showMrc=traitlets.Any(buttonOutput))

            #adding on_click actions to buttons dynamically, lambda is an anonymous function
            #lambda arguments: function
            dataButton.on_click(lambda dataButton, num=i: self.dynamicOnClick(
                ctfs[num], dataButton))
            mrcButton.on_click(lambda mrcButton, num=i: self.dynamicOnClick(
                ctfs[num], mrcButton))

            micrograph = VBox(
                [img, HBox([dataButton, mrcButton]), buttonOutput])
            allMicrographs.append(micrograph)

        return allMicrographs
Ejemplo n.º 2
0
 def __init__(self, value=None, *args, **kwargs):
     super(LoadedButton, self).__init__(*args, **kwargs)
     # Create the value attribute.
     self.add_traits(value=traitlets.Any(value))
Ejemplo n.º 3
0
 def __init__(self, dframe=None, *args, **kwargs):
     super(fatButton, self).__init__(*args, **kwargs)
     self.add_traits(dframe=traitlets.Any(dframe))
Ejemplo n.º 4
0
 def __init__(self, value=None, *args, **kwargs):
     super(LoadedButton, self).__init__(*args, **kwargs)
     self.add_traits(value=traitlets.Any(value))
Ejemplo n.º 5
0
 def __init__(self, value='', *args, **kwargs):
     super(SButton, self).__init__(*args, **kwargs)
     self.add_traits(value=traitlets.Any(value))