question 1
the source code can be compiled and run, but you can find that, the GUI interface of the bottom application is shown on the listctrl? why and how to get rid of it?
question 2
another question, how to set listctrl to fit the width? In my above code, I mean the total 3 columns always take the horizontal space
sorry to ask here because there is no wxnim discussion and I hope it is because I don't know wxWidgets well, but not the bug in wxnim
Why not to use Cpp? No, I give up after studying several times
Why not to use wxPython? Yes, I use it but want to extend my language skill
Code: Select all
import "wx", "richtext", "stc"
{.experimental.}
{.emit: "#include <wx/spinctrl.h>" .}
{.emit: "#include <wx/listctrl.h>" .}
converter toClong(x: int): clong = x.clong
proc createFrame(): ptr WxFrame
let f = createFrame()
proc handleButtonClick(e: var WxCommandEvent) {.cdecl.} =
echo $WxCommandEvent
f.setStatusText("Quit called!")
proc createFrame(): ptr WxFrame =
result = cnew constructWxFrame(nil, wxID_ANY, "Hello World",
constructWxPoint(50, 50),
constructWxSize(450, 340))
result.createStatusBar()
result.setStatusText("Welcome to wxWidgets!")
let menuFile = cnew constructWxMenu()
let helloID = newControlId()
menuFile.append(helloID, "&Hello...\tCtrl-H",
"Help string shown in status bar for this menu item")
menuFile.appendSeparator()
menuFile.append(wxID_EXIT)
let menuHelp = cnew constructWxMenu()
menuHelp.append(wxID_ABOUT)
let menuBar = cnew constructWxMenuBar()
menuBar.append(menuFile, "&File")
menuBar.append(menuHelp, "&Help")
result.setMenuBar(menuBar)
menuBar.`bind`(wxEVT_MENU, handleButtonClick, wxID_EXIT)
let btn = cnew constructWxButton(result, wxID_ANY, "click")
let lstctl = cnew constructwxListCtrl(result, wxID_ANY, style=wxLC_REPORT)
# Add first column
var info = WxListItem()
info.mItemId = 0
info.mText = "A"
info.mWidth = 50
info.mMask = wxLIST_MASK_TEXT
discard insertColumn(lstctl, 0, info)
# Add second column
info = WxListItem(mText:"B", mItemId:1, mMask:wxLIST_MASK_TEXT)
discard insertColumn(lstctl, 1, info)
# Add third column
info = WxListItem(mText:"C", mItemId:2, mMask:wxLIST_MASK_TEXT)
discard insertColumn(lstctl, 2, info)
var item_amount = 3
for n in 0 ..< item_amount:
var item = WxListItem()
item.mItemId = n
discard insertItem(lstctl, item)
# set value in first column
setItem(lstctl, n, 0, $n & ":0")
# set value in second column
setItem(lstctl, n, 1, $n & ":1")
# set value in third column
setItem(lstctl, n, 2, $n & ":2")
if (getItemCount(lstctl) mod 2) == 1 :
setItemBackgroundColour(lstctl, n, constructWxColour( 255, 0, 0 ))
setItemTextColour(lstctl, n, constructWxColour( 255, 255, 255 ))
let text = cnew constructWxStyledTextCtrl(result, wxID_ANY)
text.styleClearAll()
text.setLexer(wxSTC_LEX_CPP)
text.setMarginWidth(0, 50)
text.styleSetForeground(wxSTC_STYLE_LINENUMBER, constructWxColour(75, 75, 75) )
text.styleSetBackground(wxSTC_STYLE_LINENUMBER, constructWxColour(220, 220, 220))
text.setMarginType(0, wxSTC_MARGIN_NUMBER)
text.setKeyWords(0, "return for while break continue")
text.setKeyWords(1, "const int float void char double")
let sizer = cnew constructWxBoxSizer(wxVERTICAL)
sizer.add(btn, 1, wxSTRETCH_NOT)
sizer.add(lstctl, 2, wxEXPAND)
sizer.add(text, 3, wxEXPAND)
result.setSizer(sizer)
f.show(true)
runMainLoop()