- Offizieller Beitrag
Ich habe mir mal aus mehreren Beispielcodes ein Programm erstellt. Nichts nützliches, nur etwas zu experimentieren.
Hier erstmal der Code:
Code
import wNim
const sTitle = "My Gui-Window"
let app = App()
let frame = Frame(title=sTitle, size=(600, 480))
frame.icon = Icon(r".\prog.ico")
frame.dpiAutoScale:
frame.minSize = (480, 200)
frame.maxSize = (800, 600)
let menuBar = MenuBar(frame)
let statusBar = StatusBar(frame)
let menu = Menu(menuBar, "&File")
menu.append(wIdExit, "E&xit\tAlt-F4", "Close window and exit program.")
let accel = AcceleratorTable(frame)
accel.add(wAccelAlt, wKey_F4, wIdExit)
let panel = Panel(frame)
let staticText = StaticText(panel, label="Hello, World!")
staticText.font = Font(14, family=wFontFamilySwiss, weight=wFontWeightBold)
staticText.cursor = wHandCursor
staticText.fit()
let button = Button(panel, label="Font")
proc layout() =
panel.autolayout """
HV:|-[staticText]->[button]-|
"""
staticText.wEvent_CommandLeftClick do ():
let textEntryDialog = TextEntryDialog(frame, value=staticText.label,
caption="Change The Text")
if textEntryDialog.showModal() == wIdOk:
staticText.label = textEntryDialog.value
staticText.fit()
staticText.refresh()
button.wEvent_Button do ():
let fontDialog = FontDialog(frame, staticText.font)
fontDialog.color = staticText.foregroundColor
fontDialog.enableSymbols(false)
fontDialog.range = 0..72
if fontDialog.showModal() == wIdOk:
staticText.font = fontDialog.chosenFont
staticText.foregroundColor = fontDialog.color
staticText.fit()
staticText.refresh()
frame.wIdExit do ():
frame.close()
frame.wEvent_Close do (event: wEvent):
let dlg = MessageDialog(frame, "Das Programm wirklich beenden?",
sTitle, wYesNo or wIconQuestion)
if dlg.showModal() != wIdYes:
event.veto()
panel.wEvent_Size do ():
layout()
layout()
frame.center()
frame.show()
app.mainLoop()
Alles anzeigen
Und hier die Fragen:- Was macht "app.mainloop()"? Ist das nur eine Endlosschleife, weil das Programm ja auf die Events reagiert? Also wie in AutoIt mit dem OnEventMode?
- Wenn ich das richtig verstanden habe, dann muss man sich bei Nim nicht um die Freigabe der Ressourcen kümmern?
- Ich erstelle einen Frame (Window). Wozu dann noch ein Panel?
- Gibt es irgendwo eine Erklärung, wie das mit dem (Auto-)Layout funktioniert?