I made some modifications to awesome text-search.
It now matches sub-strings.
When the searched text matches more than one node, all matching nodes are highlighted.
When there is just one match, pressing the return-key centers the node.
And I moved the search box into the toolbar.
http://code.google.com/p/jrfonseca/issues/detail?id=68
... | ... |
@@ -1813,6 +1813,14 @@ class DotWidget(gtk.DrawingArea): |
1813 | 1813 |
return self.graph.get_jump(x, y) |
1814 | 1814 |
|
1815 | 1815 |
|
1816 |
+class FindMenuToolAction(gtk.Action): |
|
1817 |
+ __gtype_name__ = "FindMenuToolAction" |
|
1818 |
+ |
|
1819 |
+ def __init__(self, *args, **kw): |
|
1820 |
+ gtk.Action.__init__(self, *args, **kw) |
|
1821 |
+ self.set_tool_item_type(gtk.ToolItem) |
|
1822 |
+ |
|
1823 |
+ |
|
1816 | 1824 |
class DotWindow(gtk.Window): |
1817 | 1825 |
|
1818 | 1826 |
ui = ''' |
... | ... |
@@ -1826,6 +1834,8 @@ class DotWindow(gtk.Window): |
1826 | 1834 |
<toolitem action="ZoomOut"/> |
1827 | 1835 |
<toolitem action="ZoomFit"/> |
1828 | 1836 |
<toolitem action="Zoom100"/> |
1837 |
+ <separator/> |
|
1838 |
+ <toolitem name="Find" action="Find"/> |
|
1829 | 1839 |
</toolbar> |
1830 | 1840 |
</ui> |
1831 | 1841 |
''' |
... | ... |
@@ -1868,6 +1878,11 @@ class DotWindow(gtk.Window): |
1868 | 1878 |
('Zoom100', gtk.STOCK_ZOOM_100, None, None, None, self.widget.on_zoom_100), |
1869 | 1879 |
)) |
1870 | 1880 |
|
1881 |
+ find_action = FindMenuToolAction("Find", None, |
|
1882 |
+ "Find a node by name", None) |
|
1883 |
+ #find_action.set_tool_item_type(gtk.ToolItem) |
|
1884 |
+ actiongroup.add_action(find_action) |
|
1885 |
+ |
|
1871 | 1886 |
# Add the actiongroup to the uimanager |
1872 | 1887 |
uimanager.insert_action_group(actiongroup, 0) |
1873 | 1888 |
|
... | ... |
@@ -1883,28 +1898,48 @@ class DotWindow(gtk.Window): |
1883 | 1898 |
self.set_focus(self.widget) |
1884 | 1899 |
|
1885 | 1900 |
# Add Find text search |
1901 |
+ find_toolitem = uimanager.get_widget('/ToolBar/Find') |
|
1886 | 1902 |
self.textentry = gtk.Entry(max=20) |
1887 |
- vbox.pack_start(self.textentry, False) |
|
1903 |
+ self.textentry.set_icon_from_stock(0, gtk.STOCK_FIND) |
|
1904 |
+ find_toolitem.add(self.textentry) |
|
1905 |
+ |
|
1888 | 1906 |
self.textentry.set_activates_default(True) |
1889 | 1907 |
self.textentry.connect ("activate", self.textentry_activate, self.textentry); |
1908 |
+ self.textentry.connect ("changed", self.textentry_changed, self.textentry); |
|
1890 | 1909 |
|
1891 | 1910 |
self.show_all() |
1892 | 1911 |
|
1893 |
- def textentry_activate(self, widget, entry): |
|
1894 |
- entry_text = entry.get_text() |
|
1912 |
+ def find_text(self, entry_text): |
|
1913 |
+ found_items = [] |
|
1895 | 1914 |
dot_widget = self.widget |
1896 | 1915 |
for node in dot_widget.graph.nodes: |
1897 | 1916 |
text = filterlist(node.shapes, TextShape) |
1898 |
- if re.match (entry_text, text[0].t): |
|
1899 |
- print "found:", entry_text ,"at", node, node.x, node.y |
|
1900 |
- press = gtk.gdk.Event(gtk.gdk.BUTTON_PRESS) |
|
1901 |
- release = gtk.gdk.Event(gtk.gdk.BUTTON_RELEASE) |
|
1902 |
- press.button = release.button = 1 |
|
1903 |
- press.x, press.y, = dot_widget.graph2window(node.x, node.y) |
|
1904 |
- release.x, release.y, = dot_widget.graph2window(node.x, node.y) |
|
1905 |
- |
|
1906 |
- dot_widget.on_area_button_press(None, press) |
|
1907 |
- dot_widget.on_area_button_release(None, release) |
|
1917 |
+ if re.search (entry_text, text[0].t): |
|
1918 |
+ #print "found:", entry_text ,"at", node, node.x, node.y |
|
1919 |
+ found_items.append(node) |
|
1920 |
+ return found_items |
|
1921 |
+ |
|
1922 |
+ def textentry_changed(self, widget, entry): |
|
1923 |
+ entry_text = entry.get_text() |
|
1924 |
+ dot_widget = self.widget |
|
1925 |
+ if not entry_text: |
|
1926 |
+ dot_widget.set_highlight(None) |
|
1927 |
+ return |
|
1928 |
+ |
|
1929 |
+ found_items = self.find_text(entry_text) |
|
1930 |
+ dot_widget.set_highlight(found_items) |
|
1931 |
+ |
|
1932 |
+ def textentry_activate(self, widget, entry): |
|
1933 |
+ entry_text = entry.get_text() |
|
1934 |
+ dot_widget = self.widget |
|
1935 |
+ if not entry_text: |
|
1936 |
+ dot_widget.set_highlight(None) |
|
1937 |
+ return; |
|
1938 |
+ |
|
1939 |
+ found_items = self.find_text(entry_text) |
|
1940 |
+ dot_widget.set_highlight(found_items) |
|
1941 |
+ if(len(found_items) == 1): |
|
1942 |
+ dot_widget.animate_to(found_items[0].x, found_items[0].y) |
|
1908 | 1943 |
|
1909 | 1944 |
def update(self, filename): |
1910 | 1945 |
if not hasattr(self, "last_mtime"): |