def clear_backup(self):
     folder = vex_settings.backup_folder()
     for f in os.listdir(folder):
         try:
             os.remove(os.path.join(folder, f))
         except:
             pass
 def clear_backup(self):
     folder = vex_settings.backup_folder()
     if os.path.exists(folder):
         for f in os.listdir(folder):
             try:
                 os.remove(os.path.join(folder, f))
             except:
                 pass
    def update_backup_menu(self):
        actions = self.backup_menu_act.actions()
        for i in actions[3:]:
            self.backup_menu_act.removeAction(i)

        backupdir = vex_settings.backup_folder()
        for b in glob.glob1(backupdir, '*.backup'):
            act = QAction(b, self)
            # act.setData(os.path.join(backupdir, b).replace('\\','/'))
            path = os.path.join(backupdir, b).replace('\\', '/')
            act.triggered.connect(lambda x=path: self.restore_backup(x))
            self.backup_menu_act.addAction(act)
    def update_backup_menu(self):
        actions = self.backup_menu_act.actions()
        for i in actions[3:]:
            self.backup_menu_act.removeAction(i)

        backupdir = vex_settings.backup_folder()
        for b in glob.glob1(backupdir, '*.backup'):
            act = QAction(b, self)
            # act.setData(os.path.join(backupdir, b).replace('\\','/'))
            path = os.path.join(backupdir, b).replace('\\','/')
            act.triggered.connect(lambda x=path: self.restore_backup(x))
            self.backup_menu_act.addAction(act)
    def __init__(self):
        super(VEXEditorPanelClass, self).__init__()
        self.setupUi(self)
        ver = check_version.get_current_version()
        self.version = 'v%s.%s.%s' % (ver[0], ver[1], ver[2])
        # settings
        self.settings = vex_settings.EditorSettingsClass()
        self.theme = ''
        self.theme_colors = {}
        # self.use_help_window = False
        self.load_settings()
        self.hstyle = hqt.get_h14_style(self.theme)
        # build ui
        self.errors = error_browser.ErrorBrowserWidget()
        self.error_browser_ly.addWidget(self.errors)
        self.errors.hide()

        self.help_wd = help_window.HelpWindow(self)
        self.help_ly.addWidget(self.help_wd)
        # self.help_wd.hide()

        self.tab = tab_widget.VEXEditorTabWidget(self)
        self.tab_ly.addWidget(self.tab)
        self.tab.update_infoSignal.connect(self.set_tab_info)
        self.tab.messageSignal.connect(self.show_status_message)
        self.tab.lastClosedSignal.connect(self.last_tab_closed)
        self.tab.currentChanged.connect(self.update_help_window)

        # self.help_btn = QPushButton('H')
        # self.help_btn.setMaximumSize(QSize(20,20))

        # def toggle_help_window():
        #     res = self.help_wd.toggle_visible()
        # self.splitter.setEnabled(res)
        # if res:
        #     self.splitter.setSizes([10000,200])
        # else:
        #     self.splitter.setSizes([10000,0])
        # self.help_btn.clicked.connect(toggle_help_window)
        self.splitter.setSizes([10000, 0])
        # self.splitter.setEnabled(False)
        # self.statusBar().addPermanentWidget( self.help_btn)

        #icons
        for btn in self.load_from_file_btn, self.load_from_selected_extra_btn, self.save_current_btn, self.reload_current_btn,\
                self.blank_tab_btn, self.load_from_selected_btn:
            btn.setIconSize(QSize(30, 30))
        self.load_from_file_btn.setText('')
        self.load_from_file_btn.setIcon(QIcon(icons['header']))

        self.load_from_selected_extra_btn.setText('')
        self.load_from_selected_extra_btn.setIcon(QIcon(icons['vopnode_list']))

        self.load_from_selected_btn.setText('')
        self.load_from_selected_btn.setIcon(QIcon(icons['wrangle']))

        self.save_current_btn.setText('')
        self.save_current_btn.setIcon(QIcon(icons['save']))

        self.reload_current_btn.setText('')
        self.reload_current_btn.setIcon(QIcon(icons['reload_sourse']))

        self.blank_tab_btn.setText('')
        self.blank_tab_btn.setIcon(QIcon(icons['blank']))

        # connects
        self.load_from_selected_extra_btn.clicked.connect(self.create_parm_tab)
        self.load_from_selected_btn.clicked.connect(
            lambda: self.create_parm_tab(True))
        self.create_from_node_act.triggered.connect(self.create_parm_tab)
        self.load_from_file_btn.clicked.connect(self.create_file_tab)
        self.create_from_file_act.triggered.connect(self.create_file_tab)
        self.reload_current_btn.clicked.connect(self.tab.reload_source)
        self.reload_source_act.triggered.connect(self.tab.reload_source)
        self.save_current_btn.clicked.connect(self.tab.save_current)
        self.save_to_new_act.triggered.connect(self.tab.save_as_current)
        self.save_section_act.triggered.connect(self.tab.save_current)
        self.show_sourse_btn.clicked.connect(self.tab.select_tab_node)
        self.show_sourse_btn_2.clicked.connect(self.tab.open_tab_file)
        self.blank_tab_btn.clicked.connect(self.create_empty_tab)
        self.create_empty_act.triggered.connect(self.create_empty_tab)
        self.context_help_act.triggered.connect(self.tab.show_context_help)
        self.vex_manual_act.triggered.connect(self.tab.open_VEX_manual)
        self.manual_act.triggered.connect(
            lambda: self.open_url(vex_settings.help_url))
        self.about_act.triggered.connect(self.show_about)
        # self.save_tabs_in_hip_act.triggered.connect(self.tab.save_tabs_to_hip)
        self.load_tabs_from_hip_act.triggered.connect(
            self.tab.restore_tabs_from_hip)
        self.clear_tabs_act.triggered.connect(self.tab.clear_tabs_node)
        self.check_new_version_act.triggered.connect(
            check_version.check_version)
        for act in self.auto_create_parms_act, self.save_tabs_in_hip_act, self.use_hou_browser_act, self.help_window_act:
            act.triggered.connect(self.save_settings)
        # self.set_font_size_act.triggered.connect(self.set_font_size)
        self.live_template_editor_act.triggered.connect(
            self.open_live_template_editor)
        self.options_act.triggered.connect(self.open_options_dialog)
        self.menu_tabs.aboutToShow.connect(self.update_backup_menu)
        self.open_backup_folder_act.triggered.connect(
            lambda: webbrowser.open(vex_settings.backup_folder()))
        self.clear_backups_act.triggered.connect(self.clear_backup)
        self.open_theme_editor_act.triggered.connect(self.open_theme_editor)
        self.open_settings_folder_act.triggered.connect(
            self.open_settings_folder)
        self.find_replace_act.triggered.connect(self.tab.update_replace_dialog)

        # default visibility
        self.file_info_wd.setVisible(0)
        self.node_info_wd.setVisible(0)
        self.reload_current_btn.setEnabled(0)
        self.save_current_btn.setEnabled(0)

        # temp ui state
        # menu
        self.theme_menu()
        # save main widget to main namespace
        main['vexeditor'] = self

        # start
        self.check_tabs_exists()
        self.update_templates_menu()
        QTimer.singleShot(50, lambda: self.set_theme(self.theme))
        vex_parser.generate()
    def __init__(self):
        super(VEXEditorPanelClass, self).__init__()
        self.setupUi(self)
        ver = check_version.get_current_version()
        self.version = 'v%s.%s.%s' % (ver[0], ver[1], ver[2])
        # settings
        self.settings = vex_settings.EditorSettingsClass()
        self.theme = ''
        self.theme_colors = {}
        self.load_settings()
        self.hstyle = hqt.get_h14_style(self.theme)
        # build ui
        self.errors = error_browser.ErrorBrowserWidget()
        self.error_browser_ly.addWidget(self.errors)
        self.errors.hide()
        self.tab = tab_widget.VEXEditorTabWidget(self)
        self.tab_ly.addWidget(self.tab)
        self.tab.update_infoSignal.connect(self.set_tab_info)
        self.tab.messageSignal.connect(self.show_status_message)
        self.tab.lastClosedSignal.connect(self.last_tab_closed)

        #icons
        for btn in self.load_from_file_btn, self.load_from_selected_extra_btn, self.save_current_btn, self.reload_current_btn,\
                self.blank_tab_btn, self.load_from_selected_btn:
            btn.setIconSize(QSize(30,30))
        self.load_from_file_btn.setText('')
        self.load_from_file_btn.setIcon(QIcon(icons['header']))

        self.load_from_selected_extra_btn.setText('')
        self.load_from_selected_extra_btn.setIcon(QIcon(icons['vopnode_list']))

        self.load_from_selected_btn.setText('')
        self.load_from_selected_btn.setIcon(QIcon(icons['wrangle']))


        self.save_current_btn.setText('')
        self.save_current_btn.setIcon(QIcon(icons['save']))

        self.reload_current_btn.setText('')
        self.reload_current_btn.setIcon(QIcon(icons['reload_sourse']))

        self.blank_tab_btn.setText('')
        self.blank_tab_btn.setIcon(QIcon(icons['blank']))

        # connects
        self.load_from_selected_extra_btn.clicked.connect(self.create_parm_tab)
        self.load_from_selected_btn.clicked.connect(lambda :self.create_parm_tab(True))
        self.create_from_node_act.triggered.connect(self.create_parm_tab)
        self.load_from_file_btn.clicked.connect(self.create_file_tab)
        self.create_from_file_act.triggered.connect(self.create_file_tab)
        self.reload_current_btn.clicked.connect(self.tab.reload_source)
        self.reload_source_act.triggered.connect(self.tab.reload_source)
        self.save_current_btn.clicked.connect(self.tab.save_current)
        self.save_section_act.triggered.connect(self.tab.save_current)
        self.show_sourse_btn.clicked.connect(self.tab.select_tab_node)
        self.show_sourse_btn_2.clicked.connect(self.tab.open_tab_file)
        self.blank_tab_btn.clicked.connect(self.create_empty_tab)
        self.create_empty_act.triggered.connect(self.create_empty_tab)
        self.context_help_act.triggered.connect(self.tab.show_context_help)
        self.vex_manual_act.triggered.connect(self.tab.open_VEX_manual)
        self.manual_act.triggered.connect(lambda :self.open_url(vex_settings.help_url))
        self.about_act.triggered.connect(self.show_about)
        # self.save_tabs_in_hip_act.triggered.connect(self.tab.save_tabs_to_hip)
        self.load_tabs_from_hip_act.triggered.connect(self.tab.restore_tabs_from_hip)
        self.clear_tabs_act.triggered.connect(self.tab.clear_tabs_node)
        self.check_new_version_act.triggered.connect(check_version.check_version)
        for act in self.auto_create_parms_act, self.save_tabs_in_hip_act, self.use_hou_browser_act:
            act.triggered.connect(self.save_settings)
        # self.set_font_size_act.triggered.connect(self.set_font_size)
        self.live_template_editor_act.triggered.connect(self.open_live_template_editor)
        self.options_act.triggered.connect(self.open_options_dialog)
        self.menu_tabs.aboutToShow.connect(self.update_backup_menu)
        self.open_backup_folder_act.triggered.connect(lambda :webbrowser.open(vex_settings.backup_folder()))
        self.clear_backups_act.triggered.connect(self.clear_backup)
        self.open_theme_editor_act.triggered.connect(self.open_theme_editor)

        # default visibility
        self.file_info_wd.setVisible(0)
        self.node_info_wd.setVisible(0)
        self.reload_current_btn.setEnabled(0)
        self.save_current_btn.setEnabled(0)

        # temp ui state
        # menu
        self.theme_menu()
        # save main widget to main namespace
        main['vexeditor'] = self

        # start
        self.check_tabs_exists()
        self.update_templates_menu()
        QTimer.singleShot(50,lambda :self.set_theme(self.theme))
        vex_parser.generate()