gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / scripts / examples / layout / personalizar_mapa3.py @ 475
History | View | Annotate | Download (3.59 KB)
1 |
|
---|---|
2 |
execfile( script.getResource("../libs/import_utils.py").getAbsolutePath() ) |
3 |
|
4 |
use_plugin("org.gvsig.app.document.layout2.app.mainplugin")
|
5 |
|
6 |
from gvsig import * |
7 |
from org.gvsig.app.project.documents.layout import DefaultLayoutManager |
8 |
from commonsdialog import * |
9 |
|
10 |
import_from_module("..libs.formpanel","ProgressBarWithTaskStatus,FormPanel") |
11 |
|
12 |
class CustomizeLayout(FormPanel): |
13 |
def __init__(self): |
14 |
FormPanel.__init__(self,script.getResource("personalizar_mapa3.xml")) |
15 |
# Llenamos el desplegable de mapas con los mapas que hay en el proyecto.
|
16 |
proyecto = currentProject()() |
17 |
docs = proyecto.getDocuments() |
18 |
for doc in docs : |
19 |
if doc.__class__.__name__ == "DefaultLayoutDocument": |
20 |
cboMapas.addItem(doc) |
21 |
pass
|
22 |
|
23 |
def actualizar_mapa(self, mapa, tagVista, tagTitulo, tagLogo, encuadre, titulo, logo): |
24 |
context = mapa.getLayoutContext() |
25 |
|
26 |
# Nos recorremos todos los elementos del mapa buscando los que hemos etiquetado
|
27 |
for elemento in context.getAllFFrames(): |
28 |
if elemento.getTag() == tagVista:
|
29 |
# Ajustamos el encuadre de la vista al del elemento seleccionado
|
30 |
mapContext = elemento.getMapContext() |
31 |
mapContext.getViewPort().setEnvelope(encuadre) |
32 |
mapContext.invalidate() |
33 |
|
34 |
elif elemento.getTag() == tagTitulo:
|
35 |
# Cambiamos el rotulo del texto que habiamos etiquetado en el mapa
|
36 |
elemento.clearText() |
37 |
elemento.addText(titulo) |
38 |
|
39 |
elif elemento.getTag() == tagLogo:
|
40 |
# Cambiamos la imagen del logotipo
|
41 |
elemento.setImage(logo) |
42 |
|
43 |
context.fullRefresh() |
44 |
|
45 |
def btnCerrar_click(*args): |
46 |
self.hide()
|
47 |
|
48 |
def cboMapas_click(*args): |
49 |
mapa = self.cboMapas.getSelectedItem()
|
50 |
|
51 |
cboTagVista = self.cboTagVista
|
52 |
cboTagTitulo = self.cboTagTitulo
|
53 |
cboTagLogotipo= self.cboTagLogotipo
|
54 |
|
55 |
for elemento in mapa.getLayoutContext().getAllFFrames(): |
56 |
#print elemento.__class__.__name__
|
57 |
if not elemento.getTag() in (None, ""): |
58 |
if elemento.__class__.__name__ == "FFrameText": |
59 |
self.cboTagTitulo.addItem(elemento.getTag())
|
60 |
|
61 |
elif elemento.__class__.__name__ == "FFrameView": |
62 |
self.cboTagVista.addItem(elemento.getTag())
|
63 |
|
64 |
elif elemento.__class__.__name__ == "FFramePicture": |
65 |
self.cboTagLogotipo.addItem(elemento.getTag())
|
66 |
|
67 |
|
68 |
def btnActualizarMapa_click(*args): |
69 |
# Obtenemos la capa activa de la vista activa
|
70 |
capa = currentLayer() |
71 |
if capa == None: |
72 |
msgbox("Debera tener seleccionada una capa.")
|
73 |
return
|
74 |
|
75 |
# Obtenemos el primer elemento seleccionado de la capa
|
76 |
seleccion = list()
|
77 |
seleccion.extend(capa.getSelection()) |
78 |
if len(seleccion) < 1: |
79 |
msgbox("Debera tener seleccionados elementos en la capa activa.")
|
80 |
return
|
81 |
entidad = seleccion[0]
|
82 |
|
83 |
mapa = self.cboMapas.getSelectedItem()
|
84 |
tagVista = self.cboTagVista.getSelectedItem()
|
85 |
tagTitulo = self.cboTagTitulo.getSelectedItem()
|
86 |
tagLogotipo = self.cboTagLogotipo.getSelectedItem()
|
87 |
if tagVista in ("",None) or tagTitulo in ("",None) : |
88 |
msgbox("Debera seleccionar el tag de la vista, titulo y logotipo")
|
89 |
return
|
90 |
|
91 |
encuadre = entidad.geometry().getEnvelope() |
92 |
try:
|
93 |
titulo = eval(self.txtTitulo.getText(), entidad) |
94 |
except:
|
95 |
titulo = self.txtTitulo.getText()
|
96 |
|
97 |
try:
|
98 |
logotipo_nombre = eval(self.txtLogotipo.getText(), entidad) |
99 |
logotipo = load_image(script.getResource(logotipo_nombre)) |
100 |
except:
|
101 |
logotipo = None
|
102 |
|
103 |
self.actualizar_mapa(mapa, tagVista, tagTitulo, tagLogotipo, encuadre, titulo, logotipo)
|
104 |
|
105 |
|
106 |
|
107 |
def main(*args): |
108 |
customizeLayout = CustomizeLayout() |
109 |
customizeLayout.showTool("Customize layout")
|
110 |
|
111 |
|