class EncodingStatus(StatusBarWidget): def __init__(self, parent, statusbar): StatusBarWidget.__init__(self, parent, statusbar) layout = self.layout() layout.addWidget(QLabel(_("Encoding:"))) self.encoding = QLabel() self.encoding.setFont(self.label_font) layout.addWidget(self.encoding) layout.addSpacing(20) def encoding_changed(self, encoding): self.encoding.setText(str(encoding).upper().ljust(15))
class EOLStatus(StatusBarWidget): def __init__(self, parent, statusbar): StatusBarWidget.__init__(self, parent, statusbar) layout = self.layout() layout.addWidget(QLabel(_("End-of-lines:"))) self.eol = QLabel() self.eol.setFont(self.label_font) layout.addWidget(self.eol) layout.addSpacing(20) def eol_changed(self, os_name): os_name = to_text_string(os_name) self.eol.setText({"nt": "CRLF", "posix": "LF"}.get(os_name, "CR"))
class ReadWriteStatus(StatusBarWidget): def __init__(self, parent, statusbar): StatusBarWidget.__init__(self, parent, statusbar) layout = self.layout() layout.addWidget(QLabel(_("Permissions:"))) self.readwrite = QLabel() self.readwrite.setFont(self.label_font) layout.addWidget(self.readwrite) layout.addSpacing(20) def readonly_changed(self, readonly): readwrite = "R" if readonly else "RW" self.readwrite.setText(readwrite.ljust(3))
class BaseTimerStatus(StatusBarWidget): TITLE = None TIP = None def __init__(self, parent, statusbar): StatusBarWidget.__init__(self, parent, statusbar) self.setToolTip(self.TIP) layout = self.layout() layout.addWidget(QLabel(self.TITLE)) self.label = QLabel() self.label.setFont(self.label_font) layout.addWidget(self.label) layout.addSpacing(20) if self.is_supported(): self.timer = QTimer() self.timer.timeout.connect(self.update_label) self.timer.start(2000) else: self.timer = None self.hide() def set_interval(self, interval): """Set timer interval (ms)""" if self.timer is not None: self.timer.setInterval(interval) def import_test(self): """Raise ImportError if feature is not supported""" raise NotImplementedError def is_supported(self): """Return True if feature is supported""" try: self.import_test() return True except ImportError: return False def get_value(self): """Return value (e.g. CPU or memory usage)""" raise NotImplementedError def update_label(self): """Update status label widget, if widget is visible""" if self.isVisible(): self.label.setText('%d %%' % self.get_value())
class CursorPositionStatus(StatusBarWidget): def __init__(self, parent, statusbar): StatusBarWidget.__init__(self, parent, statusbar) layout = self.layout() layout.addWidget(QLabel(_("Line:"))) self.line = QLabel() self.line.setFont(self.label_font) layout.addWidget(self.line) layout.addWidget(QLabel(_("Column:"))) self.column = QLabel() self.column.setFont(self.label_font) layout.addWidget(self.column) self.setLayout(layout) def cursor_position_changed(self, line, index): self.line.setText("%-6d" % (line + 1)) self.column.setText("%-4d" % (index + 1))
class CursorPositionStatus(StatusBarWidget): def __init__(self, parent, statusbar): StatusBarWidget.__init__(self, parent, statusbar) layout = self.layout() layout.addWidget(QLabel(_("Line:"))) self.line = QLabel() self.line.setFont(self.label_font) layout.addWidget(self.line) layout.addWidget(QLabel(_("Column:"))) self.column = QLabel() self.column.setFont(self.label_font) layout.addWidget(self.column) self.setLayout(layout) def cursor_position_changed(self, line, index): self.line.setText("%-6d" % (line+1)) self.column.setText("%-4d" % (index+1))
def setup_page(self): if ERR_MSG: label = QLabel(_("Could not load plugin:\n{0}".format(ERR_MSG))) layout = QVBoxLayout() layout.addWidget(label) self.setLayout(layout) return # Layout parameter indent = QCheckBox().sizeHint().width() # General options options_group = QGroupBox(_("Options")) # Hack : the spinbox widget will be added to self.spinboxes spinboxes_before = set(self.spinboxes) passes_spin = self.create_spinbox(_("Number of pep8 passes: "), "", 'passes', default=0, min_=0, max_=1000000, step=1) spinbox = set(self.spinboxes) - spinboxes_before spinbox = spinbox.pop() spinbox.setSpecialValueText(_("Infinite")) aggressive1_checkbox = self.create_checkbox("Aggressivity level 1", "aggressive1", default=False) aggressive1_label = QLabel( _("Allow possibly unsafe fixes (E711 and W6), shorten lines" " and remove trailing whitespace more aggressively (in" " docstrings and multiline strings).")) aggressive1_label.setWordWrap(True) aggressive1_label.setIndent(indent) font_description = aggressive1_label.font() font_description.setPointSizeF(font_description.pointSize() * 0.9) aggressive1_label.setFont(font_description) aggressive2_checkbox = self.create_checkbox("Aggressivity level 2", "aggressive2", default=False) aggressive2_label = QLabel( _("Allow more possibly unsafe fixes (E712) and shorten lines.")) aggressive2_label.setWordWrap(True) aggressive2_label.setIndent(indent) aggressive2_label.setFont(font_description) self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), aggressive2_checkbox.setEnabled) self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), aggressive2_label.setEnabled) aggressive2_checkbox.setEnabled(aggressive1_checkbox.isChecked()) aggressive2_label.setEnabled(aggressive1_checkbox.isChecked()) # Enable/disable error codes fix_layout = QVBoxLayout() last_group = "" FIX_LIST.sort(key=lambda item: item[0][1]) for code, description in FIX_LIST: # Create a new group if necessary if code[1] != last_group: last_group = code[1] group = QGroupBox(_(self.GROUPS.get(code[1], ""))) fix_layout.addWidget(group) group_layout = QVBoxLayout(group) # Checkbox for the option text = code default = True if code in DEFAULT_IGNORE: text += _(" (UNSAFE)") default = False option = self.create_checkbox(text, code, default=default) # Label for description if code in self.CODES: label = QLabel("{autopep8} ({pep8}).".format( autopep8=_(description).rstrip("."), pep8=self.CODES[code])) else: label = QLabel(_(description)) label.setWordWrap(True) label.setIndent(indent) label.setFont(font_description) # Add widgets to layout option_layout = QVBoxLayout() option_layout.setSpacing(0) option_layout.addWidget(option) option_layout.addWidget(label) group_layout.addLayout(option_layout) # Special cases if code in ("E711", "W6"): self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), option.setEnabled) self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), label.setEnabled) option.setEnabled(aggressive1_checkbox.isChecked()) label.setEnabled(aggressive1_checkbox.isChecked()) if code == "E712": def e712_enabled(): enabled = (aggressive1_checkbox.isChecked() and aggressive2_checkbox.isChecked()) option.setEnabled(enabled) label.setEnabled(enabled) self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), e712_enabled) self.connect(aggressive2_checkbox, SIGNAL("toggled(bool)"), e712_enabled) e712_enabled() # General layout aggressive2_layout = QVBoxLayout() margins = aggressive2_layout.contentsMargins() margins.setLeft(indent) aggressive2_layout.setContentsMargins(margins) aggressive2_layout.addWidget(aggressive2_checkbox) aggressive2_layout.addWidget(aggressive2_label) options_layout = QVBoxLayout() options_layout.addWidget(passes_spin) options_layout.addWidget(aggressive1_checkbox) options_layout.addWidget(aggressive1_label) options_layout.addLayout(aggressive2_layout) options_group.setLayout(options_layout) widget_scroll = QWidget() widget_scroll.setLayout(fix_layout) fix_scroll = QScrollArea() fix_scroll.setWidget(widget_scroll) fix_scroll.setWidgetResizable(True) fig_out_layout = QVBoxLayout() fig_out_layout.addWidget(fix_scroll, 1) fix_group = QGroupBox(_("Errors/warnings to fix")) fix_group.setLayout(fig_out_layout) vlayout = QVBoxLayout() vlayout.addWidget(options_group) vlayout.addWidget(fix_group, 1) self.setLayout(vlayout)
def setup_page(self): if ERR_MSG: label = QLabel(_("Could not load plugin:\n{0}".format(ERR_MSG))) layout = QVBoxLayout() layout.addWidget(label) self.setLayout(layout) return # Layout parameter indent = QCheckBox().sizeHint().width() # General options options_group = QGroupBox(_("Options")) # Hack : the spinbox widget will be added to self.spinboxes spinboxes_before = set(self.spinboxes) passes_spin = self.create_spinbox( _("Number of pep8 passes: "), "", 'passes', default=0, min_=0, max_=1000000, step=1) spinbox = set(self.spinboxes) - spinboxes_before spinbox = spinbox.pop() spinbox.setSpecialValueText(_("Infinite")) aggressive1_checkbox = self.create_checkbox( "Aggressivity level 1", "aggressive1", default=False) aggressive1_label = QLabel(_( "Allow possibly unsafe fixes (E711 and W6), shorten lines" " and remove trailing whitespace more aggressively (in" " docstrings and multiline strings).")) aggressive1_label.setWordWrap(True) aggressive1_label.setIndent(indent) font_description = aggressive1_label.font() font_description.setPointSizeF(font_description.pointSize() * 0.9) aggressive1_label.setFont(font_description) aggressive2_checkbox = self.create_checkbox( "Aggressivity level 2", "aggressive2", default=False) aggressive2_label = QLabel(_( "Allow more possibly unsafe fixes (E712) and shorten lines.")) aggressive2_label.setWordWrap(True) aggressive2_label.setIndent(indent) aggressive2_label.setFont(font_description) self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), aggressive2_checkbox.setEnabled) self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), aggressive2_label.setEnabled) aggressive2_checkbox.setEnabled(aggressive1_checkbox.isChecked()) aggressive2_label.setEnabled(aggressive1_checkbox.isChecked()) # Enable/disable error codes fix_layout = QVBoxLayout() last_group = "" FIX_LIST.sort(key=lambda item: item[0][1]) for code, description in FIX_LIST: # Create a new group if necessary if code[1] != last_group: last_group = code[1] group = QGroupBox(_(self.GROUPS.get(code[1], ""))) fix_layout.addWidget(group) group_layout = QVBoxLayout(group) # Checkbox for the option text = code default = True if code in DEFAULT_IGNORE: text += _(" (UNSAFE)") default = False option = self.create_checkbox(text, code, default=default) # Label for description if code in self.CODES: label = QLabel("{autopep8} ({pep8}).".format( autopep8=_(description).rstrip("."), pep8=self.CODES[code])) else: label = QLabel(_(description)) label.setWordWrap(True) label.setIndent(indent) label.setFont(font_description) # Add widgets to layout option_layout = QVBoxLayout() option_layout.setSpacing(0) option_layout.addWidget(option) option_layout.addWidget(label) group_layout.addLayout(option_layout) # Special cases if code in ("E711", "W6"): self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), option.setEnabled) self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), label.setEnabled) option.setEnabled(aggressive1_checkbox.isChecked()) label.setEnabled(aggressive1_checkbox.isChecked()) if code == "E712": def e712_enabled(): enabled = (aggressive1_checkbox.isChecked() and aggressive2_checkbox.isChecked()) option.setEnabled(enabled) label.setEnabled(enabled) self.connect(aggressive1_checkbox, SIGNAL("toggled(bool)"), e712_enabled) self.connect(aggressive2_checkbox, SIGNAL("toggled(bool)"), e712_enabled) e712_enabled() # General layout aggressive2_layout = QVBoxLayout() margins = aggressive2_layout.contentsMargins() margins.setLeft(indent) aggressive2_layout.setContentsMargins(margins) aggressive2_layout.addWidget(aggressive2_checkbox) aggressive2_layout.addWidget(aggressive2_label) options_layout = QVBoxLayout() options_layout.addWidget(passes_spin) options_layout.addWidget(aggressive1_checkbox) options_layout.addWidget(aggressive1_label) options_layout.addLayout(aggressive2_layout) options_group.setLayout(options_layout) widget_scroll = QWidget() widget_scroll.setLayout(fix_layout) fix_scroll = QScrollArea() fix_scroll.setWidget(widget_scroll) fix_scroll.setWidgetResizable(True) fig_out_layout = QVBoxLayout() fig_out_layout.addWidget(fix_scroll, 1) fix_group = QGroupBox(_("Errors/warnings to fix")) fix_group.setLayout(fig_out_layout) vlayout = QVBoxLayout() vlayout.addWidget(options_group) vlayout.addWidget(fix_group, 1) self.setLayout(vlayout)