-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhigtextviewers.py
148 lines (107 loc) · 4.47 KB
/
higtextviewers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2005-2006 Insecure.Com LLC.
# Copyright (C) 2007-2008 Adriano Monteiro Marques
#
# Author: Adriano Monteiro Marques <adriano@umitproject.org>
# Cleber Rodrigues <cleber.gnu@gmail.com>
# João Paulo de Souza Medeiros <ignotus21@gmail.com>
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This library 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 Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""
higwidgets/higtextviewers.py
text viewers related classes
"""
__all__ = ['HIGTextView']
import gtk
from higwidgets.higboxes import HIGHBox, HIGScrolledWindow
class HIGTextView(gtk.TextView):
def __init__(self, text=''):
gtk.TextView.__init__(self)
self.set_wrap_mode(gtk.WRAP_WORD)
self.get_buffer().set_text(text)
#class needed to maintain compatibility of RadialNet with higwidgets
class HIGTextViewRNet(HIGScrolledWindow):
def __init__(self):
HIGScrolledWindow.__init__(self)
self.__auto_scroll = False
self.__create_widgets()
def __create_widgets(self):
self.__textbuffer = gtk.TextBuffer()
self.__textview = gtk.TextView(self.__textbuffer)
self.add_with_viewport(self.__textview)
def _set_auto_scroll(self, value):
self.__auto_scroll = value
def _set_editable(self, editable):
self.__textview.set_editable(False)
def _modify_font(self, font):
self.__textview.modify_font(font)
def _set_text(self, text):
self.__textbuffer.set_text(text)
if self.__auto_scroll:
self._set_scroll_down()
def _get_text(self):
return self.__textbuffer.get_text(self.__textbuffer.get_start_iter(),
self.__textbuffer.get_end_iter())
def _set_scroll_down(self):
self.get_vadjustment().set_value(self.get_vadjustment().upper)
def _get_textbuffer(self):
return self.__textbuffer
class HIGTextEditor(HIGScrolledWindow):
def __init__(self):
HIGScrolledWindow.__init__(self)
self.connect('expose_event', self.__expose)
self.__auto_scroll = False
self.__create_widgets()
def __create_widgets(self):
self.__hbox = HIGHBox(spacing=6)
self.__textbuffer = gtk.TextBuffer()
self.__textview = gtk.TextView(self.__textbuffer)
self.__linebuffer = gtk.TextBuffer()
self.__lineview = gtk.TextView(self.__linebuffer)
self.__lineview.set_justification(gtk.JUSTIFY_RIGHT)
self.__lineview.set_editable(False)
self.__lineview.set_sensitive(False)
self.__hbox._pack_noexpand_nofill(self.__lineview)
self.__hbox._pack_expand_fill(self.__textview)
self.add_with_viewport(self.__hbox)
def __expose(self, widget, event):
# code to fix a gtk issue that don't show text correctly
self.__hbox.check_resize()
def _set_auto_scroll(self, value):
self.__auto_scroll = value
def _set_editable(self, editable):
self.__textview.set_editable(False)
def _modify_font(self, font):
self.__textview.modify_font(font)
self.__lineview.modify_font(font)
def _set_text(self, text):
if text != "":
count = text.count('\n') + text.count('\r')
lines = range(1, count + 2)
lines = [str(i).strip() for i in lines]
self.__textbuffer.set_text(text)
self.__linebuffer.set_text('\n'.join(lines))
if self.__auto_scroll:
self.bw_set_scroll_down()
else:
self.__textbuffer.set_text("")
self.__linebuffer.set_text("")
def _get_text(self):
return self.__textbuffer.get_text(self.__textbuffer.get_start_iter(),
self.__textbuffer.get_end_iter())
def _set_scroll_down(self):
self.get_vadjustment().set_value(self.get_vadjustment().upper)