summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile.am8
-rw-r--r--plugins/externaltools/Makefile.am6
-rw-r--r--plugins/externaltools/externaltools.plugin.desktop.in (renamed from plugins/externaltools/externaltools.pluma-plugin.desktop.in)2
-rwxr-xr-xplugins/externaltools/tools/__init__.py142
-rwxr-xr-xplugins/externaltools/tools/capture.py35
-rwxr-xr-xplugins/externaltools/tools/filelookup.py13
-rwxr-xr-xplugins/externaltools/tools/functions.py45
-rwxr-xr-xplugins/externaltools/tools/library.py5
-rwxr-xr-xplugins/externaltools/tools/manager.py221
-rwxr-xr-xplugins/externaltools/tools/outputpanel.py50
-rw-r--r--plugins/externaltools/tools/tools.ui3
-rw-r--r--plugins/pythonconsole/Makefile.am6
-rw-r--r--plugins/pythonconsole/pythonconsole.plugin.desktop.in (renamed from plugins/pythonconsole/pythonconsole.pluma-plugin.desktop.in)2
-rwxr-xr-xplugins/pythonconsole/pythonconsole/__init__.py42
-rwxr-xr-xplugins/pythonconsole/pythonconsole/console.py66
-rw-r--r--plugins/quickopen/Makefile.am6
-rw-r--r--plugins/quickopen/quickopen.plugin.desktop.in (renamed from plugins/quickopen/quickopen.pluma-plugin.desktop.in)2
-rwxr-xr-xplugins/quickopen/quickopen/__init__.py26
-rwxr-xr-xplugins/quickopen/quickopen/popup.py156
-rwxr-xr-xplugins/quickopen/quickopen/virtualdirs.py22
-rwxr-xr-xplugins/quickopen/quickopen/windowhelper.py34
-rwxr-xr-xplugins/snippets/snippets/Manager.py4
-rwxr-xr-xplugins/snippets/snippets/__init__.py30
23 files changed, 477 insertions, 449 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index a27ae69a..c4f95ea8 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,8 +1,11 @@
DIST_SUBDIRS = \
changecase \
docinfo \
+ externaltools \
filebrowser \
modelines \
+ pythonconsole \
+ quickopen \
sort \
spell \
taglist \
@@ -12,15 +15,18 @@ DIST_SUBDIRS = \
SUBDIRS = \
changecase \
docinfo \
+ externaltools \
filebrowser \
modelines \
+ pythonconsole \
+ quickopen \
sort \
taglist \
time \
trailsave
# python plugins are disabled for now
-#SUBDIRS += externaltools pythonconsole snippets quickopen
+#SUBDIRS += snippets
if ENABLE_ENCHANT
SUBDIRS += spell
diff --git a/plugins/externaltools/Makefile.am b/plugins/externaltools/Makefile.am
index bec58b63..cd6f9720 100644
--- a/plugins/externaltools/Makefile.am
+++ b/plugins/externaltools/Makefile.am
@@ -2,10 +2,10 @@
SUBDIRS = tools data scripts
plugindir = $(PLUMA_PLUGINS_LIBS_DIR)
-plugin_in_files = externaltools.pluma-plugin.desktop.in
-%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+plugin_in_files = externaltools.plugin.desktop.in
+%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin)
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
EXTRA_DIST = $(plugin_in_files)
diff --git a/plugins/externaltools/externaltools.pluma-plugin.desktop.in b/plugins/externaltools/externaltools.plugin.desktop.in
index 611ca002..b3261e77 100644
--- a/plugins/externaltools/externaltools.pluma-plugin.desktop.in
+++ b/plugins/externaltools/externaltools.plugin.desktop.in
@@ -1,4 +1,4 @@
-[Pluma Plugin]
+[Plugin]
Loader=python
Module=externaltools
IAge=2
diff --git a/plugins/externaltools/tools/__init__.py b/plugins/externaltools/tools/__init__.py
index 39522ede..2a51c97c 100755
--- a/plugins/externaltools/tools/__init__.py
+++ b/plugins/externaltools/tools/__init__.py
@@ -16,11 +16,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-__all__ = ('ExternalToolsPlugin', 'ExternalToolsWindowHelper',
- 'Manager', 'OutputPanel', 'Capture', 'UniqueById')
+__all__ = ('ExternalToolsPlugin', 'Manager', 'OutputPanel', 'Capture', 'UniqueById')
-import pluma
-import gtk
+from gi.repository import GObject, Gtk, Peas, Pluma
from manager import Manager
from library import ToolLibrary
from outputpanel import OutputPanel
@@ -28,17 +26,16 @@ from capture import Capture
from functions import *
class ToolMenu(object):
- ACTION_HANDLER_DATA_KEY = "ExternalToolActionHandlerData"
- ACTION_ITEM_DATA_KEY = "ExternalToolActionItemData"
-
- def __init__(self, library, window, menupath):
+ def __init__(self, library, window, panel, plugin, menupath):
super(ToolMenu, self).__init__()
self._library = library
self._window = window
+ self._panel = panel
+ self._plugin = plugin
self._menupath = menupath
self._merge_id = 0
- self._action_group = gtk.ActionGroup("ExternalToolsPluginToolActions")
+ self._action_group = Gtk.ActionGroup("ExternalToolsPluginToolActions")
self._signals = []
self.update()
@@ -53,17 +50,15 @@ class ToolMenu(object):
self._merge_id = 0
for action in self._action_group.list_actions():
- handler = action.get_data(self.ACTION_HANDLER_DATA_KEY)
+ if action._tool_handler is not None:
+ action.disconnect(action._tool_handler)
- if handler is not None:
- action.disconnect(handler)
-
- action.set_data(self.ACTION_ITEM_DATA_KEY, None)
- action.set_data(self.ACTION_HANDLER_DATA_KEY, None)
+ action._tool_item = None
+ action._tool_handler = None
self._action_group.remove_action(action)
- accelmap = gtk.accel_map_get()
+ accelmap = Gtk.AccelMap.get()
for s in self._signals:
accelmap.disconnect(s)
@@ -75,43 +70,44 @@ class ToolMenu(object):
for item in directory.subdirs:
action_name = 'ExternalToolDirectory%X' % id(item)
- action = gtk.Action(action_name, item.name.replace('_', '__'), None, None)
+ action = Gtk.Action(action_name, item.name.replace('_', '__'), None, None)
self._action_group.add_action(action)
manager.add_ui(self._merge_id, path,
action_name, action_name,
- gtk.UI_MANAGER_MENU, False)
+ Gtk.UIManagerItemType.MENU, False)
self._insert_directory(item, path + '/' + action_name)
for item in directory.tools:
action_name = 'ExternalToolTool%X' % id(item)
- action = gtk.Action(action_name, item.name.replace('_', '__'), item.comment, None)
- handler = action.connect("activate", capture_menu_action, self._window, item)
+ action = Gtk.Action(action_name, item.name.replace('_', '__'), item.comment, None)
+ handler = action.connect("activate", capture_menu_action, self._window, self._panel, item)
- action.set_data(self.ACTION_ITEM_DATA_KEY, item)
- action.set_data(self.ACTION_HANDLER_DATA_KEY, handler)
+ # Attach the item and the handler to the action object
+ action._tool_item = item
+ action._tool_handler = handler
# Make sure to replace accel
accelpath = '<Actions>/ExternalToolsPluginToolActions/%s' % (action_name, )
if item.shortcut:
- key, mod = gtk.accelerator_parse(item.shortcut)
- gtk.accel_map_change_entry(accelpath, key, mod, True)
+ key, mod = Gtk.accelerator_parse(item.shortcut)
+ Gtk.AccelMap.change_entry(accelpath, key, mod, True)
- self._signals.append(gtk.accel_map_get().connect('changed::%s' % (accelpath,), self.on_accelmap_changed, item))
+ self._signals.append(Gtk.AccelMap.get().connect('changed::%s' % (accelpath,), self.on_accelmap_changed, item))
self._action_group.add_action_with_accel(action, item.shortcut)
manager.add_ui(self._merge_id, path,
action_name, action_name,
- gtk.UI_MANAGER_MENUITEM, False)
+ Gtk.UIManagerItemType.MENUITEM, False)
def on_accelmap_changed(self, accelmap, path, key, mod, tool):
- tool.shortcut = gtk.accelerator_name(key, mod)
+ tool.shortcut = Gtk.accelerator_name(key, mod)
tool.save()
- self._window.get_data("ExternalToolsPluginWindowData").update_manager(tool)
+ self._plugin.update_manager(tool)
def update(self):
self.remove()
@@ -150,29 +146,36 @@ class ToolMenu(object):
language = document.get_language()
for action in self._action_group.list_actions():
- item = action.get_data(self.ACTION_ITEM_DATA_KEY)
+ if action._tool_item is not None:
+ action.set_visible(states[action._tool_item.applicability] and
+ self.filter_language(language, action._tool_item))
- if item is not None:
- action.set_visible(states[item.applicability] and self.filter_language(language, item))
+class ExternalToolsPlugin(GObject.Object, Peas.Activatable):
+ __gtype_name__ = "ExternalToolsPlugin"
-class ExternalToolsWindowHelper(object):
- def __init__(self, plugin, window):
- super(ExternalToolsWindowHelper, self).__init__()
+ object = GObject.Property(type=GObject.Object)
- self._window = window
- self._plugin = plugin
+ def __init__(self):
+ GObject.Object.__init__(self)
+
+ self._manager = None
+ self._manager_default_size = None
+
+ def do_activate(self):
self._library = ToolLibrary()
+ self._library.set_locations(os.path.join(self.plugin_info.get_data_dir(), 'tools'))
+ window = self.object
manager = window.get_ui_manager()
- self._action_group = gtk.ActionGroup('ExternalToolsPluginActions')
+ self._action_group = Gtk.ActionGroup('ExternalToolsPluginActions')
self._action_group.set_translation_domain('pluma')
self._action_group.add_actions([('ExternalToolManager',
None,
_('Manage _External Tools...'),
None,
_("Opens the External Tools Manager"),
- lambda action: plugin.open_dialog()),
+ lambda action: self.open_dialog()),
('ExternalTools',
None,
_('External _Tools'),
@@ -201,69 +204,47 @@ class ExternalToolsWindowHelper(object):
self._merge_id = manager.add_ui_from_string(ui_string)
- self.menu = ToolMenu(self._library, self._window,
+ # Create output console
+ self._output_buffer = OutputPanel(self.plugin_info.get_data_dir(), window)
+
+ self.menu = ToolMenu(self._library, window, self._output_buffer, self,
"/MenuBar/ToolsMenu/ToolsOps_4/ExternalToolsMenu/ExternalToolPlaceholder")
manager.ensure_update()
- # Create output console
- self._output_buffer = OutputPanel(self._plugin.get_data_dir(), window)
bottom = window.get_bottom_panel()
- bottom.add_item(self._output_buffer.panel,
- _("Shell Output"),
- gtk.STOCK_EXECUTE)
+ bottom.add_item_with_stock_icon(self._output_buffer.panel,
+ _("Shell Output"),
+ Gtk.STOCK_EXECUTE)
- def update_ui(self):
- self.menu.filter(self._window.get_active_document())
- self._window.get_ui_manager().ensure_update()
+ def do_deactivate(self):
+ window = self.object
+ manager = window.get_ui_manager()
- def deactivate(self):
- manager = self._window.get_ui_manager()
self.menu.deactivate()
manager.remove_ui(self._merge_id)
manager.remove_action_group(self._action_group)
manager.ensure_update()
- bottom = self._window.get_bottom_panel()
+ bottom = window.get_bottom_panel()
bottom.remove_item(self._output_buffer.panel)
- def update_manager(self, tool):
- self._plugin.update_manager(tool)
+ def do_update_state(self):
+ window = self.object
-class ExternalToolsPlugin(pluma.Plugin):
- WINDOW_DATA_KEY = "ExternalToolsPluginWindowData"
-
- def __init__(self):
- super(ExternalToolsPlugin, self).__init__()
-
- self._manager = None
- self._manager_default_size = None
-
- ToolLibrary().set_locations(os.path.join(self.get_data_dir(), 'tools'))
-
- def activate(self, window):
- helper = ExternalToolsWindowHelper(self, window)
- window.set_data(self.WINDOW_DATA_KEY, helper)
-
- def deactivate(self, window):
- window.get_data(self.WINDOW_DATA_KEY).deactivate()
- window.set_data(self.WINDOW_DATA_KEY, None)
-
- def update_ui(self, window):
- window.get_data(self.WINDOW_DATA_KEY).update_ui()
-
- def create_configure_dialog(self):
- return self.open_dialog()
+ self.menu.filter(window.get_active_document())
+ window.get_ui_manager().ensure_update()
def open_dialog(self):
if not self._manager:
- self._manager = Manager(self.get_data_dir())
+ self._manager = Manager(self.plugin_info.get_data_dir())
if self._manager_default_size:
self._manager.dialog.set_default_size(*self._manager_default_size)
self._manager.dialog.connect('destroy', self.on_manager_destroy)
+ self._manager.connect('tools-updated', self.on_manager_tools_updated)
- window = pluma.app_get_default().get_active_window()
+ window = Pluma.App.get_default().get_active_window()
self._manager.run(window)
return self._manager.dialog
@@ -275,7 +256,10 @@ class ExternalToolsPlugin(pluma.Plugin):
self._manager.tool_changed(tool, True)
def on_manager_destroy(self, dialog):
- self._manager_default_size = [dialog.allocation.width, dialog.allocation.height]
+ self._manager_default_size = self._manager.get_final_size()
self._manager = None
+ def on_manager_tools_updated(self, manager):
+ self.menu.update()
+
# ex:ts=4:et:
diff --git a/plugins/externaltools/tools/capture.py b/plugins/externaltools/tools/capture.py
index 2f065761..487c8dbb 100755
--- a/plugins/externaltools/tools/capture.py
+++ b/plugins/externaltools/tools/capture.py
@@ -21,11 +21,10 @@ __all__ = ('Capture', )
import os, sys, signal
import locale
import subprocess
-import gobject
import fcntl
-import glib
+from gi.repository import GObject, GLib
-class Capture(gobject.GObject):
+class Capture(GObject.Object):
CAPTURE_STDOUT = 0x01
CAPTURE_STDERR = 0x02
CAPTURE_BOTH = 0x03
@@ -34,14 +33,14 @@ class Capture(gobject.GObject):
WRITE_BUFFER_SIZE = 0x4000
__gsignals__ = {
- 'stdout-line' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)),
- 'stderr-line' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)),
- 'begin-execute': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, tuple()),
- 'end-execute' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,))
+ 'stdout-line' : (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,)),
+ 'stderr-line' : (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,)),
+ 'begin-execute': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, tuple()),
+ 'end-execute' : (GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_INT,))
}
def __init__(self, command, cwd = None, env = {}):
- gobject.GObject.__init__(self)
+ GObject.GObject.__init__(self)
self.pipe = None
self.env = env
self.cwd = cwd
@@ -101,8 +100,8 @@ class Capture(gobject.GObject):
flags = fcntl.fcntl(self.pipe.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK
fcntl.fcntl(self.pipe.stdout.fileno(), fcntl.F_SETFL, flags)
- gobject.io_add_watch(self.pipe.stdout,
- gobject.IO_IN | gobject.IO_HUP,
+ GLib.io_add_watch(self.pipe.stdout,
+ GObject.IO_IN | GObject.IO_HUP,
self.on_output)
if self.flags & self.CAPTURE_STDERR:
@@ -110,8 +109,8 @@ class Capture(gobject.GObject):
flags = fcntl.fcntl(self.pipe.stderr.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK
fcntl.fcntl(self.pipe.stderr.fileno(), fcntl.F_SETFL, flags)
- gobject.io_add_watch(self.pipe.stderr,
- gobject.IO_IN | gobject.IO_HUP,
+ GLib.io_add_watch(self.pipe.stderr,
+ GObject.IO_IN | GObject.IO_HUP,
self.on_output)
# IO
@@ -120,10 +119,10 @@ class Capture(gobject.GObject):
self.write_buffer = str(self.input_text)
if self.idle_write_chunk():
- self.idle_write_id = gobject.idle_add(self.idle_write_chunk)
+ self.idle_write_id = GLib.idle_add(self.idle_write_chunk)
# Wait for the process to complete
- gobject.child_watch_add(self.pipe.pid, self.on_child_end)
+ GLib.child_watch_add(self.pipe.pid, self.on_child_end)
def idle_write_chunk(self):
if not self.pipe:
@@ -153,7 +152,7 @@ class Capture(gobject.GObject):
return False
def on_output(self, source, condition):
- if condition & (glib.IO_IN | glib.IO_PRI):
+ if condition & (GLib.IOCondition.IN | GLib.IOCondition.PRI):
line = source.read()
if len(line) > 0:
@@ -179,7 +178,7 @@ class Capture(gobject.GObject):
else:
self.emit('stderr-line', line)
- if condition & ~(glib.IO_IN | glib.IO_PRI):
+ if condition & ~(GLib.IOCondition.IN | GLib.IOCondition.PRI):
if self.read_buffer:
if source == self.pipe.stdout:
self.emit('stdout-line', self.read_buffer)
@@ -197,7 +196,7 @@ class Capture(gobject.GObject):
def stop(self, error_code = -1):
if self.pipe is not None:
if self.idle_write_id:
- gobject.source_remove(self.idle_write_id)
+ GLib.source_remove(self.idle_write_id)
self.idle_write_id = 0
if not self.tried_killing:
@@ -209,6 +208,6 @@ class Capture(gobject.GObject):
def on_child_end(self, pid, error_code):
# In an idle, so it is emitted after all the std*-line signals
# have been intercepted
- gobject.idle_add(self.emit, 'end-execute', error_code)
+ GLib.idle_add(self.emit, 'end-execute', error_code)
# ex:ts=4:et:
diff --git a/plugins/externaltools/tools/filelookup.py b/plugins/externaltools/tools/filelookup.py
index ce4961f9..aa5abf9b 100755
--- a/plugins/externaltools/tools/filelookup.py
+++ b/plugins/externaltools/tools/filelookup.py
@@ -17,8 +17,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
-import gio
-import pluma
+from gi.repository import Gio, Pluma
class FileLookup:
"""
@@ -73,7 +72,7 @@ class AbsoluteFileLookupProvider(FileLookupProvider):
def lookup(self, path):
if os.path.isabs(path) and os.path.isfile(path):
- return gio.File(path)
+ return Gio.file_new_for_path(path)
else:
return None
@@ -93,7 +92,7 @@ class CwdFileLookupProvider(FileLookupProvider):
real_path = os.path.join(cwd, path)
if os.path.isfile(real_path):
- return gio.File(real_path)
+ return Gio.file_new_for_path(real_path)
else:
return None
@@ -110,14 +109,14 @@ class OpenDocumentRelPathFileLookupProvider(FileLookupProvider):
if path.startswith('/'):
return None
- for doc in pluma.app_get_default().get_documents():
+ for doc in Pluma.App.get_default().get_documents():
if doc.is_local():
location = doc.get_location()
if location:
rel_path = location.get_parent().get_path()
joined_path = os.path.join(rel_path, path)
if os.path.isfile(joined_path):
- return gio.File(joined_path)
+ return Gio.file_new_for_path(joined_path)
return None
@@ -135,7 +134,7 @@ class OpenDocumentFileLookupProvider(FileLookupProvider):
if path.startswith('/'):
return None
- for doc in pluma.app_get_default().get_documents():
+ for doc in Pluma.App.get_default().get_documents():
if doc.is_local():
location = doc.get_location()
if location and location.get_uri().endswith(path):
diff --git a/plugins/externaltools/tools/functions.py b/plugins/externaltools/tools/functions.py
index b4b666f6..e1268443 100755
--- a/plugins/externaltools/tools/functions.py
+++ b/plugins/externaltools/tools/functions.py
@@ -17,11 +17,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
-import gtk
-from gtk import gdk
-import gio
-import pluma
-#import gtksourceview
+from gi.repository import Gio, Gdk, Gtk, GtkSource, Pluma
from outputpanel import OutputPanel
from capture import *
@@ -44,7 +40,7 @@ def current_word(document):
return (start, piter)
# ==== Capture related functions ====
-def run_external_tool(window, node):
+def run_external_tool(window, panel, node):
# Configure capture environment
try:
cwd = os.getcwd()
@@ -87,13 +83,13 @@ def run_external_tool(window, node):
capture.set_env(PLUMA_CURRENT_DOCUMENT_TYPE=document.get_mime_type())
if uri is not None:
- gfile = gio.File(uri)
+ gfile = Gio.file_new_for_uri(uri)
scheme = gfile.get_uri_scheme()
name = os.path.basename(uri)
capture.set_env(PLUMA_CURRENT_DOCUMENT_URI = uri,
PLUMA_CURRENT_DOCUMENT_NAME = name,
PLUMA_CURRENT_DOCUMENT_SCHEME = scheme)
- if pluma.utils.uri_has_file_scheme(uri):
+ if Pluma.utils_uri_has_file_scheme(uri):
path = gfile.get_path()
cwd = os.path.dirname(path)
capture.set_cwd(cwd)
@@ -103,9 +99,9 @@ def run_external_tool(window, node):
documents_uri = [doc.get_uri()
for doc in window.get_documents()
if doc.get_uri() is not None]
- documents_path = [gio.File(uri).get_path()
+ documents_path = [Gio.file_new_for_uri(uri).get_path()
for uri in documents_uri
- if pluma.utils.uri_has_file_scheme(uri)]
+ if Pluma.utils_uri_has_file_scheme(uri)]
capture.set_env(PLUMA_DOCUMENTS_URI = ' '.join(documents_uri),
PLUMA_DOCUMENTS_PATH = ' '.join(documents_path))
@@ -120,8 +116,7 @@ def run_external_tool(window, node):
input_type = node.input
output_type = node.output
- # Get the panel
- panel = window.get_data("ExternalToolsPluginWindowData")._output_buffer
+ # Clear the panel
panel.clear()
if output_type == 'output-panel':
@@ -167,7 +162,7 @@ def run_external_tool(window, node):
if not end.ends_word():
end.forward_word_end()
- input_text = document.get_text(start, end)
+ input_text = document.get_text(start, end, False)
capture.set_input(input_text)
# Assign the standard output to the chosen "file"
@@ -211,8 +206,9 @@ def run_external_tool(window, node):
document.end_user_action()
class MultipleDocumentsSaver:
- def __init__(self, window, docs, node):
+ def __init__(self, window, panel, docs, node):
self._window = window
+ self._panel = panel
self._node = node
self._error = False
@@ -224,7 +220,7 @@ class MultipleDocumentsSaver:
for doc in docs:
signals[doc] = doc.connect('saving', self.on_document_saving)
- pluma.commands.save_document(window, doc)
+ Pluma.commands_save_document(window, doc)
doc.disconnect(signals[doc])
def on_document_saving(self, doc, size, total_size):
@@ -241,17 +237,17 @@ class MultipleDocumentsSaver:
self._counter -= 1
if self._counter == 0 and not self._error:
- run_external_tool(self._window, self._node)
+ run_external_tool(self._window, self._panel, self._node)
-def capture_menu_action(action, window, node):
+def capture_menu_action(action, window, panel, node):
if node.save_files == 'document' and window.get_active_document():
- MultipleDocumentsSaver(window, [window.get_active_document()], node)
+ MultipleDocumentsSaver(window, panel, [window.get_active_document()], node)
return
elif node.save_files == 'all':
- MultipleDocumentsSaver(window, window.get_documents(), node)
+ MultipleDocumentsSaver(window, panel, window.get_documents(), node)
return
- run_external_tool(window, node)
+ run_external_tool(window, panel, node)
def capture_stderr_line_panel(capture, line, panel):
if not panel.visible():
@@ -260,7 +256,7 @@ def capture_stderr_line_panel(capture, line, panel):
panel.write(line, panel.error_tag)
def capture_begin_execute_panel(capture, panel, view, label):
- view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gdk.Cursor(gdk.WATCH))
+ view.get_window(Gtk.TextWindowType.TEXT).set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
panel['stop'].set_sensitive(True)
panel.clear()
@@ -276,15 +272,14 @@ def capture_end_execute_panel(capture, exit_code, panel, view, output_type):
end = start.copy()
end.forward_chars(300)
- mtype = gio.content_type_guess(data=doc.get_text(start, end))
- lmanager = pluma.get_language_manager()
-
+ mtype, uncertain = Gio.content_type_guess(None, doc.get_text(start, end, False).encode('utf-8'))
+ lmanager = GtkSource.LanguageManager.get_default()
language = lmanager.guess_language(doc.get_uri(), mtype)
if language is not None:
doc.set_language(language)
- view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gdk.Cursor(gdk.XTERM))
+ view.get_window(Gtk.TextWindowType.TEXT).set_cursor(Gdk.Cursor.new(Gdk.CursorType.XTERM))
view.set_cursor_visible(True)
view.set_editable(True)
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
index 09a0cd42..b4e6924e 100755
--- a/plugins/externaltools/tools/library.py
+++ b/plugins/externaltools/tools/library.py
@@ -19,6 +19,7 @@
import os
import re
import locale
+from gi.repository import GLib
class Singleton(object):
_instance = None
@@ -44,7 +45,7 @@ class ToolLibrary(Singleton):
self.locations.append(datadir)
# self.locations[0] is where we save the custom scripts
- toolsdir = os.path.expanduser('~/.config/pluma/tools')
+ toolsdir = os.path.join(GLib.get_user_config_dir(), 'pluma/tools')
self.locations.insert(0, toolsdir);
if not os.path.isdir(self.locations[0]):
@@ -68,7 +69,7 @@ class ToolLibrary(Singleton):
# storage file.
def import_old_xml_store(self):
import xml.etree.ElementTree as et
- filename = os.path.expanduser('~/.config/pluma/pluma-tools.xml')
+ filename = os.path.join(GLib.get_user_config_dir(), 'pluma/pluma-tools.xml')
if not os.path.isfile(filename):
return
diff --git a/plugins/externaltools/tools/manager.py b/plugins/externaltools/tools/manager.py
index 4d4d50aa..24d7d71a 100755
--- a/plugins/externaltools/tools/manager.py
+++ b/plugins/externaltools/tools/manager.py
@@ -18,23 +18,22 @@
__all__ = ('Manager', )
-import pluma
-import gtk
-import gtksourceview2 as gsv
import os.path
from library import *
from functions import *
import hashlib
from xml.sax import saxutils
-import gobject
+from gi.repository import GObject, Gio, Gdk, Gtk, GtkSource, Pluma
+
+class LanguagesPopup(Gtk.Window):
+ __gtype_name__ = "LanguagePopup"
-class LanguagesPopup(gtk.Window):
COLUMN_NAME = 0
COLUMN_ID = 1
COLUMN_ENABLED = 2
def __init__(self, languages):
- gtk.Window.__init__(self, gtk.WINDOW_POPUP)
+ Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP)
self.set_default_size(200, 200)
self.props.can_focus = True
@@ -43,44 +42,61 @@ class LanguagesPopup(gtk.Window):
self.init_languages(languages)
self.show()
- self.map()
self.grab_add()
- gtk.gdk.keyboard_grab(self.window, False, 0L)
- gtk.gdk.pointer_grab(self.window, False, gtk.gdk.BUTTON_PRESS_MASK |
- gtk.gdk.BUTTON_RELEASE_MASK |
- gtk.gdk.POINTER_MOTION_MASK |
- gtk.gdk.ENTER_NOTIFY_MASK |
- gtk.gdk.LEAVE_NOTIFY_MASK |
- gtk.gdk.PROXIMITY_IN_MASK |
- gtk.gdk.PROXIMITY_OUT_MASK, None, None, 0L)
+ self.keyboard = None
+ device_manager = Gdk.Display.get_device_manager(self.get_window().get_display())
+ for device in device_manager.list_devices(Gdk.DeviceType.MASTER):
+ if device.get_source() == Gdk.InputSource.KEYBOARD:
+ self.keyboard = device
+ break
+
+ self.pointer = device_manager.get_client_pointer()
+
+ if self.keyboard is not None:
+ self.keyboard.grab(self.get_window(),
+ Gdk.GrabOwnership.WINDOW, False,
+ Gdk.EventMask.KEY_PRESS_MASK |
+ Gdk.EventMask.KEY_RELEASE_MASK,
+ None, Gdk.CURRENT_TIME)
+ self.pointer.grab(self.get_window(),
+ Gdk.GrabOwnership.WINDOW, False,
+ Gdk.EventMask.BUTTON_PRESS_MASK |
+ Gdk.EventMask.BUTTON_RELEASE_MASK |
+ Gdk.EventMask.POINTER_MOTION_MASK |
+ Gdk.EventMask.ENTER_NOTIFY_MASK |
+ Gdk.EventMask.LEAVE_NOTIFY_MASK |
+ Gdk.EventMask.PROXIMITY_IN_MASK |
+ Gdk.EventMask.PROXIMITY_OUT_MASK |
+ Gdk.EventMask.SCROLL_MASK,
+ None, Gdk.CURRENT_TIME)
self.view.get_selection().select_path((0,))
def build(self):
- self.model = gtk.ListStore(str, str, bool)
+ self.model = Gtk.ListStore(str, str, bool)
- self.sw = gtk.ScrolledWindow()
+ self.sw = Gtk.ScrolledWindow()
self.sw.show()
- self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
+ self.sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
+ self.sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
- self.view = gtk.TreeView(self.model)
+ self.view = Gtk.TreeView(self.model)
self.view.show()
self.view.set_headers_visible(False)
- column = gtk.TreeViewColumn()
+ column = Gtk.TreeViewColumn()
- renderer = gtk.CellRendererToggle()
+ renderer = Gtk.CellRendererToggle()
column.pack_start(renderer, False)
column.set_attributes(renderer, active=self.COLUMN_ENABLED)
renderer.connect('toggled', self.on_language_toggled)
- renderer = gtk.CellRendererText()
+ renderer = Gtk.CellRendererText()
column.pack_start(renderer, True)
column.set_attributes(renderer, text=self.COLUMN_NAME)
@@ -94,7 +110,7 @@ class LanguagesPopup(gtk.Window):
def enabled_languages(self, model, path, piter, ret):
enabled = model.get_value(piter, self.COLUMN_ENABLED)
- if path == (0,) and enabled:
+ if path.get_indices()[0] == 0 and enabled:
return True
if enabled:
@@ -113,8 +129,9 @@ class LanguagesPopup(gtk.Window):
return val == '-'
def init_languages(self, languages):
- manager = gsv.LanguageManager()
- langs = pluma.language_manager_list_languages_sorted(manager, True)
+ manager = GtkSource.LanguageManager()
+ langs = [manager.get_language(x) for x in manager.get_language_ids()]
+ langs.sort(key=lambda x: x.get_name())
self.model.append([_('All languages'), None, not languages])
self.model.append(['-', None, False])
@@ -142,7 +159,7 @@ class LanguagesPopup(gtk.Window):
self.model.set_value(self.model.get_iter_first(), self.COLUMN_ENABLED, False)
def do_key_press_event(self, event):
- if event.keyval == gtk.keysyms.Escape:
+ if event.keyval == Gdk.KEY_Escape:
self.destroy()
return True
else:
@@ -155,34 +172,35 @@ class LanguagesPopup(gtk.Window):
def in_window(self, event, window=None):
if not window:
- window = self.window
+ window = self.get_window()
geometry = window.get_geometry()
origin = window.get_origin()
- return event.x_root >= origin[0] and \
- event.x_root <= origin[0] + geometry[2] and \
- event.y_root >= origin[1] and \
- event.y_root <= origin[1] + geometry[3]
+ return event.x_root >= origin[1] and \
+ event.x_root <= origin[1] + geometry[2] and \
+ event.y_root >= origin[2] and \
+ event.y_root <= origin[2] + geometry[3]
def do_destroy(self):
- gtk.gdk.keyboard_ungrab(0L)
- gtk.gdk.pointer_ungrab(0L)
+ if self.keyboard:
+ self.keyboard.ungrab(Gdk.CURRENT_TIME)
+ self.pointer.ungrab(Gdk.CURRENT_TIME)
- return gtk.Window.do_destroy(self)
+ return Gtk.Window.do_destroy(self)
def setup_event(self, event, window):
fr = event.window.get_origin()
to = window.get_origin()
event.window = window
- event.x += fr[0] - to[0]
- event.y += fr[1] - to[1]
+ event.x += fr[1] - to[1]
+ event.y += fr[2] - to[2]
def resolve_widgets(self, root):
res = [root]
- if isinstance(root, gtk.Container):
+ if isinstance(root, Gtk.Container):
root.forall(lambda x, y: res.extend(self.resolve_widgets(x)), None)
return res
@@ -196,14 +214,14 @@ class LanguagesPopup(gtk.Window):
return res
- def propagate_mouse_event(self, event):
+ def propagate_mouse_event(self, event, reverse=True):
allwidgets = self.resolve_widgets(self.get_child())
- allwidgets.reverse()
-
- orig = [event.x, event.y]
+
+ if reverse:
+ allwidgets.reverse()
for widget in allwidgets:
- windows = self.resolve_windows(widget.window)
+ windows = self.resolve_windows(widget.get_window())
windows.reverse()
for window in windows:
@@ -231,7 +249,7 @@ class LanguagesPopup(gtk.Window):
return self.propagate_mouse_event(event)
def do_scroll_event(self, event):
- return self.propagate_mouse_event(event)
+ return self.propagate_mouse_event(event, False)
def do_motion_notify_event(self, event):
return self.propagate_mouse_event(event)
@@ -248,25 +266,33 @@ class LanguagesPopup(gtk.Window):
def do_proximity_out_event(self, event):
return self.propagate_mouse_event(event)
-gobject.type_register(LanguagesPopup)
-
-class Manager:
+class Manager(GObject.Object):
TOOL_COLUMN = 0 # For Tree
NAME_COLUMN = 1 # For Combo
+ __gsignals__ = {
+ 'tools-updated': (GObject.SignalFlags.RUN_LAST, None, ())
+ }
+
def __init__(self, datadir):
+ GObject.Object.__init__(self)
self.datadir = datadir
self.dialog = None
+ self._size = (0, 0)
self._languages = {}
self._tool_rows = {}
self.build()
+
+ def get_final_size(self):
+ return self._size
def build(self):
callbacks = {
'on_new_tool_button_clicked' : self.on_new_tool_button_clicked,
'on_remove_tool_button_clicked' : self.on_remove_tool_button_clicked,
'on_tool_manager_dialog_response' : self.on_tool_manager_dialog_response,
+ 'on_tool_manager_dialog_configure_event': self.on_tool_manager_dialog_configure_event,
'on_tool_manager_dialog_focus_out': self.on_tool_manager_dialog_focus_out,
'on_accelerator_key_press' : self.on_accelerator_key_press,
'on_accelerator_focus_in' : self.on_accelerator_focus_in,
@@ -275,7 +301,7 @@ class Manager:
}
# Load the "main-window" widget from the ui file.
- self.ui = gtk.Builder()
+ self.ui = Gtk.Builder()
self.ui.add_from_file(os.path.join(self.datadir, 'ui', 'tools.ui'))
self.ui.connect_signals(callbacks)
self.dialog = self.ui.get_object('tool-manager-dialog')
@@ -345,7 +371,7 @@ class Manager:
del self.accelerators[shortcut]
def add_tool_to_language(self, tool, language):
- if isinstance(language, gsv.Language):
+ if isinstance(language, GtkSource.Language):
lid = language.get_id()
else:
lid = language
@@ -353,7 +379,7 @@ class Manager:
if not lid in self._languages:
piter = self.model.append(None, [language])
- parent = gtk.TreeRowReference(self.model, self.model.get_path(piter))
+ parent = Gtk.TreeRowReference.new(self.model, self.model.get_path(piter))
self._languages[lid] = parent
else:
parent = self._languages[lid]
@@ -364,11 +390,11 @@ class Manager:
if not tool in self._tool_rows:
self._tool_rows[tool] = []
- self._tool_rows[tool].append(gtk.TreeRowReference(self.model, self.model.get_path(child)))
+ self._tool_rows[tool].append(Gtk.TreeRowReference.new(self.model, self.model.get_path(child)))
return child
def add_tool(self, tool):
- manager = gsv.LanguageManager()
+ manager = GtkSource.LanguageManager()
ret = None
for lang in tool.languages:
@@ -391,16 +417,16 @@ class Manager:
self.script_hash = None
self.accelerators = dict()
- self.model = gtk.TreeStore(object)
+ self.model = Gtk.TreeStore(object)
self.view.set_model(self.model)
for tool in self.tools.tree.tools:
self.add_tool(tool)
self.model.set_default_sort_func(self.sort_tools)
- self.model.set_sort_column_id(-1, gtk.SORT_ASCENDING)
+ self.model.set_sort_column_id(-1, Gtk.SortType.ASCENDING)
- def sort_tools(self, model, iter1, iter2):
+ def sort_tools(self, model, iter1, iter2, user_data=None):
# For languages, sort All before everything else, otherwise alphabetical
t1 = model.get_value(iter1, self.TOOL_COLUMN)
t2 = model.get_value(iter2, self.TOOL_COLUMN)
@@ -413,7 +439,7 @@ class Manager:
return 1
def lang_name(lang):
- if isinstance(lang, gsv.Language):
+ if isinstance(lang, GtkSource.Language):
return lang.get_name()
else:
return _('Plain Text')
@@ -428,13 +454,13 @@ class Manager:
def __init_tools_view(self):
# Tools column
- column = gtk.TreeViewColumn('Tools')
- renderer = gtk.CellRendererText()
+ column = Gtk.TreeViewColumn('Tools')
+ renderer = Gtk.CellRendererText()
column.pack_start(renderer, False)
renderer.set_property('editable', True)
self.view.append_column(column)
- column.set_cell_data_func(renderer, self.get_cell_data_cb)
+ column.set_cell_data_func(renderer, self.get_cell_data_cb, None)
renderer.connect('edited', self.on_view_label_cell_edited)
renderer.connect('editing-started', self.on_view_label_cell_editing_started)
@@ -493,7 +519,8 @@ class Manager:
self.current_node.save_files = combo_value(self, 'save-files')
buf = self['commands'].get_buffer()
- script = buf.get_text(*buf.get_bounds())
+ (start, end) = buf.get_bounds()
+ script = buf.get_text(start, end, False)
h = self.compute_hash(script)
if h != self.script_hash:
# script has changed -> save it
@@ -507,10 +534,10 @@ class Manager:
def clear_fields(self):
self['accelerator'].set_text('')
- buf = self['commands'].get_buffer()
- buf.begin_not_undoable_action()
- buf.set_text('')
- buf.end_not_undoable_action()
+ buf = self['commands'].get_buffer()
+ buf.begin_not_undoable_action()
+ buf.set_text('')
+ buf.end_not_undoable_action()
for nm in ('input', 'output', 'applicability', 'save-files'):
self[nm].set_active(0)
@@ -521,7 +548,7 @@ class Manager:
if not self.current_node or not self.current_node.languages:
self['languages_label'].set_text(_('All Languages'))
else:
- manager = gsv.LanguageManager()
+ manager = GtkSource.LanguageManager()
langs = []
for lang in self.current_node.languages:
@@ -542,13 +569,13 @@ class Manager:
buf = self['commands'].get_buffer()
script = default(''.join(node.get_script()), '')
- buf.begin_not_undoable_action()
- buf.set_text(script)
- buf.end_not_undoable_action()
+ buf.begin_not_undoable_action()
+ buf.set_text(script)
+ buf.end_not_undoable_action()
self.script_hash = self.compute_hash(script)
- contenttype = gio.content_type_guess(data=script)
- lmanager = pluma.get_language_manager()
+ contenttype, uncertain = Gio.content_type_guess(None, script)
+ lmanager = GtkSource.LanguageManager.get_default()
language = lmanager.guess_language(content_type=contenttype)
if language is not None:
@@ -605,7 +632,7 @@ class Manager:
piter = self.model.iter_parent(piter)
tool = self.model.get_value(piter, self.TOOL_COLUMN)
- if isinstance(tool, gsv.Language):
+ if isinstance(tool, GtkSource.Language):
return tool.get_id()
elif tool:
return 'plain'
@@ -712,7 +739,7 @@ class Manager:
piter = self.model.get_iter(path)
tool = self.model.get_value(piter, self.TOOL_COLUMN)
- if isinstance(editable, gtk.Entry):
+ if isinstance(editable, Gtk.Entry):
editable.set_text(tool.name)
editable.grab_focus()
@@ -742,7 +769,7 @@ class Manager:
# Check whether accelerator already exists
self.remove_accelerator(self.current_node)
- name = gtk.accelerator_name(keyval, mod)
+ name = Gtk.accelerator_name(keyval, mod)
if name == '':
self.current_node.shorcut = None
@@ -752,10 +779,10 @@ class Manager:
col = self.accelerator_collision(name, self.current_node)
if col:
- dialog = gtk.MessageDialog(self.dialog,
- gtk.DIALOG_MODAL,
- gtk.MESSAGE_ERROR,
- gtk.BUTTONS_OK,
+ dialog = Gtk.MessageDialog(self.dialog,
+ Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.CLOSE,
_('This accelerator is already bound to %s') % (', '.join(map(lambda x: x.name, col)),))
dialog.run()
@@ -771,20 +798,20 @@ class Manager:
return True
def on_accelerator_key_press(self, entry, event):
- mask = event.state & gtk.accelerator_get_default_mod_mask()
+ mask = event.state & Gtk.accelerator_get_default_mod_mask()
- if event.keyval == gtk.keysyms.Escape:
+ if event.keyval == Gdk.KEY_Escape:
entry.set_text(default(self.current_node.shortcut, ''))
self['commands'].grab_focus()
return True
- elif event.keyval == gtk.keysyms.Delete \
- or event.keyval == gtk.keysyms.BackSpace:
+ elif event.keyval == Gdk.KEY_Delete \
+ or event.keyval == Gdk.KEY_BackSpace:
entry.set_text('')
self.remove_accelerator(self.current_node)
self.current_node.shortcut = None
self['commands'].grab_focus()
return True
- elif event.keyval in range(gtk.keysyms.F1, gtk.keysyms.F12 + 1):
+ elif event.keyval in range(Gdk.KEY_F1, Gdk.KEY_F12 + 1):
# New accelerator
if self.set_accelerator(event.keyval, mask):
entry.set_text(default(self.current_node.shortcut, ''))
@@ -792,7 +819,7 @@ class Manager:
# Capture all `normal characters`
return True
- elif gtk.gdk.keyval_to_unicode(event.keyval):
+ elif Gdk.keyval_to_unicode(event.keyval):
if mask:
# New accelerator
if self.set_accelerator(event.keyval, mask):
@@ -817,8 +844,8 @@ class Manager:
self.tool_changed(self.current_node)
def on_tool_manager_dialog_response(self, dialog, response):
- if response == gtk.RESPONSE_HELP:
- pluma.help_display(self.dialog, 'pluma', 'pluma-external-tools-plugin')
+ if response == Gtk.ResponseType.HELP:
+ Pluma.help_display(self.dialog, 'pluma', 'pluma-external-tools-plugin')
return
self.on_tool_manager_dialog_focus_out(dialog, None)
@@ -827,20 +854,22 @@ class Manager:
self.dialog = None
self.tools = None
+ def on_tool_manager_dialog_configure_event(self, dialog, event):
+ if dialog.get_realized():
+ alloc = dialog.get_allocation()
+ self._size = (alloc.width, alloc.height)
+
def on_tool_manager_dialog_focus_out(self, dialog, event):
self.save_current_tool()
+ self.emit('tools-updated')
- for window in pluma.app_get_default().get_windows():
- helper = window.get_data("ExternalToolsPluginWindowData")
- helper.menu.update()
-
- def get_cell_data_cb(self, column, cell, model, piter):
+ def get_cell_data_cb(self, column, cell, model, piter, user_data=None):
tool = model.get_value(piter, self.TOOL_COLUMN)
if tool == None or not isinstance(tool, Tool):
if tool == None:
label = _('All Languages')
- elif not isinstance(tool, gsv.Language):
+ elif not isinstance(tool, GtkSource.Language):
label = _('Plain Text')
else:
label = tool.get_name()
@@ -869,7 +898,7 @@ class Manager:
for row in self._tool_rows[tool]:
path = row.get_path()
- if path[0] == parent[0]:
+ if path.get_indices()[0] == parent.get_indices()[0]:
return True
return False
@@ -882,7 +911,7 @@ class Manager:
ret = None
if node:
- ref = gtk.TreeRowReference(self.model, self.model.get_path(piter))
+ ref = Gtk.TreeRowReference(self.model, self.model.get_path(piter))
# Update languages, make sure to inhibit selection change stuff
self.view.get_selection().handler_block(self.selection_changed_id)
@@ -908,7 +937,7 @@ class Manager:
del self._languages[language]
# Now, add for any that are new
- manager = gsv.LanguageManager()
+ manager = GtkSource.LanguageManager()
for lang in self.current_node.languages:
if not self.tool_in_language(self.current_node, lang):
@@ -940,8 +969,8 @@ class Manager:
popup = LanguagesPopup(self.current_node.languages)
popup.set_transient_for(self.dialog)
- origin = button.window.get_origin()
- popup.move(origin[0], origin[1] - popup.allocation.height)
+ origin = button.get_window().get_origin()
+ popup.move(origin[1], origin[2] - popup.get_allocation().height)
popup.connect('destroy', self.update_languages)
diff --git a/plugins/externaltools/tools/outputpanel.py b/plugins/externaltools/tools/outputpanel.py
index 9d1da65f..9613d78c 100755
--- a/plugins/externaltools/tools/outputpanel.py
+++ b/plugins/externaltools/tools/outputpanel.py
@@ -19,17 +19,13 @@
__all__ = ('OutputPanel', 'UniqueById')
-import gtk, pluma
-import pango
-import gobject
import os
from weakref import WeakKeyDictionary
from capture import *
-from gtk import gdk
import re
-import gio
import linkparsing
import filelookup
+from gi.repository import GLib, Gdk, Gtk, Pango, Pluma
class UniqueById:
__shared_state = WeakKeyDictionary()
@@ -58,12 +54,12 @@ class OutputPanel(UniqueById):
}
self.window = window
- self.ui = gtk.Builder()
+ self.ui = Gtk.Builder()
self.ui.add_from_file(os.path.join(datadir, 'ui', 'outputpanel.ui'))
self.ui.connect_signals(callbacks)
self.panel = self["output-panel"]
- self['view'].modify_font(pango.FontDescription('Monospace'))
+ self['view'].override_font(Pango.font_description_from_string('Monospace'))
buffer = self['view'].get_buffer()
@@ -73,18 +69,18 @@ class OutputPanel(UniqueById):
self.error_tag.set_property('foreground', 'red')
self.italic_tag = buffer.create_tag('italic')
- self.italic_tag.set_property('style', pango.STYLE_OBLIQUE)
+ self.italic_tag.set_property('style', Pango.Style.OBLIQUE)
self.bold_tag = buffer.create_tag('bold')
- self.bold_tag.set_property('weight', pango.WEIGHT_BOLD)
+ self.bold_tag.set_property('weight', Pango.Weight.BOLD)
self.invalid_link_tag = buffer.create_tag('invalid_link')
self.link_tag = buffer.create_tag('link')
- self.link_tag.set_property('underline', pango.UNDERLINE_SINGLE)
+ self.link_tag.set_property('underline', Pango.Underline.SINGLE)
- self.link_cursor = gdk.Cursor(gdk.HAND2)
- self.normal_cursor = gdk.Cursor(gdk.XTERM)
+ self.link_cursor = Gdk.Cursor.new(Gdk.CursorType.HAND2)
+ self.normal_cursor = Gdk.Cursor.new(Gdk.CursorType.XTERM)
self.process = None
@@ -108,7 +104,7 @@ class OutputPanel(UniqueById):
def scroll_to_end(self):
iter = self['view'].get_buffer().get_end_iter()
- self['view'].scroll_to_iter(iter, 0.0)
+ self['view'].scroll_to_iter(iter, 0.0, False, 0.5, 0.5)
return False # don't requeue this handler
def clear(self):
@@ -153,7 +149,7 @@ class OutputPanel(UniqueById):
buffer.apply_tag(tag, start_iter, end_iter)
buffer.delete_mark(insert)
- gobject.idle_add(self.scroll_to_end)
+ GLib.idle_add(self.scroll_to_end)
def show(self):
panel = self.window.get_bottom_panel()
@@ -166,16 +162,16 @@ class OutputPanel(UniqueById):
else:
cursor = self.normal_cursor
- view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(cursor)
+ view.get_window(Gtk.TextWindowType.TEXT).set_cursor(cursor)
def on_view_motion_notify_event(self, view, event):
- if event.window == view.get_window(gtk.TEXT_WINDOW_TEXT):
+ if event.window == view.get_window(Gtk.TextWindowType.TEXT):
self.update_cursor_style(view, int(event.x), int(event.y))
return False
def on_view_visibility_notify_event(self, view, event):
- if event.window == view.get_window(gtk.TEXT_WINDOW_TEXT):
+ if event.window == view.get_window(Gtk.TextWindowType.TEXT):
x, y, m = event.window.get_pointer()
self.update_cursor_style(view, x, y)
@@ -192,9 +188,17 @@ class OutputPanel(UniqueById):
"""
# get the offset within the buffer from the x,y coordinates
- buff_x, buff_y = view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT,
+ buff_x, buff_y = view.window_to_buffer_coords(Gtk.TextWindowType.TEXT,
x, y)
- iter_at_xy = view.get_iter_at_location(buff_x, buff_y)
+ # usual API breakage in GTK+3, nothing new...
+ # see https://bugzilla.gnome.org/768793
+ if Gtk.get_minor_version() >= 20:
+ (over_text, iter_at_xy) = view.get_iter_at_location(buff_x, buff_y)
+ if not over_text:
+ return None
+ else:
+ iter_at_xy = view.get_iter_at_location(buff_x, buff_y)
+
offset = iter_at_xy.get_offset()
# find the first link that contains the offset
@@ -206,8 +210,8 @@ class OutputPanel(UniqueById):
return None
def on_view_button_press_event(self, view, event):
- if event.button != 1 or event.type != gdk.BUTTON_PRESS or \
- event.window != view.get_window(gtk.TEXT_WINDOW_TEXT):
+ if event.button != 1 or event.type != Gdk.EventType.BUTTON_PRESS or \
+ event.window != view.get_window(Gtk.TextWindowType.TEXT):
return False
link = self.get_link_at_location(view, int(event.x), int(event.y))
@@ -217,8 +221,8 @@ class OutputPanel(UniqueById):
gfile = self.file_lookup.lookup(link.path)
if gfile:
- pluma.commands.load_uri(self.window, gfile.get_uri(), None,
+ Pluma.commands.load_uri(self.window, gfile.get_uri(), None,
link.line_nr)
- gobject.idle_add(self.idle_grab_focus)
+ GLib.idle_add(self.idle_grab_focus)
# ex:ts=4:et:
diff --git a/plugins/externaltools/tools/tools.ui b/plugins/externaltools/tools/tools.ui
index fde220d1..afdd3f9d 100644
--- a/plugins/externaltools/tools/tools.ui
+++ b/plugins/externaltools/tools/tools.ui
@@ -131,6 +131,7 @@
<property name="default_height">500</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
+ <signal name="configure_event" handler="on_tool_manager_dialog_configure_event"/>
<signal name="focus_out_event" handler="on_tool_manager_dialog_focus_out"/>
<signal name="response" handler="on_tool_manager_dialog_response"/>
<child internal-child="vbox">
@@ -551,6 +552,8 @@
</child>
</object>
<packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
diff --git a/plugins/pythonconsole/Makefile.am b/plugins/pythonconsole/Makefile.am
index 53361183..0a9ff965 100644
--- a/plugins/pythonconsole/Makefile.am
+++ b/plugins/pythonconsole/Makefile.am
@@ -2,10 +2,10 @@
SUBDIRS = pythonconsole
plugindir = $(PLUMA_PLUGINS_LIBS_DIR)
-plugin_in_files = pythonconsole.pluma-plugin.desktop.in
-%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+plugin_in_files = pythonconsole.plugin.desktop.in
+%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin)
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
EXTRA_DIST = $(plugin_in_files)
diff --git a/plugins/pythonconsole/pythonconsole.pluma-plugin.desktop.in b/plugins/pythonconsole/pythonconsole.plugin.desktop.in
index 1d6747e1..50d2a7a7 100644
--- a/plugins/pythonconsole/pythonconsole.pluma-plugin.desktop.in
+++ b/plugins/pythonconsole/pythonconsole.plugin.desktop.in
@@ -1,4 +1,4 @@
-[Pluma Plugin]
+[Plugin]
Loader=python
Module=pythonconsole
IAge=2
diff --git a/plugins/pythonconsole/pythonconsole/__init__.py b/plugins/pythonconsole/pythonconsole/__init__.py
index 347df0ee..59ac413e 100755
--- a/plugins/pythonconsole/pythonconsole/__init__.py
+++ b/plugins/pythonconsole/pythonconsole/__init__.py
@@ -24,38 +24,42 @@
# Bits from pluma Python Console Plugin
# Copyrignt (C), 2005 Raphaƫl Slinckx
-import gtk
-import pluma
+from gi.repository import GObject, Gtk, Peas, Pluma
from console import PythonConsole
from config import PythonConsoleConfigDialog
from config import PythonConsoleConfig
-PYTHON_ICON = 'mate-mime-text-x-python'
+PYTHON_ICON = 'text-x-python'
+
+class PythonConsolePlugin(GObject.Object, Peas.Activatable):
+ __gtype_name__ = "PythonConsolePlugin"
+
+ object = GObject.Property(type=GObject.Object)
-class PythonConsolePlugin(pluma.Plugin):
def __init__(self):
- pluma.Plugin.__init__(self)
+ GObject.Object.__init__(self)
self.dlg = None
- def activate(self, window):
- console = PythonConsole(namespace = {'__builtins__' : __builtins__,
- 'pluma' : pluma,
+ def do_activate(self):
+ window = self.object
+
+ self._console = PythonConsole(namespace = {'__builtins__' : __builtins__,
+ 'pluma' : Pluma,
'window' : window})
- console.eval('print "You can access the main window through ' \
+ self._console.eval('print "You can access the main window through ' \
'\'window\' :\\n%s" % window', False)
bottom = window.get_bottom_panel()
- image = gtk.Image()
- image.set_from_icon_name(PYTHON_ICON, gtk.ICON_SIZE_MENU)
- bottom.add_item(console, _('Python Console'), image)
- window.set_data('PythonConsolePluginInfo', console)
-
- def deactivate(self, window):
- console = window.get_data("PythonConsolePluginInfo")
- console.stop()
- window.set_data("PythonConsolePluginInfo", None)
+ image = Gtk.Image()
+ image.set_from_icon_name(PYTHON_ICON, Gtk.IconSize.MENU)
+ bottom.add_item(self._console, _('Python Console'), image)
+
+ def do_deactivate(self):
+ window = self.object
+
+ self._console.stop()
bottom = window.get_bottom_panel()
- bottom.remove_item(console)
+ bottom.remove_item(self._console)
def create_configure_dialog(self):
diff --git a/plugins/pythonconsole/pythonconsole/console.py b/plugins/pythonconsole/pythonconsole/console.py
index 5a01e311..75f60e4d 100755
--- a/plugins/pythonconsole/pythonconsole/console.py
+++ b/plugins/pythonconsole/pythonconsole/console.py
@@ -28,29 +28,27 @@ import string
import sys
import re
import traceback
-import gobject
-import gtk
-import pango
+from gi.repository import GObject, Gdk, Gtk, Pango
from config import PythonConsoleConfig
__all__ = ('PythonConsole', 'OutFile')
-class PythonConsole(gtk.ScrolledWindow):
+class PythonConsole(Gtk.ScrolledWindow):
__gsignals__ = {
'grab-focus' : 'override',
}
def __init__(self, namespace = {}):
- gtk.ScrolledWindow.__init__(self)
+ Gtk.ScrolledWindow.__init__(self)
- self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
- self.set_shadow_type(gtk.SHADOW_IN)
- self.view = gtk.TextView()
- self.view.modify_font(pango.FontDescription('Monospace'))
+ self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+ self.set_shadow_type(Gtk.ShadowType.IN)
+ self.view = Gtk.TextView()
+ self.view.modify_font(Pango.font_description_from_string('Monospace'))
self.view.set_editable(True)
- self.view.set_wrap_mode(gtk.WRAP_WORD_CHAR)
+ self.view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
self.add(self.view)
self.view.show()
@@ -98,19 +96,19 @@ class PythonConsole(gtk.ScrolledWindow):
self.namespace = None
def __key_press_event_cb(self, view, event):
- modifier_mask = gtk.accelerator_get_default_mod_mask()
+ modifier_mask = Gtk.accelerator_get_default_mod_mask()
event_state = event.state & modifier_mask
- if event.keyval == gtk.keysyms.d and event_state == gtk.gdk.CONTROL_MASK:
+ if event.keyval == Gdk.KEY_D and event_state == Gdk.ModifierType.CONTROL_MASK:
self.destroy()
- elif event.keyval == gtk.keysyms.Return and event_state == gtk.gdk.CONTROL_MASK:
+ elif event.keyval == Gdk.KEY_Return and event_state == Gdk.ModifierType.CONTROL_MASK:
# Get the command
buffer = view.get_buffer()
inp_mark = buffer.get_mark("input")
inp = buffer.get_iter_at_mark(inp_mark)
cur = buffer.get_end_iter()
- line = buffer.get_text(inp, cur)
+ line = buffer.get_text(inp, cur, False)
self.current_command = self.current_command + line + "\n"
self.history_add(line)
@@ -127,10 +125,10 @@ class PythonConsole(gtk.ScrolledWindow):
cur = buffer.get_end_iter()
buffer.place_cursor(cur)
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.Return:
+ elif event.keyval == Gdk.KEY_Return:
# Get the marks
buffer = view.get_buffer()
lin_mark = buffer.get_mark("input-line")
@@ -139,7 +137,7 @@ class PythonConsole(gtk.ScrolledWindow):
# Get the command line
inp = buffer.get_iter_at_mark(inp_mark)
cur = buffer.get_end_iter()
- line = buffer.get_text(inp, cur)
+ line = buffer.get_text(inp, cur, False)
self.current_command = self.current_command + line + "\n"
self.history_add(line)
@@ -171,25 +169,25 @@ class PythonConsole(gtk.ScrolledWindow):
cur = buffer.get_end_iter()
buffer.move_mark(inp_mark, cur)
buffer.place_cursor(cur)
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.KP_Down or event.keyval == gtk.keysyms.Down:
+ elif event.keyval == Gdk.KEY_KP_Down or event.keyval == Gdk.KEY_Down:
# Next entry from history
view.emit_stop_by_name("key_press_event")
self.history_down()
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.KP_Up or event.keyval == gtk.keysyms.Up:
+ elif event.keyval == Gdk.KEY_KP_Up or event.keyval == Gdk.KEY_Up:
# Previous entry from history
view.emit_stop_by_name("key_press_event")
self.history_up()
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
return True
- elif event.keyval == gtk.keysyms.KP_Left or event.keyval == gtk.keysyms.Left or \
- event.keyval == gtk.keysyms.BackSpace:
+ elif event.keyval == Gdk.KEY_KP_Left or event.keyval == Gdk.KEY_Left or \
+ event.keyval == Gdk.KEY_BackSpace:
buffer = view.get_buffer()
inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
cur = buffer.get_iter_at_mark(buffer.get_insert())
@@ -202,8 +200,8 @@ class PythonConsole(gtk.ScrolledWindow):
# For the console we enable smart/home end behavior incoditionally
# since it is useful when editing python
- elif (event.keyval == gtk.keysyms.KP_Home or event.keyval == gtk.keysyms.Home) and \
- event_state == event_state & (gtk.gdk.SHIFT_MASK|gtk.gdk.CONTROL_MASK):
+ elif (event.keyval == Gdk.KEY_KP_Home or event.keyval == Gdk.KEY_Home) and \
+ event_state == event_state & (Gdk.ModifierType.SHIFT_MASK|Gdk.ModifierType.CONTROL_MASK):
# Go to the begin of the command instead of the begin of the line
buffer = view.get_buffer()
iter = buffer.get_iter_at_mark(buffer.get_mark("input"))
@@ -215,14 +213,14 @@ class PythonConsole(gtk.ScrolledWindow):
if iter.equal(ins):
iter = buffer.get_iter_at_mark(buffer.get_mark("input"))
- if event_state & gtk.gdk.SHIFT_MASK:
+ if event_state & Gdk.ModifierType.SHIFT_MASK:
buffer.move_mark_by_name("insert", iter)
else:
buffer.place_cursor(iter)
return True
- elif (event.keyval == gtk.keysyms.KP_End or event.keyval == gtk.keysyms.End) and \
- event_state == event_state & (gtk.gdk.SHIFT_MASK|gtk.gdk.CONTROL_MASK):
+ elif (event.keyval == Gdk.KEY_KP_End or event.keyval == Gdk.KEY_End) and \
+ event_state == event_state & (Gdk.ModifierType.SHIFT_MASK|Gdk.ModifierType.CONTROL_MASK):
buffer = view.get_buffer()
iter = buffer.get_end_iter()
@@ -238,7 +236,7 @@ class PythonConsole(gtk.ScrolledWindow):
if iter.equal(ins):
iter = buffer.get_end_iter()
- if event_state & gtk.gdk.SHIFT_MASK:
+ if event_state & Gdk.ModifierType.SHIFT_MASK:
buffer.move_mark_by_name("insert", iter)
else:
buffer.place_cursor(iter)
@@ -253,7 +251,7 @@ class PythonConsole(gtk.ScrolledWindow):
buffer = self.view.get_buffer()
inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
cur = buffer.get_end_iter()
- return buffer.get_text(inp, cur)
+ return buffer.get_text(inp, cur, False)
def set_command_line(self, command):
buffer = self.view.get_buffer()
@@ -284,7 +282,7 @@ class PythonConsole(gtk.ScrolledWindow):
def scroll_to_end(self):
iter = self.view.get_buffer().get_end_iter()
- self.view.scroll_to_iter(iter, 0.0)
+ self.view.scroll_to_iter(iter, 0.0, False, 0.5, 0.5)
return False
def write(self, text, tag = None):
@@ -293,7 +291,7 @@ class PythonConsole(gtk.ScrolledWindow):
buffer.insert(buffer.get_end_iter(), text)
else:
buffer.insert_with_tags(buffer.get_end_iter(), text, tag)
- gobject.idle_add(self.scroll_to_end)
+ GObject.idle_add(self.scroll_to_end)
def eval(self, command, display_command = False):
buffer = self.view.get_buffer()
@@ -316,7 +314,7 @@ class PythonConsole(gtk.ScrolledWindow):
buffer.insert(cur, ">>> ")
cur = buffer.get_end_iter()
buffer.move_mark_by_name("input", cur)
- self.view.scroll_to_iter(buffer.get_end_iter(), 0.0)
+ self.view.scroll_to_iter(buffer.get_end_iter(), 0.0, False, 0.5, 0.5)
def __run(self, command):
sys.stdout, self.stdout = self.stdout, sys.stdout
diff --git a/plugins/quickopen/Makefile.am b/plugins/quickopen/Makefile.am
index 74cc89a0..4e5f8d85 100644
--- a/plugins/quickopen/Makefile.am
+++ b/plugins/quickopen/Makefile.am
@@ -2,10 +2,10 @@
SUBDIRS = quickopen
plugindir = $(PLUMA_PLUGINS_LIBS_DIR)
-plugin_in_files = quickopen.pluma-plugin.desktop.in
-%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+plugin_in_files = quickopen.plugin.desktop.in
+%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin)
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
EXTRA_DIST = $(plugin_in_files)
diff --git a/plugins/quickopen/quickopen.pluma-plugin.desktop.in b/plugins/quickopen/quickopen.plugin.desktop.in
index 0dcc3704..891a0c3f 100644
--- a/plugins/quickopen/quickopen.pluma-plugin.desktop.in
+++ b/plugins/quickopen/quickopen.plugin.desktop.in
@@ -1,4 +1,4 @@
-[Pluma Plugin]
+[Plugin]
Loader=python
Module=quickopen
IAge=2
diff --git a/plugins/quickopen/quickopen/__init__.py b/plugins/quickopen/quickopen/__init__.py
index 1a617d93..54e95984 100755
--- a/plugins/quickopen/quickopen/__init__.py
+++ b/plugins/quickopen/quickopen/__init__.py
@@ -17,25 +17,29 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
-import pluma
+from gi.repository import GObject, Peas
from windowhelper import WindowHelper
-class QuickOpenPlugin(pluma.Plugin):
+class QuickOpenPlugin(GObject.Object, Peas.Activatable):
+ __gtype_name__ = "QuickOpenPlugin"
+
+ object = GObject.Property(type=GObject.Object)
+
def __init__(self):
- pluma.Plugin.__init__(self)
+ GObject.Object.__init__(self)
self._popup_size = (450, 300)
- self._helpers = {}
- def activate(self, window):
- self._helpers[window] = WindowHelper(window, self)
+ def do_activate(self):
+ window = self.object
+ self._helper = WindowHelper(window, self)
- def deactivate(self, window):
- self._helpers[window].deactivate()
- del self._helpers[window]
+ def do_deactivate(self):
+ self._helper.deactivate()
+ self._helper = None
- def update_ui(self, window):
- self._helpers[window].update_ui()
+ def do_update_state(self):
+ self._helper.update_ui()
def get_popup_size(self):
return self._popup_size
diff --git a/plugins/quickopen/quickopen/popup.py b/plugins/quickopen/quickopen/popup.py
index edd9ab08..b571b68b 100755
--- a/plugins/quickopen/quickopen/popup.py
+++ b/plugins/quickopen/quickopen/popup.py
@@ -17,39 +17,38 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
-import gtk
-import gtk.gdk
-import gobject
import os
-import gio
-import pango
-import glib
import fnmatch
-import pluma
import xml.sax.saxutils
+from gi.repository import GObject, Gio, GLib, Gdk, Gtk, Pango, Pluma
from virtualdirs import VirtualDirectory
-class Popup(gtk.Dialog):
+class Popup(Gtk.Dialog):
+ __gtype_name__ = "QuickOpenPopup"
+
def __init__(self, window, paths, handler):
- gtk.Dialog.__init__(self,
+ Gtk.Dialog.__init__(self,
title=_('Quick Open'),
parent=window,
- flags=gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR | gtk.DIALOG_MODAL)
+ flags=Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
+ buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
- self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
- self._open_button = self.add_button(gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT)
+ self._open_button = self.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT)
self._handler = handler
self._build_ui()
+ self._size = (0, 0)
self._dirs = []
self._cache = {}
self._theme = None
self._cursor = None
self._shift_start = None
- accel_group = gtk.AccelGroup()
- accel_group.connect_group(gtk.keysyms.l, gtk.gdk.CONTROL_MASK, 0, self.on_focus_entry)
+ self._busy_cursor = Gdk.Cursor(Gdk.CursorType.WATCH)
+
+ accel_group = Gtk.AccelGroup()
+ accel_group.connect(Gdk.KEY_l, Gdk.ModifierType.CONTROL_MASK, 0, self.on_focus_entry)
self.add_accel_group(accel_group)
@@ -60,52 +59,55 @@ class Popup(gtk.Dialog):
self._dirs.append(path)
unique.append(path.get_uri())
+ def get_final_size(self):
+ return self._size
+
def _build_ui(self):
vbox = self.get_content_area()
vbox.set_spacing(3)
- self._entry = gtk.Entry()
+ self._entry = Gtk.Entry()
self._entry.connect('changed', self.on_changed)
self._entry.connect('key-press-event', self.on_key_press_event)
- sw = gtk.ScrolledWindow(None, None)
- sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- sw.set_shadow_type(gtk.SHADOW_OUT)
+ sw = Gtk.ScrolledWindow()
+ sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
+ sw.set_shadow_type(Gtk.ShadowType.OUT)
- tv = gtk.TreeView()
+ tv = Gtk.TreeView()
tv.set_headers_visible(False)
- self._store = gtk.ListStore(gio.Icon, str, object, int)
+ self._store = Gtk.ListStore(Gio.Icon, str, GObject.Object, Gio.FileType)
tv.set_model(self._store)
self._treeview = tv
tv.connect('row-activated', self.on_row_activated)
- renderer = gtk.CellRendererPixbuf()
- column = gtk.TreeViewColumn()
+ renderer = Gtk.CellRendererPixbuf()
+ column = Gtk.TreeViewColumn()
column.pack_start(renderer, False)
- column.set_attributes(renderer, gicon=0)
+ column.add_attribute(renderer, "gicon", 0)
- renderer = gtk.CellRendererText()
+ renderer = Gtk.CellRendererText()
column.pack_start(renderer, True)
- column.set_attributes(renderer, markup=1)
+ column.add_attribute(renderer, "markup", 1)
- column.set_cell_data_func(renderer, self.on_cell_data_cb)
+ column.set_cell_data_func(renderer, self.on_cell_data_cb, None)
tv.append_column(column)
sw.add(tv)
selection = tv.get_selection()
selection.connect('changed', self.on_selection_changed)
- selection.set_mode(gtk.SELECTION_MULTIPLE)
+ selection.set_mode(Gtk.SelectionMode.MULTIPLE)
vbox.pack_start(self._entry, False, False, 0)
vbox.pack_start(sw, True, True, 0)
- lbl = gtk.Label()
+ lbl = Gtk.Label()
lbl.set_alignment(0, 0.5)
- lbl.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
+ lbl.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
self._info_label = lbl
vbox.pack_start(lbl, False, False, 0)
@@ -114,23 +116,23 @@ class Popup(gtk.Dialog):
self.on_selection_changed(tv.get_selection())
vbox.show_all()
- def on_cell_data_cb(self, column, cell, model, piter):
+ def on_cell_data_cb(self, column, cell, model, piter, user_data):
path = model.get_path(piter)
if self._cursor and path == self._cursor.get_path():
style = self._treeview.get_style()
- bg = style.bg[gtk.STATE_PRELIGHT]
+ bg = style.bg[Gtk.StateType.PRELIGHT]
cell.set_property('cell-background-gdk', bg)
- cell.set_property('style', pango.STYLE_ITALIC)
+ cell.set_property('style', Pango.Style.ITALIC)
else:
cell.set_property('cell-background-set', False)
cell.set_property('style-set', False)
def _icon_from_stock(self, stock):
- theme = gtk.icon_theme_get_default()
- size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
- pixbuf = theme.load_icon(stock, size[0], gtk.ICON_LOOKUP_USE_BUILTIN)
+ theme = Gtk.icon_theme_get_default()
+ size = Gtk.icon_size_lookup(Gtk.IconSize.MENU)
+ pixbuf = theme.load_icon(stock, size[0], Gtk.IconLookupFlags.USE_BUILTIN)
return pixbuf
@@ -138,19 +140,25 @@ class Popup(gtk.Dialog):
entries = []
try:
- entries = gfile.enumerate_children("standard::*")
- except glib.GError:
+ ret = gfile.enumerate_children("standard::*", Gio.FileQueryInfoFlags.NONE, None)
+ except GLib.GError:
pass
+ if isinstance(ret, Gio.FileEnumerator):
+ while True:
+ entry = ret.next_file(None)
+
+ if not entry:
+ break
+
+ entries.append((gfile.get_child(entry.get_name()), entry))
+ else:
+ entries = ret
+
children = []
for entry in entries:
- if isinstance(gfile, VirtualDirectory):
- child, entry = entry
- else:
- child = gfile.get_child(entry.get_name())
-
- children.append((child, entry.get_name(), entry.get_file_type(), entry.get_icon()))
+ children.append((entry[0], entry[1].get_name(), entry[1].get_file_type(), entry[1].get_icon()))
return children
@@ -195,12 +203,12 @@ class Popup(gtk.Dialog):
lentry = entry[1].lower()
if not lpart or lpart in lentry or self._match_glob(lentry, lpart):
- if entry[2] == gio.FILE_TYPE_DIRECTORY:
+ if entry[2] == Gio.FileType.DIRECTORY:
if len(parts) > 1:
newdirs.append(entry[0])
else:
found.append(entry)
- elif entry[2] == gio.FILE_TYPE_REGULAR and \
+ elif entry[2] == Gio.FileType.REGULAR and \
(not lpart or len(parts) == 1):
found.append(entry)
@@ -244,7 +252,7 @@ class Popup(gtk.Dialog):
return os.sep.join(out)
def _get_icon(self, f):
- query = f.query_info(gio.FILE_ATTRIBUTE_STANDARD_ICON)
+ query = f.query_info(Gio.FILE_ATTRIBUTE_STANDARD_ICON, Gio.FileQueryInfoFlags.NONE, None)
if not query:
return None
@@ -296,9 +304,17 @@ class Popup(gtk.Dialog):
def _show_virtuals(self):
for d in self._dirs:
if isinstance(d, VirtualDirectory):
- for entry in d.enumerate_children("standard::*"):
+ for entry in d.enumerate_children("standard::*", 0, None):
self._append_to_store((entry[1].get_icon(), xml.sax.saxutils.escape(entry[1].get_name()), entry[0], entry[1].get_file_type()))
+ def _set_busy(self, busy):
+ if busy:
+ self.get_window().set_cursor(self._busy_cursor)
+ else:
+ self.get_window().set_cursor(None)
+
+ Gdk.flush()
+
def _remove_cursor(self):
if self._cursor:
path = self._cursor.get_path()
@@ -307,7 +323,7 @@ class Popup(gtk.Dialog):
self._store.row_changed(path, self._store.get_iter(path))
def do_search(self):
- self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
+ self._set_busy(True)
self._remove_cursor()
text = self._entry.get_text().strip()
@@ -329,10 +345,11 @@ class Popup(gtk.Dialog):
if piter:
self._treeview.get_selection().select_path(self._store.get_path(piter))
- self.window.set_cursor(None)
+ self.get_window().set_cursor(None)
+ self._set_busy(False)
def do_show(self):
- gtk.Window.do_show(self)
+ Gtk.Window.do_show(self)
self._entry.grab_focus()
self._entry.set_text("")
@@ -350,7 +367,7 @@ class Popup(gtk.Dialog):
model, rows = selection.get_selected_rows()
start = rows[0]
- self._shift_start = gtk.TreeRowReference(self._store, start)
+ self._shift_start = Gtk.TreeRowReference(self._store, start)
else:
start = self._shift_start.get_path()
@@ -375,7 +392,7 @@ class Popup(gtk.Dialog):
self._remove_cursor()
if hasctrl or hasshift:
- self._cursor = gtk.TreeRowReference(self._store, path)
+ self._cursor = Gtk.TreeRowReference(self._store, path)
piter = self._store.get_iter(path)
self._store.row_changed(path, piter)
@@ -418,10 +435,10 @@ class Popup(gtk.Dialog):
uri = self._entry.get_text()
gfile = None
- if pluma.utils.uri_is_valid(uri):
- gfile = gio.File(uri)
+ if Pluma.utils_is_valid_uri(uri):
+ gfile = Gio.file_new_for_uri(uri)
elif os.path.isabs(uri):
- f = gio.File(uri)
+ f = Gio.file_new_for_uri(uri)
if f.query_exists():
gfile = f
@@ -436,7 +453,7 @@ class Popup(gtk.Dialog):
s = model.get_iter(row)
info = model.get(s, 2, 3)
- if info[1] != gio.FILE_TYPE_DIRECTORY:
+ if info[1] != Gio.FileType.DIRECTORY:
ret = ret and self._handler(info[0])
else:
text = self._entry.get_text()
@@ -479,20 +496,20 @@ class Popup(gtk.Dialog):
def on_key_press_event(self, widget, event):
move_mapping = {
- gtk.keysyms.Down: 1,
- gtk.keysyms.Up: -1,
- gtk.keysyms.Page_Down: 5,
- gtk.keysyms.Page_Up: -5
+ Gdk.KEY_Down: 1,
+ Gdk.KEY_Up: -1,
+ Gdk.KEY_Page_Down: 5,
+ Gdk.KEY_Page_Up: -5
}
- if event.keyval == gtk.keysyms.Escape:
+ if event.keyval == Gdk.KEY_Escape:
self.destroy()
return True
elif event.keyval in move_mapping:
- return self._move_selection(move_mapping[event.keyval], event.state & gtk.gdk.CONTROL_MASK, event.state & gtk.gdk.SHIFT_MASK)
- elif event.keyval in [gtk.keysyms.Return, gtk.keysyms.KP_Enter, gtk.keysyms.Tab, gtk.keysyms.ISO_Left_Tab]:
+ return self._move_selection(move_mapping[event.keyval], event.state & Gdk.ModifierType.CONTROL_MASK, event.state & Gdk.ModifierType.SHIFT_MASK)
+ elif event.keyval in [Gdk.KEY_Return, Gdk.KEY_KP_Enter, Gdk.KEY_Tab, Gdk.KEY_ISO_Left_Tab]:
return self._activate()
- elif event.keyval == gtk.keysyms.space and event.state & gtk.gdk.CONTROL_MASK:
+ elif event.keyval == Gdk.KEY_space and event.state & Gdk.ModifierType.CONTROL_MASK:
self.toggle_cursor()
return False
@@ -501,9 +518,16 @@ class Popup(gtk.Dialog):
self._activate()
def do_response(self, response):
- if response != gtk.RESPONSE_ACCEPT or not self._activate():
+ if response != Gtk.ResponseType.ACCEPT or not self._activate():
self.destroy()
+ def do_configure_event(self, event):
+ if self.get_realized():
+ alloc = self.get_allocation()
+ self._size = (alloc.width, alloc.height)
+
+ return Gtk.Dialog.do_configure_event(self, event)
+
def on_selection_changed(self, selection):
model, rows = selection.get_selected_rows()
@@ -529,6 +553,4 @@ class Popup(gtk.Dialog):
def on_focus_entry(self, group, accel, keyval, modifier):
self._entry.grab_focus()
-gobject.type_register(Popup)
-
# ex:ts=8:et:
diff --git a/plugins/quickopen/quickopen/virtualdirs.py b/plugins/quickopen/quickopen/virtualdirs.py
index 9fc1c796..a2d6985a 100755
--- a/plugins/quickopen/quickopen/virtualdirs.py
+++ b/plugins/quickopen/quickopen/virtualdirs.py
@@ -17,10 +17,9 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
-import gtk
-import gio
+from gi.repository import Gio, Gtk
-class VirtualDirectory:
+class VirtualDirectory(object):
def __init__(self, name):
self._name = name
self._children = []
@@ -31,7 +30,7 @@ class VirtualDirectory:
def get_parent(self):
return None
- def enumerate_children(self, attr):
+ def enumerate_children(self, attr, flags, callback):
return self._children
def append(self, child):
@@ -39,7 +38,7 @@ class VirtualDirectory:
return
try:
- info = child.query_info("standard::*")
+ info = child.query_info("standard::*", Gio.FileQueryInfoFlags.NONE, None)
if info:
self._children.append((child, info))
@@ -47,17 +46,14 @@ class VirtualDirectory:
pass
class RecentDocumentsDirectory(VirtualDirectory):
- def __init__(self, maxitems=10, screen=None):
+ def __init__(self, maxitems=10):
VirtualDirectory.__init__(self, 'recent')
self._maxitems = maxitems
- self.fill(screen)
+ self.fill()
- def fill(self, screen):
- if screen:
- manager = gtk.recent_manager_get_for_screen(screen)
- else:
- manager = gtk.recent_manager_get_default()
+ def fill(self):
+ manager = Gtk.RecentManager.get_default()
items = manager.get_items()
items.sort(lambda a, b: cmp(b.get_visited(), a.get_visited()))
@@ -66,7 +62,7 @@ class RecentDocumentsDirectory(VirtualDirectory):
for item in items:
if item.has_group('pluma'):
- self.append(gio.File(item.get_uri()))
+ self.append(Gio.file_new_for_uri(item.get_uri()))
added += 1
if added >= self._maxitems:
diff --git a/plugins/quickopen/quickopen/windowhelper.py b/plugins/quickopen/quickopen/windowhelper.py
index 57ec414f..c23629cf 100755
--- a/plugins/quickopen/quickopen/windowhelper.py
+++ b/plugins/quickopen/quickopen/windowhelper.py
@@ -17,13 +17,9 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
-import pluma
-import gtk
from popup import Popup
import os
-import pluma.commands
-import gio
-import glib
+from gi.repository import Gio, GLib, Gtk, Pluma
from virtualdirs import RecentDocumentsDirectory
from virtualdirs import CurrentDocumentsDirectory
@@ -64,9 +60,9 @@ class WindowHelper:
def _install_menu(self):
manager = self._window.get_ui_manager()
- self._action_group = gtk.ActionGroup("PlumaQuickOpenPluginActions")
+ self._action_group = Gtk.ActionGroup("PlumaQuickOpenPluginActions")
self._action_group.add_actions([
- ("QuickOpen", gtk.STOCK_OPEN, _("Quick open"),
+ ("QuickOpen", Gtk.STOCK_OPEN, _("Quick open"),
'<Ctrl><Alt>O', _("Quickly open documents"),
self.on_quick_open_activate)
])
@@ -97,7 +93,7 @@ class WindowHelper:
uri = msg.get_value('uri')
if uri:
- gfile = gio.File(uri)
+ gfile = Gio.file_new_for_uri(uri)
if gfile.is_native():
paths.append(gfile)
@@ -106,7 +102,7 @@ class WindowHelper:
pass
# Recent documents
- paths.append(RecentDocumentsDirectory(screen=self._window.get_screen()))
+ paths.append(RecentDocumentsDirectory())
# Local bookmarks
for path in self._local_bookmarks():
@@ -116,16 +112,16 @@ class WindowHelper:
desktopdir = self._desktop_dir()
if desktopdir:
- paths.append(gio.File(desktopdir))
+ paths.append(Gio.file_new_for_path(desktopdir))
# Home directory
- paths.append(gio.File(os.path.expanduser('~')))
+ paths.append(Gio.file_new_for_path(os.path.expanduser('~')))
self._popup = Popup(self._window, paths, self.on_activated)
self._popup.set_default_size(*self._plugin.get_popup_size())
self._popup.set_transient_for(self._window)
- self._popup.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
+ self._popup.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
self._window.get_group().add_window(self._popup)
@@ -141,15 +137,15 @@ class WindowHelper:
for line in file(filename, 'r').xreadlines():
uri = line.strip().split(" ")[0]
- f = gio.File(uri)
+ f = Gio.file_new_for_uri(uri)
if f.is_native():
try:
- info = f.query_info("standard::type")
+ info = f.query_info(Gio.FILE_ATTRIBUTE_STANDARD_TYPE, Gio.FileQueryInfoFlags.NONE, None)
- if info and info.get_file_type() == gio.FILE_TYPE_DIRECTORY:
+ if info and info.get_file_type() == Gio.FileType.DIRECTORY:
paths.append(f)
- except glib.GError:
+ except GLib.GError:
pass
return paths
@@ -185,13 +181,11 @@ class WindowHelper:
self._popup.show()
def on_popup_destroy(self, popup):
- alloc = popup.get_allocation()
- self._plugin.set_popup_size((alloc.width, alloc.height))
-
+ self._plugin.set_popup_size(popup.get_final_size())
self._popup = None
def on_activated(self, gfile):
- pluma.commands.load_uri(self._window, gfile.get_uri(), None, -1)
+ Pluma.commands_load_uri(self._window, gfile.get_uri(), None, -1)
return True
# ex:ts=8:et:
diff --git a/plugins/snippets/snippets/Manager.py b/plugins/snippets/snippets/Manager.py
index 96220c6e..4c58a3b3 100755
--- a/plugins/snippets/snippets/Manager.py
+++ b/plugins/snippets/snippets/Manager.py
@@ -878,7 +878,7 @@ class Manager:
if len(export_snippets) == 0 and show_dialogs:
message = _('There are no snippets selected to be exported')
- message_dialog(self.dlg, gtk.MESSAGE_INFORMATION, message)
+ message_dialog(self.dlg, gtk.MESSAGE_INFO, message)
return False
if not filename:
@@ -948,7 +948,7 @@ class Manager:
dlg.destroy()
message = _('There are no snippets selected to be exported')
- message_dialog(self.dlg, gtk.MESSAGE_INFORMATION, message)
+ message_dialog(self.dlg, gtk.MESSAGE_INFO, message)
return
dlg.add_filter(self.file_filter(_('All supported archives'), ('*.gz','*.bz2','*.tar')))
diff --git a/plugins/snippets/snippets/__init__.py b/plugins/snippets/snippets/__init__.py
index e74ecd28..4b8db4b9 100755
--- a/plugins/snippets/snippets/__init__.py
+++ b/plugins/snippets/snippets/__init__.py
@@ -22,7 +22,6 @@ import shutil
import gtk
from gtk import gdk
import pluma
-import platform
from WindowHelper import WindowHelper
from Library import Library
@@ -38,31 +37,22 @@ class SnippetsPlugin(pluma.Plugin):
library = Library()
library.set_accelerator_callback(self.accelerator_activated)
- if platform.platform() == 'Windows':
- snippetsdir = os.path.expanduser('~/pluma/snippets')
- else:
- userdir = os.getenv('MATE22_USER_DIR')
- if userdir:
- snippetsdir = os.path.join(userdir, 'pluma/snippets')
- else:
- snippetsdir = os.path.expanduser('~/.config/pluma/snippets')
-
+ snippetsdir = os.path.expanduser('~/.config/pluma/snippets')
library.set_dirs(snippetsdir, self.system_dirs())
def system_dirs(self):
- if platform.platform() != 'Windows':
- if 'XDG_DATA_DIRS' in os.environ:
- datadirs = os.environ['XDG_DATA_DIRS']
- else:
- datadirs = '/usr/local/share' + os.pathsep + '/usr/share'
+ if 'XDG_DATA_DIRS' in os.environ:
+ datadirs = os.environ['XDG_DATA_DIRS']
+ else:
+ datadirs = '/usr/local/share' + os.pathsep + '/usr/share'
- dirs = []
+ dirs = []
- for d in datadirs.split(os.pathsep):
- d = os.path.join(d, 'pluma', 'plugins', 'snippets')
+ for d in datadirs.split(os.pathsep):
+ d = os.path.join(d, 'pluma', 'plugins', 'snippets')
- if os.path.isdir(d):
- dirs.append(d)
+ if os.path.isdir(d):
+ dirs.append(d)
dirs.append(self.get_data_dir())
return dirs