# -*- coding: utf-8 -*- # Copyright © 2005 Lateef Alabi-Oki # # This file is part of Scribes. # # Scribes 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 of the License, or # (at your option) any later version. # # Scribes 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 Scribes; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 # USA """ This module documents a class that creates a trigger for the text editor's about dialog. @author: Lateef Alabi-Oki @organization: The Scribes Project @copyright: Copyright © 2005 Lateef Alabi-Oki @license: GNU GPLv2 or Later @contact: mystilleef@gmail.com """ from gobject import GObject, SIGNAL_RUN_LAST, TYPE_NONE class AboutTrigger(GObject): """ This class creates an object that shows the text editor's about dialog. """ __gsignals__ = { "destroy": (SIGNAL_RUN_LAST, TYPE_NONE, ()), } def __init__(self, editor): """ Initialize the trigger. @param self: Reference to the AboutTrigger instance. @type self: An AboutTrigger object. @param editor: Reference to the text editor. @type editor: An Editor object. """ GObject.__init__(self) self.__init_attributes(editor) self.__create_trigger() self.__signal_id_1 = self.__trigger.connect("activate", self.__show_about_dialog_cb) self.__signal_id_2 = self.connect_after("destroy", self.__destroy_cb) self.__signal_id_3 = self.__editor.textview.connect_after("populate-popup", self.__popup_cb) def __init_attributes(self, editor): """ Initialize the trigger's attributes. @param self: Reference to the AboutTrigger instance. @type self: A AboutTrigger object. @param editor: Reference to the text editor. @type editor: An Editor object. """ self.__editor = editor self.__about_dialog = None self.__trigger = None self.__signal_id_1 = None self.__signal_id_2 = None self.__signal_id_3 = None return def __create_trigger(self): """ Create the trigger. @param self: Reference to the AboutTrigger instance. @type self: A AboutTrigger object. """ # Trigger to show the about dialog. from SCRIBES.trigger import Trigger self.__trigger = Trigger("show_about_dialog") self.__editor.triggermanager.add_trigger(self.__trigger) return def __show_about_dialog_cb(self, trigger): """ Handles callback when the "activate" signal is emitted. @param self: Reference to the AboutTrigger instance. @type self: A AboutTrigger object. @param trigger: An object to show the document browser. @type trigger: A Trigger object. """ try: self.__about_dialog.show_dialog() except AttributeError: from AboutDialog import ScribesAboutDialog self.__about_dialog = ScribesAboutDialog(self.__editor) self.__about_dialog.show_dialog() return def __destroy_cb(self, trigger): """ Handles callback when the "destroy" signal is emitted. @param self: Reference to the AboutTrigger instance. @type self: An AboutTrigger object. @param trigger: Reference to the AboutTrigger instance. @type trigger: An AboutTrigger object. """ self.__editor.triggermanager.remove_trigger(self.__trigger) from SCRIBES.utils import disconnect_signal, delete_attributes disconnect_signal(self.__signal_id_1, self.__trigger) disconnect_signal(self.__signal_id_2, self) disconnect_signal(self.__signal_id_3, self.__editor.textview) if self.__about_dialog: self.__about_dialog.emit("delete") delete_attributes(self) del self self = None return def __popup_cb(self, textview, menu): """ Handles callback when the "populate-popup" signal is emitted. @param self: Reference to the AboutTrigger instance. @type self: An AboutTrigger object. @param textview: Reference to the editor's textview. @type textview: A ScribesTextView object. @param menu: Reference to the editor's popup menu. @type menu: A gtk.Menu object. """ from gtk import SeparatorMenuItem menu.append(SeparatorMenuItem()) from PopupMenuItem import AboutPopupMenuItem menu.append(AboutPopupMenuItem(self.__editor)) menu.show_all() return False