Skip to content

Commit

Permalink
actualizado al uso del nuevo expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Martinez committed Oct 5, 2019
1 parent 5209e13 commit 52187b7
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 539 deletions.
6 changes: 3 additions & 3 deletions actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def isLayerValid(self, layer):
if layer == None:
trace("QuickinfoExtension.isLayerValid: None, return False")
return False
mode = layer.getProperty("quickinfo.mode")
if mode in ("", None):
active = layer.getProperty("quickinfo.active")
if active == None:
# Si la capa no tiene configurado el campo a mostrar
# no activamos la herramienta
return False
return True
return active

def isEnabled(self):
layer = currentLayer()
Expand Down
3 changes: 2 additions & 1 deletion i18n/text.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#
#Tue Oct 24 16:39:16 CEST 2017
#Sat Oct 05 18:21:35 CEST 2019
_Select_field_to_show_in_the_tip=Seleccione un campo a mostrar en el 'tip'
_Use_expression=Usar una expresi\u00F3n
_Correct_expression=Expresi\u00F3n correcta
_Quickinfo=Informaci\u00F3n rapida
_Use_a_field=Usar un campo
_Fields=Campos
_Show_quick_info=Mostrar informaci\u00F3n rapida
_Activate_quickinfo_tool=Activar herramienta de informaci\u00F3n r\u00E1pida
_Test=Test
_Errors_have_occurred_checking_the_expression=Se han producido errores comprobando la expresion
3 changes: 2 additions & 1 deletion i18n/text_en.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#
#Tue Oct 24 16:39:31 CEST 2017
#Sat Oct 05 18:21:25 CEST 2019
_Select_field_to_show_in_the_tip=Select field to show in the 'tip'
_Use_expression=Use expression
_Correct_expression=Correct expression
_Quickinfo=Quickinfo
_Use_a_field=Use a field
_Fields=Fields
_Show_quick_info=Show quick info
_Activate_quickinfo_tool=Activate quick info tool
_Test=Test
_Errors_have_occurred_checking_the_expression=Errors have occurred checking the expression
30 changes: 17 additions & 13 deletions quickinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from org.gvsig.fmap.mapcontext.layers.vectorial import SpatialEvaluatorsFactory
from gvsig import logger
from gvsig import LOGGER_WARN,LOGGER_INFO,LOGGER_ERROR
from org.gvsig.expressionevaluator import ExpressionEvaluatorLocator
from org.gvsig.fmap.dal import DALLocator

def trace(msg):
#print "###> ", msg
pass
Expand All @@ -22,6 +25,9 @@ def getTooltipValue(self, point, projection):
fieldName = self.__layer.getProperty("quickinfo.fieldname")
expression = self.__layer.getProperty("quickinfo.expression")
mode = self.__layer.getProperty("quickinfo.mode")
activate = self.__layer.getProperty("quickinfo.active")
if activate == False:
return
if mode == "useField":
if fieldName in ("", None):
trace('QuickInfo.getTooltipValue: %s return ""' % repr(fieldName))
Expand All @@ -41,22 +47,20 @@ def getTooltipValue(self, point, projection):

# Con que nos devuelba la primera linea es suficiente.
query.setLimit(1)
query.retrievesAllAttributes();
l = store.getFeatures(query,100)
if len(l) < 1:
query.retrievesAllAttributes()
firstfeature = store.findFirst(query)
if firstfeature == None:
trace('QuickInfo.getTooltipValue: %s point %s, no records selected return ""' % (repr(fieldName), point.convertToWKT()) )
return ""
if mode == "useField":
return str(l[0].get(fieldName))
_globals = dict()
_globals.update(globals())
_globals["store"] = store
_globals["layer"] = self.__layer
_locals = dict()
_locals.update(l[0])
expression = expression.replace("\n"," ")
x = eval(expression, _globals,_locals)
trace("tooltip: %s" % repr(x))
return str(firstfeature.get(fieldName))

# Eval expression with expression
manager = ExpressionEvaluatorLocator.getManager()
dataManager = DALLocator.getDataManager()
featureSymbolTable = dataManager.createFeatureSymbolTable()
featureSymbolTable.setFeature(firstfeature)
x = expression.execute(featureSymbolTable)
return x
except:
ex = sys.exc_info()[1]
Expand Down
106 changes: 40 additions & 66 deletions quickinfopanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,67 @@
from java.lang import Float
from java.io import File
from org.gvsig.tools.dataTypes import DataTypes

from gvsig import logger
from gvsig import LOGGER_WARN,LOGGER_INFO,LOGGER_ERROR
from org.gvsig.tools.evaluator import EvaluatorException

from org.gvsig.expressionevaluator.swing import ExpressionEvaluatorSwingLocator


from org.gvsig.fmap.dal.swing import DALSwingLocator

class QuickinfoPanel(FormPanel):
def __init__(self, layer=None):
FormPanel.__init__(self,getResource(__file__,"quickinfopanel.xml"))
i18n = ToolsSwingLocator.getToolsSwingManager()
i18n.translate(self.rdoUseField)
i18n.translate(self.lblSelectField)
i18n.translate(self.rdoUseExpression)
i18n.translate(self.lblFields)
i18n.translate(self.btnTest)
i18n.translate(self.chbActivate)

self.btgMode = ButtonGroup()
self.btgMode.add(self.rdoUseField)
self.btgMode.add(self.rdoUseExpression)

## Picker
self.store = layer.getFeatureStore()
self.expPicker = ExpressionEvaluatorSwingLocator.getManager().createExpressionPickerController(self.txtExp, self.btnExp)
self.expFilterStore = DALSwingLocator.getSwingManager().createFeatureStoreElement(self.store)
self.expPicker.addElement(self.expFilterStore)


self.rdoUseField.setSelected(True)
self.cboFields.setEnabled(True)
self.expPicker.setEnabled(False)
self.setLayer(layer)

def setLayer(self, layer):
self.__layer = layer
if layer==None:
self.cboFields.removeAllItems()
self.lstFields.setModel(DefaultListModel())
self.txtExpression.setText("")
self.rdoUseField.setSelected(True)
else:
featureType = self.__layer.getFeatureStore().getDefaultFeatureType()
self.fillCombo( self.cboFields, featureType )
self.lstFields.setModel(self.getListModel(featureType))
s = self.__layer.getProperty("quickinfo.expression")
if s == None:
s = ""
self.txtExpression.setText(s)
self.expPicker.set(s)
if self.__layer.getProperty("quickinfo.active") != None:
self.chbActivate.setSelected(self.__layer.getProperty("quickinfo.active"))

if self.__layer.getProperty("quickinfo.mode") == "useField":
self.rdoUseField.setSelected(True)
else:
self.rdoUseField.setSelected(True)
self.cboFields.setEnabled(True)
self.expPicker.setEnabled(False)
elif self.__layer.getProperty("quickinfo.mode") == "useExpression":
self.rdoUseExpression.setSelected(True)
else:
self.rdoUseField.setSelected(True)

def getListModel(self, featureType):
model = DefaultListModel()
for attr in featureType:
model.addElement(attr.getName())
return model
#def getListModel(self, featureType):
# model = DefaultListModel()
# for attr in featureType:
# model.addElement(attr.getName())
# return model

def getLayer(self):
return self.__layer
Expand All @@ -82,19 +98,13 @@ def getFieldName(self):
return name

def getExpression(self):
return self.txtExpression.getText()

return self.expPicker.get()
def getMode(self):
if self.rdoUseField.isSelected():
return "useField"
else:
return "useExpression"

def lstFields_mouseClick(self, e):
if e.getClickCount()==2 and e.getID() == MouseEvent.MOUSE_CLICKED:
x = self.lstFields.getSelectedValue()
self.txtExpression.replaceSelection(x+" ")
self.txtExpression.requestFocusInWindow()

def fillCombo(self, combo, featureType):
combo.removeAllItems()
Expand All @@ -116,6 +126,10 @@ def save(self):
"quickinfo.expression",
self.getExpression()
)
self.__layer.setProperty(
"quickinfo.active",
self.chbActivate.isSelected()
)
if self.rdoUseField.isSelected():
self.__layer.setProperty(
"quickinfo.mode",
Expand All @@ -130,50 +144,10 @@ def save(self):
def rdoUseField_change(self, *args):
if self.rdoUseField.isSelected():
self.cboFields.setEnabled(True)
self.lstFields.setEnabled(False)
self.txtExpression.setEnabled(False)
self.btnTest.setEnabled(False)
self.expPicker.setEnabled(False)
else:
self.cboFields.setEnabled(False)
self.lstFields.setEnabled(True)
self.txtExpression.setEnabled(True)
self.btnTest.setEnabled(True)

def btnTest_click(self, *args):
i18n = ToolsLocator.getI18nManager()

defaultValues = dict()
defaultValues[DataTypes.BOOLEAN] = True
defaultValues[DataTypes.BYTE] = 0
defaultValues[DataTypes.CHAR] = 0
defaultValues[DataTypes.INT] = 0
defaultValues[DataTypes.LONG] = 0
defaultValues[DataTypes.FLOAT] = Float(0.0)
defaultValues[DataTypes.DOUBLE] = Double(0.0)
defaultValues[DataTypes.STRING] = ""
defaultValues[DataTypes.DATE] = Date()
defaultValues[DataTypes.TIME] = Date()
defaultValues[DataTypes.FILE] = File(getResource(__file__))
defaultValues[DataTypes.FOLDER] = File(getResource(__file__)).getParentFile()
defaultValues[DataTypes.URL] = URL("http://acme.com")
defaultValues[DataTypes.URI] = URI("http://acme.com")
defaultValues[DataTypes.VERSION] = ToolsLocator.getPackageManager().createVersion("1.0.0")
defaultValues[DataTypes.BIGDECIMAL] = BigDecimal(0)

values = dict()
featureType = self.__layer.getFeatureStore().getDefaultFeatureType()
for attr in featureType:
values[attr.getName()] = defaultValues.get(attr.getType(),None)
try:
expression = self.getExpression().replace("\n"," ")
x = eval(expression,globals(),values)
#print "x = ", x
gvsig.commonsdialog.msgbox(i18n.getTranslation("_Correct_expression"))
except Exception,ex:
gvsig.commonsdialog.msgbox(i18n.getTranslation("_Errors_have_occurred_checking_the_expression") + "\n\n" + str(ex))
except :
gvsig.commonsdialog.msgbox(i18n.getTranslation("_Errors_have_occurred_checking_the_expression") + "\n\n")

self.expPicker.setEnabled(True)

def main(*args):
viewDoc = gvsig.currentView()
Expand Down
Loading

0 comments on commit 52187b7

Please sign in to comment.