Revision 734

View differences:

org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig/utils.py
3 3
import time
4 4
import sys
5 5
import StringIO
6
import random
6 7

  
7 8
from java.util.prefs import Preferences
8 9
from java.awt import Color
......
403 404

  
404 405
  return color
405 406

  
406
def getDefaultColor(c = None):
407
def getDefaultColor():
407 408
  """Returns gvsig default symbol fill color or ramdom color"""
408
  if MapContextLocator.getSymbolManager().isDefaultSymbolFillColorAleatory():
409
    color = Color(random.randint(0-255),
410
                random.randint(0-255),
411
                random.randint(0-255)
409
  if MapContextLocator.getMapContextManager().isDefaultSymbolFillColorAleatory():
410
    color = Color(random.randint(0, 255),
411
                random.randint(0, 255),
412
                random.randint(0, 255)
412 413
            )
413 414
  else:
414 415
    sp = MapContextLocator.getSymbolManager().getSymbolPreferences()
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig/project.py
30 30
    return view
31 31

  
32 32
def __getView(self, name=None):
33
  if name == None:
34
    try:
35
      activeDocument = self.getActiveDocument()
36
      if activeDocument == None:
37
	  return None
38
      if isinstance(activeDocument, ViewDocument):
39
	  return activeDocument
40
      return None
33
    if name == None:
34
        try:
35
            activeDocument = self.getActiveDocument()
36
            if activeDocument == None:
37
                return None
38
            if isinstance(activeDocument, ViewDocument):
39
                return activeDocument
40
            return None
41 41

  
42
    except Exception, ex:
43
      raise Exception("%s" % repr(ex))
44
  else:
45
    views = self.getViews()
46
    if len(views) >0:
47
      for view in views:
48
	if name == view.getName():
49
	  return view
42
        except Exception, ex:
43
            raise Exception("%s" % repr(ex))
44
    else:
45
        views = self.getViews()
46
        if len(views) >0:
47
            for view in views:
48
                if name == view.getName():
49
                    return view
50 50
    return None
51 51

  
52 52
def __getTable(self, name=None):
53
  if name == None:
54
    try:
55
      activeDocument = self.getActiveDocument()
56
      if activeDocument == None:
57
	  return None
58
      if isinstance(activeDocument, TableDocument):
59
	  return activeDocument
60
      return None
53
    if name == None:
54
        try:
55
            activeDocument = self.getActiveDocument()
56
            if activeDocument == None:
57
                return None
58
            if isinstance(activeDocument, TableDocument):
59
                return activeDocument
60
            return None
61
        except Exception, ex:
62
            raise Exception("%s"%repr(ex))
63
    else:
64
        tables = self.getDocuments("project.document.table")
65
        if len(tables) >0:
66
            for table in tables:
67
                if name == table.getName():
68
                    return table
69
        return None
61 70

  
62
    except Exception, ex:
63
      raise Exception("%s"%repr(ex))
64
  else:
65
    tables = self.getDocuments("project.document.table")
66
    if len(tables) >0:
67
      for table in tables:
68
	if name == table.getName():
69
	  return table
70
    return None
71

  
72 71
def __getProjectionCode(self):
73
  return self.getProjection().getFullCode()
72
    return self.getProjection().getFullCode()
74 73

  
75 74
def __call(self):
76
  return self
75
    return self
77 76

  
78 77
def __iter(self):
79
  it = self.iterator()
80
  while it.hasNext() :
81
    doc = it.next()
82
    yield doc
78
    it = self.iterator()
79
    while it.hasNext() :
80
        doc = it.next()
81
        yield doc
83 82

  
84 83
def __len(self):
85
  return self.getDocuments().size()
84
    return self.getDocuments().size()
86 85

  
87 86
def __getitem(self,index):
88
  return self.getDocuments().get(index)
87
    return self.getDocuments().get(index)
89 88

  
90 89
def currentProject():
91
  application = ApplicationLocator.getManager()
92
  project = application.getCurrentProject()
93
  return project
90
    application = ApplicationLocator.getManager()
91
    project = application.getCurrentProject()
92
    return project
94 93

  
95 94
def currentDocument(documentClass = None):
96
  application = ApplicationLocator.getManager()
95
    application = ApplicationLocator.getManager()
97 96

  
98
  if documentClass == None:
99
    doc = application.getActiveDocument()
100
  else:
101
    doc = application.getActiveDocument(documentClass)
102
  return doc
97
    if documentClass == None:
98
        doc = application.getActiveDocument()
99
    else:
100
        doc = application.getActiveDocument(documentClass)
101
    return doc
103 102

  
104 103
def currentTable():
105
  return currentDocument(TableDocument)
104
    return currentDocument(TableDocument)
106 105

  
107 106
def currentView():
108
  return currentDocument(ViewDocument)
107
    return currentDocument(ViewDocument)
109 108

  
110 109

  
111 110

  

Also available in: Unified diff