def _setup_scripts(self): """ Initialize the combo box with a list of scripts available """ file_pattern = os.path.join(get_data_folder(), 'scripts', '*.xml') for infile in glob.glob(file_pattern): try: xml = parse(infile) script = Script.create_from_xml(xml) self.logger.info('Adding the script "%s" (%d command(s))', script.name, script.count()) # Connect listeners self.connect(script, QtCore.SIGNAL('displayMessage(QString)'), self.display_message) self.connect(script, QtCore.SIGNAL('displayChar(QString)'), self.display_char) self.connect(script, QtCore.SIGNAL('updateProgressBar(int)'), self.update_progress_bar) # Add the script to the list self.scripts.append(script) except ExpatError as e: self.logger.warning('Unable to parse the XML file for "%s" script (%s)', infile, e) # Sort scripts by position for script in sorted(self.scripts, key=lambda s: s.position): self.script_list.addItem(script.name) if len(self.scripts) is 0: self.logger.warning('No script found for the pattern "%s"', file_pattern) else: self.ui.script_list.setCurrentIndex(-1)
def __init__(self, app): QtGui.QMainWindow.__init__(self) self.app = app self.logger = logging.getLogger('PacketProcessing') self.scripts = list() self.current_script = None uifile = 'packetprocessing.ui' uidir = os.path.join(get_data_folder(), 'ui') self.logger.info('Loading UI informations from "%s" XML file...', uifile) try: self.ui = uic.loadUi(os.path.join(uidir, uifile), self) except IOError as e: self.logger.critical('Unable to load the XML UI file (%s)', e) sys.exit() self._setup_scripts()
def __init__(self, app, main_win, script): QtGui.QMainWindow.__init__(self) self.main_win = main_win self.app = app self.script = script self.edits = dict() self.logger = logging.getLogger('PacketProcessing') uifile = 'params.ui' uidir = os.path.join(get_data_folder(), 'ui') try: self.ui = uic.loadUi(os.path.join(uidir, uifile), self) except IOError as e: self.logger.critical('Unable to load the XML UI file (%s)', e) sys.exit() self._generate_window()
def open_scripts_folder(self): """ Opens the script folder inside Explorer/Finder.. """ open_folder(os.path.join(get_data_folder(), 'scripts'))