def __init__(self, filepath=None):
        """
        MainWindow(intruments, scripts, probes)
            - intruments: depth 1 dictionary where keys are instrument names and keys are instrument classes
            - scripts: depth 1 dictionary where keys are script names and keys are script classes
            - probes: depth 1 dictionary where to be decided....?

        MainWindow(settings_file)
            - settings_file is the path to a json file that contains all the settings for the old_gui

        Returns:

        """

        print(self.startup_msg)
        self.config_filepath = None
        super(MainWindow, self).__init__()
        self.setupUi(self)

        def setup_trees():
            # COMMENT_ME

            # define data container
            self.history = deque(maxlen=500)  # history of executed commands
            self.history_model = QtGui.QStandardItemModel(self.list_history)
            self.list_history.setModel(self.history_model)
            self.list_history.show()

            self.tree_scripts.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
            self.tree_probes.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
            self.tree_settings.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)

            self.tree_gui_settings.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
            self.tree_gui_settings.doubleClicked.connect(self.edit_tree_item)

            self.current_script = None
            self.probe_to_plot = None

            # create models for tree structures, the models reflect the data
            self.tree_dataset_model = QtGui.QStandardItemModel()
            self.tree_dataset.setModel(self.tree_dataset_model)
            self.tree_dataset_model.setHorizontalHeaderLabels(['time', 'name (tag)', 'type (script)'])

            # create models for tree structures, the models reflect the data
            self.tree_gui_settings_model = QtGui.QStandardItemModel()
            self.tree_gui_settings.setModel(self.tree_gui_settings_model)
            self.tree_gui_settings_model.setHorizontalHeaderLabels(['parameter', 'value'])

            self.tree_scripts.header().setStretchLastSection(True)
        def connect_controls():
            # COMMENT_ME
            # =============================================================
            # ===== LINK WIDGETS TO FUNCTIONS =============================
            # =============================================================

            # link buttons to old_functions
            self.btn_start_script.clicked.connect(self.btn_clicked)
            self.btn_stop_script.clicked.connect(self.btn_clicked)
            self.btn_skip_subscript.clicked.connect(self.btn_clicked)
            self.btn_validate_script.clicked.connect(self.btn_clicked)
            # self.btn_plot_script.clicked.connect(self.btn_clicked)
            # self.btn_plot_probe.clicked.connect(self.btn_clicked)
            self.btn_store_script_data.clicked.connect(self.btn_clicked)
            # self.btn_plot_data.clicked.connect(self.btn_clicked)
            self.btn_save_data.clicked.connect(self.btn_clicked)
            self.btn_delete_data.clicked.connect(self.btn_clicked)


            self.btn_save_gui.triggered.connect(self.btn_clicked)
            self.btn_load_gui.triggered.connect(self.btn_clicked)
            self.btn_about.triggered.connect(self.btn_clicked)
            self.btn_exit.triggered.connect(self.close)

            self.actionSave.triggered.connect(self.btn_clicked)
            self.actionExport.triggered.connect(self.btn_clicked)
            self.actionGo_to_pylabcontrol_GitHub_page.triggered.connect(self.btn_clicked)

            self.btn_load_instruments.clicked.connect(self.btn_clicked)
            self.btn_load_scripts.clicked.connect(self.btn_clicked)
            self.btn_load_probes.clicked.connect(self.btn_clicked)

            # Helper function to make only column 1 editable
            def onScriptParamClick(item, column):
                tree = item.treeWidget()
                if column == 1 and not isinstance(item.value, (Script, Instrument)) and not item.is_point():
                    # self.tree_scripts.editItem(item, column)
                    tree.editItem(item, column)

            # tree structures
            self.tree_scripts.itemClicked.connect(
                lambda: onScriptParamClick(self.tree_scripts.currentItem(), self.tree_scripts.currentColumn()))
            self.tree_scripts.itemChanged.connect(lambda: self.update_parameters(self.tree_scripts))
            self.tree_scripts.itemClicked.connect(self.btn_clicked)
            # self.tree_scripts.installEventFilter(self)
            # QtWidgets.QTreeWidget.installEventFilter(self)


            self.tabWidget.currentChanged.connect(lambda : self.switch_tab())
            self.tree_dataset.clicked.connect(lambda: self.btn_clicked())

            self.tree_settings.itemClicked.connect(
                lambda: onScriptParamClick(self.tree_settings.currentItem(), self.tree_settings.currentColumn()))
            self.tree_settings.itemChanged.connect(lambda: self.update_parameters(self.tree_settings))
            self.tree_settings.itemExpanded.connect(lambda: self.refresh_instruments())


            # set the log_filename when checking loggin
            self.chk_probe_log.toggled.connect(lambda: self.set_probe_file_name(self.chk_probe_log.isChecked()))
            self.chk_probe_plot.toggled.connect(self.btn_clicked)

            self.chk_show_all.toggled.connect(self._show_hide_parameter)

        self.create_figures()


        # create a "delegate" --- an editor that uses our new Editor Factory when creating editors,
        # and use that for tree_scripts
        # needed to avoid rounding of numbers
        delegate = QtWidgets.QStyledItemDelegate()
        new_factory = CustomEditorFactory()
        delegate.setItemEditorFactory(new_factory)
        self.tree_scripts.setItemDelegate(delegate)
        setup_trees()

        connect_controls()

        if filepath is None:
            path_to_config = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'save_config.json'))
            if os.path.isfile(path_to_config) and os.access(path_to_config, os.R_OK):
                print('path_to_config', path_to_config)
                with open(path_to_config) as f:
                    config_data = json.load(f)
                if 'last_save_path' in config_data.keys():
                    self.config_filepath = config_data['last_save_path']
                    self.log('Checking for previous save of GUI here: {0}'.format(self.config_filepath))
            else:
                self.log('Starting with blank GUI; configuration files will be saved here: {0}'.format(self._DEFAULT_CONFIG["gui_settings"]))

        elif os.path.isfile(filepath) and os.access(filepath, os.R_OK):
            self.config_filepath = filepath

        elif not os.path.isfile(filepath):
            self.log('Could not find file given to open --- starting with a blank GUI')

        self.instruments = {}
        self.scripts = {}
        self.probes = {}
        self.gui_settings = {'scripts_folder': '', 'data_folder': ''}
        self.gui_settings_hidden = {'scripts_source_folder': ''}

        self.load_config(self.config_filepath)

        self.data_sets = {}  # todo: load datasets from tmp folder
        self.read_probes = ReadProbes(self.probes)
        self.tabWidget.setCurrentIndex(0) # always show the script tab

        # == create a thread for the scripts ==
        self.script_thread = QThread()
        self._last_progress_update = None # used to keep track of status updates, to block updates when they occur to often

        self.chk_show_all.setChecked(True)
        self.actionSave.setShortcut(QtGui.QKeySequence.Save)
        self.actionExport.setShortcut(self.tr('Ctrl+E'))
        self.list_history.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)

        if self.config_filepath is None:
            self.config_filepath = os.path.join(self._DEFAULT_CONFIG["gui_settings"], 'gui.b26')
def __init__ ( self , filepath = None ) : print ( self . startup_msg ) self . config_filepath = None super ( MainWindow , self ) . __init__ ( ) self . setupUi ( self ) def setup_trees ( ) : self . history = deque ( maxlen = 500 ) self . history_model = QtGui . QStandardItemModel ( self . list_history ) self . list_history . setModel ( self . history_model ) self . list_history . show ( ) self . tree_scripts . setEditTriggers ( QtWidgets . QAbstractItemView . NoEditTriggers ) self . tree_probes . setEditTriggers ( QtWidgets . QAbstractItemView . NoEditTriggers ) self . tree_settings . setEditTriggers ( QtWidgets . QAbstractItemView . NoEditTriggers ) self . tree_gui_settings . setEditTriggers ( QtWidgets . QAbstractItemView . NoEditTriggers ) self . tree_gui_settings . doubleClicked . connect ( self . edit_tree_item ) self . current_script = None self . probe_to_plot = None self . tree_dataset_model = QtGui . QStandardItemModel ( ) self . tree_dataset . setModel ( self . tree_dataset_model ) self . tree_dataset_model . setHorizontalHeaderLabels ( [ 'time' , 'name (tag)' , 'type (script)' ] ) self . tree_gui_settings_model = QtGui . QStandardItemModel ( ) self . tree_gui_settings . setModel ( self . tree_gui_settings_model ) self . tree_gui_settings_model . setHorizontalHeaderLabels ( [ 'parameter' , 'value' ] ) self . tree_scripts . header ( ) . setStretchLastSection ( True ) def connect_controls ( ) : self . btn_start_script . clicked . connect ( self . btn_clicked ) self . btn_stop_script . clicked . connect ( self . btn_clicked ) self . btn_skip_subscript . clicked . connect ( self . btn_clicked ) self . btn_validate_script . clicked . connect ( self . btn_clicked ) self . btn_store_script_data . clicked . connect ( self . btn_clicked ) self . btn_save_data . clicked . connect ( self . btn_clicked ) self . btn_delete_data . clicked . connect ( self . btn_clicked ) self . btn_save_gui . triggered . connect ( self . btn_clicked ) self . btn_load_gui . triggered . connect ( self . btn_clicked ) self . btn_about . triggered . connect ( self . btn_clicked ) self . btn_exit . triggered . connect ( self . close ) self . actionSave . triggered . connect ( self . btn_clicked ) self . actionExport . triggered . connect ( self . btn_clicked ) self . actionGo_to_pylabcontrol_GitHub_page . triggered . connect ( self . btn_clicked ) self . btn_load_instruments . clicked . connect ( self . btn_clicked ) self . btn_load_scripts . clicked . connect ( self . btn_clicked ) self . btn_load_probes . clicked . connect ( self . btn_clicked ) def onScriptParamClick ( item , column ) : tree = item . treeWidget ( ) if column == 1 and not isinstance ( item . value , ( Script , Instrument ) ) and not item . is_point ( ) : tree . editItem ( item , column ) self . tree_scripts . itemClicked . connect ( lambda : onScriptParamClick ( self . tree_scripts . currentItem ( ) , self . tree_scripts . currentColumn ( ) ) ) self . tree_scripts . itemChanged . connect ( lambda : self . update_parameters ( self . tree_scripts ) ) self . tree_scripts . itemClicked . connect ( self . btn_clicked ) self . tabWidget . currentChanged . connect ( lambda : self . switch_tab ( ) ) self . tree_dataset . clicked . connect ( lambda : self . btn_clicked ( ) ) self . tree_settings . itemClicked . connect ( lambda : onScriptParamClick ( self . tree_settings . currentItem ( ) , self . tree_settings . currentColumn ( ) ) ) self . tree_settings . itemChanged . connect ( lambda : self . update_parameters ( self . tree_settings ) ) self . tree_settings . itemExpanded . connect ( lambda : self . refresh_instruments ( ) ) self . chk_probe_log . toggled . connect ( lambda : self . set_probe_file_name ( self . chk_probe_log . isChecked ( ) ) ) self . chk_probe_plot . toggled . connect ( self . btn_clicked ) self . chk_show_all . toggled . connect ( self . _show_hide_parameter ) self . create_figures ( ) delegate = QtWidgets . QStyledItemDelegate ( ) new_factory = CustomEditorFactory ( ) delegate . setItemEditorFactory ( new_factory ) self . tree_scripts . setItemDelegate ( delegate ) setup_trees ( ) connect_controls ( ) if filepath is None : path_to_config = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , os . pardir , 'save_config.json' ) ) if os . path . isfile ( path_to_config ) and os . access ( path_to_config , os . R_OK ) : print ( 'path_to_config' , path_to_config ) with open ( path_to_config ) as f : config_data = json . load ( f ) if 'last_save_path' in config_data . keys ( ) : self . config_filepath = config_data [ 'last_save_path' ] self . log ( 'Checking for previous save of GUI here: {0}' . format ( self . config_filepath ) ) else : self . log ( 'Starting with blank GUI; configuration files will be saved here: {0}' . format ( self . _DEFAULT_CONFIG [ "gui_settings" ] ) ) elif os . path . isfile ( filepath ) and os . access ( filepath , os . R_OK ) : self . config_filepath = filepath elif not os . path . isfile ( filepath ) : self . log ( 'Could not find file given to open --- starting with a blank GUI' ) self . instruments = { } self . scripts = { } self . probes = { } self . gui_settings = { 'scripts_folder' : '' , 'data_folder' : '' } self . gui_settings_hidden = { 'scripts_source_folder' : '' } self . load_config ( self . config_filepath ) self . data_sets = { } self . read_probes = ReadProbes ( self . probes ) self . tabWidget . setCurrentIndex ( 0 ) self . script_thread = QThread ( ) self . _last_progress_update = None self . chk_show_all . setChecked ( True ) self . actionSave . setShortcut ( QtGui . QKeySequence . Save ) self . actionExport . setShortcut ( self . tr ( 'Ctrl+E' ) ) self . list_history . setEditTriggers ( QtWidgets . QAbstractItemView . NoEditTriggers ) if self . config_filepath is None : self . config_filepath = os . path . join ( self . _DEFAULT_CONFIG [ "gui_settings" ] , 'gui.b26' )
MainWindow(intruments, scripts, probes)
            - intruments: depth 1 dictionary where keys are instrument names and keys are instrument classes
            - scripts: depth 1 dictionary where keys are script names and keys are script classes
            - probes: depth 1 dictionary where to be decided....?

        MainWindow(settings_file)
            - settings_file is the path to a json file that contains all the settings for the old_gui

        Returns: