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

« back to all changes in this revision

Viewing changes to plugins/RemoteDialog/Manager.py

  • Committer: goldenmyst
  • Date: 2008-03-05 15:49:42 UTC
  • Revision ID: goldenmyst@goldenmyst-desktop-20080305154942-lu3eqminvhjfs14d
Ported remote dialog to glade. The open/save dialog still crash scribes occassionally. May be as a result of the new gio libraries. More investigation is needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright © 2008 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 modules documents a class that manages essential components of the
 
23
open dialog file chooser.
 
24
 
 
25
@author: Lateef Alabi-Oki
 
26
@organization: Scribes
 
27
@copyright: Copyright © 2008 Lateef Alabi-Oki
 
28
@license: GNU GPLv3 or Later
 
29
@contact: mystilleef@gmail.com
 
30
"""
 
31
 
 
32
from gobject import GObject, SIGNAL_RUN_LAST, TYPE_NONE, TYPE_PYOBJECT
 
33
 
 
34
class Manager(GObject):
 
35
        """
 
36
        This class manages the components of the filechooser window.
 
37
        """
 
38
 
 
39
        __gsignals__ = {
 
40
                "destroy": (SIGNAL_RUN_LAST, TYPE_NONE, ()),
 
41
                "show-window": (SIGNAL_RUN_LAST, TYPE_NONE, ()),
 
42
                "hide-window": (SIGNAL_RUN_LAST, TYPE_NONE, ()),
 
43
                "load-file": (SIGNAL_RUN_LAST, TYPE_NONE, ()),
 
44
                "error": (SIGNAL_RUN_LAST, TYPE_NONE, (TYPE_PYOBJECT,)),
 
45
                "encoding": (SIGNAL_RUN_LAST, TYPE_NONE, (TYPE_PYOBJECT,)),
 
46
        }
 
47
 
 
48
        def __init__(self, editor):
 
49
                """
 
50
                Initialize object.
 
51
 
 
52
                @param self: Reference to the Manager instance.
 
53
                @type self: A Manager object.
 
54
 
 
55
                @param editor: Reference to the text editor.
 
56
                @type editor: An Editor object.
 
57
                """
 
58
                GObject.__init__(self)
 
59
                self.__init_attributes(editor)
 
60
                self.__sig_id1 = self.connect("encoding", self.__encoding_cb)
 
61
                from EncodingComboBox import ComboBox
 
62
                ComboBox(editor, self)
 
63
                from OpenButton import Button
 
64
                Button(editor, self)
 
65
                from ComboBoxEntry import ComboBoxEntry
 
66
                ComboBoxEntry(editor, self)
 
67
                from CancelButton import Button
 
68
                Button(editor, self)
 
69
                from Window import Window
 
70
                Window(editor, self)
 
71
 
 
72
        def __init_attributes(self, editor):
 
73
                """
 
74
                Initialize data attributes.
 
75
 
 
76
                @param self: Reference to the Manager instance.
 
77
                @type self: A Manager object.
 
78
 
 
79
                @param editor: Reference to the text editor.
 
80
                @type editor: An Editor object.
 
81
                """
 
82
                self.__editor = editor
 
83
                from os.path import join, split
 
84
                current_folder = split(globals()["__file__"])[0]
 
85
                glade_file = join(current_folder, "RemoteDialog.glade")
 
86
                from gtk.glade import XML
 
87
                self.__glade = XML(glade_file, "Window", "scribes")
 
88
                self.__encoding = None
 
89
                return
 
90
 
 
91
        def __get_glade(self):
 
92
                return self.__glade
 
93
 
 
94
        def __get_encoding(self):
 
95
                return self.__encoding
 
96
 
 
97
        glade = property(__get_glade)
 
98
        encoding = property(__get_encoding)
 
99
 
 
100
        def show_dialog(self):
 
101
                """
 
102
                Show the open file chooser dialog.
 
103
 
 
104
                @param self: Reference to the Manager instance.
 
105
                @type self: A Manager object.
 
106
                """
 
107
                self.emit("show-window")
 
108
                return
 
109
 
 
110
        def destroy(self):
 
111
                """
 
112
                Handles callback when the "destroy" signal is emitted.
 
113
 
 
114
                @param self: Reference to the Manager instance.
 
115
                @type self: A Manager object.
 
116
                """
 
117
                self.__editor.disconnect_signal(self.__sig_id1, self)
 
118
                self.emit("destroy")
 
119
                del self
 
120
                self = None
 
121
                return
 
122
 
 
123
        def __encoding_cb(self, manager, encoding):
 
124
                """
 
125
                Handles callback when encoding information changes.
 
126
 
 
127
                @param self: Reference to the Manager instance.
 
128
                @type self: A Manager object.
 
129
                """
 
130
                self.__encoding = encoding
 
131
                return False