示例#1
0
    def __init__(self, doc):
        """Initialisation method for the View
        """
        
        QWidget.__init__(self)
        logging.debug("New Session------------------------------")
        self.doc = doc
        # The ui from designer is setup as self.ui
        self.ui = Ui_sansReduceUI()
        self.ui.setupUi(self)
        self.setGeometry(20, 100, 570, 420)

        # Init GUI elements
        self.initMenus()

        #######################################
        # Initialise connections from the view#
        #######################################

        # Incoming file path
        self.connect(self.ui.inPathPushButton, 
                     SIGNAL("clicked()"),
                     self.selectDirectoryDialog)

        self.connect(self.ui.inPathLineEdit,
                     SIGNAL("editingFinished()"),
                     self.setIncomingDirectory)

        # Run, bgd, trans selection menus
        self.connect(self.ui.sansRunMenu,
                     SIGNAL("activated(int)"),
                     self.setSansRun)

        self.connect(self.ui.sansTransMenu,
                     SIGNAL("activated(int)"),
                     self.setSansTrans)

        self.connect(self.ui.bgdRunMenu,
                     SIGNAL("activated(int)"),
                     self.setBgdRun)

        self.connect(self.ui.bgdTransMenu,
                     SIGNAL("activated(int)"),
                     self.setBgdTrans)

        # Options for the run selection
        self.connect(self.ui.showRawCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.showRawCheckStateChanged)

        self.connect(self.ui.showNexusCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.showNexusCheckStateChanged)

        self.connect(self.ui.maskFilePushButton,
                     SIGNAL("clicked()"),
                     self.selectMaskFileDialog)

        self.connect(self.ui.directBeamRunMenu,
                     SIGNAL("activated(int)"),
                     self.setDirectBeam)

        # Options for the reduction output
        self.connect(self.ui.outputLOQCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.outputLOQCheckStateChanged)

        self.connect(self.ui.outputCanSASCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.outputCanSASCheckStateChanged)

        self.connect(self.ui.useRunnumberCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.useRunnumberCheckStateChanged)

        self.connect(self.ui.blogReductionCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.blogReductionCheckStateChanged)

        self.connect(self.ui.outPathPushButton,
                     SIGNAL("clicked()"),
                     self.setOutPathDialog)

        # Final selections, Queue vs Reduce and Reduce button
        self.connect(self.ui.queueReductionsCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.queueReductionsCheckStateChanged)

        self.connect(self.ui.reducePushButton,
                     SIGNAL("clicked()"),
                     self.doReduceOrQueue)

        self.connect(self.ui.cancelPushButton,
                     SIGNAL("clicked()"),
                     self.exitWidget)
示例#2
0
class SansReduceView(QWidget):
    """The view for the SANS Reduce GUI

    The view was built in QtDesigner and is imported from
    sansReduceUI above. The view simply initialises, 
    connects up signal and implements some convenience
    methods for handling population of menus and UI changes.
    """

    def __init__(self, doc):
        """Initialisation method for the View
        """
        
        QWidget.__init__(self)
        logging.debug("New Session------------------------------")
        self.doc = doc
        # The ui from designer is setup as self.ui
        self.ui = Ui_sansReduceUI()
        self.ui.setupUi(self)
        self.setGeometry(20, 100, 570, 420)

        # Init GUI elements
        self.initMenus()

        #######################################
        # Initialise connections from the view#
        #######################################

        # Incoming file path
        self.connect(self.ui.inPathPushButton, 
                     SIGNAL("clicked()"),
                     self.selectDirectoryDialog)

        self.connect(self.ui.inPathLineEdit,
                     SIGNAL("editingFinished()"),
                     self.setIncomingDirectory)

        # Run, bgd, trans selection menus
        self.connect(self.ui.sansRunMenu,
                     SIGNAL("activated(int)"),
                     self.setSansRun)

        self.connect(self.ui.sansTransMenu,
                     SIGNAL("activated(int)"),
                     self.setSansTrans)

        self.connect(self.ui.bgdRunMenu,
                     SIGNAL("activated(int)"),
                     self.setBgdRun)

        self.connect(self.ui.bgdTransMenu,
                     SIGNAL("activated(int)"),
                     self.setBgdTrans)

        # Options for the run selection
        self.connect(self.ui.showRawCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.showRawCheckStateChanged)

        self.connect(self.ui.showNexusCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.showNexusCheckStateChanged)

        self.connect(self.ui.maskFilePushButton,
                     SIGNAL("clicked()"),
                     self.selectMaskFileDialog)

        self.connect(self.ui.directBeamRunMenu,
                     SIGNAL("activated(int)"),
                     self.setDirectBeam)

        # Options for the reduction output
        self.connect(self.ui.outputLOQCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.outputLOQCheckStateChanged)

        self.connect(self.ui.outputCanSASCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.outputCanSASCheckStateChanged)

        self.connect(self.ui.useRunnumberCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.useRunnumberCheckStateChanged)

        self.connect(self.ui.blogReductionCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.blogReductionCheckStateChanged)

        self.connect(self.ui.outPathPushButton,
                     SIGNAL("clicked()"),
                     self.setOutPathDialog)

        # Final selections, Queue vs Reduce and Reduce button
        self.connect(self.ui.queueReductionsCheckbox,
                     SIGNAL("stateChanged(int)"),
                     self.queueReductionsCheckStateChanged)

        self.connect(self.ui.reducePushButton,
                     SIGNAL("clicked()"),
                     self.doReduceOrQueue)

        self.connect(self.ui.cancelPushButton,
                     SIGNAL("clicked()"),
                     self.exitWidget)

        
        ###########################################
        # Initialise connections from the document#
        ###########################################

        # TODO Catch state changes that might be caused by
        # scripts running against the document

    ##############################
    # GUI initialisation Methods #
    ##############################

    def initMenus(self):
        runlist = self.doc.getRunListForMenu()
        menulist = [self.ui.sansRunMenu,
                    self.ui.sansTransMenu,
                    self.ui.bgdRunMenu,
                    self.ui.bgdTransMenu,
                    self.ui.directBeamRunMenu]

        for menu in menulist:
            menu.clear()

        self.ui.directBeamRunMenu.addItem("Direct Beam Run")
        self.ui.directBeamRunMenu.setCurrentIndex(0)
        for run in runlist:
            for menu in menulist:
                menu.addItem(run)

    ####################################
    #Method definitions for GUI actions#
    ####################################

    def selectDirectoryDialog(self):
        """Select the input file directory"""

        directory = QFileDialog.getExistingDirectory(self, 
                    'Open Directory',
                    self.doc.getInPath())
        self.setIncomingDirectory(directory)

    def setIncomingDirectory(self, qstring = None):
        """Method for setting the input file directory"""

        if qstring:
            self.doc.setInPath(qstring)
            self.ui.inPathLineEdit.setText(qstring)
        else:
            if self.ui.inPathLineEdit.displayText() != self.doc.getInPath():
                self.doc.setInPath(self.ui.inPathLineEdit.displayText())
        self.initMenus()

    def setSansRun(self, int):
        """Set the run from the current menu selection"""

        logging.debug("Gui:setSansRun: settto " +
                        self.ui.sansRunMenu.currentText())
        self.doc.setSansRun(self.ui.sansRunMenu.currentText())

    def setSansTrans(self, int):
        """Set the run from the current menu selection"""
        logging.debug("Gui:setSansTrans: settto " +
                        self.ui.sansTransMenu.currentText())
        self.doc.setSansTrans(self.ui.sansTransMenu.currentText())

    def setBgdRun(self, int):
        """Set the run from the current menu selection"""
        logging.debug("Gui:setBgdRun: settto " +
                        self.ui.bgdRunMenu.currentText())
        self.doc.setBackgroundRun(self.ui.bgdRunMenu.currentText())
    
    def setBgdTrans(self, int):
        """Set the run from the current menu selection"""
        logging.debug("Gui:setBgdTrans: settto " +
                        self.ui.bgdTransMenu.currentText())
        self.doc.setBackgroundTrans(self.ui.bgdTransMenu.currentText())

    def showRawCheckStateChanged(self, integer):
        """Reset the menus to show required input files"""
        logging.debug('SRGui: Show Raw Checkbox activated: ' + str(integer))
        if integer == 0:
            self.doc.setShowRawInMenus(False)
        elif integer == 2:
            self.doc.setShowRawInMenus(True)
        else:
            raise TypeError('Checkbox should be sending 0 or 2')
        
        self.initMenus()
        
    def showNexusCheckStateChanged(self, integer):
        """Reset the menus to show required input files"""
        logging.debug('SRGui: Show Nexus Checkbox activated: ' + str(integer))
        if integer == 0:
            self.doc.setShowNexusInMenus(False)
        elif integer == 2:
            self.doc.setShowNexusInMenus(True)
        else:
            raise TypeError('Checkbox should be sending 0 or 2')

        self.initMenus()

    def selectMaskFileDialog(self):
        """Select and set the mask file"""

        maskfilepath = QFileDialog.getOpenFileName(self, 
                    'Open Directory',
                    self.doc.getInPath())
        self.doc.setMaskfile(maskfilepath)


    def setDirectBeam(self, int):
        """Set the direct beam from the menu selection"""
        self.doc.setDirectBeam(self.ui.directBeamRunMenu.currentText())
        logging.debug("View:setDirectBeam: set to: " + 
                      self.ui.directBeamRunMenu.currentText())

    def outputLOQCheckStateChanged(self, integer):
        """Set whether a LOQ file will be output"""
        logging.debug('SRGui: Output LOQ Checkbox activated: ' + str(integer))
        if integer == 0:
            self.doc.setOutputLOQ(False)
        elif integer == 2:
            self.doc.setOutputLOQ(True)
        else:
            raise TypeError('Checkbox should be sending 0 or 2')

    def outputCanSASCheckStateChanged(self, integer):
        """Set whether a CanSAS file will be output"""
        logging.debug('SRGui: Output CanSAS Checkbox activated: ' 
                        + str(integer))
        if integer == 0:
            self.doc.setOutputCanSAS(False)
        elif integer == 2:
            self.doc.setOutputCanSAS(True)
        else:
            raise TypeError('Checkbox should be sending 0 or 2')

    def useRunnumberCheckStateChanged(self, integer):
        """Set whether the Runnumber will be used as filename"""
        logging.debug('SRGui: Use runno Checkbox activated: ' + str(integer))
        if integer == 0:
            self.doc.setUseRunnumberForOutput(False)
            self.ui.outPathPushButton.setText("Output filename...")
        elif integer == 2:
            self.doc.setUseRunnumberForOutput(True)
            self.ui.outPathPushButton.setText("Output directory...")

        else:
            raise TypeError('Checkbox should be sending 0 or 2')

    def blogReductionCheckStateChanged(self, integer):
        """Set whether the output will be blogged

        This checkbox will need to open a new widget window for
        setting various blog settings"""
        logging.debug('SRGui: Blog Checkbox activated: ' + str(integer))
        if integer == 0:
            self.doc.setBlogReduction(False)
        elif integer == 2:
            self.doc.setBlogReduction(True)
        else:
            raise TypeError('Checkbox should be sending 0 or 2')

    def setOutPathDialog(self):
        """Trigger a dialog for setting the output path

        If the filename is set to be taken from the runnumber then
        a directory selection dialog is presented. Otherwise a save
        file dialog is given. The path is given the same in both 
        cases and we will clean up when we are ready to write the
        file out. Extensions will be cleaned up at that point as 
        well.
        """
  
        if self.doc.getUseRunnumberForOutput():
            outfilepath = QFileDialog.getExistingDirectory(self, 
                    'Select Directory',
                    self.doc.getInPath())

        else:
            outfilepath = QFileDialog.getSaveFileName(self,
                    'Choose path and set filename',
                    self.doc.getInPath())
        # Then set that as the path
        self.doc.setOutPath(outfilepath)                                                      

    def queueReductionsCheckStateChanged(self, integer):
        """Set whether reductions will be run or queued"""
        logging.debug('SRGui: Queue Checkbox activated: ' + str(integer))
        if integer == 0:
            self.doc.setQueue(False)
            self.ui.reducePushButton.setText("Reduce!")
        elif integer == 2:
            self.doc.setQueue(True)
            self.ui.reducePushButton.setText("Queue...")
        else:
            raise TypeError('Checkbox should be sending 0 or 2')

    def doReduceOrQueue(self):
        """Do the reduction or add it to the queue

        The menu selections are called just to be safe. The '1's are
        required because these are usually triggered via the 
        comboboxes activated(int) signal"""

        logging.debug("View:doReduceOrQueue")
        self.setSansRun(1); self.setSansTrans(1)
        self.setBgdRun(1); self.setBgdTrans(1)
        self.setDirectBeam(1)

        if not self.doc.getQueue():
            logging.debug("View:doReduceOrQueue: Starting single reduction")
            self.doc.doSingleReduction()

        else:
            logging.debug("View:doReduceOrQueue: Starting to queue reduction")
            self.doc.queueReduction()
            if self.doc.getQueueViewVisible():
                self.queueWindow.tablemodel = QueueTableModel(self.doc)
                self.queueWindow.ui.reductionQueueTableView.setModel(
                                          self.queueWindow.tablemodel)
                self.queueWindow.show()
                return
            else:
                self.queueWindow = QueueWindowView(self.doc)
                self.queueWindow.show()
                self.doc.setQueueViewVisible(True)

    def exitWidget(self):
        """Close the window"""
        self.close()
        self.destroy()