Path: blob/main/tools/contributed/sumopy/agilepy/lib_wx/test_app.py
169689 views
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo1# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.2# SUMOPy module3# Copyright (C) 2012-2021 University of Bologna - DICAM4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file test_app.py15# @author Joerg Schweizer16# @date 20121718from ogleditor import *19from mainframe import *20import os21import sys2223import wx24from wx.lib.wordwrap import wordwrap252627if __name__ == '__main__':28try:29APPDIR = os.path.dirname(os.path.abspath(__file__))30except:31APPDIR = os.path.dirname(os.path.abspath(sys.argv[0]))32AGILEDIR = os.path.join(APPDIR, '..')33print 'APPDIR,AGILEDIR', APPDIR, AGILEDIR34sys.path.append(AGILEDIR)35libpaths = [AGILEDIR, os.path.join(AGILEDIR, "lib_base"), os.path.join(AGILEDIR, "lib_wx"), ]36for libpath in libpaths:37print ' libpath=', libpath38lp = os.path.abspath(libpath)39if not lp in sys.path:40# print ' append',lp41sys.path.append(lp)424344# import corepackages45#from test_glcanvas import *46##47##import wx48##4950# try:51## dirName = os.path.dirname(os.path.abspath(__file__))52# except:53## dirName = os.path.dirname(os.path.abspath(sys.argv[0]))54##55# sys.path.append(os.path.split(dirName)[0])565758IMAGEDIR = os.path.join(os.path.dirname(__file__), "images")59ICONPATH = os.path.join(IMAGEDIR, 'icon_color_small.png') # None606162class MyApp(wx.App):63def __init__(self, redirect=False, filename=None):64wx.App.__init__(self, redirect, filename)65#self.frame = wx.Frame(None, wx.ID_ANY, title='My Title')66self.mainframe = AgileMainframe(title='MyApp', size_toolbaricons=(32, 32))67if ICONPATH is not None:68icon = wx.Icon(ICONPATH, wx.BITMAP_TYPE_PNG, 16, 16)69self.mainframe.SetIcon(icon)7071self.gleditor = self.mainframe.add_view("OGleditor", OGleditor)7273self.mainframe.Show()74self.on_test()75self.make_menu()76self.make_toolbar()77#canvas = gleditor.get_canvas()78# canvas.add_element(lines)79# canvas.add_element(triangles)80# canvas.add_element(rectangles)8182def make_toolbar(self):83tsize = self.mainframe.get_size_toolbaricons()84new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)85open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)86save_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize)87#cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize)88#copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)89#paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)9091self.mainframe.add_tool('new', self.on_open, new_bmp, 'create new doc')92self.mainframe.add_tool('open', self.on_open, open_bmp, 'Open doc')93self.mainframe.add_tool('save', self.on_save, save_bmp, 'Save doc')94# self.toolbar.AddSeparator()95# self.add_tool('cut',self.on_open,cut_bmp,'Cut')96# self.add_tool('copy',self.on_open,copy_bmp,'Copy')97# self.add_tool('paste',self.on_open,paste_bmp,'Paste')9899def make_menu(self):100self.mainframe.menubar.append_menu('file')101self.mainframe.menubar.append_menu('file/doc')102103self.mainframe.menubar.append_item('file/doc/open', self.on_open,104shortkey='Ctrl+o', info='open it out')105106self.mainframe.menubar.append_item('file/doc/save', self.on_save,107shortkey='Ctrl+s', info='save it out')108109def on_save(self, event):110print 'save it!!'111112def on_open(self, event):113"""Open a document"""114#wildcards = CreateWildCards() + "All files (*.*)|*.*"115print 'open it!!'116117def on_test(self, event=None):118print '\non_test'119vertices = np.array([120[[0.0, 0.0, 0.0], [0.2, 0.0, 0.0]], # 0 green121[[0.0, 0.0, 0.0], [0.0, 0.9, 0.0]], # 1 red122])123124colors = np.array([125[0.0, 0.9, 0.0, 0.9], # 0126[0.9, 0.0, 0.0, 0.9], # 1127])128129colors2 = np.array([130[0.5, 0.9, 0.5, 0.5], # 0131[0.9, 0.5, 0.9, 0.5], # 1132])133colors2o = np.array([134[0.8, 0.9, 0.8, 0.9], # 0135[0.9, 0.8, 0.9, 0.9], # 1136])137138drawing = OGLdrawing()139# -------------------------------------------------------------------------------140141if 0:142lines = Lines('lines', drawing)143lines.add_drawobjs(vertices, colors)144drawing.add_drawobj(lines)145# -------------------------------------------------------------------------------146if 0:147fancylines = Fancylines('fancylines', drawing)148vertices_fancy = np.array([149[[0.0, -1.0, 0.0], [2, -1.0, 0.0]], # 0 green150[[0.0, -1.0, 0.0], [0.0, -5.0, 0.0]], # 1 red151])152153widths = [0.5,1540.3,155]156# print ' vertices_fancy\n',vertices_fancy157# FLATHEAD = 0158#BEVELHEAD = 1159#TRIANGLEHEAD = 2160#ARROWHEAD = 3161fancylines.add_drawobjs(vertices_fancy,162widths, # width163colors,164beginstyles=[TRIANGLEHEAD, TRIANGLEHEAD],165endstyles=[ARROWHEAD, ARROWHEAD])166drawing.add_drawobj(fancylines)167# -------------------------------------------------------------------------------168if 0:169polylines = Polylines('polylines', drawing, joinstyle=BEVELHEAD)170colors_poly = np.array([171[0.0, 0.8, 0.5, 0.9], # 0172[0.8, 0.0, 0.5, 0.9], # 1173])174175vertices_poly = np.array([176[[0.0, 2.0, 0.0], [5.0, 2.0, 0.0], [5.0, 7.0, 0.0], [0.0, 7.0, 0.0]], # 0 green177[[0.0, -2.0, 0.0], [-2.0, -2.0, 0.0]], # 1 red178], np.object)179180widths = [0.5,1810.3,182]183# print ' vertices_poly\n',vertices_poly184polylines.add_drawobjs(vertices_poly,185widths, # width186colors_poly,187beginstyles=[ARROWHEAD, ARROWHEAD],188endstyles=[ARROWHEAD, ARROWHEAD])189drawing.add_drawobj(polylines)190191# -------------------------------------------------------------------------------192if 1:193polygons = Polygons('polygons', drawing, linewidth=5)194colors_poly = np.array([195[0.0, 0.9, 0.9, 0.9], # 0196[0.8, 0.2, 0.2, 0.9], # 1197])198199vertices_poly = np.array([200[[0.0, 2.0, 0.0], [5.0, 2.0, 0.0], [5.0, 7.0, 0.0], [0.0, 7.0, 0.0]], # 0 green201[[0.0, -2.0, 0.0], [-2.0, -2.0, 0.0], [-2.0, 0.0, 0.0]], # 1 red202], np.object)203204print ' vertices_polygon\n', vertices_poly205polygons.add_drawobjs(vertices_poly,206colors_poly)207drawing.add_drawobj(polygons)208209canvas = self.gleditor.get_canvas()210canvas.set_drawing(drawing)211212#lines.add_drawobj([[0.0,0.0,0.0],[-0.2,-0.8,0.0]], [0.0,0.9,0.9,0.9])213#circles.add_drawobj([1.5,0.0,0.0],0.6,colors2o[0], colors2[0])214215# canvas.zoom_tofit()216wx.CallAfter(canvas.zoom_tofit)217218219if __name__ == '__main__':220# if len(sys.argv)==3:221# ident = sys.argv[1]222# dirpath = sys.argv[2]223# else:224# ident = None225# dirpath = None226myapp = MyApp(0)227228myapp.MainLoop()229230231