Skip to content

Instantly share code, notes, and snippets.

@Klice
Last active October 10, 2018 04:42
Show Gist options
  • Save Klice/e50851bb62cd92353149c008fc756676 to your computer and use it in GitHub Desktop.
Save Klice/e50851bb62cd92353149c008fc756676 to your computer and use it in GitHub Desktop.
from scripting import *
import org.eclipse.swt as swt
import org.eclipse.swt.widgets as widgets
import org.eclipse.swt.layout as layout
# get a CityEngine instance
ce = CE()
if __name__ == '__main__':
result = None
display = widgets.Display()
shell = widgets.Shell(display)
shell.pack()
shell.open()
dialog = widgets.Shell(shell, swt.SWT.DIALOG_TRIM | swt.SWT.APPLICATION_MODAL)
dialog.setLayout(layout.RowLayout(swt.SWT.VERTICAL))
dialog.setText("Objects search")
sceneShapes = ce.getObjectsFrom(ce.scene, ce.isShape)
search_fileds = ['amenity', 'barrier', 'addr__housenumber', 'addr__street', 'building', 'building__levels', 'osm_id']
search_widgets = {}
for f in search_fileds:
widgets.Label(dialog, swt.SWT.NULL).setText(f)
w = widgets.Text(dialog, swt.SWT.SINGLE | swt.SWT.BORDER)
search_widgets[f] = w
ok = widgets.Button(dialog, swt.SWT.PUSH)
ok.setText ("OK")
cancel = widgets.Button(dialog, swt.SWT.PUSH);
cancel.setText("Cancel");
search_data = None
class MyListener(widgets.Listener):
def handleEvent(self, event):
global search_data
if event.widget == ok:
search_data = {}
for w_name, w in search_widgets.items():
search_data[w_name] = w.getText()
print search_data
dialog.close()
listener = MyListener()
ok.addListener(swt.SWT.Selection, listener)
cancel.addListener(swt.SWT.Selection, listener)
dialog.pack()
dialog.open()
while not dialog.isDisposed():
if not display.readAndDispatch():
display.sleep()
display.dispose()
if search_data is not None:
print "Selection:", search_data
search_result = []
for o in sceneShapes:
for key, value in search_data.items():
if value is not None and value != '' and ce.getAttribute(o, key) == value:
search_result.append(o)
print "Found:", len(search_result)
ce.setSelection(search_result)
views = ce.getObjectsFrom(ce.get3DViews())
views[0].frame(ce.selection())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment