1. Ronny Pfannschmidt
  2. pida-patches

Source

pida-patches / kill-completer-types-enum

# HG changeset patch
# User Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
# Date 1280876358 -7200
# Node ID dc2797856c153b649049583ebef79122fcfe43fd
# Parent aabde088e793c433aefdcd3576681d60c79b63cf
imported patch kill-completer-types-enum

diff --git a/pida-plugins/python/python.py b/pida-plugins/python/python.py
--- a/pida-plugins/python/python.py
+++ b/pida-plugins/python/python.py
@@ -37,7 +37,8 @@ from pida.core.languages import (Languag
     Completer, LanguageServiceFeaturesConfig, LanguageInfo, Definer, 
     Documentator, External)
 
-from pida.utils.languages import (LANG_COMPLETER_TYPES,
+from pida.utils.languages import (
+    COMPLETER,
     LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_OUTLINER_TYPES, 
     LANG_PRIO, Definition, Suggestion, Documentation, ValidationError)
 
@@ -342,22 +343,15 @@ class PythonCompleter(Completer):
                 r = Suggestion(c.name)
                 #'variable', 'class', 'function', 'imported' , 'paramter'
                 if keyword.iskeyword(c.name):
-                    r.type_ = LANG_COMPLETER_TYPES.KEYWORD
-                elif c.type == 'variable':
-                    r.type_ = LANG_COMPLETER_TYPES.VARIABLE
-                elif c.type == 'class':
-                    r.type_ = LANG_COMPLETER_TYPES.CLASS
-                elif c.type == 'builtin':
-                    r.type_ = LANG_COMPLETER_TYPES.BUILTIN
-                elif c.type == 'function':
-                    r.type_ = LANG_COMPLETER_TYPES.FUNCTION
-                elif c.type == 'parameter':
-                    r.type_ = LANG_COMPLETER_TYPES.PARAMETER
+                    r.type_ = COMPLETER.KEYWORD
+                elif c.type in ('variable','class', 'builtin',
+                                'function', 'parameter',):
+                    r.type_ = getattr(COMPLETER, c.type.upper())
                 elif c.type == None:
                     if c.kind == "parameter_keyword":
-                        r.type_ = LANG_COMPLETER_TYPES.PARAMETER
+                        r.type_ = COMPLETER.PARAMETER
                 else:
-                    r.type_ = LANG_COMPLETER_TYPES.UNKNOWN
+                    r.type_ = COMPLETER.UNKNOWN
                 yield r
 
 class PythonDefiner(Definer):
diff --git a/pida-plugins/python_lint/python_lint.py b/pida-plugins/python_lint/python_lint.py
--- a/pida-plugins/python_lint/python_lint.py
+++ b/pida-plugins/python_lint/python_lint.py
@@ -21,7 +21,7 @@ from pida.core.options import OptionsCon
 from pida.core.log import Log
 
 from pida.core.languages import (LanguageService, Validator, External)
-from pida.utils.languages import (LANG_COMPLETER_TYPES,
+from pida.utils.languages import (
     LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_PRIO,
    Definition, Suggestion, Documentation, ValidationError)
 
diff --git a/pida/core/languages.py b/pida/core/languages.py
--- a/pida/core/languages.py
+++ b/pida/core/languages.py
@@ -15,7 +15,7 @@ from pida.core.document import Document
 from pida.core.projects import Project
 from pida.core.service import Service
 from pida.core.features import FeaturesConfig
-from pida.utils.languages import (LANG_COMPLETER_TYPES,
+from pida.utils.languages import (
     LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_PRIO,
     Suggestion, Definition, ValidationError, Documentation)
 from pida.utils.path import get_relative_path
diff --git a/pida/ui/completer.py b/pida/ui/completer.py
--- a/pida/ui/completer.py
+++ b/pida/ui/completer.py
@@ -7,8 +7,10 @@
 import gtk
 import gobject
 import os
-from pida.utils.languages import LANG_COMPLETER_TYPES
+from pida.utils.languages import COMPLETER
 
+
+#XXX: register as stock icons
 def _load_pix(fn):
     return gtk.gdk.pixbuf_new_from_file(
         os.path.join(os.path.dirname(__file__),
@@ -16,19 +18,19 @@ def _load_pix(fn):
 
 
 _PIXMAPS = {
-    LANG_COMPLETER_TYPES.UNKNOWN:     _load_pix('element-event-16.png'),
-    LANG_COMPLETER_TYPES.ATTRIBUTE:   _load_pix('source-attribute.png'),
-    LANG_COMPLETER_TYPES.CLASS:       _load_pix('source-class.png'),
-    LANG_COMPLETER_TYPES.FUNCTION:    _load_pix('source-attribute.png'), # FIXME
-    LANG_COMPLETER_TYPES.METHOD:      _load_pix('source-attribute.png'),
-    LANG_COMPLETER_TYPES.MODULE:      _load_pix('source-method.png'),
-    LANG_COMPLETER_TYPES.PROPERTY:    _load_pix('source-property.png'),
-    LANG_COMPLETER_TYPES.EXTRAMETHOD: _load_pix('source-extramethod.png'),
-    LANG_COMPLETER_TYPES.VARIABLE:    _load_pix('source-attribute.png'), # FIXME
-    LANG_COMPLETER_TYPES.IMPORT:      _load_pix('source-import.png'),
-    LANG_COMPLETER_TYPES.PARAMETER:   _load_pix('source-attribute.png'), # FIXME
-    LANG_COMPLETER_TYPES.BUILTIN:     _load_pix('source-attribute.png'), # FIXME
-    LANG_COMPLETER_TYPES.KEYWORD:     _load_pix('source-attribute.png'), # FIXME
+    'unknown':     _load_pix('element-event-16.png'),
+    'attribute':   _load_pix('source-attribute.png'),
+    'class':       _load_pix('source-class.png'),
+    'function':    _load_pix('source-attribute.png'), # FIXME
+    'method':      _load_pix('source-attribute.png'),
+    'module':      _load_pix('source-method.png'),
+    'property':    _load_pix('source-property.png'),
+    'extramethod': _load_pix('source-extramethod.png'),
+    'variable':    _load_pix('source-attribute.png'), # FIXME
+    'import':      _load_pix('source-import.png'),
+    'parameter':   _load_pix('source-attribute.png'), # FIXME
+    'builtin':     _load_pix('source-attribute.png'), # FIXME
+    'keyword':     _load_pix('source-attribute.png'), # FIXME
 }
 
 
@@ -39,10 +41,7 @@ class SuggestionsList(gtk.ListStore):
     @staticmethod
     def from_dbus(args):
         rv = list(args)
-        if args[0] in _PIXMAPS:
-            rv[0] = _PIXMAPS[args[0]]
-        else:
-            rv[0] = _PIXMAPS[LANG_COMPLETER_TYPES.UNKNOWN]
+        rv[0] = _PIXMAPS.get(args[0], _PIXMAPS['unknown'])
         return rv
 
 class PidaCompleterWindow(gtk.Window):
@@ -379,8 +378,8 @@ if __name__ == "__main__":
     i = 0
     for x in ['ase', 'assdf', 'Asdf', 'zasd', 'Zase', 'form', 'in', 'of', 'BLA',
               'taT', 'tUt', 'df', 'asdf', 'asdfa', 'sd', 'sdfsf', 'ssdfsdf', 'sd']:
-        l.append(SuggestionsList.from_dbus((i, x)))
-        i = i + 1%7
+        l.append(SuggestionsList.from_dbus((COMPLETER[i], x)))
+        i = (i + 1)%7
 
     p.set_model(l)
 
diff --git a/pida/utils/languages.py b/pida/utils/languages.py
--- a/pida/utils/languages.py
+++ b/pida/utils/languages.py
@@ -8,9 +8,11 @@ List of general Language classes.
 
 """
 from .addtypes import Enumeration
+from .symbols import Symbols
 from .path import get_line_from_file
 from .descriptors import cached_property
 
+import itertools
 
 
 #!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -20,12 +22,23 @@ from .descriptors import cached_property
 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 
+COMPLETER = Symbols('completer', [
+    'unknown',
+    'attribute',
+    'class',
+    'method',
+    'function',
+    'module',
+    'property',
+    'extramethod',
+    'variable',
+    'import',
+    'parameter',
+    'builtin',
+    'keyword',
+    'snippet',
+])
 
-# completer types
-LANG_COMPLETER_TYPES = Enumeration('LANG_COMPLETER_TYPES',
-    ('UNKNOWN', 'ATTRIBUTE', 'CLASS', 'METHOD', 'FUNCTION', 'MODULE', 
-    'PROPERTY', 'EXTRAMETHOD', 'VARIABLE', 'IMPORT', 'PARAMETER', 'BUILTIN', 
-    'KEYWORD', 'SNIPPET'))
 
 
 # main types
@@ -237,7 +250,7 @@ class Suggestion(unicode):
     """
     Suggestions are returned by an Completer class
     """
-    type_ = LANG_TYPES.UNKNOWN
+    type_ = COMPLETER.UNKNOWN
     doc = None
     docpath = None
     signature = None