changed macros in lqt_common.hpp to reflect new header name
[lqt.git] / tutorial.lua
blobd050ff0f642a6edfc2cf88cc16bf1da22e80514d
1 #!/usr/bin/lua
3 while false do
4 local i = QLabel.__index
5 QLabel.__index = function (...) print('QLabel required', ...) return i(...) end
6 end
8 if false then
9 local i = QPushButton.__index
10 QPushButton.__index = function (...) print(...) local ret = { i(...) } print(unpack(ret)) return unpack(ret) end
11 end
13 qt = {
14 slot = function(s) return '1'..tostring(s) end,
15 signal = function(s) return '2'..tostring(s) end,
19 --app = QApplication.new()
21 --print'====='
22 --print(app, app())
24 --QApplication.new = app
27 --print( app )
28 --print( pcall( app ) )
30 --[[
31 QApplication.new = app
32 --]]
34 --print( QApplication.new )
35 --print( pcall( QApplication.new ) )
38 app = QApplication.new()
39 --print(app)
42 mainwin = QWidget.new()
43 --print(mainwin)
44 mainwin:show()
46 layout = QVBoxLayout.new()
48 mainwin:setLayout(layout)
49 mainwin:setWindowTitle'lqt test window'
51 te = QTextEdit.new()
52 layout:addWidget(te)
53 te:setToolTip'I\'m the Code Edit Box: I hold the code while you edit'
55 --[==[
56 te:setPlainText[[
57 but = QPushButton.new()
58 but:show()
59 but:connect(qt.signal'pressed()', but, qt.slot'close()')
60 but:setText'Close Me!'
61 but:resize(150, 50)
62 but:setFont(QFont.new('Times', 18, 75))
64 --]==]
66 te:setPlainText[[
67 buttons = buttons or {}
68 i = #buttons + 1
70 but = QPushButton.new()
72 but:show()
73 but:connect(qt.signal'pressed()', but, qt.slot'close()')
74 but:setText'Close Me!'
75 but:setWindowTitle('Button '..i)
76 but:resize(180, 50)
77 but:setFont(QFont.new('Times', 18, 75))
79 buttons[i] = but
81 return 'Created button '..i
84 --te:show()
86 --print'----'
88 print'-----'
89 pb = QPushButton.new()
90 print'-----'
91 layout:addWidget(pb)
92 print'-----'
93 pb:setText'Exec'
94 print'-----'
95 pb:setToolTip'I\'m the Exec button: push me to execute your code'
96 print'-----'
97 --pb:show()
99 quit = QPushButton.new()
100 layout:addWidget(quit)
101 quit:setText'Quit'
102 quit:setToolTip'I\'m the Quit button: push me to close all windows'
105 --pb:connect('2pressed()', SLOT(function() print 'lqt RULES!' end))
106 --pb:connect('2pressed()', SLOT(function() print 'lqt ROCKS!' end))
108 results = QLabel.new()
109 results:setToolTip'I\'m the result bar: I will show you your results and your errors'
110 layout:addWidget(results)
112 pb:connect('2pressed()', SLOT(function()
113 local f, err = loadstring(te:toPlainText())
114 if f==nil then
115 results:setText(err)
116 else
117 local res = { pcall( f ) }
118 if res[1] then
119 local string = ''
120 for i, r in ipairs(res) do
121 if i~=1 then string = string .. tostring(r) .. ', ' end
123 results:setText(string)
124 else
125 results:setText(res[2])
128 end))
129 quit:connect('2pressed()', app, '1closeAllWindows()')
131 app:exec()