Google

main
dspblog
cyclic_signals
FFT_interpolation
FFT_interpolation_how_does_it_work
FFT_smoothness_cyclic
discrete_time_reconstruction
discrete_time_reconstruction2
Nyquist_on_the_edge
FFT_delay_special_case
Fourier_reconstruction
pulse_and_Nyquist
FFT_complexError
matlabOctave
matlab_upsampling
matlab_downsampling
FFT_delay
FFT_filter_example
FFT_interpolation_example
FFT_bin_frequencies
fit_signal
FFT_peaksearch_audio_example
matlab_binary_readwrite
Octavesvg
C
FFTW_example
looprecord
SNR
SNR3
SNR_example_96kAudio
SNR_FFT_correlation_example
lua
luagpib
luasplit
luadump
mnoofltk
wxLuaDll
wxLua_loadAsDll
wxLua_HelloWorld
wxLua_simpleButton
wxLua_resourceManagement
wxLua_XMLparser
DSP
IQ_LO
IQ_LO_2
optimum_receiver
DSP_basics
sampleRateChange_terms
dirac_pulse
freqresp_s
zfilter_example
freqresp_z
freqresp_z_sign
misc
zero_forcing_equalizer_example
nonminphase_inverse
periodic_spectrum
lagrange_multipliers
Entropy
RC_chopper
TRex450_setup
EP100
EP100SE
EP100Gremlins
essential_spares
tail_rotor
motoradjustment
blade_balancing
blade_repair
GAUI_SAE12A
Walkera43


valid html (click to verify)



prevupnextdisable ads

wxLua Hello World

Summary

"Hello World" example in wxLua
Application skeleton and some drawing functions

Output

Code

Download
if not wx then require("wx") end -- (optional) explicitly load wxLua libraries

-- The "frame" is the main window
local my_frame = wx.wxFrame(wx.NULL,
			 wx.wxID_ANY,
			 "this is the title of the HelloWorld (tm) application",
			 wx.wxDefaultPosition,
			 wx.wxSize(640, 200), -- initial size of the window
			 wx.wxDEFAULT_FRAME_STYLE 
		      )
-- note, the frame is invisible unless shown.

-- The "panel" is a region inside the frame. By itself it is invisible.
local my_panel = wx.wxPanel(my_frame, wx.wxID_ANY)

-- The callback function will be called from wxLua
function my_redraw_callback(event)

   -- "my_dc" is a so-called "drawing context".
   -- This one is obtained from the panel.
   -- If we'd get one for a bitmap instead, we could save the window contents as image.
   -- Or similar for a printer dc to get the contents on paper.
   local my_dc = wx.wxPaintDC(my_panel)

   -- the "pen" draws the border of the rectangle
   local my_pen=wx.wxPen("black", 13, wx.wxLONG_DASH)
   -- the "brush" fills the area of the rectangle
   local my_brush=wx.wxBrush("yellow", wx.wxSOLID)

   -- set pen / brush on the device context
   my_dc:SetPen(my_pen)
   my_dc:SetBrush(my_brush, wx.wxSOLID)

   -- request the size of the panel, because we don't know the menu bar, window borders etc.
   local my_size=my_panel:GetSize()
   my_dc:DrawRectangle(10, 10, my_size:GetWidth()-20, my_size:GetHeight()-20) -- x, y, width, height

   my_dc:DrawText("Hello World", 200, 100);

   -- need to explicitly delete a dc when it is not needed anymore.
   my_dc:delete()
end

-- Tell wxlua to call "my_redraw_callback", whenever "my_panel" requires a redraw
my_panel:Connect(wx.wxEVT_PAINT, my_redraw_callback)

-- Show the window
my_frame:Show(true)

wx.wxGetApp():MainLoop() -- (optional) explicitly hand over control to wxLua

Discussion

First, a “frame” is created. The top-level frame is the window.
Inside the frame, a “panel” is added. The panel is an area within its parent.

A callback function is created, and bound to the “paint” event on the panel:
Every time the window needs a redraw, the callback function is called by wxLua from the main loop.

The window is shown, and control is handed over to wxLua's main loop.
Control returns, when the last window disappears from the screen.


prevupnextdisable ads

© Markus Nentwig 2007-2008
The content of this page is provided without any warranty and may not be reproduced without permission.

Comments? Questions?

Please send me a mail! mnentwig@elisanet.fi