Skip to content

Commit cea93ee

Browse files
committed
reordered input args; best practice README, @eval func defs, optional parent
1 parent 683c0c5 commit cea93ee

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ Gtk.jl also supports GtkMessageDialog and provides several convenience functions
475475

476476
```
477477
info_dialog("Julia rocks!")
478-
ask_dialog('Do you like chocolate ice cream?) && println("That's my favorite too.")
479-
warn_dialog("Oops!... I did it again", parent=win)
478+
ask_dialog('Do you like chocolate ice cream?, "I like it", "Not at all") && println("That's my favorite too.")
479+
warn_dialog("Oops!... I did it again", win)
480480
481481
```

src/Gtk.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ include("base.jl")
3737
include("gdk.jl")
3838
include("events.jl")
3939
include("container.jl")
40-
include("windows.jl")
4140
include("layout.jl")
4241
include("displays.jl")
4342
include("lists.jl")
@@ -73,6 +72,8 @@ end
7372
const _ = GAccessor
7473
using .GConstants
7574

75+
include("windows.jl")
76+
7677
# Alternative Interface (`using Gtk.ShortNames`)
7778
module ShortNames
7879
using ..Gtk

src/selectors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function makefilters(dlgp::GtkFileChooser, filters::Union(AbstractVector,Tuple))
6565
end
6666
end
6767

68-
function open_dialog(title::String; parent = GtkNullContainer(), filters::Union(AbstractVector,Tuple) = ASCIIString[], multiple::Bool = false)
68+
function open_dialog(title::String, parent = GtkNullContainer(); filters::Union(AbstractVector,Tuple) = ASCIIString[], multiple::Bool = false)
6969
dlg = @GtkFileChooserDialog(title, parent, GConstants.GtkFileChooserAction.OPEN,
7070
"_Cancel", GConstants.GtkResponseType.CANCEL,
7171
"_Open", GConstants.GtkResponseType.ACCEPT)
@@ -96,7 +96,7 @@ function open_dialog(title::String; parent = GtkNullContainer(), filters::Union(
9696
selection
9797
end
9898

99-
function save_dialog(title::String; parent = GtkNullContainer(), filters::Union(AbstractVector,Tuple) = ASCIIString[])
99+
function save_dialog(title::String, parent = GtkNullContainer(); filters::Union(AbstractVector,Tuple) = ASCIIString[])
100100
dlg = @GtkFileChooserDialog(title, parent, GConstants.GtkFileChooserAction.SAVE,
101101
"_Cancel", GConstants.GtkResponseType.CANCEL,
102102
"_Save", GConstants.GtkResponseType.ACCEPT)

src/windows.jl

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,44 +46,39 @@ end
4646
GtkAboutDialogLeaf() = GtkAboutDialogLeaf(
4747
ccall((:gtk_about_dialog_new,libgtk),Ptr{GObject},()))
4848

49-
function GtkMessageDialogLeaf(parent::GtkContainer, flags::Integer, typ::Integer,
50-
message::StringLike, buttons)
49+
function GtkMessageDialogLeaf(message::StringLike, buttons, flags::Integer, typ::Integer, parent = GtkNullContainer())
5150
w = GtkMessageDialogLeaf(ccall((:gtk_message_dialog_new,libgtk), Ptr{GObject},
5251
(Ptr{GObject},Cint,Cint,Cint,Ptr{Uint8}),
53-
parent, flags, typ, GtkButtonsType.NONE, bytestring(message) ))
52+
parent, flags, typ, GtkButtonsType.NONE, C_NULL))
53+
setproperty!(w, :text, bytestring(message))
5454
for (k,v) in buttons
5555
push!(w, k, v)
5656
end
5757
w
5858
end
5959

60-
function info_dialog(message::String; parent = GtkNullContainer())
61-
dlg = @GtkMessageDialog(parent, GtkDialogFlags.DESTROY_WITH_PARENT,
62-
GtkMessageType.INFO, GtkButtonsType.CLOSE, message)
63-
run(dlg)
64-
destroy(dlg)
65-
end
60+
ask_dialog(message::String, parent = GtkNullContainer()) =
61+
ask_dialog(message, "Yes", "No", parent)
6662

67-
function ask_dialog(message::String, yes_text="Yes", no_text="No"; parent = GtkNullContainer())
68-
dlg = @GtkMessageDialog(parent, GtkDialogFlags.DESTROY_WITH_PARENT,
69-
GtkMessageType.QUESTION, message, ((yes_text,1), (no_text,2)))
63+
function ask_dialog(message::String, yes_text, no_text, parent = GtkNullContainer())
64+
dlg = @GtkMessageDialog(message, ((yes_text,1), (no_text,2)),
65+
GtkDialogFlags.DESTROY_WITH_PARENT, GtkMessageType.QUESTION, parent)
7066
response = run(dlg)
7167
destroy(dlg)
7268
response == 1
7369
end
7470

75-
function warn_dialog(message::String; parent = GtkNullContainer())
76-
dlg = @GtkMessageDialog(parent, GtkDialogFlags.DESTROY_WITH_PARENT,
77-
GtkMessageType.WARNING, GtkButtonsType.CLOSE, message)
78-
run(dlg)
79-
destroy(dlg)
80-
end
81-
82-
function error_dialog(message::String; parent = GtkNullContainer())
83-
dlg = @GtkMessageDialog(parent, GtkDialogFlags.DESTROY_WITH_PARENT,
84-
GtkMessageType.ERROR, GtkButtonsType.CLOSE, message)
85-
run(dlg)
86-
destroy(dlg)
71+
for (func, flag) in (
72+
(:info_dialog, GtkMessageType.INFO),
73+
(:warn_dialog, GtkMessageType.WARNING),
74+
(:error_dialog, GtkMessageType.ERROR))
75+
@eval function $func(message::String, parent = GtkNullContainer())
76+
w = GtkMessageDialogLeaf(ccall((:gtk_message_dialog_new,libgtk), Ptr{GObject},
77+
(Ptr{GObject},Cint,Cint,Cint,Ptr{Uint8}),
78+
parent, GtkDialogFlags.DESTROY_WITH_PARENT,
79+
$flag, GtkButtonsType.CLOSE, C_NULL))
80+
setproperty!(w, :text, bytestring(message))
81+
run(w)
82+
destroy(w)
83+
end
8784
end
88-
89-
#GtkSeparator — A separator widget

0 commit comments

Comments
 (0)