~sir-rainbow/+junk/scribes-on-win

« back to all changes in this revision

Viewing changes to plugins/NewWindow/Trigger.py

  • Committer: goldenmyst
  • Date: 2007-09-25 17:15:52 UTC
  • Revision ID: goldenmyst@goldenmyst-desktop-20070925171552-mvrhxdd39iibs0sr
New branch. New Trigger Management System. New Trigger API. New Plugin Management System. Fix for bug triggered by PyGTK+ version 2.11 or better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright © 2006 Lateef Alabi-Oki
 
3
#
 
4
# This file is part of Scribes.
 
5
#
 
6
# Scribes is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# Scribes is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with Scribes; if not, write to the Free Software
 
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 
19
# USA
 
20
 
 
21
"""
 
22
This module documents a class that creates a trigger to show a new
 
23
window.
 
24
 
 
25
@author: Lateef Alabi-Oki
 
26
@organization: The Scribes Project
 
27
@copyright: Copyright © 2006 Lateef Alabi-Oki
 
28
@license: GNU GPLv2 or Later
 
29
@contact: mystilleef@gmail.com
 
30
"""
 
31
 
 
32
from gobject import GObject, SIGNAL_RUN_LAST, TYPE_NONE
 
33
 
 
34
class NewWindowTrigger(GObject):
 
35
        """
 
36
        This class creates an object, a trigger, that allows users to show
 
37
        a new scribes window.
 
38
        """
 
39
 
 
40
        __gsignals__ = {
 
41
                "destroy": (SIGNAL_RUN_LAST, TYPE_NONE, ()),
 
42
        }
 
43
 
 
44
        def __init__(self, editor):
 
45
                """
 
46
                Initialize the trigger.
 
47
 
 
48
                @param self: Reference to the NewWindowTrigger instance.
 
49
                @type self: A NewWindowTrigger object.
 
50
 
 
51
                @param editor: Reference to the text editor.
 
52
                @type editor: An Editor object.
 
53
                """
 
54
                GObject.__init__(self)
 
55
                self.__init_attributes(editor)
 
56
                self.__create_trigger()
 
57
                self.__signal_id_1 = self.__trigger.connect("activate", self.__new_window_cb)
 
58
                self.__signal_id_2 = self.connect("destroy", self.__destroy_cb)
 
59
 
 
60
        def __init_attributes(self, editor):
 
61
                """
 
62
                Initialize the trigger's attributes.
 
63
 
 
64
                @param self: Reference to the NewWindowTrigger instance.
 
65
                @type self: A NewWindowTrigger object.
 
66
 
 
67
                @param editor: Reference to the text editor.
 
68
                @type editor: An Editor object.
 
69
                """
 
70
                self.__editor = editor
 
71
                self.__trigger = None
 
72
                self.__signal_id_2 = None
 
73
                self.__signal_id_1 = None
 
74
                return
 
75
 
 
76
        def __create_trigger(self):
 
77
                """
 
78
                Create the trigger.
 
79
 
 
80
                @param self: Reference to the NewWindowTrigger instance.
 
81
                @type self: A NewWindowTrigger object.
 
82
                """
 
83
                # Trigger to show the a new Scribes window.
 
84
                from SCRIBES.Trigger import Trigger
 
85
                self.__trigger = Trigger("new_window", "ctrl - n")
 
86
                self.__editor.triggermanager.add_trigger(self.__trigger)
 
87
                return
 
88
 
 
89
        def __new_window_cb(self, trigger):
 
90
                """
 
91
                Handles callback when the "activate" signal is emitted.
 
92
 
 
93
                @param self: Reference to the NewWindowTrigger instance.
 
94
                @type self: A NewWindowTrigger object.
 
95
 
 
96
                @param trigger: An object to show the document browser.
 
97
                @type trigger: A Trigger object.
 
98
                """
 
99
                from thread import start_new_thread
 
100
                from SCRIBES.Editor import Editor
 
101
                start_new_thread(Editor, (self.__editor.instance_manager,))
 
102
                return
 
103
 
 
104
        def __destroy_cb(self, trigger):
 
105
                """
 
106
                Handles callback when the "activate" signal is emitted.
 
107
 
 
108
                @param self: Reference to the NewWindowTrigger instance.
 
109
                @type self: An NewWindowTrigger object.
 
110
 
 
111
                @param trigger: Reference to the NewWindowTrigger instance.
 
112
                @type trigger: A NewWindowTrigger object.
 
113
                """
 
114
                self.__editor.triggermanager.remove_trigger(self.__trigger)
 
115
                if self.__signal_id_1 and self.__trigger.handler_is_connected(self.__signal_id_1):
 
116
                        self.__trigger.disconnect(self.__signal_id_1)
 
117
                if self.__signal_id_2 and self.handler_is_connected(self.__signal_id_2):
 
118
                        self.disconnect(self.__signal_id_2)
 
119
                del self.__editor, self.__trigger
 
120
                del self.__signal_id_2, self.__signal_id_1
 
121
                del self
 
122
                self = None
 
123
                return