Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/agilepy/lib_wx/test_app.py
169689 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.
3
# SUMOPy module
4
# Copyright (C) 2012-2021 University of Bologna - DICAM
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file test_app.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
from ogleditor import *
20
from mainframe import *
21
import os
22
import sys
23
24
import wx
25
from wx.lib.wordwrap import wordwrap
26
27
28
if __name__ == '__main__':
29
try:
30
APPDIR = os.path.dirname(os.path.abspath(__file__))
31
except:
32
APPDIR = os.path.dirname(os.path.abspath(sys.argv[0]))
33
AGILEDIR = os.path.join(APPDIR, '..')
34
print 'APPDIR,AGILEDIR', APPDIR, AGILEDIR
35
sys.path.append(AGILEDIR)
36
libpaths = [AGILEDIR, os.path.join(AGILEDIR, "lib_base"), os.path.join(AGILEDIR, "lib_wx"), ]
37
for libpath in libpaths:
38
print ' libpath=', libpath
39
lp = os.path.abspath(libpath)
40
if not lp in sys.path:
41
# print ' append',lp
42
sys.path.append(lp)
43
44
45
# import corepackages
46
#from test_glcanvas import *
47
##
48
##import wx
49
##
50
51
# try:
52
## dirName = os.path.dirname(os.path.abspath(__file__))
53
# except:
54
## dirName = os.path.dirname(os.path.abspath(sys.argv[0]))
55
##
56
# sys.path.append(os.path.split(dirName)[0])
57
58
59
IMAGEDIR = os.path.join(os.path.dirname(__file__), "images")
60
ICONPATH = os.path.join(IMAGEDIR, 'icon_color_small.png') # None
61
62
63
class MyApp(wx.App):
64
def __init__(self, redirect=False, filename=None):
65
wx.App.__init__(self, redirect, filename)
66
#self.frame = wx.Frame(None, wx.ID_ANY, title='My Title')
67
self.mainframe = AgileMainframe(title='MyApp', size_toolbaricons=(32, 32))
68
if ICONPATH is not None:
69
icon = wx.Icon(ICONPATH, wx.BITMAP_TYPE_PNG, 16, 16)
70
self.mainframe.SetIcon(icon)
71
72
self.gleditor = self.mainframe.add_view("OGleditor", OGleditor)
73
74
self.mainframe.Show()
75
self.on_test()
76
self.make_menu()
77
self.make_toolbar()
78
#canvas = gleditor.get_canvas()
79
# canvas.add_element(lines)
80
# canvas.add_element(triangles)
81
# canvas.add_element(rectangles)
82
83
def make_toolbar(self):
84
tsize = self.mainframe.get_size_toolbaricons()
85
new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
86
open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)
87
save_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize)
88
#cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize)
89
#copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)
90
#paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)
91
92
self.mainframe.add_tool('new', self.on_open, new_bmp, 'create new doc')
93
self.mainframe.add_tool('open', self.on_open, open_bmp, 'Open doc')
94
self.mainframe.add_tool('save', self.on_save, save_bmp, 'Save doc')
95
# self.toolbar.AddSeparator()
96
# self.add_tool('cut',self.on_open,cut_bmp,'Cut')
97
# self.add_tool('copy',self.on_open,copy_bmp,'Copy')
98
# self.add_tool('paste',self.on_open,paste_bmp,'Paste')
99
100
def make_menu(self):
101
self.mainframe.menubar.append_menu('file')
102
self.mainframe.menubar.append_menu('file/doc')
103
104
self.mainframe.menubar.append_item('file/doc/open', self.on_open,
105
shortkey='Ctrl+o', info='open it out')
106
107
self.mainframe.menubar.append_item('file/doc/save', self.on_save,
108
shortkey='Ctrl+s', info='save it out')
109
110
def on_save(self, event):
111
print 'save it!!'
112
113
def on_open(self, event):
114
"""Open a document"""
115
#wildcards = CreateWildCards() + "All files (*.*)|*.*"
116
print 'open it!!'
117
118
def on_test(self, event=None):
119
print '\non_test'
120
vertices = np.array([
121
[[0.0, 0.0, 0.0], [0.2, 0.0, 0.0]], # 0 green
122
[[0.0, 0.0, 0.0], [0.0, 0.9, 0.0]], # 1 red
123
])
124
125
colors = np.array([
126
[0.0, 0.9, 0.0, 0.9], # 0
127
[0.9, 0.0, 0.0, 0.9], # 1
128
])
129
130
colors2 = np.array([
131
[0.5, 0.9, 0.5, 0.5], # 0
132
[0.9, 0.5, 0.9, 0.5], # 1
133
])
134
colors2o = np.array([
135
[0.8, 0.9, 0.8, 0.9], # 0
136
[0.9, 0.8, 0.9, 0.9], # 1
137
])
138
139
drawing = OGLdrawing()
140
# -------------------------------------------------------------------------------
141
142
if 0:
143
lines = Lines('lines', drawing)
144
lines.add_drawobjs(vertices, colors)
145
drawing.add_drawobj(lines)
146
# -------------------------------------------------------------------------------
147
if 0:
148
fancylines = Fancylines('fancylines', drawing)
149
vertices_fancy = np.array([
150
[[0.0, -1.0, 0.0], [2, -1.0, 0.0]], # 0 green
151
[[0.0, -1.0, 0.0], [0.0, -5.0, 0.0]], # 1 red
152
])
153
154
widths = [0.5,
155
0.3,
156
]
157
# print ' vertices_fancy\n',vertices_fancy
158
# FLATHEAD = 0
159
#BEVELHEAD = 1
160
#TRIANGLEHEAD = 2
161
#ARROWHEAD = 3
162
fancylines.add_drawobjs(vertices_fancy,
163
widths, # width
164
colors,
165
beginstyles=[TRIANGLEHEAD, TRIANGLEHEAD],
166
endstyles=[ARROWHEAD, ARROWHEAD])
167
drawing.add_drawobj(fancylines)
168
# -------------------------------------------------------------------------------
169
if 0:
170
polylines = Polylines('polylines', drawing, joinstyle=BEVELHEAD)
171
colors_poly = np.array([
172
[0.0, 0.8, 0.5, 0.9], # 0
173
[0.8, 0.0, 0.5, 0.9], # 1
174
])
175
176
vertices_poly = np.array([
177
[[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 green
178
[[0.0, -2.0, 0.0], [-2.0, -2.0, 0.0]], # 1 red
179
], np.object)
180
181
widths = [0.5,
182
0.3,
183
]
184
# print ' vertices_poly\n',vertices_poly
185
polylines.add_drawobjs(vertices_poly,
186
widths, # width
187
colors_poly,
188
beginstyles=[ARROWHEAD, ARROWHEAD],
189
endstyles=[ARROWHEAD, ARROWHEAD])
190
drawing.add_drawobj(polylines)
191
192
# -------------------------------------------------------------------------------
193
if 1:
194
polygons = Polygons('polygons', drawing, linewidth=5)
195
colors_poly = np.array([
196
[0.0, 0.9, 0.9, 0.9], # 0
197
[0.8, 0.2, 0.2, 0.9], # 1
198
])
199
200
vertices_poly = np.array([
201
[[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 green
202
[[0.0, -2.0, 0.0], [-2.0, -2.0, 0.0], [-2.0, 0.0, 0.0]], # 1 red
203
], np.object)
204
205
print ' vertices_polygon\n', vertices_poly
206
polygons.add_drawobjs(vertices_poly,
207
colors_poly)
208
drawing.add_drawobj(polygons)
209
210
canvas = self.gleditor.get_canvas()
211
canvas.set_drawing(drawing)
212
213
#lines.add_drawobj([[0.0,0.0,0.0],[-0.2,-0.8,0.0]], [0.0,0.9,0.9,0.9])
214
#circles.add_drawobj([1.5,0.0,0.0],0.6,colors2o[0], colors2[0])
215
216
# canvas.zoom_tofit()
217
wx.CallAfter(canvas.zoom_tofit)
218
219
220
if __name__ == '__main__':
221
# if len(sys.argv)==3:
222
# ident = sys.argv[1]
223
# dirpath = sys.argv[2]
224
# else:
225
# ident = None
226
# dirpath = None
227
myapp = MyApp(0)
228
229
myapp.MainLoop()
230
231