Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] pythonconsole: Import plugin from Pluma #658

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ subdir('filebrowser')
subdir('joinlines')
subdir('modelines')
subdir('open-uri-context-menu')
subdir('pythonconsole')
subdir('sort')
subdir('taglist')
subdir('textsize')
Expand Down
22 changes: 22 additions & 0 deletions plugins/pythonconsole/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
subdir('pythonconsole')

pythonconsole_desktop = custom_target(
'pythonconsole_desktop',
input: 'pythonconsole.plugin.desktop.in',
output: 'pythonconsole.plugin',
command: [intltool_merge, '-d', '-u', po_dir, '@INPUT@', '@OUTPUT@'],
install: true,
install_dir: pluginslibdir,
)

pythonconsole_schema_file = configure_file(
input: 'org.x.editor.plugins.pythonconsole.gschema.xml.in',
output: 'org.x.editor.plugins.pythonconsole.gschema.xml',
configuration: schema_conf,
install_dir: join_paths(datadir, 'glib-2.0', 'schemas')
)

install_data(
pythonconsole_schema_file,
install_dir: schema_dir
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="@GETTEXT_PACKAGE@">
<schema id="org.x.editor.plugins.pythonconsole" path="/org/x/editor/plugins/pythonconsole/">
<key name="command-color" type="s">
<default>'#314e6c'</default>
<summary>Command Color Text</summary>
<description>The command color text</description>
</key>
<key name="error-color" type="s">
<default>'#990000'</default>
<summary>Error Color Text</summary>
<description>The error color text</description>
</key>
<key name="use-system-font" type="b">
<default>true</default>
<summary>Whether to use the system font</summary>
<description>
If true, the terminal will use the desktop-global standard
font if it’s monospace (and the most similar font it can
come up with otherwise).
</description>
</key>
<key name="font" type="s">
<default>'Monospace 10'</default>
<summary>Font</summary>
<description>
A Pango font name. Examples are “Sans 12” or “Monospace Bold 14”.
</description>
</key>
</schema>
</schemalist>
9 changes: 9 additions & 0 deletions plugins/pythonconsole/pythonconsole.plugin.desktop.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Plugin]
Loader=python3
Module=pythonconsole
IAge=3
_Name=Python Console
_Description=Interactive Python console standing in the bottom panel
Icon=text-x-python
Authors=Steve Frécinaux <[email protected]>
Copyright=Copyright © 2006 Steve Frécinaux
64 changes: 64 additions & 0 deletions plugins/pythonconsole/pythonconsole/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-

# __init__.py -- plugin object
#
# Copyright (C) 2006 - Steve Frécinaux
# Copyright (C) 2012-2021 MATE Developers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

# Parts from "Interactive Python-GTK Console" (stolen from epiphany's console.py)
# Copyright (C), 1998 James Henstridge <[email protected]>
# Copyright (C), 2005 Adam Hooper <[email protected]>
# Bits from xed Python Console Plugin
# Copyrignt (C), 2005 Raphaël Slinckx

from gi.repository import GObject, Gtk, Peas, PeasGtk, Xed

from .console import PythonConsole
from .config import PythonConsoleConfigWidget
from .config import PythonConsoleConfig

PYTHON_ICON = 'text-x-python'

class PythonConsolePlugin(GObject.Object, Xed.WindowActivatable, PeasGtk.Configurable):
__gtype_name__ = "PythonConsolePlugin"

window = GObject.Property(type=Xed.Window)

def __init__(self):
GObject.Object.__init__(self)
self.config_widget = None

def do_activate(self):
self._console = PythonConsole(namespace = {'__builtins__' : __builtins__,
'xed' : Xed,
'window' : self.window})
self._console.eval('print("You can access the main window through ' \
'\'window\' :\\n%s" % window)', False)
bottom = self.window.get_bottom_panel()
bottom.add_item(self._console, _('Python Console'), PYTHON_ICON)

def do_deactivate(self):
self._console.stop()
bottom = self.window.get_bottom_panel()
bottom.remove_item(self._console)

def do_create_configure_widget(self):
if not self.config_widget:
self.config_widget = PythonConsoleConfigWidget(self.plugin_info.get_data_dir())
return self.config_widget.configure_widget()

# ex:et:ts=4:
151 changes: 151 additions & 0 deletions plugins/pythonconsole/pythonconsole/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# -*- coding: utf-8 -*-

# config.py -- Config dialog
#
# Copyright (C) 2008 - B. Clausius
# Copyright (C) 2012-2021 MATE Developers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

# Parts from "Interactive Python-GTK Console" (stolen from epiphany's console.py)
# Copyright (C), 1998 James Henstridge <[email protected]>
# Copyright (C), 2005 Adam Hooper <[email protected]>
# Bits from xed Python Console Plugin
# Copyrignt (C), 2005 Raphaël Slinckx

import os
from gi.repository import Gio, Gtk, Gdk

__all__ = ('PythonConsoleConfig', 'PythonConsoleConfigWidget')

class PythonConsoleConfig(object):

CONSOLE_KEY_BASE = 'org.x.editor.plugins.pythonconsole'
CONSOLE_KEY_COMMAND_COLOR = 'command-color'
CONSOLE_KEY_ERROR_COLOR = 'error-color'
CONSOLE_KEY_USE_SYSTEM_FONT = 'use-system-font'
CONSOLE_KEY_FONT = 'font'

INTERFACE_KEY_BASE = 'org.mate.interface'
INTERFACE_KEY_MONOSPACE_FONT_NAME = 'monospace-font-name'

color_command = property(
lambda self: self.console_settings.get_string(self.CONSOLE_KEY_COMMAND_COLOR),
lambda self, value: self.console_settings.set_string(self.CONSOLE_KEY_COMMAND_COLOR, value)
)

color_error = property(
lambda self: self.console_settings.get_string(self.CONSOLE_KEY_ERROR_COLOR),
lambda self, value: self.console_settings.set_string(self.CONSOLE_KEY_ERROR_COLOR, value)
)

use_system_font = property(
lambda self: self.console_settings.get_boolean(self.CONSOLE_KEY_USE_SYSTEM_FONT),
lambda self, value: self.console_settings.set_boolean(self.CONSOLE_KEY_USE_SYSTEM_FONT, value)
)

font = property(
lambda self: self.console_settings.get_string(self.CONSOLE_KEY_FONT),
lambda self, value: self.console_settings.set_string(self.CONSOLE_KEY_FONT, value)
)

monospace_font_name = property(
lambda self: self.interface_settings.get_string(self.INTERFACE_KEY_MONOSPACE_FONT_NAME)
)

console_settings = Gio.Settings.new(CONSOLE_KEY_BASE)
interface_settings = Gio.Settings.new(INTERFACE_KEY_BASE)

def __init__(self):
object.__init__(self)

@classmethod
def enabled(self):
return self.console_settings != None

@classmethod
def add_handler(self, handler):
self.console_settings.connect("changed", handler)
self.interface_settings.connect("changed", handler)


class PythonConsoleConfigWidget(object):

CONSOLE_KEY_BASE = 'org.x.editor.plugins.pythonconsole'
CONSOLE_KEY_COMMAND_COLOR = 'command-color'
CONSOLE_KEY_ERROR_COLOR = 'error-color'

def __init__(self, datadir):
object.__init__(self)
self._widget = None
self._ui_path = os.path.join(datadir, 'ui', 'config.ui')
self._config = PythonConsoleConfig()
self._ui = Gtk.Builder()

def configure_widget(self):
if self._widget is None:
self._ui.add_from_file(self._ui_path)

self.set_colorbutton_color(self._ui.get_object('colorbutton-command'),
self._config.color_command)
self.set_colorbutton_color(self._ui.get_object('colorbutton-error'),
self._config.color_error)
checkbox = self._ui.get_object('checkbox-system-font')
checkbox.set_active(self._config.use_system_font)
self._fontbutton = self._ui.get_object('fontbutton-font')
self._fontbutton.set_font_name(self._config.font)
self.on_checkbox_system_font_toggled(checkbox)
self._ui.connect_signals(self)

self._widget = self._ui.get_object('widget-config')
self._widget.show_all()

return self._widget

@staticmethod
def set_colorbutton_color(colorbutton, value):
rgba = Gdk.RGBA()
parsed = rgba.parse(value)

if parsed:
colorbutton.set_rgba(rgba)

def on_colorbutton_command_color_set(self, colorbutton):
self._config.color_command = colorbutton.get_color().to_string()

def on_colorbutton_error_color_set(self, colorbutton):
self._config.color_error = colorbutton.get_color().to_string()

def on_checkbox_system_font_toggled(self, checkbox):
val = checkbox.get_active()
self._config.use_system_font = val
self._fontbutton.set_sensitive(not val)

def on_fontbutton_font_set(self, fontbutton):
self._config.font = fontbutton.get_font_name()

def on_widget_config_parent_set(self, widget, oldparent):
# Set icon in dialog close button.
try:
actionarea = widget.get_toplevel().get_action_area()
image = Gtk.Image.new_from_icon_name("window-close",
Gtk.IconSize.BUTTON)
for button in actionarea.get_children():
button.set_image(image)
button.set_property("always-show-image", True)
except:
pass

# ex:et:ts=4:
Loading