1 |
jonen |
1.2 |
################################################## |
2 |
jonen |
1.3 |
# $Id: FunctionSelector.py,v 1.2 2002/11/08 02:37:25 jonen Exp $ |
3 |
jonen |
1.2 |
# small plugin for glimmer |
4 |
jonen |
1.1 |
# |
5 |
jonen |
1.2 |
# Authors: |
6 |
|
|
# Andreas Motl<andreas.motl@ilo.de> |
7 |
|
|
# Sebastian Utz<su@tunemedia.de> |
8 |
|
|
# |
9 |
|
|
# ToDo: |
10 |
jonen |
1.1 |
# - Bug: FunctionList doesn't refresh on new opened files by its own |
11 |
|
|
# - tune regex for more languages |
12 |
|
|
# |
13 |
jonen |
1.2 |
# Changelog: |
14 |
jonen |
1.3 |
# $Log: FunctionSelector.py,v $ |
15 |
|
|
# Revision 1.2 2002/11/08 02:37:25 jonen |
16 |
|
|
# + added cvs header |
17 |
|
|
# + added hook for refresh on "save-file" |
18 |
|
|
# suggested by Mark McAulay |
19 |
|
|
# |
20 |
jonen |
1.2 |
# |
21 |
|
|
################################################## |
22 |
|
|
|
23 |
jonen |
1.1 |
import glimmer |
24 |
|
|
import string |
25 |
|
|
import re |
26 |
|
|
import sys |
27 |
|
|
import os |
28 |
|
|
sys.argv=[] |
29 |
|
|
sys.argv.append("null") |
30 |
|
|
from gtk import * |
31 |
|
|
import _gtk |
32 |
|
|
import _gnome |
33 |
|
|
import _gnomeui |
34 |
|
|
from gnome.ui import * |
35 |
|
|
import gnome.config |
36 |
|
|
|
37 |
|
|
global row_number |
38 |
|
|
|
39 |
|
|
row_number = [] |
40 |
|
|
|
41 |
|
|
# --------------------------------------------------------- |
42 |
|
|
# some regular expressions to scan for |
43 |
|
|
# class/function/sub/packages signatures |
44 |
|
|
# in source code |
45 |
|
|
prefix_pattern = '^[|\s]*' |
46 |
jonen |
1.3 |
sigpart = '\s+([\w|:|&]+?)\s*' |
47 |
|
|
regex_universal=re.compile(prefix_pattern + '(?:\w+?)\*??' + sigpart + '\(.*?\)[\s|:|{]*\s*$') |
48 |
|
|
regex_noparenthesis=re.compile(prefix_pattern + '(?:package|sub|class)' + sigpart + '[;|{]\s*$') |
49 |
jonen |
1.1 |
|
50 |
|
|
def get_functionNameFromLine(str): |
51 |
jonen |
1.3 |
for regex in (regex_universal, regex_noparenthesis): |
52 |
jonen |
1.1 |
match=regex.search(str) |
53 |
|
|
if match: |
54 |
|
|
str = match.group(1) |
55 |
|
|
return str |
56 |
|
|
|
57 |
|
|
def get_allFunctionNames(content): |
58 |
|
|
names=[] |
59 |
|
|
lines=string.split(content, "\n") |
60 |
|
|
count=1 |
61 |
|
|
for line in lines: |
62 |
|
|
funcname=get_functionNameFromLine(line) |
63 |
|
|
if funcname: |
64 |
|
|
names.append((funcname, count)) |
65 |
|
|
count=count+1 |
66 |
|
|
return names |
67 |
|
|
|
68 |
|
|
# --------------------------------------------------------- |
69 |
|
|
|
70 |
|
|
def get_current_text(): |
71 |
|
|
start = 0 |
72 |
|
|
end = glimmer.buffer_size() |
73 |
|
|
str = glimmer.get_text(start, end) |
74 |
|
|
return str |
75 |
|
|
|
76 |
|
|
def functionlist_init (): |
77 |
|
|
title = "Functions:" |
78 |
|
|
functionlist.set_column_title(0, title) |
79 |
|
|
functionlist.clear() |
80 |
|
|
|
81 |
|
|
def functionlist_append(label): |
82 |
|
|
listentry=[] |
83 |
|
|
listentry.append(label) |
84 |
|
|
listentry.append("") |
85 |
|
|
functionlist.append(listentry) |
86 |
|
|
|
87 |
|
|
def our_main(): |
88 |
|
|
global row_number |
89 |
|
|
gettext = get_current_text() |
90 |
|
|
if gettext: |
91 |
|
|
entries=get_allFunctionNames(gettext) |
92 |
|
|
functionlist_init() |
93 |
|
|
row_number=[] |
94 |
|
|
for entry in entries: |
95 |
|
|
label=entry[0] |
96 |
|
|
rownum=entry[1] |
97 |
|
|
functionlist_append(label) |
98 |
|
|
row_number.append(rownum) |
99 |
|
|
|
100 |
|
|
def select_row_callback(clist, row, col, event, data): |
101 |
|
|
import glimmer |
102 |
|
|
import string |
103 |
|
|
global row_number |
104 |
|
|
num = row_number[row] |
105 |
|
|
glimmer.move_to_line(num) |
106 |
|
|
glimmer.move_to(glimmer.line_start()) |
107 |
|
|
del glimmer |
108 |
|
|
del string |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
def close_function_selector(button, citem, fbox): |
112 |
|
|
citem.destroy() |
113 |
|
|
glimmer.remove_paned_object("FunctionSelector") |
114 |
|
|
|
115 |
|
|
|
116 |
|
|
def refresh_function_selector(refresh): |
117 |
|
|
our_main() |
118 |
|
|
|
119 |
|
|
def callback_change(): |
120 |
|
|
our_main() |
121 |
|
|
|
122 |
|
|
functionbox = GtkVBox(FALSE, 0) |
123 |
|
|
functionbox.show() |
124 |
|
|
titleframe = GtkFrame() |
125 |
|
|
functionbox.pack_start(titleframe, FALSE, FALSE, 2) |
126 |
|
|
titleframe.show() |
127 |
|
|
buttonbox = GtkHBox(FALSE, 0) |
128 |
|
|
titleframe.add(buttonbox) |
129 |
|
|
buttonbox.show() |
130 |
|
|
optionsbutton = GtkButton() |
131 |
|
|
optionsbutton.set_relief(RELIEF_NONE) |
132 |
|
|
buttonbox.pack_start(optionsbutton, FALSE, FALSE, 2) |
133 |
|
|
optionsbutton.show() |
134 |
|
|
optionsbuttonbox = GtkHBox(FALSE, 0) |
135 |
|
|
optionsbutton.add(optionsbuttonbox) |
136 |
|
|
optionsbuttonbox.pack_start(GtkLabel("Refresh List"), FALSE, FALSE, 0) |
137 |
|
|
optionsbuttonbox.show_all() |
138 |
|
|
|
139 |
|
|
_gtk.gtk_signal_connect(optionsbutton._o, "clicked", refresh_function_selector) |
140 |
|
|
closebutton = GtkButton() |
141 |
|
|
closebutton.set_relief(RELIEF_NONE) |
142 |
|
|
closebutton.add(GnomeStock("Close")) |
143 |
|
|
closebutton.set_usize(22, 22) |
144 |
|
|
buttonbox.pack_end(closebutton, FALSE, FALSE, 2) |
145 |
|
|
closebutton.show_all() |
146 |
|
|
functionwindow = GtkScrolledWindow() |
147 |
|
|
functionbox.pack_start(functionwindow, TRUE, TRUE, 2) |
148 |
|
|
functionwindow.set_usize(130, 500) |
149 |
|
|
functionwindow.show() |
150 |
|
|
functionlist = GtkCList(1) |
151 |
|
|
functionwindow.add(functionlist) |
152 |
|
|
functionlist.show() |
153 |
|
|
#functionlist.column_titles_show(1) |
154 |
|
|
glimmer.add_paned_object(functionbox._o, "FunctionSelector", 0) |
155 |
|
|
our_main() |
156 |
|
|
checkitem = GtkCheckMenuItem("Function Selector") |
157 |
|
|
checkitem.set_active(TRUE) |
158 |
|
|
checkitem.show() |
159 |
|
|
glimmer.add_widget_to_menu("_View/Status Bar", checkitem._o) |
160 |
|
|
|
161 |
|
|
glimmer.register_signal_hook("open-file", callback_change) |
162 |
|
|
|
163 |
|
|
glimmer.register_signal_hook("change-file", callback_change) |
164 |
jonen |
1.2 |
|
165 |
|
|
glimmer.register_signal_hook("save-file", callback_change) |
166 |
jonen |
1.1 |
|
167 |
|
|
args = (checkitem, functionbox, ) |
168 |
|
|
_gtk.gtk_signal_connect(closebutton._o, "clicked", close_function_selector, args) |
169 |
|
|
args = (None, ) |
170 |
|
|
_gtk.gtk_signal_connect(functionlist._o, "select_row", select_row_callback, args) |