Exemple #1
0
    def __init__(self, parent=None, title='Macro editor'):
        # This class derivates from a Qt Widget so we have to call
        # the class builder ".__init__()"
        QWidget.__init__(self)
        # "self" is now a Qt Widget, then we instantiate the user interface
        # generated with QtDesigner and call it self.ui
        self.ui = Ui_Macro_editor()
        # Now we have to feed the GUI building method of this object (self.ui)
        # with a reference to the Qt Widget where it will appear, i.e. itself
        # but the elements of the GUI will actually be children of the GUI (i.e of self.ui not of self)
        self.ui.setupUi(self)
        self.setWindowTitle(title)

        ### Dirty FIX: the macro editor is in a layout and a group box which somehow
        ### put it way down the list of children, so we need the 6th order parent of that to get to the main !
        ##self.main=self.parent().parent().parent().parent().parent().parent()
        ### FIXED:the main class now simply gives a link to itself when it instantiates the Macro Editor
        ### this has the added benefit of keeping track of which class may use the main
        self.main = parent
        self.macro_isActive = False
    def __init__(self,parent=None,title='Macro editor'):
        # This class derivates from a Qt Widget so we have to call
        # the class builder ".__init__()"
        QWidget.__init__(self)
        # "self" is now a Qt Widget, then we instantiate the user interface
        # generated with QtDesigner and call it self.ui
        self.ui = Ui_Macro_editor()
        # Now we have to feed the GUI building method of this object (self.ui)
        # with a reference to the Qt Widget where it will appear, i.e. itself
        # but the elements of the GUI will actually be children of the GUI (i.e of self.ui not of self)
        self.ui.setupUi(self)
        self.setWindowTitle(title)

        ### Dirty FIX: the macro editor is in a layout and a group box which somehow
        ### put it way down the list of children, so we need the 6th order parent of that to get to the main !
        ##self.main=self.parent().parent().parent().parent().parent().parent()
        ### FIXED:the main class now simply gives a link to itself when it instantiates the Macro Editor
        ### this has the added benefit of keeping track of which class may use the main
        self.main=parent
        self.macro_isActive=False
Exemple #3
0
class Macro_editor(QWidget):
    def __init__(self, parent=None, title='Macro editor'):
        # This class derivates from a Qt Widget so we have to call
        # the class builder ".__init__()"
        QWidget.__init__(self)
        # "self" is now a Qt Widget, then we instantiate the user interface
        # generated with QtDesigner and call it self.ui
        self.ui = Ui_Macro_editor()
        # Now we have to feed the GUI building method of this object (self.ui)
        # with a reference to the Qt Widget where it will appear, i.e. itself
        # but the elements of the GUI will actually be children of the GUI (i.e of self.ui not of self)
        self.ui.setupUi(self)
        self.setWindowTitle(title)

        ### Dirty FIX: the macro editor is in a layout and a group box which somehow
        ### put it way down the list of children, so we need the 6th order parent of that to get to the main !
        ##self.main=self.parent().parent().parent().parent().parent().parent()
        ### FIXED:the main class now simply gives a link to itself when it instantiates the Macro Editor
        ### this has the added benefit of keeping track of which class may use the main
        self.main = parent
        self.macro_isActive = False

    def setupmain(self, main):
        # first called at startup by main program
        self.main = main

    def update_commands(self, meas_prog_list_byname):
        global Regexprogramfile
        Regexprogramfile = "(" + "|".join(meas_prog_list_byname) + ")"
        self.valid_list_of_commands = self.get_list_of_commands()
        #initiate syntax highlighting for the macro editor
        self.highlighter = MacroHighlighter(self.ui.macro_textbox.document(),
                                            self.valid_list_of_commands)
        #update the list of available macro commands in the user interface
        model = QStandardItemModel()
        parentItem = model.invisibleRootItem()
        for command in self.valid_list_of_commands:
            parentItem.appendRow(QStandardItem(command.label))
        self.ui.macrocommandtree.setModel(model)

    def setuptimer(self):
        # second called at startup by main program
        self.valid_list_of_commands = self.get_list_of_commands()

        self.macro_timer = QTimer()
        #Use a single shot timer in between commands
        #otherwise it may fire again before the task is completed
        self.macro_timer.setSingleShot(True)
        self.macro_timer.timeout.connect(self.next_command)

    def get_list_of_commands(self):
        # List the Macro command that will be loaded and available
        # into the Macro editor.
        # Once you have created a new Macro command class in this file
        # you must add it in this list for it to be available in
        # the Macro editor.
        # You may also remove commands from this list if you want to deactivate them
        return [
            #           AngleCommand(),
            CommentsCommand(),
            WaitCommand(),
            WaitForEpoch(),
            #            SetFieldCommand(),
            #            WaitForHStableCommand(),
            WaitForMeasureCommand(),
            #            SetPersistFieldCommand(),
            #            SetTempCommand(),
            #            SetHeaterCommand(),
            #            WaitForTStableCommand(),
            #            SetTempVTICommand(),
            #            SetVTIHeaterCommand(),
            SetPPMSTempCommand(),
            SetPPMSFieldCommand(),
            WaitForTPPMSStableCommand(),
            WaitForHPPMSStableCommand(),
            SetSaveFileCommand(),
            StartMeasureCommand(),
            StopMeasureCommand(),
            EmailCommand(),
            EmailFileCommand(),
            EmailDirCommand(),
            SetICommand(),
            SetVCommand(),
            SetUICommand(self.main)
        ]

    def save_macro(self):
        #the static method calls the native file system method
        fileName = QFileDialog.getSaveFileName(self,
                                               "Save Macro",
                                               directory="./Macro",
                                               filter="Macro file (*.mac)")
        #open() does not work with 'unicode' type object, conversion is needed
        #        fileName=fileName[0].encode('utf8')
        if fileName != "":
            #get the macro text from frontpanel text box
            mac_unicode = self.ui.macro_textbox.toPlainText()
            #print fileName
            #(u'C:/Python27/Lib/site-packages/pyqtgraph/examples/test.txt', u'All Files (*.*)')
            #WARNING: write() and open() do not work with 'unicode' type object
            #they have to be converted to a string first (i.e. a list of bytes)
            savefile = open(fileName, 'w')
            savefile.write(mac_unicode.encode('utf8'))
            savefile.close()

    def open_macro(self):
        fileName = QFileDialog.getOpenFileName(self,
                                               "Open Macro",
                                               directory="./Macro",
                                               filter="Macro file (*.mac)")
        #open() does not work with 'unicode' type object, conversion is needed
        #        fileName=fileName[0].encode('utf8')
        if fileName != "":
            open_file = open(fileName, 'r')
            self.ui.macro_textbox.setPlainText(
                unicode(
                    open_file.read(-1),
                    encoding='utf-8'))  #'-1' to read the whole file at once
            open_file.close()

    def run_macro(self):
        if not (self.macro_isActive):
            self.macro_isActive = True
            self.current_macro = self.ui.macro_textbox.toPlainText().encode(
                'utf8').split('\n')
            self.current_line = 0
            self.cur_mac_max = len(self.current_macro)
            #single shot timer
            print "Starting Macro"
            self.macro_timer.start(0)

    def next_command(self):
        if self.current_line < self.cur_mac_max:
            #update the info line with the line being analyzed
            action = self.current_macro[self.current_line]
            self.ui.mac_curr_line.setText("line " + str(self.current_line) +
                                          ": " + action)

            next_move = 1
            wait_time = 500
            for command in self.valid_list_of_commands:
                #run the command, if command matches the line being analyzed
                if command.regexp.indexIn(action) != -1:
                    command.run(self.main)
                    next_move = command.next_move
                    wait_time = command.wait_time
                    break  #break the for loop
            #go to line N+next_move of the current macro, after wait_time milliseconds
            self.current_line += next_move
            self.macro_timer.start(wait_time)
        else:
            #end of macro reached
            self.stop_macro()

    def stop_macro(self):
        self.macro_timer.stop()
        self.macro_isActive = False
        #TODO : signal/slot !!!
        if self.main.measurements_thread.isAlive():
            self.main.stop_measurements()
        print "End of Macro"
class Macro_editor(QWidget):
    def __init__(self,parent=None,title='Macro editor'):
        # This class derivates from a Qt Widget so we have to call
        # the class builder ".__init__()"
        QWidget.__init__(self)
        # "self" is now a Qt Widget, then we instantiate the user interface
        # generated with QtDesigner and call it self.ui
        self.ui = Ui_Macro_editor()
        # Now we have to feed the GUI building method of this object (self.ui)
        # with a reference to the Qt Widget where it will appear, i.e. itself
        # but the elements of the GUI will actually be children of the GUI (i.e of self.ui not of self)
        self.ui.setupUi(self)
        self.setWindowTitle(title)

        ### Dirty FIX: the macro editor is in a layout and a group box which somehow
        ### put it way down the list of children, so we need the 6th order parent of that to get to the main !
        ##self.main=self.parent().parent().parent().parent().parent().parent()
        ### FIXED:the main class now simply gives a link to itself when it instantiates the Macro Editor
        ### this has the added benefit of keeping track of which class may use the main
        self.main=parent
        self.macro_isActive=False

    def setupmain(self,main):
        # first called at startup by main program
        self.main = main

    def update_commands(self,meas_prog_list_byname):
        global Regexprogramfile
        Regexprogramfile="("+"|".join(meas_prog_list_byname)+")"
        self.valid_list_of_commands = self.get_list_of_commands()
        #initiate syntax highlighting for the macro editor
        self.highlighter = MacroHighlighter(self.ui.macro_textbox.document(),self.valid_list_of_commands)
        #update the list of available macro commands in the user interface
        model=QStandardItemModel()
        parentItem = model.invisibleRootItem()
        for command in self.valid_list_of_commands:
            parentItem.appendRow(QStandardItem(command.label))
        self.ui.macrocommandtree.setModel(model)

    def setuptimer(self):
        # second called at startup by main program
        self.valid_list_of_commands = self.get_list_of_commands()

        self.macro_timer = QTimer()
        #Use a single shot timer in between commands
        #otherwise it may fire again before the task is completed
        self.macro_timer.setSingleShot(True)
        self.macro_timer.timeout.connect(self.next_command)
                       


    def get_list_of_commands(self):        
        # List the Macro command that will be loaded and available
        # into the Macro editor.
        # Once you have created a new Macro command class in this file
        # you must add it in this list for it to be available in 
        # the Macro editor.
        # You may also remove commands from this list if you want to deactivate them
        return [
#           AngleCommand(),
            CommentsCommand(),
            WaitCommand(),
            WaitForEpoch(),
#            SetFieldCommand(),
#            WaitForHStableCommand(),
            WaitForMeasureCommand(),
#            SetPersistFieldCommand(),
#            SetTempCommand(),
#            SetHeaterCommand(),
#            WaitForTStableCommand(),
#            SetTempVTICommand(),
#            SetVTIHeaterCommand(),
            SetPPMSTempCommand(),
            SetPPMSFieldCommand(),
            WaitForTPPMSStableCommand(),
            WaitForHPPMSStableCommand(),
            SetSaveFileCommand(),
            StartMeasureCommand(),
            StopMeasureCommand(),
            EmailCommand(),
            EmailFileCommand(),
            EmailDirCommand(),
            SetICommand(),
            SetVCommand(),
            SetUICommand(self.main)]
                
    def save_macro(self):
        #the static method calls the native file system method
        fileName = QFileDialog.getSaveFileName(self,"Save Macro",directory= "./Macro",filter="Macro file (*.mac)")
        #open() does not work with 'unicode' type object, conversion is needed 
#        fileName=fileName[0].encode('utf8')
        if fileName!="":
            #get the macro text from frontpanel text box
            mac_unicode=self.ui.macro_textbox.toPlainText()
            #print fileName
            #(u'C:/Python27/Lib/site-packages/pyqtgraph/examples/test.txt', u'All Files (*.*)')
            #WARNING: write() and open() do not work with 'unicode' type object
            #they have to be converted to a string first (i.e. a list of bytes)
            savefile=open(fileName,'w')
            savefile.write(mac_unicode.encode('utf8'))
            savefile.close()
                
    def open_macro(self):
        fileName = QFileDialog.getOpenFileName(self,"Open Macro",directory= "./Macro",filter="Macro file (*.mac)")
        #open() does not work with 'unicode' type object, conversion is needed 
#        fileName=fileName[0].encode('utf8')
        if fileName!="":
            open_file=open(fileName,'r')
            self.ui.macro_textbox.setPlainText(unicode(open_file.read(-1),encoding='utf-8')) #'-1' to read the whole file at once
            open_file.close()

    def run_macro(self):
        if not(self.macro_isActive):
            self.macro_isActive=True
            self.current_macro=self.ui.macro_textbox.toPlainText().encode('utf8').split('\n')
            self.current_line=0
            self.cur_mac_max=len(self.current_macro)
            #single shot timer
            print "Starting Macro"
            self.macro_timer.start(0)
    
    def next_command(self):
        if self.current_line<self.cur_mac_max:
            #update the info line with the line being analyzed
            action=self.current_macro[self.current_line]
            self.ui.mac_curr_line.setText("line "+str(self.current_line)+": "+action)
            
            next_move=1
            wait_time=500
            for command in self.valid_list_of_commands:
                #run the command, if command matches the line being analyzed
                if command.regexp.indexIn(action)!=-1:
                    command.run(self.main)
                    next_move=command.next_move
                    wait_time=command.wait_time
                    break #break the for loop
            #go to line N+next_move of the current macro, after wait_time milliseconds
            self.current_line+=next_move
            self.macro_timer.start(wait_time)
        else:
            #end of macro reached
            self.stop_macro()
            
    def stop_macro(self):
        self.macro_timer.stop()
        self.macro_isActive=False
        #TODO : signal/slot !!!
        if self.main.measurements_thread.isAlive(): 
            self.main.stop_measurements()
        print "End of Macro"
Exemple #5
0
 def __init__(self,parent=None,title='Macro editor'):
     # This class derivates from a Qt Widget so we have to call
     # the class builder ".__init__()"
     QWidget.__init__(self)
     # "self" is now a Qt Widget, then we instantiate the user interface
     # generated with QtDesigner and call it self.ui
     self.ui = Ui_Macro_editor()
     # Now we have to feed the GUI building method of this object (self.ui)
     # with a reference to the Qt Widget where it will appear, i.e. itself
     # but the elements of the GUI will actually be children of the GUI (i.e of self.ui not of self)
     self.ui.setupUi(self)
     self.setWindowTitle(title)
     
     # List the Macro command that will be loaded and available
     # into the Macro editor.
     # Once you have created a new Macro command class in this file
     # you must add it in this list for it to be available in 
     # the Macro editor.
     # You may also remove commands from this list if you want to deactivate them
     self.valid_list_of_commands=[
                                 AngleCommand(),
                                 CommentsCommand(),
                                 WaitCommand(),
                                 WaitForEpoch(),
                                 SetFieldCommand(),
                                 WaitForHStableCommand(),
                                 WaitForMeasureCommand(),
                                 SetPersistFieldCommand(),
                                 SetTempCommand(),
                                 SetHeaterCommand(),
                                 WaitForTStableCommand(),
                                 SetTempVTICommand(),
                                 SetVTIHeaterCommand(),
                                 SetSaveFileCommand(),
                                 StartMeasureCommand(),
                                 StopMeasureCommand(),
                                 EmailCommand(),
                                 EmailFileCommand(),
                                 EmailDirCommand(),
                                 SetICommand(),
                                 SetVCommand()]        
     
     ### Dirty FIX: the macro editor is in a layout and a group box which somehow
     ### put it way down the list of children, so we need the 6th order parent of that to get to the main !
     ##self.main=self.parent().parent().parent().parent().parent().parent()
     ### FIXED:the main class now simply gives a link to itself when it instantiates the Macro Editor
     ### this has the added benefit of keeping track of which class may use the main
     self.main=parent
     self.macro_isActive=False
     
     self.macro_timer = QTimer()
     #Use a single shot timer in between commands
     #otherwise it may fire again before the task is completed
     self.macro_timer.setSingleShot(True)
     self.macro_timer.timeout.connect(self.next_command)
            
     #initiate syntax highlighting for the macro editor
     self.highlighter = MacroHighlighter(self.ui.macro_textbox.document(),self.valid_list_of_commands)
     
     #update the list of available macro commands in the user interface
     model=QStandardItemModel()
     parentItem = model.invisibleRootItem()
     for command in self.valid_list_of_commands:
         parentItem.appendRow(QStandardItem(command.label))
     self.ui.macrocommandtree.setModel(model)