Пример #1
0
    def __init__(self, parent):
        qt.QTreeView.__init__(self, parent)

        #
        # Model is qt.QFileSystemModel()
        #
        fsModel = qt.QFileSystemModel()
        self.setModel(fsModel)

        #
        # Set up monitor for the file system
        #
        self.watcher = qt.QFileSystemWatcher()
        self.watcher.directoryChanged.connect(
            self.handleDirectoryChangedSignal)

        #
        # Context menu
        #
        self.setContextMenuPolicy(qt.Qt.DefaultContextMenu)
        if hasattr(parent, 'handleContextMenuAction'):
            self.callback = parent.handleContextMenuAction
        else:
            self.callback = None

        #
        # List to keep track of files and avoid unnecessary
        #
        self.fileList = []
Пример #2
0
    def add_overlay(self,
                    flag,
                    image,
                    alpha,
                    colorTableAlpha,
                    minValue=-1,
                    maxValue=1):

        if flag:
            self.flagAlpha = True
            self.dataVolumeAlpha = image
            self.alpha = alpha
            self.colortableAlpha = []

            if (minValue == -1) and (maxValue == -1):
                self.maxAlpha = self.dataVolumeAlpha.max()
                self.minAlpha = self.dataVolumeAlpha.min()
            else:
                self.maxAlpha = maxValue
                self.minAlpha = minValue

            R = colorTableAlpha[1]
            G = colorTableAlpha[2]
            B = colorTableAlpha[3]

            for i in range(256):
                if int(alpha * 255) > i:
                    self.colortableAlpha.append(qt.qRgba(R[i], G[i], B[i], i))
                else:
                    self.colortableAlpha.append(
                        qt.qRgba(R[i], G[i], B[i], int(alpha * 255)))
        else:
            self.flagAlpha = False
Пример #3
0
    def mouseMoved(self, ddict):
        if (ddict['event'] == 'MouseMoved'):
            x = int(ddict['x'])
            y = int(ddict['y'])
            ddict = {}
            ddict['event'] = "MouseMoved"

            if (self.currentPlaneSection == 0):
                z = self.sliceSlider.value()
                ddict['PlaneSection'] = 0
                ddict['x'] = x
                ddict['y'] = y
                ddict['z'] = z
                self.emit(qt.SIGNAL("movedOnVizualizer"), ddict)

            if (self.currentPlaneSection == 1):
                z = self.sliceSlider.value()
                ddict['PlaneSection'] = 1
                ddict['x'] = x
                ddict['y'] = z
                ddict['z'] = y
                self.emit(qt.SIGNAL("movedOnVizualizer"), ddict)

            if (self.currentPlaneSection == 2):
                z = self.sliceSlider.value()
                ddict['PlaneSection'] = 2
                ddict['x'] = z
                ddict['y'] = x
                ddict['z'] = y
                self.emit(qt.SIGNAL("movedOnVizualizer"), ddict)
Пример #4
0
    def __init__(
        self,
        scan_list,
        parent=None,
    ):
        qt.QWidget.__init__(self, parent)

        self.mainLayout = qt.QGridLayout()
        self.scan_list = scan_list
        self.widgetList = []

        for scan in self.scan_list:
            w = qt.QCheckBox(scan)
            self.widgetList.append(w)

        self.startImporting = qt.QPushButton("OK")

        index = 0
        for w in self.widgetList:
            w.setChecked(True)
            self.mainLayout.addWidget(w, index % 15, int(index / 15))
            index += 1

        self.mainLayout.addWidget(self.startImporting)
        self.setLayout(self.mainLayout)
Пример #5
0
    def check_parameters_files(self):
        source_file_color = open('./VTK_parameters/history', "r")
        files_para = source_file_color.readlines()

        if len(files_para) != 3:
            msgBox = qt.QMessageBox(self)
            msgBox.setText('Missing parameters files in the history')
            msgBox.exec_()
        else:
            matching = [s for s in files_para if ".col" in s]
            if len(str(matching)) != 2:
                self.color_file = str(matching[0]).rstrip('\n')
            else:
                self.color_file = 'empty'
                msgBox = qt.QMessageBox(self)
                msgBox.setText('Missing color file')
                msgBox.exec_()

            matching = [s for s in files_para if ".alp" in s]
            if len(str(matching)) != 2:
                self.alpha_file = str(matching[0]).rstrip('\n')
            else:
                self.alpha_file = 'empty'
                msgBox = qt.QMessageBox(self)
                msgBox.setText('Missing alpha file')
                msgBox.exec_()

            matching = [s for s in files_para if ".pr" in s]
            if len(str(matching)) != 2:
                self.para_file = str(matching[0]).rstrip('\n')
            else:
                self.para_file = 'empty'
                msgBox = qt.QMessageBox(self)
                msgBox.setText('Missing parameters file')
                msgBox.exec_()
Пример #6
0
    def fill_alphaTable(self):
        if self.alpha_file != 'empty':
            try:
                source_file_alpha = open('./VTK_parameters/' + self.alpha_file,
                                         "r")
            except IOError:
                msgBox = qt.QMessageBox(self)
                msgBox.setText('The alpha file ' + self.alpha_file +
                               ' does not exist')
                msgBox.exec_()

            all_lines = source_file_alpha.readlines()
            j = 0
            for line in all_lines:

                line = line.rstrip('\n')
                line = line.split(' ')
                try:
                    line.remove('')
                except:
                    pass
                if len(line) == 2:
                    for i in range(2):
                        Item = qt.QTableWidgetItem()
                        Item.setText(str(line[i]))
                        self.AlphaCoef.setItem(j, i, Item)
                elif len(line) == 4:
                    for i in range(4):
                        Item = qt.QTableWidgetItem()

                        Item.setText(str(line[i]))
                        self.AlphaCoef.setItem(j, i, Item)
                j += 1
Пример #7
0
    def display_image(self):

        self.flagFirstCircle = True

        self.image = qt.QImage(self.data, self.data.shape[1],
                               self.data.shape[0], self.data.shape[1],
                               qt.QImage.Format_Indexed8)
        self.image.setColorTable(self.colortable)
        pixMap = qt.QPixmap.fromImage(self.image)
        pixItem = qt.QGraphicsPixmapItem(pixMap)
        pixItem.setZValue(-1)
        self.scene.addItem(pixItem)
        self.scene.setSceneRect(0, 0, self.image.width(), self.image.height())

        if self.flagAlpha:

            imageAlpha = qt.QImage(self.dataAlpha, self.dataAlpha.shape[1],
                                   self.dataAlpha.shape[0],
                                   self.dataAlpha.shape[1],
                                   qt.QImage.Format_Indexed8)

            imageAlpha.setColorTable(self.colortableAlpha)
            #
            pixMapAlpha = qt.QPixmap.fromImage(imageAlpha)
            pixMapAlpha.hasAlpha()
            pixItemAlpha = qt.QGraphicsPixmapItem(pixMapAlpha)
            #
            self.scene.addItem(pixItemAlpha)
            self.scene.setSceneRect(0, 0, self.image.width(),
                                    self.image.height())

        self.scene.update
Пример #8
0
    def drawEllipse(self, x, y, r):

        self.Item = qt.QGraphicsEllipseItem(x - r / 2, y - r / 2, r, r)
        self.Item.setFlag(qt.QGraphicsItem.ItemIsMovable)

        pen = qt.QPen(qt.Qt.blue)
        pen.setWidth(3)
        brush = qt.QBrush(qt.QColor(0xFF, 0, 0, 0x00))
        self.Item.setBrush(brush)
        self.Item.setPen(pen)
        self.scene.addItem(self.Item)
Пример #9
0
    def __init__(self, parent=None):
        uiPath = UiPaths.bandPassFilterID32UiPath()
        super(BandPassID32Window, self).__init__(uiPath=uiPath, parent=parent)
        self.setUI()
        self.setWindowTitle('Band Pass Filter ID32')

        self._values = {
            'energy': self.photonEdit,
            'binning': self.binningEdit,
            'preset': self.exposureEdit
        }

        self.setValues({
            'energy': str(932.0),
            'binning': str(4),
            'preset': str(300)
        })

        #
        # Set validators for the line edits
        #
        photonValidator = qt.QDoubleValidator()
        photonValidator.setBottom(0.0)
        photonValidator.setTop(10000.0)
        photonValidator.setDecimals(4)

        binningValidator = qt.QIntValidator()
        binningValidator.setBottom(0)
        binningValidator.setTop(512)

        exposureValidator = qt.QIntValidator()
        exposureValidator.setBottom(0)
        exposureValidator.setTop(100000)

        self.photonEdit.setValidator(photonValidator)
        self.binningEdit.setValidator(binningValidator)
        self.exposureEdit.setValidator(exposureValidator)

        #
        # Connects
        #
        self.photonEdit.textEdited.connect(self.emitValuesChangedSignal)
        self.binningEdit.textEdited.connect(self.emitValuesChangedSignal)
        self.exposureEdit.textEdited.connect(self.emitValuesChangedSignal)

        self.photonEdit.returnPressed.connect(self.emitValuesChangedSignal)
        self.binningEdit.returnPressed.connect(self.emitValuesChangedSignal)
        self.exposureEdit.returnPressed.connect(self.emitValuesChangedSignal)

        #
        # Process
        #
        self.process = Filter.bandPassFilterID32
Пример #10
0
 def __init__(self,parent=None, Orientation=1) :
     qt.QWidget.__init__(self, parent)
     self.slider=qt.QSlider(1)
     self.slider.setMinimum(1)
     self.slider.setMaximum(100)
     self.Label=qt.QLabel("0")
     self.Label.setFixedSize(45,45)
     self.layout=qt.QHBoxLayout()
     self.layout.addWidget(self.slider)
     self.layout.addWidget(self.Label)
     self._changeLabel()
     self.connect(self.slider,qt.SIGNAL("valueChanged(int)"),self._changeLabel)
     self.setLayout(self.layout)
Пример #11
0
def unitTest_FileSystemBrowser():
    app = qt.QApplication([])

    browser = FileSystemBrowser()
    browser.addSignal.connect(DummyNotifier.signalReceived)
    browser.show()
    app.exec_()
Пример #12
0
 def changeColorMap(self, R, G, B):
     if len(R) != 256 or len(G) != 256 or len(B) != 256:
         print "Wrong Color Array shape"
     else:
         self.colortable = []
         for i in range(256):
             self.colortable.append(qt.qRgba(R[i], G[i], B[i], 255))
Пример #13
0
    def mousePressEvent(self, event):

        if (event.button() == qt.Qt.LeftButton):
            dx = event.pos().x()
            dy = event.pos().y()
            clickPosition = self.mapToScene(dx, dy)
 
            ddict = {}
            ddict['event'] = "MousePressed"
            ddict['x'] = clickPosition.x()
            ddict['y'] = clickPosition.y()

        if (event.button() == qt.Qt.RightButton):
            dx = event.pos().x()
            dy = event.pos().y()

            clickPosition = self.mapToScene(dx, dy)
            ddict = {}
            ddict['event'] = "RMousePressed"
            ddict['x'] = clickPosition.x()
            ddict['y'] = clickPosition.y()

        self.emit(qt.SIGNAL("CustomGraphicsViewEvent"), ddict)

        return qt.QGraphicsView.mousePressEvent(self, event)
Пример #14
0
    def run(self):
        self.FileReference = str(self.inputFiles[0])
        self.inputDir = os.path.dirname(self.FileReference)

        image = ImageReader(self.FileReference, 'rb')

        data = image.getData()
        self.shapeReference = data.shape
        typeImage = data.dtype
        self.inputData = np.zeros((len(
            self.inputFiles), self.shapeReference[0], self.shapeReference[1]),
                                  dtype=typeImage)

        i = 0
        for filename in self.inputFiles:
            filename = str(filename)
            image = ImageReader(filename, 'rb')
            data = image.getData()

            if (data.ndim == 2):
                self.inputData[i, :, :] = data
            else:
                self.inputData[i, :, :] = data[:, :, 0]

            i += 1
            self.emit(qt.SIGNAL("Progress"), i)
Пример #15
0
    def fill_para(self):

        if self.para_file != 'empty':
            try:
                source_file_para = open('./VTK_parameters/' + self.para_file,
                                        "r")

            except IOError:
                msgBox = qt.QMessageBox(self)
                msgBox.setText('The parameters fil : ' + self.para_file +
                               ' does not exist')
                msgBox.exec_()

            line = source_file_para.readlines()[0]
            parameters = line.split(' ')

            if int(parameters[0]) == 2:
                self.checkBox.setChecked(2)
            else:
                self.checkBox.setChecked(0)

            self.sliderAmb._defaultValue(float(parameters[1]))
            self.sliderDif._defaultValue(float(parameters[2]))
            self.sliderSpe._defaultValue(float(parameters[3]))
            self.sliderSpeP._defaultValue(float(parameters[4]))
            self.sliderOpa._defaultValue(float(parameters[5]))
        else:
            self.sliderAmb._defaultValue(1)
            self.sliderDif._defaultValue(1)
            self.sliderSpe._defaultValue(1)
            self.sliderSpeP._defaultValue(1)
            self.sliderOpa._defaultValue(1)
Пример #16
0
    def _buttonAlphaSavePushed(self):
        source_file_color = open('./VTK_parameters/history', "r")
        files_para = source_file_color.readlines()
        matching = [s for s in files_para if ".alp" in s]

        if len(str(matching)) != 2:
            alpha_file = str(matching[0]).rstrip('\n')
            if alpha_file == 'alpha_rendering_default.alp':
                msgBox = qt.QMessageBox(self)
                msgBox.setText(
                    'Overwrite the default file is not allowed. Create a new file to save your table'
                )
                msgBox.exec_()
            else:

                alphaFileToWrite = open('./VTK_parameters/' + alpha_file, "w")

                for i in range(10):
                    for j in range(4):
                        try:
                            alphaFileToWrite.writelines(
                                self.AlphaCoef.item(i, j).text() + ' ')
                        except:
                            if j == 4:
                                alphaFileToWrite.writelines('0.5 ')
                            else:
                                alphaFileToWrite.writelines('0 ')
                    alphaFileToWrite.writelines('\n')

        self.check_parameters_files()
Пример #17
0
    def _buttonParaSavePushed(self):
        source_file_color = open('./VTK_parameters/history', "r")
        files_para = source_file_color.readlines()
        matching = [s for s in files_para if ".pr" in s]

        if len(str(matching)) != 2:
            para_file = str(matching[0]).rstrip('\n')
            if para_file == 'para_rendering_default.pr':
                msgBox = qt.QMessageBox(self)
                msgBox.setText(
                    'Overwrite the default file is not allowed. Create a new file to save your table'
                )
                msgBox.exec_()
            else:

                paraFileToWrite = open('./VTK_parameters/' + para_file, "w")
                paraFileToWrite.writelines(
                    str(self.checkBox.checkState()) + ' ')
                paraFileToWrite.writelines(str(self.sliderAmb.value()) + ' ')
                paraFileToWrite.writelines(str(self.sliderDif.value()) + ' ')
                paraFileToWrite.writelines(str(self.sliderSpe.value()) + ' ')
                paraFileToWrite.writelines(str(self.sliderSpe.value()) + ' ')
                paraFileToWrite.writelines(str(self.sliderSpeP.value()) + ' ')
                paraFileToWrite.writelines(str(self.sliderOpa.value()))

        self.check_parameters_files()
Пример #18
0
def test():
    from PyMca5.PyMca import SpecfitFunctions
    a = SpecfitFunctions.SpecfitFunctions()
    x = numpy.arange(1000).astype(numpy.float64)
    p1 = numpy.array([1500, 100., 50.0])
    p2 = numpy.array([1500, 700., 50.0])
    y = a.gauss(p1, x) + 1
    y = y + a.gauss(p2, x)

    fit = SimpleFit()
    fit.importFunctions(SpecfitFunctions)
    fit.setFitFunction('Gaussians')
    #fit.setBackgroundFunction('Gaussians')
    #fit.setBackgroundFunction('Constant')
    fit.setData(x, y)
    fit.fit()
    print("Expected parameters 1500,100.,50.0, 1500,700.,50.0")
    print("Found: ", fit.paramlist)
    from PyMca5.PyMca import PyMcaQt as qt
    from PyMca5.PyMca import Parameters
    a = qt.QApplication(sys.argv)
    a.lastWindowClosed.connect(a.quit)
    w = Parameters.Parameters()
    w.fillfromfit(fit.paramlist)
    w.show()
    a.exec_()
Пример #19
0
def unitTest_BandPassFilter():
    dummy = DummyNotifier()
    app = qt.QApplication([])
    filterWindow = ImageAlignmenWindow()
    # filterWindow.exportSelectedSignal.connect(dummy.signalReceived)
    # filterWindow.exportCurrentSignal.connect(dummy.signalReceived)
    filterWindow.show()
    app.exec_()
Пример #20
0
    def _build(self) :
        self.layout=qt.QHBoxLayout()
        self.label =None
        self.lineEdit =None
        self.button =None
        if(self.boolLabel) :
            self.label=qt.QLabel(self.textLabel,self)
            self.layout.addWidget(self.label)
        if(self.booltextEdit) :
            self.lineEdit= qt.QLineEdit(self.textEdit,self)
            self.layout.addWidget(self.lineEdit)

        if(self.boolButton) :
            self.button=qt.QPushButton(self.textButton,self)
            self.layout.addWidget(self.button)
            self.connect(self.button,qt.SIGNAL("clicked()"),self.buttonPushed)

        self.setLayout(self.layout)
Пример #21
0
 def _axialViewClicked(self, ddict):
     x = int(ddict['x'])
     y = int(ddict['y'])
     ddict = {}
     z = self.axialWidget.sliceSlider.value()
     ddict['event'] = "MousePressed"
     ddict['x'] = x
     ddict['y'] = y
     ddict['z'] = z
     self.emit(qt.SIGNAL("CustomGraphicsViewEvent"), ddict)
Пример #22
0
def test():
    from PyMca5 import StackBase
    testFileName = "TiffTest.tif"
    nrows = 2000
    ncols = 2000
    #create a dummy stack with 100 images
    nImages = 100
    imagestack = True
    a = numpy.ones((nrows, ncols), numpy.float32)
    if not os.path.exists(testFileName):
        print("Creating test filename %s" % testFileName)
        tif = TiffIO.TiffIO(testFileName, mode='wb+')

        for i in range(nImages):
            data = (a * i).astype(numpy.float32)
            if i == 1:
                tif = TiffIO.TiffIO(testFileName, mode='rb+')
            tif.writeImage(data,
                           info={'Title': 'Image %d of %d' % (i + 1, nImages)})
        tif = None

    stackData = TiffStack(imagestack=imagestack)
    stackData.loadFileList([testFileName], dynamic=True)

    if 0:
        stack = StackBase.StackBase()
        stack.setStack(stackData)
        print("This should be 0 = %f" %
              stack.calculateROIImages(0, 0)['ROI'].sum())
        print("This should be %f = %f" %\
              (a.sum(),stack.calculateROIImages(1, 2)['ROI'].sum()))
        if imagestack:
            print("%f should be = %f" %\
                  (stackData.data[0:10,:,:].sum(),
                   stack.calculateROIImages(0, 10)['ROI'].sum()))
            print("Test small ROI 10 should be = %f" %\
                  stackData.data[10:11,[10],11].sum())
            print("Test small ROI 40 should be = %f" %\
                  stackData.data[10:11,[10,12,14,16],11].sum())
        else:
            print("%f should be = %f" %\
                  (stackData.data[:,:, 0:10].sum(),
                   stack.calculateROIImages(0, 10)['ROI'].sum()))
            print("Test small ROI %f" %\
                  stackData.data[10:11,[29],:].sum())
    else:
        from PyMca5.PyMca import PyMcaQt as qt
        from PyMca5.PyMca import QStackWidget
        app = qt.QApplication([])
        w = QStackWidget.QStackWidget()
        print("Setting stack")
        w.setStack(stackData)
        w.show()
        app.exec_()
Пример #23
0
    def __init__(self, planeSection, parent=None):
        qt.QWidget.__init__(self, parent)

        self.currentPlaneSection = planeSection

        self.scene = qt.QGraphicsScene()
        self.view = CustomGraphicsView(self.scene, self)

        self.sliceSlider = SliderAndLabel(self)
        self.sliceSlider._setRange(0, 0)

        self.flagFirstCircle = True

        self.connect(self.view, qt.SIGNAL("CustomGraphicsViewEvent"),
                     self.clickedOnView)
        self.connect(self.view, qt.SIGNAL("CustomGraphicsViewEvent"),
                     self.mouseMoved)
        self.connect(self.sliceSlider.slider, qt.SIGNAL("valueChanged(int)"),
                     self._changeSlice)

        self.flagAlpha = False

        self.Items = {}
        self.colortable = []
        self.posPolyPoints = []
        for i in range(256):
            self.colortable.append(qt.qRgba(i, i, i, 255))

        layout = qt.QVBoxLayout()
        layout.addWidget(self.view)
        layout.addWidget(self.sliceSlider)
        self.setLayout(layout)
Пример #24
0
    def __init__(
        self,
        scan_list,
        parent=None,
    ):
        qt.QWidget.__init__(self, parent)

        self.mainLayout = qt.QGridLayout()
        self.scan_list = scan_list
        self.widgetList = []

        for scan in self.scan_list:
            w = qt.QCheckBox(scan)
            self.widgetList.append(w)

        self.startImporting = qt.QPushButton("OK")

        for w in self.widgetList:
            self.mainLayout.addWidget(w)

        self.mainLayout.addWidget(self.startImporting)
        self.setLayout(self.mainLayout)
Пример #25
0
    def mouseMoveEvent(self, event):
        if (event.button() == qt.Qt.NoButton):
            dx = event.pos().x()
            dy = event.pos().y()

            clickPosition = self.mapToScene(dx, dy)
            ddict = {}
            ddict['event'] = "MouseMoved"
            ddict['x'] = clickPosition.x()
            ddict['y'] = clickPosition.y()

            self.emit(qt.SIGNAL("CustomGraphicsViewEvent"), ddict)

        return qt.QGraphicsView.mouseMoveEvent(self, event) # <-- added this line.
Пример #26
0
    def run(self):

        if self.extension == '.mat':
            filename = self.outputFiles + self.extension
            writter = ImageWritter(filename, self.dataToSave)
            writter.writeData()
        else:
            for i in range(0, self.dataToSave.shape[0] - 1):

                image = self.dataToSave[i, :, :]
                filename = self.outputFiles + '%4.4d' % i + self.extension
                writter = ImageWritter(filename, image)
                writter.writeData()
                self.emit(qt.SIGNAL("Progress"), i)
Пример #27
0
class SumImageTool(AbstractToolWindow):
    __doc__ = """GUI to transform image to spectrum by summation along lines/columns"""

    exportSelectedSignal = qt.pyqtSignal()
    exportCurrentSignal = qt.pyqtSignal()

    def __init__(self, parent=None):
        uiPath = UiPaths.sumToolUiPath()
        super(SumImageTool, self).__init__(uiPath=uiPath, parent=parent)
        self.setUI()
        self.setWindowTitle('Integration')

        self._values = {'axis': self.axisComboBox}

        self.axisComboBox.addItems(['columns', 'rows'])

        self.setValues({'axis': 'columns'})

        #
        # Connect the buttons
        #
        self.selectedButton.clicked.connect(self.exportSelectedSignal.emit)
        self.currentButton.clicked.connect(self.exportCurrentSignal.emit)

        #
        # Process
        #
        self.process = self.sumImage

    def sumImage(self, image, param=None):
        params = self.getValues()
        if str(params['axis']) == 'columns':
            axis = 1
        else:
            axis = 0
        return Integration.axisSum(image, {'axis': axis})
Пример #28
0
class EnergyScaleTool(AbstractToolWindow):
    __doc__ = """GUI to set an energy scale to the project"""

    energyScaleSignal = qt.pyqtSignal()

    def __init__(self, parent=None):
        uiPath = UiPaths.energyAlignmentUiPath()
        super(EnergyScaleTool, self).__init__(uiPath=uiPath, parent=parent)
        self.setUI()
        self.setWindowTitle('Energy alignment')

        self._values = {'slope': self.slopeSpinBox, 'zero': self.zeroSpinBox}

        self.setValues({'slope': 1.0, 'zero': 0.})

        #
        # Connect the spin boxes
        #
        self.slopeSpinBox.valueChanged.connect(self.energyScaleSignal)

        #
        # Process
        #
        self.process = self.energyScale

    def energyScale(self):
        #
        # Create function item
        #
        scale = FunctionItem('Energy scale', '')

        #
        # Set expression
        #
        scale.setExpression(lambda x, a, b: a * x + b)

        #
        # Set parameters
        #
        parameters = self.getValues()
        scale.setParameters({
            'a': parameters['slope'],
            'b': parameters['zero']
        })

        if DEBUG >= 1:
            print('EnergyScaleTool.energyScale -- called')
        return scale
Пример #29
0
    def closeDir(self, safeClose=True):
        """
        :param bool safeClose: Prompts user to confirm closing of working directory. Default: True

        Removes the working directory currently selected in the drop down menu.
        """
        #
        # Prompt warning
        #
        if safeClose:
            msg = qt.QMessageBox()
            msg.setIcon(qt.QMessageBox.Warning)
            msg.setWindowTitle('Close directory')
            msg.setText(
                'Are you shure you want to close the current working directory?'
            )
            msg.setStandardButtons(qt.QMessageBox.Ok | qt.QMessageBox.Cancel)
            if msg.exec_() == qt.QMessageBox.Cancel:
                if DEBUG >= 1:
                    print('FileSystemBrowser.closeDir -- Abort')
                return

        #
        # Inteact with QDirListModel
        #
        currentIdx = self.workingDirCB.currentIndex()
        model = self.workingDirCB.model()

        if model.rowCount() > 0:
            model.removeDirs(row=currentIdx, count=1)
        if model.rowCount() <= 0:
            self.closeDirButton.setEnabled(False)
            self.workingDirCB.setCurrentIndex(-1)
        else:
            self.workingDirCB.setCurrentIndex(0)

        #
        # Reset the DirTree to the users home directory
        #
        homeDir = qt.QDir.home()
        self.fsView.setRootDirectory(homeDir)
Пример #30
0
    def handleFilesChanged(self, fileList):
        """
        :param list fileList: Contains file paths to modified files

        Emits addSignal with the a :py:class:`qt.QFileInfoList` as parameter
        """
        #
        # Check if files shall be automatically added to the project
        #
        if self.autoAddCheckBox.checkState() == qt.Qt.Unchecked:
            if DEBUG >= 1:
                print('FileSystemBrowser.handleFilesChanged -- AutoAdd off')
            return

        #
        # Create a file info list
        #
        if DEBUG >= 1:
            print('FileSystemBrowser.handleFilesChanged -- \n\tfileList: %s' %
                  str(fileList))
        fileInfoList = [qt.QFileInfo(path) for path in fileList]
        self.addSignal.emit(fileInfoList)