the list of duplicates is ready (still not used)
[lqt.git] / old_bindings / tutorial.lua
blobdb771c46a66f273aa6be1eea7da5b6f9f5300c81
1 #!/usr/bin/lua
2 --[[
4 Copyright (c) 2007-2008 Mauro Iazzi
6 Permission is hereby granted, free of charge, to any person
7 obtaining a copy of this software and associated documentation
8 files (the "Software"), to deal in the Software without
9 restriction, including without limitation the rights to use,
10 copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following
13 conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 OTHER DEALINGS IN THE SOFTWARE.
27 --]]
30 while false do
31 local i = QLabel.__index
32 QLabel.__index = function (...) print('QLabel required', ...) return i(...) end
33 end
35 if false then
36 local i = QPushButton.__index
37 QPushButton.__index = function (...) print(...) local ret = { i(...) } print(unpack(ret)) return unpack(ret) end
38 end
40 qt = {
41 slot = function(s) return '1'..tostring(s) end,
42 signal = function(s) return '2'..tostring(s) end,
46 --app = QApplication.new()
48 --print'====='
49 --print(app, app())
51 --QApplication.new = app
54 --print( app )
55 --print( pcall( app ) )
57 --[[
58 QApplication.new = app
59 --]]
61 --print( QApplication.new )
62 --print( pcall( QApplication.new ) )
65 app = QApplication.new()
66 --print(app)
69 mainwin = QWidget.new()
70 --print(mainwin)
71 mainwin:show()
73 layout = QVBoxLayout.new()
75 mainwin:setLayout(layout)
76 mainwin:setWindowTitle'lqt test window'
78 te = QTextEdit.new()
79 layout:addWidget(te)
80 te:setToolTip'I\'m the Code Edit Box: I hold the code while you edit'
82 --[==[
83 te:setPlainText[[
84 but = QPushButton.new()
85 but:show()
86 but:connect(qt.signal'pressed()', but, qt.slot'close()')
87 but:setText'Close Me!'
88 but:resize(150, 50)
89 but:setFont(QFont.new('Times', 18, 75))
91 --]==]
93 te:setPlainText[[
94 buttons = buttons or {}
95 i = #buttons + 1
97 but = QPushButton.new()
99 but:show()
100 but:connect(qt.signal'pressed()', but, qt.slot'close()')
101 but:setText'Close Me!'
102 but:setWindowTitle('Button '..i)
103 but:resize(180, 50)
104 but:setFont(QFont.new('Times', 18, 75))
106 buttons[i] = but
108 return 'Created button '..i
111 --te:show()
113 --print'----'
115 print'-----'
116 pb = QPushButton.new()
117 print'-----'
118 layout:addWidget(pb)
119 print'-----'
120 pb:setText'Exec'
121 print'-----'
122 pb:setToolTip'I\'m the Exec button: push me to execute your code'
123 print'-----'
124 --pb:show()
126 quit = QPushButton.new()
127 layout:addWidget(quit)
128 quit:setText'Quit'
129 quit:setToolTip'I\'m the Quit button: push me to close all windows'
132 --pb:connect('2pressed()', SLOT(function() print 'lqt RULES!' end))
133 --pb:connect('2pressed()', SLOT(function() print 'lqt ROCKS!' end))
135 results = QLabel.new()
136 results:setToolTip'I\'m the result bar: I will show you your results and your errors'
137 layout:addWidget(results)
139 pb:connect('2pressed()', SLOT(function()
140 local f, err = loadstring(te:toPlainText())
141 if f==nil then
142 results:setText(err)
143 else
144 local res = { pcall( f ) }
145 if res[1] then
146 local string = ''
147 for i, r in ipairs(res) do
148 if i~=1 then string = string .. tostring(r) .. ', ' end
150 results:setText(string)
151 else
152 results:setText(res[2])
155 end))
156 quit:connect('2pressed()', app, '1closeAllWindows()')
158 app:exec()