1
# -*- coding: utf-8 -*-
2
# Copyright © 2005 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 USA
21
This module implements a class that creates a container for the text editor's
24
@author: Lateef Alabi-Oki
25
@organization: The Scribes Project
26
@copyright: Copyright © 2005 Lateef Alabi-Oki
27
@license: GNU GPLv2 or Later
28
@contact: mystilleef@gmail.com
31
from gtksourceview import SourceView
33
class ScribesTextView(SourceView):
35
This class creates the container object that holds the text editor's buffer.
36
It defines the state, properties and behavior of the container object,
37
popular called the text editor's view. The view also defines the look and
38
feel of the buffer. The color of text in the buffer, the size of fonts, the
39
width of tabs are all defined by the view. As such the view is the only
40
user customizable part of the text editor. The class inherits from
41
gtksourceview.SourceView. See the PyGTK, or GTK+, manual for details on the
42
gtksourceview.SourceView class.
45
def __init__(self, editor):
49
@param self: Reference to the ScribesTextView instance.
50
@type self: A ScribesTextView object.
52
@param editor: Reference to the text editor instance.
53
@type editor: An Editor object.
55
SourceView.__init__(self)
56
self.__init_attributes(editor)
57
self.__set_properties()
58
# Monitor signals and events.
59
self.__signal_id_1 = self.connect("map-event", self.__map_event_cb)
60
self.__signal_id_2 = self.connect("focus-in-event", self.__focus_in_event_cb)
61
self.__signal_id_3 = self.connect("drag-motion", self.__drag_motion_cb)
62
self.__signal_id_4 = self.connect("drag-drop", self.__drag_drop_cb)
63
self.__signal_id_5 = self.connect("drag-data-received", self.__drag_data_received_cb)
64
self.__signal_id_6 = self.connect_after("populate-popup", self.__populate_popup_cb)
65
self.__signal_id_7 = self.connect("copy-clipboard", self.__copy_clipboard_cb)
66
self.__signal_id_8 = self.connect("cut-clipboard", self.__cut_clipboard_cb)
67
self.__signal_id_9 = self.connect("paste-clipboard", self.__paste_clipboard_cb)
68
self.__signal_id_10 = self.connect_after("paste-clipboard", self.__paste_clipboard_after_cb)
69
self.__signal_id_11 = self.connect("button-press-event", self.__button_press_event_cb)
70
self.__signal_id_12 = editor.connect("checking-document", self.__checking_document_cb)
71
self.__signal_id_13 = editor.connect("loaded-document", self.__loaded_document_cb)
72
self.__signal_id_14 = editor.connect("load-error", self.__load_error_cb)
73
self.__signal_id_15 = editor.connect("enable-readonly", self.__enable_readonly_cb)
74
self.__signal_id_16 = editor.connect("disable-readonly", self.__disable_readonly_cb)
75
self.__signal_id_17 = editor.connect("renamed-document", self.__renamed_document_cb)
76
self.__signal_id_18 = editor.connect("hide-dialog", self.__hide_dialog_cb)
77
self.__signal_id_19 = editor.connect("show-bar", self.__show_bar_cb)
78
self.__signal_id_20 = editor.connect("hide-bar", self.__hide_bar_cb)
79
self.__signal_id_21 = editor.connect("close-document", self.__close_document_cb)
80
self.__signal_id_22 = editor.connect("close-document-no-save", self.__close_document_cb)
81
self.__signal_id_23 = self.connect("scroll-event", self.__scroll_event_cb)
82
self.__signal_id_24 = self.connect("move-cursor", self.__move_cursor_cb)
83
self.__signal_id_25 = editor.connect("reload-document", self.__reload_document_cb)
84
# GConf notification monitors.
85
self.__client.notify_add("/apps/scribes/font", self.__font_changed_cb)
86
self.__client.notify_add("/apps/scribes/tab", self.__tab_width_cb)
87
self.__client.notify_add("/apps/scribes/text_wrapping", self.__text_wrapping_cb)
88
self.__client.notify_add("/apps/scribes/margin", self.__show_margin_cb)
89
self.__client.notify_add("/apps/scribes/margin_position", self.__margin_position_cb)
90
self.__client.notify_add("/apps/scribes/spell_check", self.__spell_check_cb)
91
self.__client.notify_add("/apps/scribes/use_theme_colors", self.__themes_cb)
92
self.__client.notify_add("/apps/scribes/fgcolor", self.__foreground_cb)
93
self.__client.notify_add("/apps/scribes/bgcolor", self.__background_cb)
94
self.__client.notify_add("/apps/scribes/use_tabs", self.__use_tabs_cb)
95
self.__client.notify_add("/apps/scribes/SyntaxHighlight", self.__syntax_cb)
97
def __init_attributes(self, editor):
99
Initialize the buffer container's attributes.
101
@param self: Reference to the ScribesTextView instance.
102
@type self: A ScribesTextView object.
104
@param editor: Reference to the text editor.
105
@type editor: An Editor object.
107
self.__client = editor.gconf_client
108
self.__editor = editor
109
self.__registration_id = editor.register_termination_id()
110
self.__spell_checker = None
111
self.__bar_is_visible = False
113
self.__scroll_id = None
114
self.__move_id = None
117
def __set_properties(self):
119
Set default properties.
121
Much of the properties of the view can be defined by users. So the
122
properties of the view are stored in GNOME's configuration database,
123
GConf. During the text editor's initialization process,
125
@param self: Reference to the ScribesTextView instance.
126
@type self: A ScribesTextView object.
128
@param editor: Reference to the text editor instance.
129
@type editor: An Editor object.
131
# Drag and drop setup.
132
targets = [("text/uri-list", 0, 80)]
133
from gtk import DEST_DEFAULT_ALL
134
from gtk.gdk import ACTION_COPY, BUTTON1_MASK, ACTION_DEFAULT
135
self.drag_dest_set(DEST_DEFAULT_ALL, targets, ACTION_COPY)
136
self.set_property("buffer", self.__editor.textbuffer)
137
from gtk import RESIZE_PARENT
138
self.set_resize_mode(RESIZE_PARENT)
139
self.set_highlight_current_line(True)
140
self.set_show_line_numbers(True)
141
self.set_auto_indent(True)
142
if self.__client.get("/apps/scribes/spell_check"):
143
spell_check = self.__client.get_bool("/apps/scribes/spell_check")
146
from gobject import GError
147
from gtkspell import Spell
148
from locale import getdefaultlocale
149
self.__spell_checker = Spell(self, getdefaultlocale()[0])
153
if self.__client.get("/apps/scribes/margin_position"):
154
margin_position = self.__client.get_int("/apps/scribes/margin_position")
155
self.set_margin(margin_position)
157
if self.__client.get("/apps/scribes/margin"):
158
show_margin = self.__client.get_bool("/apps/scribes/margin")
159
self.set_show_margin(show_margin)
161
if self.__client.get("/apps/scribes/tab"):
162
tab_width = self.__client.get_int("/apps/scribes/tab")
163
self.set_tabs_width(tab_width)
165
if self.__client.get("/apps/scribes/use_tabs"):
166
use_tabs = self.__client.get_bool("/apps/scribes/use_tabs")
167
self.set_insert_spaces_instead_of_tabs(not use_tabs)
168
gconf_font = "Monospace 12"
169
if self.__client.get("/apps/scribes/font"):
170
gconf_font = self.__client.get_string("/apps/scribes/font")
171
from pango import FontDescription
172
font = FontDescription(gconf_font)
173
self.modify_font(font)
174
wrap_mode_bool = True
175
if self.__client.get("/apps/scribes/text_wrapping"):
176
wrap_mode_bool = self.__client.get_bool("/apps/scribes/text_wrapping")
177
use_theme_colors = True
178
if self.__client.get("/apps/scribes/use_theme_colors"):
179
use_theme_colors = self.__client.get_bool("/apps/scribes/use_theme_colors")
180
from gtk import WRAP_WORD, WRAP_NONE
182
self.set_wrap_mode(WRAP_WORD)
184
self.set_wrap_mode(WRAP_NONE)
185
if use_theme_colors is False:
186
# Use foreground and background colors specified by the user stored
187
# in GConf, the GNOME configuration database.
188
from gconf import VALUE_STRING
191
if self.__client.get("/apps/scribes/fgcolor"):
192
fgcolor = self.__client.get_string("/apps/scribes/fgcolor")
193
if self.__client.get("/apps/scribes/bgcolor"):
194
bgcolor = self.__client.get_string("/apps/scribes/bgcolor")
196
from gtk.gdk import color_parse
197
foreground_color = color_parse(fgcolor)
198
background_color = color_parse(bgcolor)
200
foreground_color = color_parse("#000000")
201
background_color = color_parse("#ffffff")
202
from gtk import STATE_NORMAL
203
self.modify_base(STATE_NORMAL, background_color)
204
self.modify_text(STATE_NORMAL, foreground_color)
207
################################################################################
209
# Signal and Event Handlers
211
################################################################################
213
def __map_event_cb(self, widget, event):
215
Handles callback when the textview widget is drawn to screen.
217
@param self: Reference to the ScribesTextView instance.
218
@type self: A ScribesTextView object.
220
@param widget: Reference to the text editor's buffer container.
221
@type widget: A gtk.SourceView object.
223
@param event: An event that occurs when the widgets are displayed on
225
@type event: A gtk.Event object.
227
self.__refresh_view()
230
def __drag_motion_cb(self, textview, context, x, y, time):
232
Handles callback when a drag operation begins.
234
@param self: Reference to the ScribesTextView instance.
235
@type self: A ScribesTextView object.
237
@param textview: The text editor's view, or buffer container.
238
@type textview: A gtk.SourceView object.
240
@param context: The type of information being dragged.
241
@type context: A gtk.Context object.
243
@param x: The xcordinate of the cursor.
244
@type x: An Integer object.
246
@param y: The ycordinate of the cursor.
247
@type y: An Integer object.
249
@param time: The time the drag operation began.
250
@type time: An Integer object.
252
@return: False to propagate signals to parent widgets, True otherwise.
253
@rtype: A Boolean object.
255
from operator import contains
256
if contains(context.targets, "text/uri-list"): return True
259
def __drag_drop_cb(self, textview, context, x, y, time):
261
Handles callback when a drop operation begins.
263
@param self: Reference to the ScribesTextView instance.
264
@type self: A ScribesTextView object.
266
@param textview: The text editor's view, or buffer container.
267
@type textview: A gtk.SourceView object.
269
@param context: The type of information being dragged.
270
@type context: A gtk.Context object.
272
@param x: The xcordinate of the cursor.
273
@type x: An Integer object.
275
@param y: The ycordinate of the cursor.
276
@type y: An Integer object.
278
@param time: The time the drag operation began.
279
@type time: An Integer object.
281
@return: False to propagate signals to parent widgets, True otherwise.
282
@rtype: A Boolean object.
284
from operator import contains
285
if contains(context.targets, "text/uri-list"): return True
288
def __drag_data_received_cb(self, textview, context, xcord, ycord,
289
selection_data, info, timestamp):
291
Handles callback when a drop operation finishes.
293
@param self: Reference to the ScribesTextView instance.
294
@type self: A ScribesTextView object.
296
@param textview: The text editor's view, or buffer container.
297
@type textview: A gtk.SourceView object.
299
@param context: The type of information being dragged.
300
@type context: A gtk.Context object.
302
@param xcord: The xcordinate of the cursor.
303
@type xcord: An Integer object.
305
@param ycord: The ycordinate of the cursor.
306
@type ycord: An Integer object.
308
@param selection_data: A data selection
309
@type selection_data: A gtk.Selection object.
312
@type info: ? ? object.
314
@param timestamp: The time the drag operation began.
315
@type timestamp: An Integer object.
317
@return: False to propagate signals to parent widgets, True otherwise.
318
@rtype: A Boolean object.
320
from operator import contains, not_, ne
321
if not_(contains(context.targets, "text/uri-list")): return False
322
if ne(info, 80): return False
324
uri_list = list(selection_data.get_uris())
325
self.__editor.instance_manager.open_files(uri_list)
326
context.finish(True, False, timestamp)
329
def __drag_data_get_cb(self, textview, context, data, info, time):
331
Handles callback when the "drag-data-get" signal is emitted.
333
@param self: Reference to the TemplateEditorDescriptionView instance.
334
@type self: A TemplateEditorDescriptionView object.
336
@param treeview: Reference to the TemplateEditorDescriptionView
337
@type treeview: A TemplateEditorDescriptionView object.
339
@param context: An object representing context data.
340
@type context: A gtk.DragContext object.
342
@param data: An object representing selection data.
343
@type data: A gtk.SelectionData object.
345
@param info: A unique identification number for the text editor.
346
@type info: An Integer object.
348
@param time: The time of the drag and drop operation.
349
@type time: An Integer object.
351
@return: True to propagate signals to parent widgets.
352
@type: A Boolean Object.
354
selection = self.get_buffer().get_selection_bounds()
355
from operator import not_
356
if not_(selection): return False
357
string = self.get_buffer().get_text(selection[0], selection[1])
358
data.set(data.target, 8, string)
361
def __checking_document_cb(self, editor, uri):
363
Handles callback when the text editor is loading a document into the
364
text editor's buffer.
366
@param self: Reference to the ScribesTextView instance.
367
@type self: A ScribesTextView object.
369
@param editor: An instance of the text editor.
370
@type editor: An Editor object.
372
self.handler_block(self.__signal_id_23)
373
self.handler_block(self.__signal_id_24)
374
self.set_property("editable", False)
375
self.set_property("highlight-current-line", False)
376
self.set_property("cursor-visible", False)
377
self.set_property("sensitive", False)
378
self.__refresh_view()
381
def __loaded_document_cb(self, editor, uri):
383
Handles callback when the text editor has finished loading a document
384
into the text editor's buffer.
386
@param self: Reference to the ScribesTextView instance.
387
@type self: A ScribesTextView object.
389
@param editor: An instance of the text editor.
390
@type editor: An Editor object.
392
self.handler_unblock(self.__signal_id_23)
393
self.handler_unblock(self.__signal_id_24)
394
self.set_property("sensitive", True)
395
self.set_property("highlight-current-line", True)
396
self.set_property("cursor-visible", True)
397
self.set_property("editable", True)
398
self.__refresh_view()
401
def __reload_document_cb(self, *args):
402
self.set_property("editable", False)
405
def __load_error_cb(self, editor, uri):
407
Handles callback when the text editor has finished loading a document
408
into the text editor's buffer.
410
@param self: Reference to the ScribesTextView instance.
411
@type self: A ScribesTextView object.
413
@param editor: An instance of the text editor.
414
@type editor: An Editor object.
416
self.handler_unblock(self.__signal_id_23)
417
self.handler_unblock(self.__signal_id_24)
418
self.set_property("sensitive", True)
419
self.set_property("cursor-visible", True)
420
self.set_property("highlight-current-line", True)
421
self.set_property("editable", True)
422
from cursor import move_view_to_cursor
423
move_view_to_cursor(self)
426
def __enable_readonly_cb(self, editor):
428
Handles callback when the text editor is switched to readonly mode.
430
@param self: Reference to the ScribesTextView instance.
431
@type self: A ScribesTextView object.
433
@param editor: An instance of the text editor.
434
@type editor: An Editor object.
436
self.set_property("editable", False)
437
self.set_property("highlight-current-line", False)
438
self.set_property("cursor-visible", False)
439
self.set_property("show-line-numbers", False)
443
def __disable_readonly_cb(self, editor):
445
Handles callback when the text editor is switched from readonly to
448
@param self: Reference to the ScribesTextView instance.
449
@type self: A ScribesTextView object.
451
@param editor: An instance of the text editor.
452
@type editor: An Editor object.
454
self.set_property("editable", True)
455
self.set_property("highlight-current-line", True)
456
self.set_property("cursor-visible", True)
457
self.set_property("show-line-numbers", True)
458
self.__refresh_view()
461
def __renamed_document_cb(self, editor, uri):
463
Handles callback when the name of the document is renamed.
465
@param self: Reference to the ScribesTextBuffer instance.
466
@type self: A ScribesTextBuffer object.
468
@param editor: Reference to the text editor.
469
@type editor: An Editor object.
471
self.set_property("cursor-visible", True)
472
self.set_property("editable", True)
473
self.set_property("highlight-current-line", True)
474
self.set_property("cursor-visible", True)
475
self.set_property("show-line-numbers", True)
476
self.__refresh_view()
479
def __show_bar_cb(self, editor, bar):
481
Handles callback when the "hide-bar" signal is emitted.
483
@param self: Reference to the ScribesTextView instance.
484
@type self: A ScribesTextView object.
486
@param editor: Reference to the text editor.
487
@type editor: An Editor object.
489
@param bar: The text editor's bar.
490
@type bar: A ScribesBar object.
493
self.__bar_is_visible = True
494
self.set_property("editable", False)
495
self.set_property("cursor-visible", False)
496
self.set_property("accepts-tab", False)
497
self.__editor.response()
500
def __hide_bar_cb(self, editor, bar):
502
Handles callback when the "hide-bar" signal is emitted.
504
@param self: Reference to the ScribesTextView instance.
505
@type self: A ScribesTextView object.
507
@param editor: Reference to the text editor.
508
@type editor: An Editor object.
510
@param bar: The text editor's bar.
511
@type bar: A ScribesBar object.
513
self.__bar_is_visible = False
514
self.set_property("editable", True)
515
self.set_property("cursor-visible", True)
516
self.set_property("accepts-tab", True)
517
self.__refresh_view()
520
def __focus_in_event_cb(self, textview, event):
522
Handles callback when the text editor's windows "focus-in-event" signal
525
@param self: Reference to the ScribesTextView instance.
526
@type self: A ScribesTextView object.
528
@param window: The text editor's buffer container, or view.
529
@type window: A ScribesTextView object.
531
@param event: An event triggered when the text editor's window is focused.
532
@type event: A gtk.Event object.
534
@return: True to propagate signals to parent widgets.
535
@type: A Boolean Object.
537
if self.__bar_is_visible is False:
538
self.__refresh_view()
541
def __button_press_event_cb(self, textview, event):
543
Handles callback when the "button-press-event" signal is emitted.
545
@param self: Reference to the ScribesTextView instance.
546
@type self: A ScribesTextView object.
548
@param textview: The text editor's view.
549
@type textview: A ScribesTextView object.
551
@param event: An event that occurs when the mouse buttons are pressed.
552
@type event: A gtk.Event object.
554
@param bar: The text editor's bar.
555
@type bar: A ScribesBar object.
557
@return: True to propagate signals to parent widgets.
558
@type: A Boolean Object.
560
if self.__bar_is_visible:
561
self.__bar.hide_bar()
565
def __populate_popup_cb(self, textview, menu):
567
Handles callback when the "populate-popup" signal is emitted.
569
@param self: Reference to the ScribesTextView instance.
570
@type self: A ScribesTextView object.
572
@param textview: The text editor's buffer container.
573
@type textview: A ScribesTextView object.
575
@param menu: The text editor's popup menu.
576
@type menu: A gtk.Menu object.
578
@return: True to propagate signals to parent widgets.
579
@type: A Boolean Object.
581
from gtk import MenuItem, SeparatorMenuItem
582
menu.insert(SeparatorMenuItem(), 0)
585
def __hide_dialog_cb(self, *args):
586
self.__refresh_view()
589
def __copy_clipboard_cb(self, textview):
590
textbuffer = self.get_buffer()
591
feedback = self.__editor.feedback
592
# Get selection bounds
593
selection = textbuffer.get_selection_bounds()
595
# Depending on whether or not text is selected and copied, send appropriate
596
# feedback back to the user via the statusbar.
598
from internationalization import msg0089
599
feedback.update_status_message(msg0089, "copy")
601
from internationalization import msg0090
602
feedback.update_status_message(msg0090, "fail")
605
def __cut_clipboard_cb(self, textview):
606
feedback = self.__editor.feedback
607
if self.__editor.is_readonly:
608
from internationalization import msg0145
609
feedback.update_status_message(msg0145, "fail")
611
textbuffer = self.get_buffer()
613
# Get selection bounds
614
selection = textbuffer.get_selection_bounds()
615
self.__refresh_view()
616
# Depending on whether or not text is selected and copied, send appropriate
617
# feedback back to the user via the statusbar.
619
from internationalization import msg0091
620
feedback.update_status_message(msg0091, "cut")
622
from internationalization import msg0092
623
feedback.update_status_message(msg0092, "fail")
626
def __paste_clipboard_cb(self, textview):
628
feedback = self.__editor.feedback
629
if self.__editor.is_readonly:
630
from internationalization import msg0145
631
feedback.update_status_message(msg0145, "fail")
633
# Check to see if there is text in the clipboard manager.
634
from gtk import clipboard_get
635
clipboard = clipboard_get()
636
selection = clipboard.wait_for_text()
638
# Depending on whether or not there is text in the clipboard manager, send
639
# appropriate feedback back to the user via the statusbar.
641
from internationalization import msg0093
642
feedback.update_status_message(msg0093, "paste")
644
from internationalization import msg0094
645
feedback.update_status_message(msg0094, "fail")
648
def __paste_clipboard_after_cb(self, textview):
649
self.__refresh_view()
652
def __scroll_event_cb(self, *args):
653
from gobject import idle_add, PRIORITY_LOW, source_remove
655
source_remove(self.__scroll_id)
658
self.__scroll_id = idle_add(self.__test_response, priority=PRIORITY_LOW)
661
def __move_cursor_cb(self, *args):
662
from gobject import idle_add, PRIORITY_LOW, source_remove
664
source_remove(self.__move_id)
667
self.__move_id = idle_add(self.__test_response, priority=PRIORITY_LOW)
670
def __test_response(self):
671
self.__editor.response()
674
def __close_document_cb(self, editor):
676
Handles callback when the "close-document" signal is emitted.
678
@param self: Reference to the Store instance.
679
@type self: A Store object.
681
@param editor: Reference to the text editor.
682
@type editor: An Editor object.
687
################################################################################
689
# GConf Notification Handlers
691
################################################################################
693
def __font_changed_cb(self, client, cnxn_id, entry, data):
695
Handles callback when the font of the text editor changes.
697
@param self: Reference to the ScribesTextView instance.
698
@type self: A ScribesTextView object.
700
@param client: A client used to query the GConf daemon and database
701
@type client: A gconf.Client object.
703
@param cnxn_id: The identification number for the GConf client.
704
@type cnxn_id: An Integer object.
706
@param entry: An entry from the GConf database.
707
@type entry: A gconf.Entry object.
709
@param data: Optional data
710
@type data: Any type object.
712
from pango import FontDescription
713
new_font = FontDescription(entry.value.to_string())
714
self.modify_font(new_font)
715
self.__refresh_view()
718
def __tab_width_cb(self, client, cnxn_id, entry, data):
720
Handles callback when the tab width of the text editor changes.
722
@param self: Reference to the ScribesTextView instance.
723
@type self: A ScribesTextView object.
725
@param client: A client used to query the GConf daemon and database
726
@type client: A gconf.Client object.
728
@param cnxn_id: The identification number for the GConf client.
729
@type cnxn_id: An Integer object.
731
@param entry: An entry from the GConf database.
732
@type entry: A gconf.Entry object.
734
@param data: Optional data
735
@type data: Any type object.
737
self.set_tabs_width(int(entry.value.to_string()))
738
self.__refresh_view()
741
def __text_wrapping_cb(self, client, cnxn_id, entry, data):
743
Handles callback when the text wrapping mode of the text editor changes.
745
@param self: Reference to the ScribesTextView instance.
746
@type self: A ScribesTextView object.
748
@param client: A client used to query the GConf daemon and database
749
@type client: A gconf.Client object.
751
@param cnxn_id: The identification number for the GConf client.
752
@type cnxn_id: An Integer object.
754
@param entry: An entry from the GConf database.
755
@type entry: A gconf.Entry object.
757
@param data: Optional data
758
@type data: Any type object.
760
from gtk import WRAP_NONE, WRAP_WORD
761
if entry.value.get_bool():
762
self.set_wrap_mode(WRAP_WORD)
764
self.set_wrap_mode(WRAP_NONE)
765
self.__refresh_view()
768
def __margin_position_cb(self, client, cnxn_id, entry, data):
770
Handles callback when the right margin position of the text editor
773
@param self: Reference to the ScribesTextView instance.
774
@type self: A ScribesTextView object.
776
@param client: A client used to query the GConf daemon and database
777
@type client: A gconf.Client object.
779
@param cnxn_id: The identification number for the GConf client.
780
@type cnxn_id: An Integer object.
782
@param entry: An entry from the GConf database.
783
@type entry: A gconf.Entry object.
785
@param data: Optional data
786
@type data: Any type object.
788
self.set_margin(int(entry.value.to_string()))
789
self.__refresh_view()
792
def __show_margin_cb(self, client, cnxn_id, entry, data):
794
Handles callback when the right margin of the text editor is hidden or
797
@param self: Reference to the ScribesTextView instance.
798
@type self: A ScribesTextView object.
800
@param client: A client used to query the GConf daemon and database
801
@type client: A gconf.Client object.
803
@param cnxn_id: The identification number for the GConf client.
804
@type cnxn_id: An Integer object.
806
@param entry: An entry from the GConf database.
807
@type entry: A gconf.Entry object.
809
@param data: Optional data
810
@type data: Any type object.
812
self.set_show_margin(entry.value.get_bool())
813
self.__refresh_view()
816
def __spell_check_cb(self, client, cnxn_id, entry, data):
818
Handles callback when spell checking is toggled on or off in the text
821
@param self: Reference to the ScribesTextView instance.
822
@type self: A ScribesTextView object.
824
@param client: A client used to query the GConf daemon and database
825
@type client: A gconf.Client object.
827
@param cnxn_id: The identification number for the GConf client.
828
@type cnxn_id: An Integer object.
830
@param entry: An entry from the GConf database.
831
@type entry: A gconf.Entry object.
833
@param data: Optional data
834
@type data: Any type object.
837
if entry.value.get_bool():
838
from gobject import GError
840
from gtkspell import Spell
841
from locale import getdefaultlocale
842
self.__spell_checker = Spell(self, getdefaultlocale()[0])
846
self.__spell_checker.detach()
847
self.__refresh_view()
850
def __themes_cb(self, client, cnxn_id, entry, data):
852
Handles callback when of the text editor's view theme changes.
854
@param self: Reference to the ScribesTextView instance.
855
@type self: A ScribesTextView object.
857
@param client: A client used to query the GConf daemon and database
858
@type client: A gconf.Client object.
860
@param cnxn_id: The identification number for the GConf client.
861
@type cnxn_id: An Integer object.
863
@param entry: An entry from the GConf database.
864
@type entry: A gconf.Entry object.
866
@param data: Optional data
867
@type data: Any type object.
869
# Set the foreground and background color of the text editor's buffer.
870
if entry.value.get_bool():
871
# Use foreground and background colors specified by the GTK+ theme.
872
from gtk import RcStyle
874
self.modify_style(style)
875
# Reset font to value in GConf
876
value = client.get_string("/apps/scribes/font")
877
from pango import FontDescription
878
font = FontDescription(value)
879
self.modify_font(font)
882
# Use foreground and background colors specified by the
883
# user stored in GConf, the GNOME configuration database.
884
color = client.get_string("/apps/scribes/fgcolor")
885
from gtk.gdk import color_parse
886
foreground_color = color_parse(color)
887
color = client.get_string("/apps/scribes/bgcolor")
888
background_color = color_parse(color)
890
foreground_color = color_parse("#000000")
891
background_color = color_parse("#ffffff")
892
from gtk import STATE_NORMAL
893
self.modify_base(STATE_NORMAL, background_color)
894
self.modify_text(STATE_NORMAL, foreground_color)
895
self.__refresh_view()
898
def __foreground_cb(self, client, cnxn_id, entry, data):
900
Handles callback when the color text within the text editor changes.
902
@param self: Reference to the ScribesTextView instance.
903
@type self: A ScribesTextView object.
905
@param client: A client used to query the GConf daemon and database
906
@type client: A gconf.Client object.
908
@param cnxn_id: The identification number for the GConf client.
909
@type cnxn_id: An Integer object.
911
@param entry: An entry from the GConf database.
912
@type entry: A gconf.Entry object.
914
@param data: Optional data
915
@type data: Any type object.
917
color = client.get_string("/apps/scribes/fgcolor")
918
from gtk.gdk import color_parse
919
foreground_color = color_parse(color)
920
from gtk import STATE_NORMAL
921
self.modify_text(STATE_NORMAL, foreground_color)
922
self.__refresh_view()
925
def __background_cb(self, client, cnxn_id, entry, data):
927
Handles callback when the background color of the text editor changes.
929
@param self: Reference to the ScribesTextView instance.
930
@type self: A ScribesTextView object.
932
@param client: A client used to query the GConf daemon and database
933
@type client: A gconf.Client object.
935
@param cnxn_id: The identification number for the GConf client.
936
@type cnxn_id: An Integer object.
938
@param entry: An entry from the GConf database.
939
@type entry: A gconf.Entry object.
941
@param data: Optional data
942
@type data: Any type object.
944
color = client.get_string("/apps/scribes/bgcolor")
945
from gtk.gdk import color_parse
946
background_color = color_parse(color)
947
from gtk import STATE_NORMAL
948
self.modify_base(STATE_NORMAL, background_color)
949
self.__refresh_view()
952
def __use_tabs_cb(self, client, cnxn_id, entry, data):
954
Handles callback #FIXME: yeap
956
@param self: Reference to the ScribesTextView instance.
957
@type self: A ScribesTextView object.
959
@param client: A client used to query the GConf daemon and database
960
@type client: A gconf.Client object.
962
@param cnxn_id: The identification number for the GConf client.
963
@type cnxn_id: An Integer object.
965
@param entry: An entry from the GConf database.
966
@type entry: A gconf.Entry object.
968
@param data: Optional data
969
@type data: Any type object.
971
use_tabs = client.get_bool("/apps/scribes/use_tabs")
972
self.set_insert_spaces_instead_of_tabs(not use_tabs)
973
self.__refresh_view()
976
def __syntax_cb(self, client, cnxn_id, entry, data):
978
Handles callback #FIXME: yeap
980
@param self: Reference to the ScribesTextView instance.
981
@type self: A ScribesTextView object.
983
@param client: A client used to query the GConf daemon and database
984
@type client: A gconf.Client object.
986
@param cnxn_id: The identification number for the GConf client.
987
@type cnxn_id: An Integer object.
989
@param entry: An entry from the GConf database.
990
@type entry: A gconf.Entry object.
992
@param data: Optional data
993
@type data: Any type object.
995
from syntax import activate_syntax_highlight
996
from utils import get_language
998
if self.__editor.uri:
999
language = get_language(self.__editor.uri)
1000
activate_syntax_highlight(self.get_buffer(), language)
1001
from gobject import idle_add, PRIORITY_LOW
1002
idle_add(self.__refresh, priority=PRIORITY_LOW)
1005
def __refresh_view(self):
1007
Redraw elements of the view and its children.
1009
@param self: Reference to the ScribesTextView instance.
1010
@type self: A ScribesTextView object.
1012
from gobject import idle_add, PRIORITY_LOW
1013
idle_add(self.__refresh, priority=PRIORITY_LOW)
1017
def __refresh(self):
1020
self.resize_children()
1022
self.window.process_updates(True)
1025
self.__editor.response()
1028
def __destroy(self):
1030
Destroy instance of this class.
1032
@param self: Reference to the Store instance.
1033
@type self: A Store object.
1035
# Disconnect signals.
1036
from utils import disconnect_signal, delete_attributes
1037
disconnect_signal(self.__signal_id_1, self)
1038
disconnect_signal(self.__signal_id_2, self)
1039
disconnect_signal(self.__signal_id_3, self)
1040
disconnect_signal(self.__signal_id_4, self)
1041
disconnect_signal(self.__signal_id_5, self)
1042
disconnect_signal(self.__signal_id_6, self)
1043
disconnect_signal(self.__signal_id_7, self)
1044
disconnect_signal(self.__signal_id_8, self)
1045
disconnect_signal(self.__signal_id_9, self)
1046
disconnect_signal(self.__signal_id_10, self)
1047
disconnect_signal(self.__signal_id_11, self)
1048
disconnect_signal(self.__signal_id_12, self.__editor)
1049
disconnect_signal(self.__signal_id_13, self.__editor)
1050
disconnect_signal(self.__signal_id_14, self.__editor)
1051
disconnect_signal(self.__signal_id_15, self.__editor)
1052
disconnect_signal(self.__signal_id_16, self.__editor)
1053
disconnect_signal(self.__signal_id_17, self.__editor)
1054
disconnect_signal(self.__signal_id_18, self.__editor)
1055
disconnect_signal(self.__signal_id_19, self.__editor)
1056
disconnect_signal(self.__signal_id_20, self.__editor)
1057
disconnect_signal(self.__signal_id_21, self.__editor)
1058
disconnect_signal(self.__signal_id_22, self.__editor)
1059
disconnect_signal(self.__signal_id_23, self)
1060
disconnect_signal(self.__signal_id_24, self)
1061
disconnect_signal(self.__signal_id_25, self.__editor)
1063
# Unregister object so that editor can quit.
1064
self.__editor.unregister_termination_id(self.__registration_id)
1065
delete_attributes(self)
1066
# Delete data attributes.