def __init__(self, parent, controller_widget, control_name): super(ListValuesEditor, self).__init__(parent) self.controller_widget = controller_widget self.control_name = control_name self.format = 'JSON' self.separator = ',' self.modified = False layout = QtGui.QVBoxLayout() self.setLayout(layout) textedit = QtGui.QTextEdit() layout.addWidget(textedit) hlayout2 = QtGui.QHBoxLayout() layout.addLayout(hlayout2) hlayout2.addWidget(QtGui.QLabel('Format:')) format_c = QtGui.QComboBox() hlayout2.addWidget(format_c) hlayout2.addWidget(QtGui.QLabel('Separator:')) sep_c = QtGui.QComboBox() hlayout2.addWidget(sep_c) format_c.addItem('JSON') format_c.addItem('CSV') sep_c.addItem(',') sep_c.addItem(';') sep_c.addItem(' ') hlayout2.addStretch(1) ok = QtGui.QPushButton('OK') cancel = QtGui.QPushButton('Cancel') hlayout2.addWidget(ok) hlayout2.addWidget(cancel) ok.pressed.connect(self.accept) cancel.pressed.connect(self.reject) parent_controller = controller_widget.controller value = getattr(parent_controller, control_name) text = json.dumps(value) textedit.setText(text) self.textedit = textedit self.format_c = format_c self.separator_c = sep_c self.internal_change = False textedit.textChanged.connect(self.set_modified) format_c.currentIndexChanged.connect(self.format_changed) sep_c.currentIndexChanged.connect(self.separator_changed)
def __init__(self, extra_options=None): """ Method to initialize the Application class. The capsulview application can be executed with command line options (that can also be passed to the class constructor as extra_options). From the command line, we can set the debug level with the -d option: * debug * info * warning * error * critical For exemple: >>> capsulview -d debug The default mode is error. From the command line we can also redirect all messages to a graphical message box with the -r option: >>> capsulview -r Parameters ---------- extra_options: list (optional) some additional options that are not passed through the command line. """ # Inheritance QtGui.QApplication.__init__(self, []) # Extra application options extra_options = extra_options or [] # Define a mapping to the logging level levels = { "debug": logging.DEBUG, "info": logging.INFO, "warning": logging.WARNING, "error": logging.ERROR, "critical": logging.CRITICAL } # Parse command line and internal options parser = optparse.OptionParser() parser.add_option("-d", "--debug", dest="debug", help="Set the logging level " "(debug, info, warning, error, or critical", metavar="LEVEL") parser.add_option("-r", "--redirect-to-messagebox", dest="redirect", action="store_true", default=False, help="Redirect all messages to the console") parser.add_option("-t", "--test", dest="test", action="store_true", default=False, help="Add a set of test pipelines") for args, kwargs in extra_options: parser.add_option(*args, **kwargs) self.options, self.arguments = parser.parse_args() # Logging format logging_format = ("[%(asctime)s] " "{%(pathname)s:%(lineno)d} " "%(levelname)s - %(message)s") date_format = "%Y-%m-%d %H:%M:%S" # If someone tried to log something before basicConfig is called, # Python creates a default handler that goes to the console and # will ignore further basicConfig calls: we need to remove the # handlers if there is one. while len(logging.root.handlers) > 0: logging.root.removeHandler(logging.root.handlers[-1]) # If the logging level is specified if self.options.debug is not None: # Get the real logging level from the mapping level = levels.get(self.options.debug, None) # If a no valid logging level is found raise an Exception if level is None: raise Exception("Warning : unknown logging level " "{0}".format(self.options.debug)) # Configure the logging module logging.basicConfig(level=level, format=logging_format, datefmt=date_format) # Disable deprecation warnings if we are not in the debug mode if level != logging.DEBUG: warnings.simplefilter("ignore", DeprecationWarning) # Set the default logging level else: logging.basicConfig(level=logging.ERROR, format=logging_format, datefmt=date_format) # Disable deprecation warnings warnings.simplefilter("ignore", DeprecationWarning) # Check if the redirection option is found: redirecect stdout and # stderr to a message box if self.options.redirect: # Create a message box self.message_box = QtGui.QTextEdit() # Redirect stdout and stderr sys.stdout = EmittingStream() sys.stderr = EmittingStream() # Connect with text written signal self.connect(sys.stdout, QtCore.SIGNAL('textWritten(QString)'), self._on_text_print) self.connect(sys.stderr, QtCore.SIGNAL('textWritten(QString)'), self._on_text_print) # Update root logger handler root_logger = logging.getLogger() h = root_logger.handlers[0] h.stream = sys.stdout