def create_fontgroup(self, option=None, text=None, tip=None, fontfilters=None): """Option=None -> setting plugin font""" fontlabel = QLabel(_("Font: ")) fontbox = QFontComboBox() if fontfilters is not None: fontbox.setFontFilters(fontfilters) sizelabel = QLabel(" " + _("Size: ")) sizebox = QSpinBox() sizebox.setRange(7, 100) self.fontboxes[(fontbox, sizebox)] = option layout = QHBoxLayout() for subwidget in (fontlabel, fontbox, sizelabel, sizebox): layout.addWidget(subwidget) layout.addStretch(1) if text is None: text = _("Font style") group = QGroupBox(text) group.setLayout(layout) if tip is not None: group.setToolTip(tip) return group
def create_browsefile(self, text, option, default=NoDefault, tip=None, filters=None): widget = self.create_lineedit(text, option, default, alignment=Qt.Horizontal) for edit in self.lineedits: if widget.isAncestorOf(edit): break msg = _("Invalid file path") self.validate_data[edit] = (osp.isfile, msg) browse_btn = QPushButton(get_std_icon('FileIcon'), "", self) browse_btn.setToolTip(_("Select file")) self.connect(browse_btn, SIGNAL("clicked()"), lambda: self.select_file(edit, filters)) layout = QHBoxLayout() layout.addWidget(widget) layout.addWidget(browse_btn) layout.setContentsMargins(0, 0, 0, 0) browsedir = QWidget(self) browsedir.setLayout(layout) return browsedir
def create_scedit(self, text, option, default=NoDefault, tip=None, without_layout=False): label = QLabel(text) clayout = ColorLayout(QColor(Qt.black), self) clayout.lineedit.setMaximumWidth(80) if tip is not None: clayout.setToolTip(tip) cb_bold = QCheckBox() cb_bold.setIcon(get_icon("bold.png")) cb_bold.setToolTip(_("Bold")) cb_italic = QCheckBox() cb_italic.setIcon(get_icon("italic.png")) cb_italic.setToolTip(_("Italic")) self.scedits[(clayout, cb_bold, cb_italic)] = (option, default) if without_layout: return label, clayout, cb_bold, cb_italic layout = QHBoxLayout() layout.addWidget(label) layout.addLayout(clayout) layout.addSpacing(10) layout.addWidget(cb_bold) layout.addWidget(cb_italic) layout.addStretch(1) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.setLayout(layout) return widget
def show_docstring(self, text, call=False, force=False): """Show docstring or arguments""" text = unicode(text) # Useful only for ExternalShellBase insp_enabled = self.inspector_enabled or force if force and self.inspector is not None: self.inspector.dockwidget.setVisible(True) self.inspector.dockwidget.raise_() if insp_enabled and (self.inspector is not None) and \ (self.inspector.dockwidget.isVisible()): # ObjectInspector widget exists and is visible self.inspector.set_shell(self) self.inspector.set_object_text(text, ignore_unknown=True) self.setFocus() # if inspector was not at top level, raising it to # top will automatically give it focus because of # the visibility_changed signal, so we must give # focus back to shell if call and self.calltips: # Display argument list if this is function call iscallable = self.iscallable(text) if iscallable is not None: if iscallable: arglist = self.get_arglist(text) if isinstance(arglist, bool): arglist = [] if arglist: self.show_calltip(_("Arguments"), arglist, '#129625') elif self.calltips: # inspector is not visible or link is disabled doc = self.get__doc__(text) if doc is not None: self.show_calltip(_("Documentation"), doc)
def set_user_env(reg, parent=None): """Set HKCU (current user) environment variables""" reg = listdict2envdict(reg) types = dict() key = OpenKey(HKEY_CURRENT_USER, "Environment") for name in reg: try: _x, types[name] = QueryValueEx(key, name) except WindowsError: types[name] = REG_EXPAND_SZ key = OpenKey(HKEY_CURRENT_USER, "Environment", 0, KEY_SET_VALUE) for name in reg: SetValueEx(key, name, 0, types[name], reg[name]) try: from win32gui import SendMessageTimeout from win32con import (HWND_BROADCAST, WM_SETTINGCHANGE, SMTO_ABORTIFHUNG) SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", SMTO_ABORTIFHUNG, 5000) except ImportError: QMessageBox.warning( parent, _("Warning"), _("Module <b>pywin32 was not found</b>.<br>" "Please restart this Windows <i>session</i> " "(not the computer) for changes to take effect."))
def select_file(self, edit, filters=None): """Select File""" basedir = osp.dirname(unicode(edit.text())) if not osp.isdir(basedir): basedir = os.getcwdu() if filters is None: filters = _("All files (*)") title = _("Select file") filename, _selfilter = getopenfilename(self, title, basedir, filters) if filename: edit.setText(filename)
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)
class MemoryStatus(BaseTimerStatus): TITLE = _("Memory:") TIP = _("Memory usage status: " "requires the `psutil` (>=v0.3) library on non-Windows platforms") def import_test(self): """Raise ImportError if feature is not supported""" from src.gui.utils.system import memory_usage # analysis:ignore def get_value(self): """Return memory usage""" from src.gui.utils.system import memory_usage return memory_usage()
def setup(self): iofuncs = self.get_internal_funcs() + self.get_3rd_party_funcs() load_extensions = {} save_extensions = {} load_funcs = {} save_funcs = {} load_filters = [] save_filters = [] load_ext = [] for ext, name, loadfunc, savefunc in iofuncs: filter_str = unicode(name + " (*%s)" % ext) if loadfunc is not None: load_filters.append(filter_str) load_extensions[filter_str] = ext load_funcs[ext] = loadfunc load_ext.append(ext) if savefunc is not None: save_extensions[filter_str] = ext save_filters.append(filter_str) save_funcs[ext] = savefunc load_filters.insert(0, unicode(_("Supported files")+" (*"+\ " *".join(load_ext)+")")) self.load_filters = "\n".join(load_filters) self.save_filters = "\n".join(save_filters) self.load_funcs = load_funcs self.save_funcs = save_funcs self.load_extensions = load_extensions self.save_extensions = save_extensions
class CPUStatus(BaseTimerStatus): TITLE = _("CPU:") TIP = _("CPU usage status: requires the `psutil` (>=v0.3) library") def import_test(self): """Raise ImportError if feature is not supported""" from src.gui.utils import programs if not programs.is_module_installed('psutil', '>=0.2.0'): # The `interval` argument in `psutil.cpu_percent` function # was introduced in v0.2.0 raise ImportError def get_value(self): """Return CPU usage""" import psutil return psutil.cpu_percent(interval=0)
def setup(self): iofuncs = self.get_internal_funcs()+self.get_3rd_party_funcs() load_extensions = {} save_extensions = {} load_funcs = {} save_funcs = {} load_filters = [] save_filters = [] load_ext = [] for ext, name, loadfunc, savefunc in iofuncs: filter_str = unicode(name + " (*%s)" % ext) if loadfunc is not None: load_filters.append(filter_str) load_extensions[filter_str] = ext load_funcs[ext] = loadfunc load_ext.append(ext) if savefunc is not None: save_extensions[filter_str] = ext save_filters.append(filter_str) save_funcs[ext] = savefunc load_filters.insert(0, unicode(_("Supported files")+" (*"+\ " *".join(load_ext)+")")) self.load_filters = "\n".join(load_filters) self.save_filters = "\n".join(save_filters) self.load_funcs = load_funcs self.save_funcs = save_funcs self.load_extensions = load_extensions self.save_extensions = save_extensions
def get_internal_funcs(self): return [ ('.spydata', _("Spyder data files"), load_dictionary, save_dictionary), ('.npy', _("NumPy arrays"), load_array, None), ('.mat', _("Matlab files"), load_matlab, save_matlab), ('.csv', _("CSV text files"), 'import_wizard', None), ('.txt', _("Text files"), 'import_wizard', None), ('.jpg', _("JPEG images"), load_image, None), ('.png', _("PNG images"), load_image, None), ('.gif', _("GIF images"), load_image, None), ('.tif', _("TIFF images"), load_image, None), ]
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 __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 __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 __init__(self, parent=None): super(WinUserEnvDialog, self).__init__(parent) self.setup(get_user_env(), title="HKEY_CURRENT_USER\Environment", width=600) if parent is None: parent = self QMessageBox.warning(parent, _("Warning"), _("If you accept changes, " "this will modify the current user environment " "variables directly <b>in Windows registry</b>. " "Use it with precautions, at your own risks.<br>" "<br>Note that for changes to take effect, you will " "need to restart the parent process of this applica" "tion (simply restart Openfisca if you have executed it " "from a Windows shortcut, otherwise restart any " "application from which you may have executed it, " "like <i>Python(x,y) Home</i> for example)"))
def select_directory(self, edit): """Select directory""" basedir = unicode(edit.text()) if not osp.isdir(basedir): basedir = os.getcwdu() title = _("Select directory") directory = getexistingdirectory(self, title, basedir) if directory: edit.setText(directory)
def create_browsedir(self, text, option, default=NoDefault, tip=None): widget = self.create_lineedit(text, option, default, alignment=Qt.Horizontal) for edit in self.lineedits: if widget.isAncestorOf(edit): break msg = _("Invalid directory path") self.validate_data[edit] = (osp.isdir, msg) browse_btn = QPushButton(get_std_icon('DirOpenIcon'), "", self) browse_btn.setToolTip(_("Select directory")) self.connect(browse_btn, SIGNAL("clicked()"), lambda: self.select_directory(edit)) layout = QHBoxLayout() layout.addWidget(widget) layout.addWidget(browse_btn) layout.setContentsMargins(0, 0, 0, 0) browsedir = QWidget(self) browsedir.setLayout(layout) return browsedir
def __init__(self, parent=None): super(WinUserEnvDialog, self).__init__(parent) self.setup(get_user_env(), title="HKEY_CURRENT_USER\Environment", width=600) if parent is None: parent = self QMessageBox.warning( parent, _("Warning"), _("If you accept changes, " "this will modify the current user environment " "variables directly <b>in Windows registry</b>. " "Use it with precautions, at your own risks.<br>" "<br>Note that for changes to take effect, you will " "need to restart the parent process of this applica" "tion (simply restart Openfisca if you have executed it " "from a Windows shortcut, otherwise restart any " "application from which you may have executed it, " "like <i>Python(x,y) Home</i> for example)"))
def setup_page(self): self.table = ShortcutsTable(self) self.connect(self.table.model, SIGNAL("dataChanged(QModelIndex,QModelIndex)"), lambda i1, i2, opt='': self.has_been_modified(opt)) vlayout = QVBoxLayout() vlayout.addWidget(self.table) reset_btn = QPushButton(_("Reset to default values")) self.connect(reset_btn, SIGNAL('clicked()'), self.reset_to_default) vlayout.addWidget(reset_btn) self.setLayout(vlayout)
def check_shortcuts(self): """Check shortcuts for conflicts""" conflicts = [] for index, sh1 in enumerate(self.model.shortcuts): if index == len(self.model.shortcuts)-1: break for sh2 in self.model.shortcuts[index+1:]: if sh2 is sh1: continue if str(sh2.key) == str(sh1.key) \ and (sh1.context == sh2.context or sh1.context == '_' or sh2.context == '_'): conflicts.append((sh1, sh2)) if conflicts: self.parent().emit(SIGNAL('show_this_page()')) cstr = "\n".join(['%s <---> %s' % (sh1, sh2) for sh1, sh2 in conflicts]) QMessageBox.warning(self, _( "Conflicts"), _("The following conflicts have been " "detected:")+"\n"+cstr, QMessageBox.Ok)
def check_shortcuts(self): """Check shortcuts for conflicts""" conflicts = [] for index, sh1 in enumerate(self.model.shortcuts): if index == len(self.model.shortcuts) - 1: break for sh2 in self.model.shortcuts[index + 1:]: if sh2 is sh1: continue if str(sh2.key) == str(sh1.key) \ and (sh1.context == sh2.context or sh1.context == '_' or sh2.context == '_'): conflicts.append((sh1, sh2)) if conflicts: self.parent().emit(SIGNAL('show_this_page()')) cstr = "\n".join( ['%s <---> %s' % (sh1, sh2) for sh1, sh2 in conflicts]) QMessageBox.warning( self, _("Conflicts"), _("The following conflicts have been " "detected:") + "\n" + cstr, QMessageBox.Ok)
def create_fontgroup(self, option=None, text=None, tip=None, fontfilters=None): """Option=None -> setting plugin font""" fontlabel = QLabel(_("Font: ")) fontbox = QFontComboBox() if fontfilters is not None: fontbox.setFontFilters(fontfilters) sizelabel = QLabel(" "+_("Size: ")) sizebox = QSpinBox() sizebox.setRange(7, 100) self.fontboxes[(fontbox, sizebox)] = option layout = QHBoxLayout() for subwidget in (fontlabel, fontbox, sizelabel, sizebox): layout.addWidget(subwidget) layout.addStretch(1) if text is None: text = _("Font style") group = QGroupBox(text) group.setLayout(layout) if tip is not None: group.setToolTip(tip) return group
def set_user_env(reg, parent=None): """Set HKCU (current user) environment variables""" reg = listdict2envdict(reg) types = dict() key = OpenKey(HKEY_CURRENT_USER, "Environment") for name in reg: try: _x, types[name] = QueryValueEx(key, name) except WindowsError: types[name] = REG_EXPAND_SZ key = OpenKey(HKEY_CURRENT_USER, "Environment", 0, KEY_SET_VALUE) for name in reg: SetValueEx(key, name, 0, types[name], reg[name]) try: from win32gui import SendMessageTimeout from win32con import (HWND_BROADCAST, WM_SETTINGCHANGE, SMTO_ABORTIFHUNG) SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", SMTO_ABORTIFHUNG, 5000) except ImportError: QMessageBox.warning(parent, _("Warning"), _("Module <b>pywin32 was not found</b>.<br>" "Please restart this Windows <i>session</i> " "(not the computer) for changes to take effect."))
def run_vcs_tool(path, tool): """If path is a valid VCS repository, run the corresponding VCS tool Supported VCS tools: 'commit', 'browse' Return False if the VCS tool is not installed""" infos = get_vcs_infos(get_vcs_root(path)) for name, args in infos[tool]: if programs.find_program(name): programs.run_program(name, args, cwd=path) return else: raise RuntimeError(_("For %s support, please install one of the<br/> " "following tools:<br/><br/> %s") % (infos['name'], ', '.join([name for name,cmd in infos['commit']]) ))
def run_vcs_tool(path, tool): """If path is a valid VCS repository, run the corresponding VCS tool Supported VCS tools: 'commit', 'browse' Return False if the VCS tool is not installed""" infos = get_vcs_infos(get_vcs_root(path)) for name, args in infos[tool]: if programs.find_program(name): programs.run_program(name, args, cwd=path) return else: raise RuntimeError( _("For %s support, please install one of the<br/> " "following tools:<br/><br/> %s") % (infos['name'], ', '.join([name for name, cmd in infos['commit']])))
def __init__(self, parent=None): QDialog.__init__(self, parent) # Destroying the C++ object right after closing the dialog box, # otherwise it may be garbage-collected in another QThread # (e.g. the editor's analysis thread in Spyder), thus leading to # a segmentation fault on UNIX or an application crash on Windows self.setAttribute(Qt.WA_DeleteOnClose) self.contents_widget = QListWidget() self.contents_widget.setMovement(QListView.Static) self.contents_widget.setSpacing(1) bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Apply | QDialogButtonBox.Cancel) self.apply_btn = bbox.button(QDialogButtonBox.Apply) self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()")) self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()")) self.connect(bbox, SIGNAL("clicked(QAbstractButton*)"), self.button_clicked) self.pages_widget = QStackedWidget() self.connect(self.pages_widget, SIGNAL("currentChanged(int)"), self.current_page_changed) self.connect(self.contents_widget, SIGNAL("currentRowChanged(int)"), self.pages_widget.setCurrentIndex) self.contents_widget.setCurrentRow(0) hsplitter = QSplitter() hsplitter.addWidget(self.contents_widget) hsplitter.addWidget(self.pages_widget) btnlayout = QHBoxLayout() btnlayout.addStretch(1) btnlayout.addWidget(bbox) vlayout = QVBoxLayout() vlayout.addWidget(hsplitter) vlayout.addLayout(btnlayout) self.setLayout(vlayout) self.setWindowTitle(_("Preferences")) self.setWindowIcon(get_icon("configure.png"))
def __init__(self, parent=None): QDialog.__init__(self, parent) # Destroying the C++ object right after closing the dialog box, # otherwise it may be garbage-collected in another QThread # (e.g. the editor's analysis thread in Spyder), thus leading to # a segmentation fault on UNIX or an application crash on Windows self.setAttribute(Qt.WA_DeleteOnClose) self.contents_widget = QListWidget() self.contents_widget.setMovement(QListView.Static) self.contents_widget.setSpacing(1) bbox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Apply |QDialogButtonBox.Cancel) self.apply_btn = bbox.button(QDialogButtonBox.Apply) self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()")) self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()")) self.connect(bbox, SIGNAL("clicked(QAbstractButton*)"), self.button_clicked) self.pages_widget = QStackedWidget() self.connect(self.pages_widget, SIGNAL("currentChanged(int)"), self.current_page_changed) self.connect(self.contents_widget, SIGNAL("currentRowChanged(int)"), self.pages_widget.setCurrentIndex) self.contents_widget.setCurrentRow(0) hsplitter = QSplitter() hsplitter.addWidget(self.contents_widget) hsplitter.addWidget(self.pages_widget) btnlayout = QHBoxLayout() btnlayout.addStretch(1) btnlayout.addWidget(bbox) vlayout = QVBoxLayout() vlayout.addWidget(hsplitter) vlayout.addLayout(btnlayout) self.setLayout(vlayout) self.setWindowTitle(_("Preferences")) self.setWindowIcon(get_icon("configure.png"))
def headerData(self, section, orientation, role=Qt.DisplayRole): if role == Qt.TextAlignmentRole: if orientation == Qt.Horizontal: return to_qvariant(int(Qt.AlignHCenter|Qt.AlignVCenter)) return to_qvariant(int(Qt.AlignRight|Qt.AlignVCenter)) if role != Qt.DisplayRole: return to_qvariant() if orientation == Qt.Horizontal: if section == CONTEXT: return to_qvariant(_("Context")) elif section == NAME: return to_qvariant(_("Name")) elif section == MOD1: return to_qvariant(_("Mod1")) elif section == MOD2: return to_qvariant(_("Mod2")) elif section == MOD3: return to_qvariant(_("Mod3")) elif section == KEY: return to_qvariant(_("Key")) return to_qvariant()
def headerData(self, section, orientation, role=Qt.DisplayRole): if role == Qt.TextAlignmentRole: if orientation == Qt.Horizontal: return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter)) if role != Qt.DisplayRole: return to_qvariant() if orientation == Qt.Horizontal: if section == CONTEXT: return to_qvariant(_("Context")) elif section == NAME: return to_qvariant(_("Name")) elif section == MOD1: return to_qvariant(_("Mod1")) elif section == MOD2: return to_qvariant(_("Mod2")) elif section == MOD3: return to_qvariant(_("Mod3")) elif section == KEY: return to_qvariant(_("Key")) return to_qvariant()
def setup_page(self): interface_group = QGroupBox(_("Interface")) styles = [str(txt) for txt in QStyleFactory.keys()] choices = zip(styles, [style.lower() for style in styles]) style_combo = self.create_combobox(_('Qt windows style'), choices, 'windows_style', default=self.main.default_style) newcb = self.create_checkbox vertdock_box = newcb(_("Vertical dockwidget title bars"), 'vertical_dockwidget_titlebars') verttabs_box = newcb(_("Vertical dockwidget tabs"), 'vertical_tabs') animated_box = newcb(_("Animated toolbars and dockwidgets"), 'animated_docks') margin_box = newcb(_("Custom dockwidget margin:"), 'use_custom_margin') margin_spin = self.create_spinbox("", "pixels", 'custom_margin', 0, 0, 30) self.connect(margin_box, SIGNAL("toggled(bool)"), margin_spin.setEnabled) margin_spin.setEnabled(self.get_option('use_custom_margin')) margins_layout = QHBoxLayout() margins_layout.addWidget(margin_box) margins_layout.addWidget(margin_spin) interface_layout = QVBoxLayout() interface_layout.addWidget(style_combo) interface_layout.addWidget(vertdock_box) interface_layout.addWidget(verttabs_box) interface_layout.addWidget(animated_box) interface_layout.addLayout(margins_layout) interface_group.setLayout(interface_layout) vlayout = QVBoxLayout() vlayout.addWidget(interface_group) vlayout.addStretch(1) self.setLayout(vlayout)
def get_name(self): return _("General")
def sphinxify(docstring, context, buildername='html'): """ Runs Sphinx on a docstring and outputs the processed documentation. Parameters ---------- docstring : str a ReST-formatted docstring context : dict Variables to be passed to the layout template to control how its rendered (through the Sphinx variable *html_context*). buildername: str It can be either `html` or `text`. Returns ------- An Sphinx-processed string, in either HTML or plain text format, depending on the value of `buildername` """ srcdir = mkdtemp() srcdir = encoding.to_unicode_from_fs(srcdir) base_name = osp.join(srcdir, 'docstring') rst_name = base_name + '.rst' if buildername == 'html': suffix = '.html' else: suffix = '.txt' output_name = base_name + suffix # This is needed so users can type \\ on latex eqnarray envs inside of raw # docstrings if context['right_sphinx_version'] and context['math_on']: docstring = docstring.replace('\\\\', '\\\\\\\\') # Add a class to several characters on the argspec. This way we can # colorize them using css, in a similar way to what IPython does. argspec = context['argspec'] for char in ['=', ',', '(', ')', '*', '**']: argspec = argspec.replace(char, '<span class="argspec-highlight">' + char + '</span>') context['argspec'] = argspec doc_file = codecs.open(rst_name, 'w', encoding='utf-8') doc_file.write(docstring) doc_file.close() temp_confdir = False if temp_confdir: # TODO: This may be inefficient. Find a faster way to do it. confdir = mkdtemp() confdir = encoding.to_unicode_from_fs(confdir) generate_configuration(confdir) else: confdir = osp.join(get_module_source_path('src.gui.utils.inspector')) confoverrides = {'html_context': context} doctreedir = osp.join(srcdir, 'doctrees') sphinx_app = Sphinx(srcdir, confdir, srcdir, doctreedir, buildername, confoverrides, status=None, warning=None, freshenv=True, warningiserror=False, tags=None) try: sphinx_app.build(None, [rst_name]) except SystemMessage: output = _("It was not possible to generate rich text help for this " "object.</br>" "Please see it in plain text.") return warning(output) # TODO: Investigate if this is necessary/important for us if osp.exists(output_name): output = codecs.open(output_name, 'r', encoding='utf-8').read() output = output.replace('<pre>', '<pre class="literal-block">') else: output = _("It was not possible to generate rich text help for this " "object.</br>" "Please see it in plain text.") return warning(output) if temp_confdir: shutil.rmtree(confdir, ignore_errors=True) shutil.rmtree(srcdir, ignore_errors=True) return output
def setup_page(self): tabs = QTabWidget() names = self.get_option("names") names.pop(names.index(CUSTOM_COLOR_SCHEME_NAME)) names.insert(0, CUSTOM_COLOR_SCHEME_NAME) fieldnames = { "background": _("Background:"), "currentline": _("Current line:"), "occurence": _("Occurence:"), "ctrlclick": _("Link:"), "sideareas": _("Side areas:"), "matched_p": _("Matched parentheses:"), "unmatched_p": _("Unmatched parentheses:"), "normal": _("Normal text:"), "keyword": _("Keyword:"), "builtin": _("Builtin:"), "definition": _("Definition:"), "comment": _("Comment:"), "string": _("String:"), "number": _("Number:"), "instance": _("Instance:"), } from src.gui.spyder_widgets.sourcecode import syntaxhighlighters assert all([ key in fieldnames for key in syntaxhighlighters.COLOR_SCHEME_KEYS ]) for tabname in names: cs_group = QGroupBox(_("Color scheme")) cs_layout = QGridLayout() for row, key in enumerate(syntaxhighlighters.COLOR_SCHEME_KEYS): option = "%s/%s" % (tabname, key) value = self.get_option(option) name = fieldnames[key] if isinstance(value, basestring): label, clayout = self.create_coloredit(name, option, without_layout=True) label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) cs_layout.addWidget(label, row + 1, 0) cs_layout.addLayout(clayout, row + 1, 1) else: label, clayout, cb_bold, cb_italic = self.create_scedit( name, option, without_layout=True) label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) cs_layout.addWidget(label, row + 1, 0) cs_layout.addLayout(clayout, row + 1, 1) cs_layout.addWidget(cb_bold, row + 1, 2) cs_layout.addWidget(cb_italic, row + 1, 3) cs_group.setLayout(cs_layout) if tabname in COLOR_SCHEME_NAMES: def_btn = self.create_button( _("Reset to default values"), lambda: self.reset_to_default(tabname)) tabs.addTab(self.create_tab(cs_group, def_btn), tabname) else: tabs.addTab(self.create_tab(cs_group), tabname) vlayout = QVBoxLayout() vlayout.addWidget(tabs) self.setLayout(vlayout)
] if sys.platform == 'darwin': BIG = MEDIUM = SMALL = 12 elif os.name == 'nt': BIG = 12 MEDIUM = 10 SMALL = 9 else: BIG = 12 MEDIUM = 9 SMALL = 9 # Extensions supported by Openfisca_GA EDIT_FILETYPES = ( (_("Python files"), ('.py', '.pyw', '.ipy')), (_("Cython/Pyrex files"), ('.pyx', '.pxd', '.pxi')), (_("C files"), ('.c', '.h')), (_("C++ files"), ('.cc', '.cpp', '.cxx', '.h', '.hh', '.hpp', '.hxx')), (_("OpenCL files"), ('.cl', )), (_("Fortran files"), ('.f', '.for', '.f77', '.f90', '.f95', '.f2k')), (_("Patch and diff files"), ('.patch', '.diff', '.rej')), (_("Batch files"), ('.bat', '.cmd')), (_("Text files"), ('.txt', )), (_("reStructured Text files"), ('.txt', '.rst')), (_("gettext files"), ('.po', '.pot')), (_("Web page files"), ( '.css', '.htm', '.html', )),
def get_plugin_title(self): """Return widget title""" return _('Online help')
def load(self, filename): ext = osp.splitext(filename)[1].lower() if ext in self.load_funcs: return self.load_funcs[ext](filename) else: return None, _("<b>Unsupported file type '%s'</b>") % ext
def get_name(self): return _("Syntax coloring")
def save(self, data, filename): ext = osp.splitext(filename)[1].lower() if ext in self.save_funcs: return self.save_funcs[ext](data, filename) else: return _("<b>Unsupported file type '%s'</b>") % ext
def setup_page(self): tabs = QTabWidget() names = self.get_option("names") names.pop(names.index(CUSTOM_COLOR_SCHEME_NAME)) names.insert(0, CUSTOM_COLOR_SCHEME_NAME) fieldnames = { "background": _("Background:"), "currentline": _("Current line:"), "occurence": _("Occurence:"), "ctrlclick": _("Link:"), "sideareas": _("Side areas:"), "matched_p": _("Matched parentheses:"), "unmatched_p": _("Unmatched parentheses:"), "normal": _("Normal text:"), "keyword": _("Keyword:"), "builtin": _("Builtin:"), "definition": _("Definition:"), "comment": _("Comment:"), "string": _("String:"), "number": _("Number:"), "instance": _("Instance:"), } from src.gui.spyder_widgets.sourcecode import syntaxhighlighters assert all([key in fieldnames for key in syntaxhighlighters.COLOR_SCHEME_KEYS]) for tabname in names: cs_group = QGroupBox(_("Color scheme")) cs_layout = QGridLayout() for row, key in enumerate(syntaxhighlighters.COLOR_SCHEME_KEYS): option = "%s/%s" % (tabname, key) value = self.get_option(option) name = fieldnames[key] if isinstance(value, basestring): label, clayout = self.create_coloredit(name, option, without_layout=True) label.setAlignment(Qt.AlignRight|Qt.AlignVCenter) cs_layout.addWidget(label, row+1, 0) cs_layout.addLayout(clayout, row+1, 1) else: label, clayout, cb_bold, cb_italic = self.create_scedit( name, option, without_layout=True) label.setAlignment(Qt.AlignRight|Qt.AlignVCenter) cs_layout.addWidget(label, row+1, 0) cs_layout.addLayout(clayout, row+1, 1) cs_layout.addWidget(cb_bold, row+1, 2) cs_layout.addWidget(cb_italic, row+1, 3) cs_group.setLayout(cs_layout) if tabname in COLOR_SCHEME_NAMES: def_btn = self.create_button(_("Reset to default values"), lambda: self.reset_to_default(tabname)) tabs.addTab(self.create_tab(cs_group, def_btn), tabname) else: tabs.addTab(self.create_tab(cs_group), tabname) vlayout = QVBoxLayout() vlayout.addWidget(tabs) self.setLayout(vlayout)
def get_label(self): """Return address label text""" return _("Module or package:")
'Courier New', 'Courier', 'monospace', 'Fixed', 'Terminal'] if sys.platform == 'darwin': BIG = MEDIUM = SMALL = 12 elif os.name == 'nt': BIG = 12 MEDIUM = 10 SMALL = 9 else: BIG = 12 MEDIUM = 9 SMALL = 9 # Extensions supported by Openfisca_GA EDIT_FILETYPES = ( (_("Python files"), ('.py', '.pyw', '.ipy')), (_("Cython/Pyrex files"), ('.pyx', '.pxd', '.pxi')), (_("C files"), ('.c', '.h')), (_("C++ files"), ('.cc', '.cpp', '.cxx', '.h', '.hh', '.hpp', '.hxx')), (_("OpenCL files"), ('.cl', )), (_("Fortran files"), ('.f', '.for', '.f77', '.f90', '.f95', '.f2k')), (_("Patch and diff files"), ('.patch', '.diff', '.rej')), (_("Batch files"), ('.bat', '.cmd')), (_("Text files"), ('.txt',)), (_("reStructured Text files"), ('.txt', '.rst')), (_("gettext files"), ('.po', '.pot')), (_("Web page files"), ('.css', '.htm', '.html',)), (_("Configuration files"), ('.properties', '.session', '.ini', '.inf', '.reg', '.cfg', '.desktop')), (_("Composiiton"), ('.ofct',)), )
def _get_filters(filetypes): filters = [] for title, ftypes in filetypes: filters.append("%s (*%s)" % (title, " *".join(ftypes))) filters.append("%s (*)" % _("All files")) return ";;".join(filters)