From e197eab669084a78f43dd334f06029b994b8ce8b Mon Sep 17 00:00:00 2001 From: Luigi 'Comio' Mantellini Date: Thu, 28 Feb 2008 22:26:29 +0100 Subject: [PATCH] Code cleanup --- cscope/cscope.glade | 14 ++- cscope/gedit_bind.py | 249 ++++++++++++++++++++++++--------------------------- 2 files changed, 128 insertions(+), 135 deletions(-) rewrite cscope/gedit_bind.py (78%) diff --git a/cscope/cscope.glade b/cscope/cscope.glade index a7f3dd8..b1fc053 100644 --- a/cscope/cscope.glade +++ b/cscope/cscope.glade @@ -1,9 +1,11 @@ - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_MENU True @@ -36,6 +38,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Select a cscope.out file 1 @@ -71,6 +74,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 Find this C symbol: Find this global definition: Find functions called by this function: @@ -90,6 +94,7 @@ Find files #including this file: True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 1 @@ -104,7 +109,6 @@ Find files #including this file: GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK Search 0 - False @@ -130,16 +134,18 @@ Find files #including this file: GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK GTK_POLICY_AUTOMATIC GTK_POLICY_AUTOMATIC + GTK_SHADOW_ETCHED_IN - True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False True True True - 1 + False GTK_TREE_VIEW_GRID_LINES_BOTH + True diff --git a/cscope/gedit_bind.py b/cscope/gedit_bind.py dissimilarity index 78% index 757a082..c4628dc 100644 --- a/cscope/gedit_bind.py +++ b/cscope/gedit_bind.py @@ -1,131 +1,118 @@ -import gedit -import os -import gtk -import gtk.glade - -GLADE_FILE = os.path.join(os.path.dirname(__file__), "cscope.glade") - -class CScopePluginHelper: - def __init__(self, plugin, window): - self._plugin = plugin - self._window = window - self._panel = self._window.get_bottom_panel() - self._cspanel = None - self.create_panel() - return - - def deactivate(self): - self._plugin = None - self._window = None - self._panel = None - self._cspanel = None - - def update_ui(self): - return - - def create_panel(self): - # Open the Interface and bind with Botton Panel - glade_xml = gtk.glade.XML(GLADE_FILE, "CScopeBox") - self._cspanel = glade_xml.get_widget("CScopeBox") - image = gtk.Image() - image.set_from_stock(gtk.STOCK_DND_MULTIPLE, gtk.ICON_SIZE_BUTTON) - self._panel.add_item(self._cspanel, "CScope", image) - - # Objects - self._fcDatabase = glade_xml.get_widget("fcDatabase") - self._bOpen = glade_xml.get_widget("bOpen") - self._bSearch = glade_xml.get_widget("bSearch") - self._eQuery = glade_xml.get_widget("eQuery") - self._cbTypeOfQuery = glade_xml.get_widget("cbTypeOfQuery") - self._tvResults = glade_xml.get_widget("tvResult") - - self._search_data = gtk.ListStore(int, str, str, int, str, str) - self._tvResults.set_model(self._search_data) - - tree_selection = self._tvResults.get_selection() - - # Properties... - tree_selection.set_mode(gtk.SELECTION_SINGLE) - - cell_no = gtk.TreeViewColumn("#") - cell_no.set_resizable(True) - cell_no.set_reorderable(True) - cell_no.set_sort_column_id(0) - cell_dir = gtk.TreeViewColumn("Directory") - cell_dir.set_resizable(True) - cell_dir.set_reorderable(True) - cell_dir.set_sort_column_id(1) - cell_filename = gtk.TreeViewColumn("File") - cell_filename.set_resizable(True) - cell_filename.set_reorderable(True) - cell_filename.set_sort_column_id(2) - cell_line_number = gtk.TreeViewColumn("Line") - cell_line_number.set_resizable(True) - cell_line_number.set_reorderable(True) - cell_line_number.set_sort_column_id(3) - cell_symbol = gtk.TreeViewColumn("Symbol") - cell_symbol.set_resizable(True) - cell_symbol.set_reorderable(True) - cell_symbol.set_sort_column_id(4) - cell_text = gtk.TreeViewColumn("Text") - cell_text.set_resizable(True) - cell_text.set_reorderable(True) - cell_text.set_sort_column_id(5) - - # Now add the cell objects to the results_list treeview object - self._tvResults.append_column(cell_no) - self._tvResults.append_column(cell_dir) - self._tvResults.append_column(cell_filename) - self._tvResults.append_column(cell_line_number) - self._tvResults.append_column(cell_symbol) - self._tvResults.append_column(cell_text) - - # Create text-rendering objects so that we can actually - # see the data that we'll put into the objects - text_renderer_no = gtk.CellRendererText() - text_renderer_dir = gtk.CellRendererText() - text_renderer_filename = gtk.CellRendererText() - text_renderer_line_number = gtk.CellRendererText() - text_renderer_symbol = gtk.CellRendererText() - text_renderer_text = gtk.CellRendererText() - - # Pack the text renderer objects into the cell objects we created - cell_no.pack_start(text_renderer_no, True) - cell_dir.pack_start(text_renderer_dir, True) - cell_filename.pack_start(text_renderer_filename, True) - cell_line_number.pack_start(text_renderer_line_number, True) - cell_symbol.pack_start(text_renderer_symbol, True) - cell_text.pack_start(text_renderer_text, True) - - # Now set the IDs to each of the text renderer objects and set them to "text" mode - cell_no.add_attribute(text_renderer_no, "text", 0) - cell_dir.add_attribute(text_renderer_dir, "text", 1) - cell_filename.add_attribute(text_renderer_filename, "text", 2) - cell_line_number.add_attribute(text_renderer_line_number, "text", 3) - cell_symbol.add_attribute(text_renderer_symbol, "text", 4) - cell_text.add_attribute(text_renderer_text, "text", 5) - - - self._search_data.append( (1, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - self._search_data.append( (2, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - self._search_data.append( (3, "/usr/sr/linux/arch/m68k/process", "process.c", 102, "do_up", "int do_up(int test)") ) - self._search_data.append( (4, "/usr/sr/linux/arch/m68k/process", "process.c", 104, "do_up", "int do_up(int test)") ) - self._search_data.append( (5, "/usr/sr/linux/arch/m68k/process", "process.c", 150, "do_up", "int do_up(int test)") ) - self._search_data.append( (6, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - self._search_data.append( (7, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - self._search_data.append( (8, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - self._search_data.append( (9, "/usr/sr/linux/arch/m68k/process", "process.c", 102, "do_up", "int do_up(int test)") ) - self._search_data.append( (10, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - self._search_data.append( (11, "/usr/sr/linux/arch/m68k/process", "process.c", 103, "do_up", "int do_up(int test)") ) - self._search_data.append( (12, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - self._search_data.append( (13, "/usr/sr/linux/arch/m68k/process", "process.c", 104, "do_up", "int do_up(int test)") ) - self._search_data.append( (14, "/usr/sr/linux/arch/m68k/process", "process.c", 150, "do_up", "int do_up(int test)") ) - self._search_data.append( (15, "/usr/sr/linux/arch/m68k/process", "process.c", 160, "do_up", "int do_up(int test)") ) - self._search_data.append( (16, "/usr/sr/linux/arch/m68k/process", "process.c", 170, "do_up", "int do_up(int test)") ) - self._search_data.append( (17, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - self._search_data.append( (18, "/usr/sr/linux/arch/m68k/process", "process.c", 110, "do_up", "int do_up(int test)") ) - self._search_data.append( (19, "/usr/sr/linux/arch/m68k/process", "process.c", 190, "do_up", "int do_up(int test)") ) - self._search_data.append( (20, "/usr/sr/linux/arch/m68k/process", "process.c", 120, "do_up", "int do_up(int test)") ) - self._search_data.append( (21, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) - - return +import gedit +import os +import gtk +import gtk.glade + +GLADE_FILE = os.path.join(os.path.dirname(__file__), "cscope.glade") + +[ COL_ID_ID, COL_TEXT_ID, COL_TYPE_ID ] = [ 0, "#", "text" ] +[ COL_ID_DIR, COL_TEXT_DIR, COL_TYPE_DIR ] = [ 1, "Directory", "text" ] +[ COL_ID_FILE, COL_TEXT_FILE, COL_TYPE_FILE ] = [ 2, "File", "text" ] +[ COL_ID_LINE, COL_TEXT_LINE, COL_TYPE_LINE ] = [ 3, "Line#", "text" ] +[ COL_ID_SYMBOL, COL_TEXT_SYMBOL, COL_TYPE_SYMBOL ] = [ 4, "Symbol", "text" ] +[ COL_ID_TEXT, COL_TEXT_TEXT, COL_TYPE_TEXT ] = [ 5, "Text", "text" ] + + + +class CScopeResult: + def __init__(self, result): + self._result = result + self._search_data = gtk.ListStore(int, str, str, int, str, str) + self._result.set_model(self._search_data) + tree_selection = self._result.get_selection() + tree_selection.set_mode(gtk.SELECTION_SINGLE) + + self.addColumn(COL_TEXT_ID, COL_ID_ID, COL_TYPE_ID) + self.addColumn(COL_TEXT_DIR, COL_ID_DIR, COL_TYPE_DIR) + self.addColumn(COL_TEXT_FILE, COL_ID_FILE, COL_TYPE_FILE) + self.addColumn(COL_TEXT_LINE, COL_ID_LINE, COL_TYPE_LINE) + self.addColumn(COL_TEXT_SYMBOL, COL_ID_SYMBOL, COL_TYPE_SYMBOL) + self.addColumn(COL_TEXT_TEXT, COL_ID_TEXT, COL_TYPE_TEXT) + + self._result.set_headers_visible(True) + self._result.show() + + + def addColumn(self, name, colid, coltype): + cell = gtk.TreeViewColumn(name) + cell.set_resizable(True) + cell.set_reorderable(True) + cell.set_sort_column_id(colid) + + self._result.append_column(cell) + + text_renderer = gtk.CellRendererText() + + # Pack the text renderer objects into the cell objects we created + cell.pack_start(text_renderer, True) + + # Now set the IDs to each of the text renderer objects and set them to "text" mode + cell.add_attribute(text_renderer, coltype, colid) + + def clear(self): + self._search_data.clear() + + def append(self, data): + self._search_data.append(data) + +class CScopePluginHelper: + def __init__(self, plugin, window): + self._plugin = plugin + self._window = window + self._panel = self._window.get_bottom_panel() + self._cspanel = None + self.create_panel() + return + + def deactivate(self): + self._plugin = None + self._window = None + self._panel = None + self._cspanel = None + + def update_ui(self): + return + + def create_panel(self): + # Open the Interface and bind with Botton Panel + glade_xml = gtk.glade.XML(GLADE_FILE, "CScopeBox") + self._cspanel = glade_xml.get_widget("CScopeBox") + image = gtk.Image() + image.set_from_stock(gtk.STOCK_DND_MULTIPLE, gtk.ICON_SIZE_BUTTON) + self._panel.add_item(self._cspanel, "CScope", image) + + # Objects + self._fcDatabase = glade_xml.get_widget("fcDatabase") + self._bOpen = glade_xml.get_widget("bOpen") + self._bSearch = glade_xml.get_widget("bSearch") + self._eQuery = glade_xml.get_widget("eQuery") + self._cbTypeOfQuery = glade_xml.get_widget("cbTypeOfQuery") + self._tvResults = glade_xml.get_widget("tvResult") + + self._cbTypeOfQuery.set_active(0) + + self._result = CScopeResult(self._tvResults) + + self._result.append( (1, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + self._result.append( (2, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + self._result.append( (3, "/usr/sr/linux/arch/m68k/process", "process.c", 102, "do_up", "int do_up(int test)") ) + self._result.append( (4, "/usr/sr/linux/arch/m68k/process", "process.c", 104, "do_up", "int do_up(int test)") ) + self._result.append( (5, "/usr/sr/linux/arch/m68k/process", "process.c", 150, "do_up", "int do_up(int test)") ) + self._result.append( (6, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + self._result.append( (7, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + self._result.append( (8, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + self._result.append( (9, "/usr/sr/linux/arch/m68k/process", "process.c", 102, "do_up", "int do_up(int test)") ) + self._result.append( (10, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + self._result.append( (11, "/usr/sr/linux/arch/m68k/process", "process.c", 103, "do_up", "int do_up(int test)") ) + self._result.append( (12, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + self._result.append( (13, "/usr/sr/linux/arch/m68k/process", "process.c", 104, "do_up", "int do_up(int test)") ) + self._result.append( (14, "/usr/sr/linux/arch/m68k/process", "process.c", 150, "do_up", "int do_up(int test)") ) + self._result.append( (15, "/usr/sr/linux/arch/m68k/process", "process.c", 160, "do_up", "int do_up(int test)") ) + self._result.append( (16, "/usr/sr/linux/arch/m68k/process", "process.c", 170, "do_up", "int do_up(int test)") ) + self._result.append( (17, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + self._result.append( (18, "/usr/sr/linux/arch/m68k/process", "process.c", 110, "do_up", "int do_up(int test)") ) + self._result.append( (19, "/usr/sr/linux/arch/m68k/process", "process.c", 190, "do_up", "int do_up(int test)") ) + self._result.append( (20, "/usr/sr/linux/arch/m68k/process", "process.c", 120, "do_up", "int do_up(int test)") ) + self._result.append( (21, "/usr/sr/linux/arch/m68k/process", "process.c", 100, "do_up", "int do_up(int test)") ) + + return -- 2.11.4.GIT