1
# -*- coding: utf-8 -*-
2
# Copyright © 2006 Lateef Alabi-Oki
4
# This file is part of Scribes.
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.
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.
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
22
This module documents a class that creates a trigger to show a new
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
32
from gobject import GObject, SIGNAL_RUN_LAST, TYPE_NONE
34
class NewWindowTrigger(GObject):
36
This class creates an object, a trigger, that allows users to show
41
"destroy": (SIGNAL_RUN_LAST, TYPE_NONE, ()),
44
def __init__(self, editor):
46
Initialize the trigger.
48
@param self: Reference to the NewWindowTrigger instance.
49
@type self: A NewWindowTrigger object.
51
@param editor: Reference to the text editor.
52
@type editor: An Editor object.
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)
60
def __init_attributes(self, editor):
62
Initialize the trigger's attributes.
64
@param self: Reference to the NewWindowTrigger instance.
65
@type self: A NewWindowTrigger object.
67
@param editor: Reference to the text editor.
68
@type editor: An Editor object.
70
self.__editor = editor
72
self.__signal_id_2 = None
73
self.__signal_id_1 = None
76
def __create_trigger(self):
80
@param self: Reference to the NewWindowTrigger instance.
81
@type self: A NewWindowTrigger object.
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)
89
def __new_window_cb(self, trigger):
91
Handles callback when the "activate" signal is emitted.
93
@param self: Reference to the NewWindowTrigger instance.
94
@type self: A NewWindowTrigger object.
96
@param trigger: An object to show the document browser.
97
@type trigger: A Trigger object.
99
from thread import start_new_thread
100
from SCRIBES.Editor import Editor
101
start_new_thread(Editor, (self.__editor.instance_manager,))
104
def __destroy_cb(self, trigger):
106
Handles callback when the "activate" signal is emitted.
108
@param self: Reference to the NewWindowTrigger instance.
109
@type self: An NewWindowTrigger object.
111
@param trigger: Reference to the NewWindowTrigger instance.
112
@type trigger: A NewWindowTrigger object.
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