mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 08:51:21 +00:00
examples/lib use the new wrappers
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import cairo
|
||||
|
||||
var surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 240, 80)
|
||||
var cr = cairo_create(surface)
|
||||
var surface = image_surface_create(FORMAT_ARGB32, 240, 80)
|
||||
var cr = create(surface)
|
||||
|
||||
select_font_face(cr, "serif", FONT_SLANT_NORMAL,
|
||||
FONT_WEIGHT_BOLD)
|
||||
set_font_size(cr, 32.0)
|
||||
set_source_rgb(cr, 0.0, 0.0, 1.0)
|
||||
move_to(cr, 10.0, 50.0)
|
||||
show_text(cr, "Hello, world")
|
||||
destroy(cr)
|
||||
discard write_to_png(surface, "hello.png")
|
||||
destroy(surface)
|
||||
|
||||
cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL,
|
||||
CAIRO_FONT_WEIGHT_BOLD)
|
||||
cairo_set_font_size(cr, 32.0)
|
||||
cairo_set_source_rgb(cr, 0.0, 0.0, 1.0)
|
||||
cairo_move_to(cr, 10.0, 50.0)
|
||||
cairo_show_text(cr, "Hello, world")
|
||||
cairo_destroy(cr)
|
||||
discard cairo_surface_write_to_png(surface, "hello.png")
|
||||
cairo_surface_destroy(surface)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import
|
||||
libcurl
|
||||
|
||||
var hCurl = curl_easy_init()
|
||||
var hCurl = easy_init()
|
||||
if hCurl != nil:
|
||||
discard curl_easy_setopt(hCurl, CURLOPT_VERBOSE, True)
|
||||
discard curl_easy_setopt(hCurl, CURLOPT_URL, "http://force7.de/nimrod")
|
||||
discard curl_easy_perform(hCurl)
|
||||
curl_easy_cleanup(hCurl)
|
||||
discard easy_setopt(hCurl, OPT_VERBOSE, True)
|
||||
discard easy_setopt(hCurl, OPT_URL, "http://force7.de/nimrod")
|
||||
discard easy_perform(hCurl)
|
||||
easy_cleanup(hCurl)
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import
|
||||
cairo, glib2, gtk2
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer) {.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer) {.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
var
|
||||
window: pGtkWidget
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
|
||||
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
gtk_widget_show(window)
|
||||
gtk_main()
|
||||
window: pWidget
|
||||
nimrod_init()
|
||||
window = window_new(WINDOW_TOPLEVEL)
|
||||
discard signal_connect(window, "destroy",
|
||||
SIGNAL_FUNC(ex1.destroy), nil)
|
||||
show(window)
|
||||
main()
|
||||
|
||||
@@ -2,20 +2,21 @@
|
||||
import
|
||||
glib2, gtk2
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
var
|
||||
window: PGtkWidget
|
||||
button: PGtkWidget
|
||||
window: PWidget
|
||||
button: PWidget
|
||||
|
||||
nimrod_init()
|
||||
window = window_new(WINDOW_TOPLEVEL)
|
||||
button = button_new_with_label("Click me")
|
||||
set_border_width(PContainer(Window), 5)
|
||||
add(PContainer(window), button)
|
||||
discard signal_connect(window, "destroy",
|
||||
SIGNAL_FUNC(ex2.destroy), nil)
|
||||
show(button)
|
||||
show(window)
|
||||
main()
|
||||
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
|
||||
button = gtk_button_new_with_label("Click me")
|
||||
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
|
||||
gtk_container_add(GTK_Container(window), button)
|
||||
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
gtk_widget_show(button)
|
||||
gtk_widget_show(window)
|
||||
gtk_main()
|
||||
|
||||
@@ -2,38 +2,33 @@
|
||||
import
|
||||
glib2, gtk2
|
||||
|
||||
proc newbutton(ALabel: cstring): PGtkWidget =
|
||||
Result = gtk_button_new_with_label(ALabel)
|
||||
gtk_widget_show(result)
|
||||
proc newbutton(ALabel: cstring): PWidget =
|
||||
Result = button_new_with_label(ALabel)
|
||||
show(result)
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
var
|
||||
window, totalbox, hbox, vbox: PgtkWidget
|
||||
nimrod_init()
|
||||
var window = window_new(WINDOW_TOPLEVEL) # Box to divide window in 2 halves:
|
||||
var totalbox = vbox_new(true, 10)
|
||||
show(totalbox) # A box for each half of the screen:
|
||||
var hbox = hbox_new(false, 5)
|
||||
show(hbox)
|
||||
var vbox = vbox_new(true, 5)
|
||||
show(vbox) # Put boxes in their halves
|
||||
pack_start(totalbox, hbox, true, true, 0)
|
||||
pack_start(totalbox, vbox, true, true, 0) # Now fill boxes with buttons.
|
||||
|
||||
pack_start(hbox, newbutton("Button 1"), false, false, 0)
|
||||
pack_start(hbox, newbutton("Button 2"), false, false, 0)
|
||||
pack_start(hbox, newbutton("Button 3"), false, false, 0) # Vertical box
|
||||
pack_start(vbox, newbutton("Button A"), true, true, 0)
|
||||
pack_start(vbox, newbutton("Button B"), true, true, 0)
|
||||
pack_start(vbox, newbutton("Button C"), true, true, 0) # Put totalbox in window
|
||||
set_border_width(PCONTAINER(Window), 5)
|
||||
add(PContainer(window), totalbox)
|
||||
discard signal_connect(window, "destroy", SIGNAL_FUNC(ex3.destroy), nil)
|
||||
show(window)
|
||||
main()
|
||||
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL) # Box to divide window in 2 halves:
|
||||
totalbox = gtk_vbox_new(true, 10)
|
||||
gtk_widget_show(totalbox) # A box for each half of the screen:
|
||||
hbox = gtk_hbox_new(false, 5)
|
||||
gtk_widget_show(hbox)
|
||||
vbox = gtk_vbox_new(true, 5)
|
||||
gtk_widget_show(vbox) # Put boxes in their halves
|
||||
gtk_box_pack_start(GTK_BOX(totalbox), hbox, true, true, 0)
|
||||
gtk_box_pack_start(GTK_BOX(totalbox), vbox, true, true, 0) # Now fill boxes with buttons.
|
||||
# Horizontal box
|
||||
gtk_box_pack_start(GTK_BOX(hbox), newbutton("Button 1"), false, false, 0)
|
||||
gtk_box_pack_start(GTK_BOX(hbox), newbutton("Button 2"), false, false, 0)
|
||||
gtk_box_pack_start(GTK_BOX(hbox), newbutton("Button 3"), false, false, 0) #
|
||||
# Vertical box
|
||||
gtk_box_pack_start(GTK_BOX(vbox), newbutton("Button A"), true, true, 0)
|
||||
gtk_box_pack_start(GTK_BOX(vbox), newbutton("Button B"), true, true, 0)
|
||||
gtk_box_pack_start(GTK_BOX(vbox), newbutton("Button C"), true, true, 0) # Put
|
||||
# totalbox in window
|
||||
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
|
||||
gtk_container_add(GTK_Container(window), totalbox)
|
||||
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
gtk_widget_show(window)
|
||||
gtk_main()
|
||||
|
||||
@@ -2,30 +2,28 @@
|
||||
import
|
||||
glib2, gtk2
|
||||
|
||||
proc newbutton(ALabel: cstring): PGtkWidget =
|
||||
Result = gtk_button_new_with_label(ALabel)
|
||||
gtk_widget_show(result)
|
||||
proc newbutton(ALabel: cstring): PWidget =
|
||||
Result = button_new_with_label(ALabel)
|
||||
show(result)
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
var
|
||||
window, maintable: PgtkWidget
|
||||
nimrod_init()
|
||||
var window = window_new(WINDOW_TOPLEVEL)
|
||||
var Maintable = table_new(6, 6, True)
|
||||
|
||||
proc AddToTable(Widget: PGtkWidget, Left, Right, Top, Bottom: guint) =
|
||||
gtk_table_attach_defaults(GTK_TABLE(MainTable), Widget, Left, right, top,
|
||||
bottom)
|
||||
proc AddToTable(Widget: PWidget, Left, Right, Top, Bottom: guint) =
|
||||
attach_defaults(MainTable, Widget, Left, right, top, bottom)
|
||||
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
|
||||
Maintable = gtk_table_new(6, 6, True)
|
||||
gtk_widget_show(MainTable)
|
||||
show(MainTable)
|
||||
AddToTable(newbutton("1,1 At 1,1"), 1, 2, 1, 2)
|
||||
AddToTable(newbutton("2,2 At 3,1"), 3, 5, 1, 3)
|
||||
AddToTable(newbutton("4,1 At 4,1"), 1, 5, 4, 5) # Put all in window
|
||||
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
|
||||
gtk_container_add(GTK_Container(window), maintable)
|
||||
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
gtk_widget_show(window)
|
||||
gtk_main()
|
||||
set_border_width(Window, 5)
|
||||
add(window, maintable)
|
||||
discard signal_connect(window, "destroy",
|
||||
SignalFunc(ex4.destroy), nil)
|
||||
show(window)
|
||||
main()
|
||||
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
import
|
||||
glib2, gtk2
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
var
|
||||
window: PGtkWidget
|
||||
button: PGtkWidget
|
||||
proc widgetDestroy(w: PWidget) {.cdecl.} =
|
||||
destroy(w)
|
||||
|
||||
nimrod_init()
|
||||
var window = window_new(WINDOW_TOPLEVEL)
|
||||
var button = button_new_with_label("Click me")
|
||||
set_border_width(Window, 5)
|
||||
add(window, button)
|
||||
discard signal_connect(window, "destroy",
|
||||
SIGNAL_FUNC(ex5.destroy), nil)
|
||||
discard signal_connect_object(button, "clicked",
|
||||
SIGNAL_FUNC(widgetDestroy),
|
||||
window)
|
||||
show(button)
|
||||
show(window)
|
||||
main()
|
||||
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
|
||||
button = gtk_button_new_with_label("Click me")
|
||||
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
|
||||
gtk_container_add(GTK_Container(window), button)
|
||||
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
discard gtk_signal_connect_object(GTKOBJECT(button), "clicked",
|
||||
GTK_SIGNAL_FUNC(gtk_widget_destroy),
|
||||
GTKOBJECT(window))
|
||||
gtk_widget_show(button)
|
||||
gtk_widget_show(window)
|
||||
gtk_main()
|
||||
|
||||
@@ -3,50 +3,49 @@ import
|
||||
glib2, gtk2
|
||||
|
||||
type
|
||||
TButtonSignalState = record
|
||||
Obj: PgtkObject
|
||||
TButtonSignalState = object
|
||||
Obj: gtk2.PObject
|
||||
SignalID: int32
|
||||
Disable: bool
|
||||
|
||||
PButtonSignalState = ptr TButtonSignalState
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
proc disablesignal(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
if PButtonSignalState(Data).Disable:
|
||||
gtk_signal_handler_block(PButtonSignalState(Data).Obj, SignalID)
|
||||
proc widgetDestroy(w: PWidget) {.cdecl.} = destroy(w)
|
||||
|
||||
proc disablesignal(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
var s = cast[PButtonSignalState](Data)
|
||||
if s.Disable:
|
||||
signal_handler_block(s.Obj, s.SignalID)
|
||||
else:
|
||||
gtk_signal_handler_unblock(PButtonSignalState(Data).Obj, SignalID)
|
||||
PButtonSignalState(Data).disable = not PButtonSignalState(Data).disable
|
||||
signal_handler_unblock(s.Obj, s.SignalID)
|
||||
s.disable = not s.disable
|
||||
|
||||
var
|
||||
window: PGtkWidget
|
||||
quitbutton: PGtkWidget
|
||||
disablebutton: PGTKWidget
|
||||
windowbox: PGTKWidget
|
||||
quitsignal: guint
|
||||
QuitState: TButtonSignalState
|
||||
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
|
||||
quitbutton = gtk_button_new_with_label("Quit program")
|
||||
disablebutton = gtk_button_new_with_label("Disable button")
|
||||
windowbox = gtk_vbox_new(TRUE, 10)
|
||||
gtk_box_pack_start(GTK_BOX(windowbox), disablebutton, True, false, 0)
|
||||
gtk_box_pack_start(GTK_BOX(windowbox), quitbutton, True, false, 0)
|
||||
gtk_container_set_border_width(GTK_CONTAINER(Window), 10)
|
||||
gtk_container_add(GTK_Container(window), windowbox)
|
||||
gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
QuitState.Obj = GTKObject(QuitButton)
|
||||
SignalID = gtk_signal_connect_object(QuitState.Obj, "clicked", GTK_SIGNAL_FUNC(
|
||||
gtk_widget_destroy), GTKOBJECT(window))
|
||||
nimrod_init()
|
||||
var window = window_new(WINDOW_TOPLEVEL)
|
||||
var quitbutton = button_new_with_label("Quit program")
|
||||
var disablebutton = button_new_with_label("Disable button")
|
||||
var windowbox = vbox_new(TRUE, 10)
|
||||
pack_start(windowbox, disablebutton, True, false, 0)
|
||||
pack_start(windowbox, quitbutton, True, false, 0)
|
||||
set_border_width(Window, 10)
|
||||
add(window, windowbox)
|
||||
discard signal_connect(window, "destroy", SIGNAL_FUNC(ex6.destroy), nil)
|
||||
QuitState.Obj = QuitButton
|
||||
quitState.SignalID = signal_connect_object(QuitState.Obj, "clicked",
|
||||
SIGNAL_FUNC(widgetDestroy), window)
|
||||
QuitState.Disable = True
|
||||
discard gtk_signal_connect(GTKOBJECT(disablebutton), "clicked",
|
||||
GTK_SIGNAL_FUNC(disablesignal), addr(QuitState))
|
||||
gtk_widget_show(quitbutton)
|
||||
gtk_widget_show(disablebutton)
|
||||
gtk_widget_show(windowbox)
|
||||
gtk_widget_show(window)
|
||||
gtk_main()
|
||||
discard signal_connect(disablebutton, "clicked",
|
||||
SIGNAL_FUNC(disablesignal), addr(QuitState))
|
||||
show(quitbutton)
|
||||
show(disablebutton)
|
||||
show(windowbox)
|
||||
show(window)
|
||||
main()
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
import
|
||||
gdk2, glib2, gtk2
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
const
|
||||
Inside: cstring = "Mouse is over label"
|
||||
@@ -11,33 +11,36 @@ const
|
||||
|
||||
var
|
||||
OverLabel: bool
|
||||
window, box1, box2, stackbox, label1, Label2: PGtkWidget
|
||||
|
||||
proc ChangeLabel(P: PGtkWidget, Event: PGdkEventCrossing,
|
||||
nimrod_init()
|
||||
var window = window_new(gtk2.WINDOW_TOPLEVEL)
|
||||
var stackbox = vbox_new(TRUE, 10)
|
||||
var box1 = event_box_new()
|
||||
var label1 = label_new("Move mouse over label")
|
||||
add(box1, label1)
|
||||
var box2 = event_box_new()
|
||||
var label2 = label_new(OutSide)
|
||||
add(box2, label2)
|
||||
pack_start(stackbox, box1, TRUE, TRUE, 0)
|
||||
pack_start(stackbox, box2, TRUE, TRUE, 0)
|
||||
set_border_width(Window, 5)
|
||||
add(window, stackbox)
|
||||
discard signal_connect(window, "destroy",
|
||||
SIGNAL_FUNC(ex7.destroy), nil)
|
||||
overlabel = False
|
||||
|
||||
|
||||
proc ChangeLabel(P: PWidget, Event: gdk2.PEventCrossing,
|
||||
Data: var bool){.cdecl.} =
|
||||
if not Data: gtk_label_set_text(GTKLABEL(Label2), Inside)
|
||||
else: gtk_label_set_text(GTKLABEL(Label2), Outside)
|
||||
if not Data: set_text(Label1, Inside)
|
||||
else: set_text(Label2, Outside)
|
||||
Data = not Data
|
||||
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
|
||||
stackbox = gtk_vbox_new(TRUE, 10)
|
||||
box1 = gtk_event_box_new()
|
||||
label1 = gtk_label_new("Move mouse over label")
|
||||
gtk_container_add(GTK_CONTAINER(box1), label1)
|
||||
box2 = gtk_event_box_new()
|
||||
label2 = gtk_label_new(OutSide)
|
||||
gtk_container_add(GTK_CONTAINER(box2), label2)
|
||||
gtk_box_pack_start(GTK_BOX(stackbox), box1, TRUE, TRUE, 0)
|
||||
gtk_box_pack_start(GTK_BOX(stackbox), box2, TRUE, TRUE, 0)
|
||||
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
|
||||
gtk_container_add(GTK_Container(window), stackbox)
|
||||
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
overlabel = False
|
||||
discard gtk_signal_connect(GTKOBJECT(box1), "enter_notify_event",
|
||||
GTK_SIGNAL_FUNC(ChangeLabel), addr(Overlabel))
|
||||
discard gtk_signal_connect(GTKOBJECT(box1), "leave_notify_event",
|
||||
GTK_SIGNAL_FUNC(ChangeLabel), addr(Overlabel))
|
||||
gtk_widget_show_all(window)
|
||||
gtk_main()
|
||||
|
||||
discard signal_connect(box1, "enter_notify_event",
|
||||
SIGNAL_FUNC(ChangeLabel), addr(Overlabel))
|
||||
discard signal_connect(box1, "leave_notify_event",
|
||||
SIGNAL_FUNC(ChangeLabel), addr(Overlabel))
|
||||
show_all(window)
|
||||
main()
|
||||
|
||||
|
||||
@@ -2,31 +2,28 @@
|
||||
import
|
||||
glib2, gtk2
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
var
|
||||
window, stackbox, label1, Label2: PGtkWidget
|
||||
labelstyle: pgtkstyle
|
||||
nimrod_init()
|
||||
var window = window_new(WINDOW_TOPLEVEL)
|
||||
var stackbox = vbox_new(TRUE, 10)
|
||||
var label1 = label_new("Red label text")
|
||||
var labelstyle = copy(get_style(label1))
|
||||
LabelStyle.fg[STATE_NORMAL].pixel = 0
|
||||
LabelStyle.fg[STATE_NORMAL].red = -1'i16
|
||||
LabelStyle.fg[STATE_NORMAL].blue = 0'i16
|
||||
LabelStyle.fg[STATE_NORMAL].green = 0'i16
|
||||
set_style(label1, labelstyle)
|
||||
# Uncomment this to see the effect of setting the default style.
|
||||
# set_default_style(labelstyle)
|
||||
var label2 = label_new("Black label text")
|
||||
pack_start(stackbox, label1, TRUE, TRUE, 0)
|
||||
pack_start(stackbox, label2, TRUE, TRUE, 0)
|
||||
set_border_width(Window, 5)
|
||||
add(window, stackbox)
|
||||
discard signal_connect(window, "destroy",
|
||||
SIGNAL_FUNC(ex8.destroy), nil)
|
||||
show_all(window)
|
||||
main()
|
||||
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
|
||||
stackbox = gtk_vbox_new(TRUE, 10)
|
||||
label1 = gtk_label_new("Red label text")
|
||||
labelstyle = gtk_style_copy(gtk_widget_get_style(label1))
|
||||
LabelStyle.fg[GTK_STATE_NORMAL].pixel = 0
|
||||
LabelStyle.fg[GTK_STATE_NORMAL].red = 0x0000FFFF
|
||||
LabelStyle.fg[GTK_STATE_NORMAL].blue = 0
|
||||
LabelStyle.fg[GTK_STATE_NORMAL].green = 0
|
||||
gtk_widget_set_style(label1, labelstyle) # Uncomment this to see the effect of setting the default style.
|
||||
#
|
||||
# gtk_widget_set_default_style(labelstyle)
|
||||
label2 = gtk_label_new("Black label text")
|
||||
gtk_box_pack_start(GTK_BOX(stackbox), label1, TRUE, TRUE, 0)
|
||||
gtk_box_pack_start(GTK_BOX(stackbox), label2, TRUE, TRUE, 0)
|
||||
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
|
||||
gtk_container_add(GTK_Container(window), stackbox)
|
||||
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
gtk_widget_show_all(window)
|
||||
gtk_main()
|
||||
|
||||
@@ -2,46 +2,48 @@
|
||||
import
|
||||
gdk2, glib2, gtk2
|
||||
|
||||
proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} =
|
||||
gtk_main_quit()
|
||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
||||
main_quit()
|
||||
|
||||
const
|
||||
Inside: cstring = "Mouse is over label"
|
||||
OutSide: cstring = "Mouse is not over label"
|
||||
|
||||
var
|
||||
window, button1, Button2, Alabel, stackbox: PGtkWidget
|
||||
buttonstyle: pgtkstyle
|
||||
OverButton: bool
|
||||
|
||||
proc ChangeLabel(P: PGtkWidget, Event: PGdkEventCrossing, Data: var bool){.cdecl.} =
|
||||
if Not Data: gtk_label_set_text(GTKLABEL(ALabel), Inside)
|
||||
else: gtk_label_set_text(GTKLABEL(ALabel), Outside)
|
||||
nimrod_init()
|
||||
var window = window_new(gtk2.WINDOW_TOPLEVEL)
|
||||
var stackbox = vbox_new(TRUE, 10)
|
||||
var button1 = button_new_with_label("Move mouse over button")
|
||||
var buttonstyle = copy(get_style(Button1))
|
||||
ButtonStyle.bg[STATE_PRELIGHT].pixel = 0
|
||||
ButtonStyle.bg[STATE_PRELIGHT].red = -1'i16
|
||||
ButtonStyle.bg[STATE_PRELIGHT].blue = 0'i16
|
||||
ButtonStyle.bg[STATE_PRELIGHT].green = 0'i16
|
||||
set_style(button1, buttonstyle)
|
||||
var button2 = button_new()
|
||||
var ALabel = label_new(Outside)
|
||||
|
||||
|
||||
proc ChangeLabel(P: PWidget, Event: gdk2.PEventCrossing,
|
||||
Data: var bool){.cdecl.} =
|
||||
if Not Data: set_text(ALabel, Inside)
|
||||
else: set_text(ALabel, Outside)
|
||||
Data = Not Data
|
||||
|
||||
gtk_nimrod_init()
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
|
||||
stackbox = gtk_vbox_new(TRUE, 10)
|
||||
button1 = gtk_button_new_with_label("Move mouse over button")
|
||||
buttonstyle = gtk_style_copy(gtk_widget_get_style(Button1))
|
||||
ButtonStyle.bg[GTK_STATE_PRELIGHT].pixel = 0
|
||||
ButtonStyle.bg[GTK_STATE_PRELIGHT].red = 0x0000FFFF'i16
|
||||
ButtonStyle.bg[GTK_STATE_PRELIGHT].blue = 0'i16
|
||||
ButtonStyle.bg[GTK_STATE_PRELIGHT].green = 0'i16
|
||||
gtk_widget_set_style(button1, buttonstyle)
|
||||
button2 = gtk_button_new()
|
||||
ALabel = gtk_label_new(Outside)
|
||||
gtk_container_add(GTK_CONTAINER(button2), ALAbel)
|
||||
gtk_box_pack_start(GTK_BOX(stackbox), button1, TRUE, TRUE, 0)
|
||||
gtk_box_pack_start(GTK_BOX(stackbox), button2, TRUE, TRUE, 0)
|
||||
gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
|
||||
gtk_container_add(GTK_Container(window), stackbox)
|
||||
discard gtk_signal_connect(GTKOBJECT(window), "destroy",
|
||||
GTK_SIGNAL_FUNC(destroy), nil)
|
||||
|
||||
add(button2, ALAbel)
|
||||
pack_start(stackbox, button1, TRUE, TRUE, 0)
|
||||
pack_start(stackbox, button2, TRUE, TRUE, 0)
|
||||
set_border_width(Window, 5)
|
||||
add(window, stackbox)
|
||||
discard signal_connect(window, "destroy",
|
||||
SIGNAL_FUNC(ex9.destroy), nil)
|
||||
overbutton = False
|
||||
discard gtk_signal_connect(GTKOBJECT(button1), "enter_notify_event",
|
||||
GTK_SIGNAL_FUNC(ChangeLabel), addr(OverButton))
|
||||
discard gtk_signal_connect(GTKOBJECT(button1), "leave_notify_event",
|
||||
GTK_SIGNAL_FUNC(ChangeLabel), addr(OverButton))
|
||||
gtk_widget_show_all(window)
|
||||
gtk_main()
|
||||
discard signal_connect(button1, "enter_notify_event",
|
||||
SIGNAL_FUNC(ChangeLabel), addr(OverButton))
|
||||
discard signal_connect(button1, "leave_notify_event",
|
||||
SIGNAL_FUNC(ChangeLabel), addr(OverButton))
|
||||
show_all(window)
|
||||
main()
|
||||
|
||||
@@ -12,7 +12,7 @@ if paramCount() < 1:
|
||||
quit("Usage: htmlrefs filename[.html]")
|
||||
|
||||
var links = 0 # count the number of links
|
||||
var filename = appendFileExt(ParamStr(1), "html")
|
||||
var filename = addFileExt(ParamStr(1), "html")
|
||||
var s = newFileStream(filename, fmRead)
|
||||
if s == nil: quit("cannot open the file " & filename)
|
||||
var x: TXmlParser
|
||||
|
||||
@@ -7,7 +7,7 @@ import os, streams, parsexml, strutils
|
||||
if paramCount() < 1:
|
||||
quit("Usage: htmltitle filename[.html]")
|
||||
|
||||
var filename = appendFileExt(ParamStr(1), "html")
|
||||
var filename = addFileExt(ParamStr(1), "html")
|
||||
var s = newFileStream(filename, fmRead)
|
||||
if s == nil: quit("cannot open the file " & filename)
|
||||
var x: TXmlParser
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Filter key=value pairs from "myfile.txt"
|
||||
import regexprs
|
||||
import re
|
||||
|
||||
for x in lines("myfile.txt"):
|
||||
if x =~ r"(\w+)=(.*)":
|
||||
if x =~ re"(\w+)=(.*)":
|
||||
echo "Key: ", matches[1],
|
||||
" Value: ", matches[2]
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ const
|
||||
print 'hi'
|
||||
"""
|
||||
|
||||
var L = luaL_newstate()
|
||||
luaL_openlibs(L)
|
||||
discard luaL_loadbuffer(L, code, code.len, "line")
|
||||
discard lua_pcall(L, 0, 0, 0)
|
||||
var L = newstate()
|
||||
openlibs(L)
|
||||
discard loadbuffer(L, code, code.len, "line")
|
||||
discard pcall(L, 0, 0, 0)
|
||||
|
||||
|
||||
@@ -4,23 +4,23 @@ import
|
||||
SDL
|
||||
|
||||
var
|
||||
screen, greeting: PSDL_Surface
|
||||
r: TSDL_Rect
|
||||
screen, greeting: PSurface
|
||||
r: TRect
|
||||
|
||||
if SDL_Init(SDL_INIT_VIDEO) == 0:
|
||||
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE or SDL_ANYFORMAT)
|
||||
if Init(INIT_VIDEO) == 0:
|
||||
screen = SetVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT)
|
||||
if screen == nil:
|
||||
write(stdout, "screen is nil!\n")
|
||||
else:
|
||||
greeting = SDL_LoadBmp("backgrnd.bmp")
|
||||
greeting = LoadBmp("backgrnd.bmp")
|
||||
if greeting == nil:
|
||||
write(stdout, "greeting is nil!")
|
||||
r.x = 0'i16
|
||||
r.y = 0'i16
|
||||
discard SDL_blitSurface(greeting, nil, screen, addr(r))
|
||||
discard SDL_flip(screen)
|
||||
SDL_Delay(3000)
|
||||
discard blitSurface(greeting, nil, screen, addr(r))
|
||||
discard flip(screen)
|
||||
Delay(3000)
|
||||
else:
|
||||
write(stdout, "SDL_Init failed!\n")
|
||||
|
||||
SDL_Quit()
|
||||
sdl.Quit()
|
||||
|
||||
@@ -8,7 +8,7 @@ import os, streams, parsecsv, strutils, math
|
||||
if paramCount() < 1:
|
||||
quit("Usage: statcsv filename[.csv]")
|
||||
|
||||
var filename = appendFileExt(ParamStr(1), "csv")
|
||||
var filename = addFileExt(ParamStr(1), "csv")
|
||||
var s = newFileStream(filename, fmRead)
|
||||
if s == nil: quit("cannot open the file " & filename)
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ bind .e <Return> {
|
||||
}
|
||||
"""
|
||||
|
||||
Tcl_FindExecutable(getApplicationFilename())
|
||||
var interp = Tcl_CreateInterp()
|
||||
FindExecutable(getApplicationFilename())
|
||||
var interp = CreateInterp()
|
||||
if interp == nil: quit("cannot create TCL interpreter")
|
||||
if Tcl_Init(interp) != TCL_OK:
|
||||
if Init(interp) != TCL_OK:
|
||||
quit("cannot init interpreter")
|
||||
if Tcl_Eval(interp, myScript) != TCL_OK:
|
||||
if Eval(interp, myScript) != TCL_OK:
|
||||
quit("cannot execute script.tcl")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user