-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpythonLuaSetupAssistant.lua
More file actions
74 lines (66 loc) · 2.75 KB
/
pythonLuaSetupAssistant.lua
File metadata and controls
74 lines (66 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
local sim = require 'sim'
local simUI
function setupForLang(lang)
local simCmd = require 'simCmd'
sim.setStringProperty(sim.handle_app, 'namedParam.simCmd.preferredSandboxLang', lang)
simCmd.setSelectedScript(-1, lang)
sim.setStringProperty(sim.handle_app, 'sandboxLang', lang)
simUI.destroy(ui)
ui = nil
end
function setupForLua()
setupForLang 'lua'
end
function setupForPython()
setupForLang 'python'
end
local function main()
local prefLang = sim.getStringProperty(sim.handle_app, 'sandboxLang')
if prefLang ~= '' then
-- already set
return
end
local resourcesDir = sim.getStringProperty(sim.handle_app, 'resourcePath')
local imagesDir = resourcesDir .. '/manual/en/images/usedByScripts/'
local imgStyle =
'background-color: white; border: 1px solid white; border-radius: 8px; padding-top: 100px;'
local function imgSize(w, h)
local platform = sim.getIntProperty(sim.handle_app, 'platform')
if platform == 1 then
return ''
else
local k = 4
return string.format('width="%d" height="%d"', w // k, h // k)
end
end
local v = sim.getIntProperty(sim.handle_app, 'productVersionNb')
v = table.join({v // 1000000, v // 10000 % 100, v // 100 % 100}, '.')
simUI = require 'simUI'
ui = simUI.create(
[[<ui closeable="true" title="Welcome to CoppeliaSim ]] .. v .. [[" modal="true">
<label text="This version of CoppeliaSim supports both <b>Lua</b> and <b>Python</b> as the scripting languages for writing child scripts, customization scripts and add-ons. Choosing your preferred language will make it easier to access (e.g. in the sandbox).<br/><br/>Which language do you want to set as the preferred language?" wordwrap="true" />
<group flat="true" layout="hbox">
<group>
<image scaled-contents="true" keep-aspect-ratio="true"
file="]] .. imagesDir .. [[lua-logo.png"
style="]] .. imgStyle .. [["
]] .. imgSize(512, 512) .. [[
/>
<button text="Set up for Lua"
on-click="setupForLua" />
</group>
<group>
<image scaled-contents="true" keep-aspect-ratio="true"
file="]] .. imagesDir .. [[python-logo.png"
style="]] .. imgStyle .. [["
]] .. imgSize(559, 512) .. [[
/>
<button text="Set up for Python"
on-click="setupForPython" />
</group>
</group>
<label text="Note: you can change it later by modifying <em>preferredSandboxLang</em> in usrset.txt." />
</ui>]]
)
end
main()