~ubuntu-branches/ubuntu/vivid/kate/vivid-proposed

« back to all changes in this revision

Viewing changes to addons/pate/src/kate/document_view_helpers.py

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# This file is part of Pate, Kate' Python scripting plugin.
 
3
#
 
4
# Copyright (C) 2006 Paul Giannaros <paul@giannaros.org>
 
5
# Copyright (C) 2013 Shaheed Haque <srhaque@theiet.org>
 
6
# Copyright (C) 2013 Alex Turbov <i.zaufi@gmail.com>
 
7
#
 
8
# This library is free software; you can redistribute it and/or
 
9
# modify it under the terms of the GNU Library General Public
 
10
# License as published by the Free Software Foundation; either
 
11
# version 2 of the License, or (at your option) version 3.
 
12
#
 
13
# This library is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
# Library General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU Library General Public License
 
19
# along with this library; see the file COPYING.LIB.  If not, write to
 
20
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
21
# Boston, MA 02110-1301, USA.
 
22
 
 
23
'''Shared code for view/document decorators'''
 
24
 
 
25
from PyQt4 import QtCore
 
26
 
 
27
from .api import qDebug
 
28
from .decorators import viewCreated
 
29
 
 
30
 
 
31
class _SubscriberInfo:
 
32
    # TODO Turn to named tuples?
 
33
    def __init__(self, signal, receiver):
 
34
        self.signal = signal
 
35
        self.receiver = receiver
 
36
 
 
37
 
 
38
def _subscribe_for_events(subscribedPlugins, source):
 
39
    for plugin, subscribers in subscribedPlugins.items():
 
40
        assert(isinstance(subscribers, list))
 
41
        for subscriber in subscribers:
 
42
            qDebug('Subscribe {}/{} to receive {}'.format(
 
43
                plugin
 
44
              , subscriber.receiver.__name__
 
45
              , subscriber.signal
 
46
              ))
 
47
            source.connect(source, QtCore.SIGNAL(subscriber.signal), subscriber.receiver)
 
48
 
 
49
 
 
50
def _make_sure_subscribers_queue_exists(plugin, dst, queue):
 
51
    if not hasattr(dst, queue):
 
52
        setattr(dst, queue, dict())
 
53
    if not plugin in getattr(dst, queue):
 
54
        getattr(dst, queue)[plugin] = list()
 
55
 
 
56
 
 
57
@viewCreated
 
58
def _on_view_created(view):
 
59
    assert(view is not None)
 
60
 
 
61
    # Subscribe registered handlers for view events
 
62
    if hasattr(_on_view_created, 'view_event_subscribers'):
 
63
        assert(isinstance(_on_view_created.view_event_subscribers, dict))
 
64
        _subscribe_for_events(_on_view_created.view_event_subscribers, view)
 
65
 
 
66
    # Subscribe registered handlers for document events
 
67
    if hasattr(_on_view_created, 'document_event_subscribers'):
 
68
        assert(isinstance(_on_view_created.document_event_subscribers, dict))
 
69
        _subscribe_for_events(_on_view_created.document_event_subscribers, view.document())