Example #1
0
def test():
    from spyderlib.utils.qthelpers import qapplication

    app = qapplication()

    from spyderlib.plugins.variableexplorer import VariableExplorer

    settings = VariableExplorer.get_settings()

    shell = ExternalPythonShell(
        pythonexecutable=sys.executable,
        interact=True,
        stand_alone=settings,
        wdir=osp.dirname(__file__),
        mpl_backend=0,
        light_background=False,
    )

    from spyderlib.qt.QtGui import QFont
    from spyderlib.config.main import CONF

    font = QFont(CONF.get("console", "font/family")[0])
    font.setPointSize(10)
    shell.shell.set_font(font)

    shell.shell.toggle_wrap_mode(True)
    shell.start_shell(False)
    shell.show()
    sys.exit(app.exec_())
Example #2
0
def test():
    from spyderlib.utils.qthelpers import qapplication
    app = qapplication()
    from spyderlib.widgets.externalshell.pythonshell import ExternalPythonShell
    from spyderlib.widgets.externalshell.systemshell import ExternalSystemShell
    import spyderlib
    from spyderlib.plugins.variableexplorer import VariableExplorer
    settings = VariableExplorer.get_settings()
    shell = ExternalPythonShell(wdir=osp.dirname(spyderlib.__file__),
                                ipykernel=True,
                                stand_alone=settings,
                                arguments="-q4thread -pylab -colors LightBG",
                                light_background=False)
    #    shell = ExternalPythonShell(wdir=osp.dirname(spyderlib.__file__),
    #                                interact=True, umr_enabled=True,
    #                                stand_alone=settings,
    #                                umr_namelist=['guidata', 'guiqwt'],
    #                                umr_verbose=True, light_background=False)
    #    shell = ExternalSystemShell(wdir=osp.dirname(spyderlib.__file__),
    #                                light_background=False)
    shell.shell.toggle_wrap_mode(True)
    shell.start_shell(False)
    from spyderlib.qt.QtGui import QFont
    font = QFont("Lucida console")
    font.setPointSize(10)
    shell.shell.set_font(font)
    shell.show()
    sys.exit(app.exec_())
def test():
    from spyderlib.utils.qthelpers import qapplication
    app = qapplication()
    from spyderlib.widgets.externalshell.pythonshell import ExternalPythonShell
    from spyderlib.widgets.externalshell.systemshell import ExternalSystemShell
    import spyderlib
    from spyderlib.plugins.variableexplorer import VariableExplorer
    settings = VariableExplorer.get_settings()
    shell = ExternalPythonShell(wdir=osp.dirname(spyderlib.__file__),
                                ipykernel=True, stand_alone=settings,
                                arguments="-q4thread -pylab -colors LightBG",
                                light_background=False)
#    shell = ExternalPythonShell(wdir=osp.dirname(spyderlib.__file__),
#                                interact=True, umr_enabled=True,
#                                stand_alone=settings,
#                                umr_namelist=['guidata', 'guiqwt'],
#                                umr_verbose=True, light_background=False)
#    shell = ExternalSystemShell(wdir=osp.dirname(spyderlib.__file__),
#                                light_background=False)
    shell.shell.toggle_wrap_mode(True)
    shell.start_shell(False)
    from spyderlib.qt.QtGui import QFont
    font = QFont("Lucida console")
    font.setPointSize(10)
    shell.shell.set_font(font)
    shell.show()
    sys.exit(app.exec_())
Example #4
0
def get_font(section='main', option='font', font_size_delta=0):
    """Get console font properties depending on OS and user options"""
    font = FONT_CACHE.get((section, option))

    if font is None:
        families = CONF.get(section, option+"/family", None)

        if families is None:
            return QFont()

        family = get_family(families)
        weight = QFont.Normal
        italic = CONF.get(section, option+'/italic', False)

        if CONF.get(section, option+'/bold', False):
            weight = QFont.Bold

        size = CONF.get(section, option+'/size', 9) + font_size_delta
        font = QFont(family, size, weight)
        font.setItalic(italic)
        FONT_CACHE[(section, option)] = font

    size = CONF.get(section, option+'/size', 9) + font_size_delta
    font.setPointSize(size)
    return font
class EditableComboBox(BaseComboBox):
    """
    Editable combo box + Validate
    """
    def __init__(self, parent):
        BaseComboBox.__init__(self, parent)
        self.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
        self.font = QFont()
        self.connect(self, SIGNAL("editTextChanged(QString)"), self.validate)
        self.connect(self, SIGNAL("activated(QString)"),
                     lambda qstr: self.validate(qstr, editing=False))
        self.set_default_style()
        self.tips = {
            True: _("Press enter to validate this entry"),
            False: _('This entry is incorrect')
        }

    def show_tip(self, tip=""):
        """Show tip"""
        QToolTip.showText(self.mapToGlobal(self.pos()), tip, self)

    def set_default_style(self):
        """Set widget style to default"""
        self.font.setBold(False)
        self.setFont(self.font)
        self.setStyleSheet("")
        self.show_tip()

    def selected(self):
        """Action to be executed when a valid item has been selected"""
        BaseComboBox.selected(self)
        self.set_default_style()

    def validate(self, qstr, editing=True):
        """Validate entered path"""
        valid = self.is_valid(qstr)
        if self.hasFocus() and valid is not None:
            self.font.setBold(True)
            self.setFont(self.font)
            if valid:
                self.setStyleSheet("color:rgb(50, 155, 50);")
            else:
                self.setStyleSheet("color:rgb(200, 50, 50);")
            if editing:
                # Combo box text is being modified: invalidate the entry
                self.show_tip(self.tips[valid])
                self.emit(SIGNAL('valid(bool)'), False)
            else:
                # A new item has just been selected
                if valid:
                    self.selected()
                else:
                    self.emit(SIGNAL('valid(bool)'), False)
        else:
            self.set_default_style()
Example #6
0
 def __init__(self, parent):
     BaseComboBox.__init__(self, parent)
     self.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
     self.font = QFont()
     self.editTextChanged.connect(self.validate)
     self.activated.connect(lambda qstr: self.validate(qstr, editing=False))
     self.set_default_style()
     self.tips = {
         True: _("Press enter to validate this entry"),
         False: _('This entry is incorrect')
     }
Example #7
0
    def font(self, prefix, size):
        """Returns QFont corresponding to the given prefix and size

        Arguments
        ---------
        prefix: str
            prefix string of the loaded font
        size: int
            size for the font
        """
        font = QFont(self.fontname[prefix])
        font.setPixelSize(size)
        return font
Example #8
0
def test():
    import os.path as osp
    from spyderlib.utils.qthelpers import qapplication
    app = qapplication()
    shell = ExternalSystemShell(wdir=osp.dirname(__file__),
                                light_background=False)

    from spyderlib.qt.QtGui import QFont
    from spyderlib.config.main import CONF
    font = QFont(CONF.get('console', 'font/family')[0])
    font.setPointSize(10)
    shell.shell.set_font(font)

    shell.shell.toggle_wrap_mode(True)
    shell.start_shell(False)
    shell.show()
    sys.exit(app.exec_())
Example #9
0
File: gui.py Project: wodole/spyder
def get_font(section='main', option='font', font_size_delta=0):
    """Get console font properties depending on OS and user options"""
    font = FONT_CACHE.get((section, option))

    if font is None:
        families = CONF.get(section, option + "/family", None)

        if families is None:
            return QFont()

        family = get_family(families)
        weight = QFont.Normal
        italic = CONF.get(section, option + '/italic', False)

        if CONF.get(section, option + '/bold', False):
            weight = QFont.Bold

        size = CONF.get(section, option + '/size', 9) + font_size_delta
        font = QFont(family, size, weight)
        font.setItalic(italic)
        FONT_CACHE[(section, option)] = font

    size = CONF.get(section, option + '/size', 9) + font_size_delta
    font.setPointSize(size)
    return font
Example #10
0
def tuple_to_qfont(tup):
    """
    Create a QFont from tuple:
        (family [string], size [int], italic [bool], bold [bool])
    """
    if not isinstance(tup, tuple) or len(tup) != 4 \
       or not font_is_installed(tup[0]) \
       or not isinstance(tup[1], int) \
       or not isinstance(tup[2], bool) \
       or not isinstance(tup[3], bool):
        return None
    font = QFont()
    family, size, italic, bold = tup
    font.setFamily(family)
    font.setPointSize(size)
    font.setItalic(italic)
    font.setBold(bold)
    return font
Example #11
0
 def set_pythonshell_font(self, font=None):
     """Python Shell only"""
     if font is None:
         font = QFont()
     for style in self.font_styles:
         style.apply_style(font=font,
                           light_background=self.light_background,
                           is_default=style is self.default_style)
     self.ansi_handler.set_base_format(self.default_style.format)
Example #12
0
def get_family(families):
    """Return the first installed font family in family list"""
    if not isinstance(families, list):
        families = [families]
    for family in families:
        if font_is_installed(family):
            return family
    else:
        print("Warning: None of the following fonts is installed: %r" %
              families)
        return QFont().family()
Example #13
0
def get_font(section, option=None):
    """Get console font properties depending on OS and user options"""
    font = FONT_CACHE.get((section, option))
    if font is None:
        if option is None:
            option = 'font'
        else:
            option += '/font'
        families = CONF.get(section, option + "/family", None)
        if families is None:
            return QFont()
        family = get_family(families)
        weight = QFont.Normal
        italic = CONF.get(section, option + '/italic', False)
        if CONF.get(section, option + '/bold', False):
            weight = QFont.Bold
        size = CONF.get(section, option + '/size', 9)
        font = QFont(family, size, weight)
        font.setItalic(italic)
        FONT_CACHE[(section, option)] = font
    return font
Example #14
0
    def __init__(self, parent):
        BaseComboBox.__init__(self, parent)
        self.font = QFont()
        self.selected_text = self.currentText()

        # Widget setup
        self.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)

        # Signals
        self.editTextChanged.connect(self.validate)
        self.tips = {True: _("Press enter to validate this entry"),
                     False: _('This entry is incorrect')}
Example #15
0
def test():
    from spyderlib.utils.qthelpers import qapplication
    app = qapplication()

    from spyderlib.plugins.variableexplorer import VariableExplorer
    settings = VariableExplorer.get_settings()

    shell = ExternalPythonShell(pythonexecutable=sys.executable,
                                interact=True,
                                stand_alone=settings,
                                wdir=osp.dirname(__file__),
                                mpl_backend=0,
                                light_background=False)

    from spyderlib.qt.QtGui import QFont
    from spyderlib.config.main import CONF
    font = QFont(CONF.get('console', 'font/family')[0])
    font.setPointSize(10)
    shell.shell.set_font(font)

    shell.shell.toggle_wrap_mode(True)
    shell.start_shell(False)
    shell.show()
    sys.exit(app.exec_())
    def populate_tree(self):
        """Create each item (and associated data) in the tree"""
        if not self.stats:
            warn_item = QTreeWidgetItem(self)
            warn_item.setData(
                0, Qt.DisplayRole,
                _('No timings to display. '
                  'Did you forget to add @profile decorators ?').format(
                      url=WEBSITE_URL))
            warn_item.setFirstColumnSpanned(True)
            warn_item.setTextAlignment(0, Qt.AlignCenter)
            font = warn_item.font(0)
            font.setStyle(QFont.StyleItalic)
            warn_item.setFont(0, font)
            return

        try:
            monospace_font = self.window().editor.get_plugin_font()
        except AttributeError:  # If run standalone for testing
            monospace_font = QFont("Courier New")
            monospace_font.setPointSize(10)

        for func_info, func_data in self.stats.iteritems():
            # Function name and position
            filename, start_line_no, func_name = func_info
            func_stats, func_total_time = func_data
            func_item = QTreeWidgetItem(self)
            func_item.setData(
                0, Qt.DisplayRole,
                _('{func_name} ({time_ms:.3f}ms) in file "{filename}", '
                  'line {line_no}').format(filename=filename,
                                           line_no=start_line_no,
                                           func_name=func_name,
                                           time_ms=func_total_time * 1e3))
            func_item.setFirstColumnSpanned(True)
            func_item.setData(COL_POS, Qt.UserRole,
                              (osp.normpath(filename), start_line_no))

            # For sorting by time
            func_item.setData(COL_TIME, Qt.DisplayRole, func_total_time * 1e3)
            func_item.setData(COL_PERCENT, Qt.DisplayRole,
                              func_total_time * 1e3)

            if self.parent().use_colors:
                # Choose deteministic unique color for the function
                md5 = hashlib.md5(filename + func_name).hexdigest()
                hue = (int(md5[:2], 16) - 68) % 360  # avoid blue (unreadable)
                func_color = QColor.fromHsv(hue, 200, 255)
            else:
                # Red color only
                func_color = QColor.fromRgb(255, 0, 0)

            # Lines of code
            for line_info in func_stats:
                line_item = QTreeWidgetItem(func_item)
                (line_no, code_line, line_total_time, time_per_hit, hits,
                 percent) = line_info
                self.fill_item(line_item, filename, line_no, code_line,
                               line_total_time, percent, time_per_hit, hits)

                # Color background
                if line_total_time is not None:
                    alpha = percent
                    color = QColor(func_color)
                    color.setAlphaF(alpha)  # Returns None
                    color = QBrush(color)
                    for col in range(self.columnCount()):
                        line_item.setBackground(col, color)
                else:

                    for col in range(self.columnCount()):
                        line_item.setForeground(col, CODE_NOT_RUN_COLOR)

                # Monospace font for code
                line_item.setFont(COL_LINE, monospace_font)