GTK DIALOGS

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

GTK DIALOGS

Postby vladimir777 » Sep 19, 2011 3:42

This is good example for using GTK3 dialogs,
I mean it will be good when TJF fix it :)

I dont have book for GTK 3 and all samples on The Net are old

Code: Select all

#LIBPATH "C:\opt\GTK-3.0.9\lib"

#include once "TJF/gtk.bi"

#define NULL 0

SUB show_info CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  Dim dialog As GtkWidget Ptr = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Download Completed", "title")
  gtk_window_set_title(GTK_WINDOW(dialog), "Information")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
End SUB
SUB show_error CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  Dim dialog As GtkWidget Ptr = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error loading file")
  gtk_window_set_title(GTK_WINDOW(dialog), "Error")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
end sub
SUB show_question CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
print "how do i read answer"
  Dim dialog As GtkWidget Ptr = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are you sure to quit?")
  gtk_window_set_title(GTK_WINDOW(dialog), "Question")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
End Sub
SUB show_warning CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  Dim dialog As GtkWidget Ptr = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Unallowed operation")
  gtk_window_set_title(GTK_WINDOW(dialog), "Warning")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
End sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog1 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
print "ok "
dim s as string
Dim dialog As GtkWidget Ptr = gtk_message_dialog_new( GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, StrPtr( s ))
gtk_dialog_run( GTK_DIALOG( dialog ) )
gtk_widget_destroy( dialog )
end sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog2 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
print "This is OK"
Dim s as String
dim filename as string
filename="FN"
dim errno as integer
errno = 1167
Dim dialog As GtkWidget Ptr = gtk_message_dialog_new (GTK_WINDOW(www),  GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error loading file '%s': %s", filename, g_strerror (errno))
gtk_dialog_run( GTK_DIALOG( dialog ) )
gtk_widget_destroy( dialog )
end sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog3 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
print "problem 111"
'dim as GdkPixbuf ptr pixbuf = gdk_pixbuf_new_from_file("mypic.png", NULL)
'dim as GtkWidget ptr dialog = gtk_about_dialog_new(GTK_WINDOW(www))
'gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(dialog), "yyyyyyyyyyy")
'gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), "0.9")
'gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), "OOOOOOOOOOOOOOO");
'gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), "dddddddddddddddddddddddddddddddddddddddd")
'gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), "http://www.ssss.net")
'gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pixbuf)
'g_object_unref(pixbuf), pixbuf = NULL
'gtk_dialog_run(GTK_DIALOG (dialog))
'gtk_widget_destroy(dialog)
end sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_ColorDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
Dim as GtkResponseType result
dim as GtkColorSelection ptr colorsel

dim as GtkWidget ptr dialog = gtk_color_selection_dialog_new("Color")
result = gtk_dialog_run(GTK_DIALOG(dialog))
print "problem 100"

' RESPONSE_HELP    Returned by Help buttons in GTK+ dialogs.
' -10   Gtk::RESPONSE_APPLY    Returned by Apply buttons in GTK+ dialogs.
' -9   Gtk::RESPONSE_NO    Returned by No buttons in GTK+ dialogs.
' -8   Gtk::RESPONSE_YES    Returned by Yes buttons in GTK+ dialogs.
' -7   Gtk::RESPONSE_CLOSE    Returned by Close buttons in GTK+ dialogs.
' -6   Gtk::RESPONSE_CANCEL    Returned by Cancel buttons in GTK+ dialogs.
' -5   Gtk::RESPONSE_OK    Returned by OK buttons in GTK+ dialogs.
' -4   Gtk::RESPONSE_DELETE_EVENT    Returned if the dialog is deleted.
' -3   Gtk::RESPONSE_ACCEPT    Generic response id, not used by GTK+ dialogs.
' -2   Gtk::RESPONSE_REJECT    Generic response id, not used by GTK+ dialogs.
' -1   Gtk::RESPONSE_NONE


if (result = GTK_RESPONSE_OK) Then
   'dim as GdkColor color
   'colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel)
   'gtk_color_selection_get_current_color(colorsel, @color)
   'gtk_widget_modify_fg(GTK_WIDGET(label), GTK_STATE_NORMAL, color)
end if

gtk_widget_destroy(dialog)
end sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_FileDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
print "Test 5 "
'Dim chooser As GtkWidget Ptr = gtk_file_chooser_dialog_new ("TITLE", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, "aa")
'GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE,GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
'gtk_dialog_run(GTK_FILE_CHOOSER_DIALOG( chooser ))
'gtk_widget_destroy( chooser )
end sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_FontDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
print "Test 6 "
dim as GtkResponseType result

  dim as GtkWidget ptr dialog = gtk_font_selection_dialog_new("Select Font")
  result = gtk_dialog_run(GTK_DIALOG(dialog))

  if (result = GTK_RESPONSE_OK or result = GTK_RESPONSE_APPLY) Then
 

    dim as PangoFontDescription ptr font_desc
    dim as gchar ptr fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog))

    font_desc = pango_font_description_from_string(fontname)

    'gtk_widget_modify_font(GTK_WIDGET(label), font_desc)
    gtk_label_set_markup(GTK_LABEL(label), fontname)
    g_free(fontname)
  end if
  gtk_widget_destroy(dialog)
end sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB ColorDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
   print "== COLOR BUTTON DATA =="
   'print gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER(pr1))
end sub

SUB FileDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
   print "== FILE BUTTON DATA =="
   'print gtk_file_chooser_get_current_folder_file (GTK_COLOR_CHOOSER(pr1))
end sub

SUB FontDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
   print "== FONT BUTTON DATA =="
   'print gtk_f_chooser_get_current_folder_file (GTK_FONT_CHOOSER(pr1))
end sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
gtk_init(@__FB_ARGC__, @__FB_ARGV__)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim As GtkWidget Ptr win = gtk_window_new(GTK_WINDOW_TOPLEVEL)
   gtk_window_set_title(GTK_WINDOW(win), "DIALOG DEMO")
   gtk_widget_set_size_request(win, 700, 450)
   gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER)
Dim As GtkWidget Ptr fixed = gtk_fixed_new()
   gtk_container_add(GTK_CONTAINER(win), fixed)
   
Dim As GtkWidget Ptr button1 = gtk_button_new_with_label("Dialog 1")
   gtk_widget_set_size_request(button1, 80, 30)
   gtk_fixed_put(GTK_FIXED(fixed), button1, 50, 10)
Dim As GtkWidget Ptr button2 = gtk_button_new_with_label("Dialog 2")
   gtk_widget_set_size_request(button2, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), button2, 150, 10)   
Dim As GtkWidget Ptr button3 = gtk_button_new_with_label("About")
   gtk_widget_set_size_request(button3, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), button3, 350, 10)      
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''   
Dim As GtkWidget Ptr button111 = gtk_button_new_with_label("INFO")
   gtk_widget_set_size_request(button111, 100, 30)
   gtk_fixed_put(GTK_FIXED(fixed), button111, 50, 50)
Dim As GtkWidget Ptr button222 = gtk_button_new_with_label("ERROR")
   gtk_widget_set_size_request(button222, 100, 30)
   gtk_fixed_put(GTK_FIXED(fixed), button222, 160, 50)   
Dim As GtkWidget Ptr button333 = gtk_button_new_with_label("QUESTION")
   gtk_widget_set_size_request(button333, 100, 30)
   gtk_fixed_put(GTK_FIXED(fixed), button333, 280, 50)      
Dim As GtkWidget Ptr button444 = gtk_button_new_with_label("WARNING")
   gtk_widget_set_size_request(button444, 100, 30)
   gtk_fixed_put(GTK_FIXED(fixed), button444, 400, 50)         
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim As GtkWidget Ptr showColorbutton4 = gtk_button_new_with_label("Color Dialog")
   gtk_widget_set_size_request(showColorbutton4, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), showColorbutton4, 500, 100)
Dim As GtkWidget Ptr showFilebutton5 = gtk_button_new_with_label("File Dialog")
   gtk_widget_set_size_request(showFilebutton5, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), showFilebutton5, 500, 140)   
Dim As GtkWidget Ptr showFontbutton6 = gtk_button_new_with_label("Font Dialog")
   gtk_widget_set_size_request(showFontbutton6, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), showFontbutton6, 500, 180)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''   
Dim As GtkWidget Ptr buttonColorData = gtk_button_new_with_label("Color Chooser Data Print")
   gtk_widget_set_size_request(buttonColorData, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), buttonColorData, 250, 100)      
Dim As GtkWidget Ptr buttonFileData = gtk_button_new_with_label("File Chooser Data Print")
   gtk_widget_set_size_request(buttonFileData, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), buttonFileData, 250, 140)   
Dim As GtkWidget Ptr buttonFontData = gtk_button_new_with_label("Font Chooser Data Print")
   gtk_widget_set_size_request(buttonFontData, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), buttonFontData, 250, 180)      
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''   
Dim As GtkWidget Ptr ColorButton = gtk_color_button_new ()
   gtk_widget_set_size_request(ColorButton, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), ColorButton, 50, 100)      
   gtk_color_button_set_title(GTK_COLOR_BUTTON(ColorButton), "Choose Color")
Dim As GtkWidget Ptr FileButton = gtk_file_chooser_button_new ("Please say something here", GTK_FILE_CHOOSER_ACTION_OPEN)
   'GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
   gtk_widget_set_size_request(FileButton, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), FileButton, 50, 140)      
   'gtk_color_button_set_title(GTK_FILE_CHOOSER_BUTTON(FileButton), "Choose File")   
Dim As GtkWidget Ptr FontButton = gtk_font_button_new ()
   gtk_widget_set_size_request(FontButton, 180, 30)
   gtk_fixed_put(GTK_FIXED(fixed), FontButton, 50, 180)      
   'gtk_color_button_set_title(GTK_FONT_BUTTON(FontButton), "Choose Font")   
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''   
Dim As GtkWidget Ptr label = gtk_label_new_with_mnemonic ("LABELABELLABELABELLABELABELLABELABEL")
   gtk_widget_set_size_request(label, 150, 15)
   gtk_fixed_put(GTK_FIXED(fixed), label, 10, 350)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
g_signal_connect(G_OBJECT(button1), "clicked", G_CALLBACK (@Dialog1), win)
g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK (@Dialog2), win)
g_signal_connect(G_OBJECT(button3), "clicked", G_CALLBACK (@Dialog3), win)

g_signal_connect(G_OBJECT(button111), "clicked", G_CALLBACK (@show_info), win)
g_signal_connect(G_OBJECT(button222), "clicked", G_CALLBACK (@show_error), win)
g_signal_connect(G_OBJECT(button333), "clicked", G_CALLBACK (@show_question), win)
g_signal_connect(G_OBJECT(button444), "clicked", G_CALLBACK (@show_warning), win)

g_signal_connect(G_OBJECT(buttonColorData), "clicked", G_CALLBACK (@ColorDataDump), ColorButton)
g_signal_connect(G_OBJECT(buttonFileData), "clicked", G_CALLBACK (@FileDataDump), FileButton)
g_signal_connect(G_OBJECT(buttonFontData), "clicked", G_CALLBACK (@FontDataDump), FontButton)

g_signal_connect(G_OBJECT(showColorbutton4), "clicked", G_CALLBACK (@show_ColorDialog), label)
g_signal_connect(G_OBJECT(showFilebutton5), "clicked", G_CALLBACK (@show_FileDialog), label)
g_signal_connect(G_OBJECT(showFontbutton6), "clicked", G_CALLBACK (@show_FontDialog), label)

g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK (@gtk_main_quit), NULL)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''     
gtk_widget_show_all(win)
gtk_main()
END 0
TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Sep 19, 2011 8:32

Good example! I modified the signal handlers for the AboutDialog and the ChooserButtons a bit (this code can be compiled against GTK3 and also against the original FB GTK version 2.06.1):

Code: Select all

#LIBPATH "C:\opt\GTK-3.0.9\lib"

#INCLUDE ONCE "TJF/gtk.bi" ' to compile against GTK3
'#INCLUDE ONCE "gtk/gtk.bi" ' to compile against GTK-2.06.1 (original FB)

#DEFINE NULL 0

SUB show_info CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  DIM dialog AS GtkWidget PTR = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Download Completed", "title")
  gtk_window_set_title(GTK_WINDOW(dialog), "Information")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
END SUB
SUB show_error CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  DIM dialog AS GtkWidget PTR = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error loading file")
  gtk_window_set_title(GTK_WINDOW(dialog), "Error")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
END SUB
SUB show_question CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
PRINT "how do i read answer"
  DIM dialog AS GtkWidget PTR = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are you sure to quit?")
  gtk_window_set_title(GTK_WINDOW(dialog), "Question")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
END SUB
SUB show_warning CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  DIM dialog AS GtkWidget PTR = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Unallowed operation")
  gtk_window_set_title(GTK_WINDOW(dialog), "Warning")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog1 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
PRINT "ok "
DIM s AS STRING
DIM dialog AS GtkWidget PTR = gtk_message_dialog_new( GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, STRPTR( s ))
gtk_dialog_run( GTK_DIALOG( dialog ) )
gtk_widget_destroy( dialog )
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog2 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
PRINT "This is OK"
DIM s AS STRING
DIM filename AS STRING
filename="FN"
DIM errno AS INTEGER
errno = 1167
DIM dialog AS GtkWidget PTR = gtk_message_dialog_new (GTK_WINDOW(www),  GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error loading file '%s': %s", filename, g_strerror (errno))
gtk_dialog_run( GTK_DIALOG( dialog ) )
gtk_widget_destroy( dialog )
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog3 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  VAR dialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new())
#IFDEF __gtkversion_bi__
    gtk_about_dialog_set_name(dialog, "GTK DIALOGS")
#ELSE
    gtk_about_dialog_set_program_name(dialog, "GTK DIALOGS")
#ENDIF
  gtk_about_dialog_set_version(dialog, "0.9")
  gtk_about_dialog_set_copyright(dialog, "vladimir777")
  gtk_about_dialog_set_comments(dialog, "An excelent example for GTK DIalogs")
  gtk_about_dialog_set_website(dialog, "http://www.freebasic.net")

  VAR pixbuf = gdk_pixbuf_new_from_file("GtkDialog.png", NULL)
  IF pixbuf THEN gtk_about_dialog_set_logo(dialog, pixbuf)

  VAR r = gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(GTK_WIDGET(dialog))
  IF pixbuf THEN g_object_unref(pixbuf)
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_ColorDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
  VAR dialog = gtk_color_selection_dialog_new("Color")
  IF gtk_dialog_run(GTK_DIALOG(dialog)) = GTK_RESPONSE_OK THEN

  ' RESPONSE_HELP        Returned by Help buttons in GTK+ dialogs.
  ' -10        Gtk::RESPONSE_APPLY        Returned by Apply buttons in GTK+ dialogs.
  ' -9        Gtk::RESPONSE_NO        Returned by No buttons in GTK+ dialogs.
  ' -8        Gtk::RESPONSE_YES        Returned by Yes buttons in GTK+ dialogs.
  ' -7        Gtk::RESPONSE_CLOSE        Returned by Close buttons in GTK+ dialogs.
  ' -6        Gtk::RESPONSE_CANCEL        Returned by Cancel buttons in GTK+ dialogs.
  ' -5        Gtk::RESPONSE_OK        Returned by OK buttons in GTK+ dialogs.
  ' -4        Gtk::RESPONSE_DELETE_EVENT        Returned if the dialog is deleted.
  ' -3        Gtk::RESPONSE_ACCEPT        Generic response id, not used by GTK+ dialogs.
  ' -2        Gtk::RESPONSE_REJECT        Generic response id, not used by GTK+ dialogs.
  ' -1        Gtk::RESPONSE_NONE

    DIM AS GdkColor colour
#IFDEF __gtkversion_bi__
    VAR colsel = GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel
#ELSE
    VAR colsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog))
#ENDIF
    gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colsel), @colour)
    gtk_widget_modify_fg(label, GTK_STATE_NORMAL, @colour)
  END IF

  gtk_widget_destroy(dialog)
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_FileDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
  VAR chooser = gtk_file_chooser_dialog_new("TITLE", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, _
    "Get it", 1, "I don't know", 2, "No, nothing", 3, 0)
  SELECT CASE AS CONST gtk_dialog_run(GTK_DIALOG(chooser))
  CASE 1 : gtk_label_set_text(GTK_LABEL(label), !"OK, you got:\n" & _
             *gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)))
  CASE 2 : gtk_label_set_text(GTK_LABEL(label), "OK, you're unsure.")
  CASE ELSE : gtk_label_set_text(GTK_LABEL(label), "Nothing? That's boring!")
  END SELECT
  gtk_widget_destroy( chooser )
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_FontDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
  VAR dialog = gtk_font_selection_dialog_new("Select Font")
  VAR result = gtk_dialog_run(GTK_DIALOG(dialog))

  IF (result = GTK_RESPONSE_OK ORELSE result = GTK_RESPONSE_APPLY) THEN
    VAR fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog))
    VAR font_desc = pango_font_description_from_string(fontname)

    gtk_widget_modify_font(label, font_desc)
    gtk_label_set_text(GTK_LABEL(label), fontname)
    g_free(fontname)
    pango_font_description_free(font_desc)
  END IF
  gtk_widget_destroy(dialog)
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB ColorDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
        PRINT "== COLOR BUTTON DATA =="
        'print gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER(pr1))
END SUB

SUB FileDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
        PRINT "== FILE BUTTON DATA =="
        'print gtk_file_chooser_get_current_folder_file (GTK_COLOR_CHOOSER(pr1))
END SUB

SUB FontDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
        PRINT "== FONT BUTTON DATA =="
        'print gtk_f_chooser_get_current_folder_file (GTK_FONT_CHOOSER(pr1))
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
gtk_init(@__FB_ARGC__, @__FB_ARGV__)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR win = gtk_window_new(GTK_WINDOW_TOPLEVEL)
        gtk_window_set_title(GTK_WINDOW(win), "DIALOG DEMO")
        gtk_widget_set_size_request(win, 700, 450)
        gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER)
DIM AS GtkWidget PTR fixed = gtk_fixed_new()
        gtk_container_add(GTK_CONTAINER(win), fixed)

DIM AS GtkWidget PTR button1 = gtk_button_new_with_label("Dialog 1")
        gtk_widget_set_size_request(button1, 80, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button1, 50, 10)
DIM AS GtkWidget PTR button2 = gtk_button_new_with_label("Dialog 2")
        gtk_widget_set_size_request(button2, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button2, 150, 10)
DIM AS GtkWidget PTR button3 = gtk_button_new_with_label("About")
        gtk_widget_set_size_request(button3, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button3, 350, 10)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR button111 = gtk_button_new_with_label("INFO")
        gtk_widget_set_size_request(button111, 100, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button111, 50, 50)
DIM AS GtkWidget PTR button222 = gtk_button_new_with_label("ERROR")
        gtk_widget_set_size_request(button222, 100, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button222, 160, 50)
DIM AS GtkWidget PTR button333 = gtk_button_new_with_label("QUESTION")
        gtk_widget_set_size_request(button333, 100, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button333, 280, 50)
DIM AS GtkWidget PTR button444 = gtk_button_new_with_label("WARNING")
        gtk_widget_set_size_request(button444, 100, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button444, 400, 50)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR showColorbutton4 = gtk_button_new_with_label("Color Dialog")
        gtk_widget_set_size_request(showColorbutton4, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), showColorbutton4, 500, 100)
DIM AS GtkWidget PTR showFilebutton5 = gtk_button_new_with_label("File Dialog")
        gtk_widget_set_size_request(showFilebutton5, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), showFilebutton5, 500, 140)
DIM AS GtkWidget PTR showFontbutton6 = gtk_button_new_with_label("Font Dialog")
        gtk_widget_set_size_request(showFontbutton6, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), showFontbutton6, 500, 180)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR buttonColorData = gtk_button_new_with_label("Color Chooser Data Print")
        gtk_widget_set_size_request(buttonColorData, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), buttonColorData, 250, 100)
DIM AS GtkWidget PTR buttonFileData = gtk_button_new_with_label("File Chooser Data Print")
        gtk_widget_set_size_request(buttonFileData, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), buttonFileData, 250, 140)
DIM AS GtkWidget PTR buttonFontData = gtk_button_new_with_label("Font Chooser Data Print")
        gtk_widget_set_size_request(buttonFontData, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), buttonFontData, 250, 180)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR ColorButton = gtk_color_button_new ()
        gtk_widget_set_size_request(ColorButton, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), ColorButton, 50, 100)
        gtk_color_button_set_title(GTK_COLOR_BUTTON(ColorButton), "Choose Color")
DIM AS GtkWidget PTR FileButton = gtk_file_chooser_button_new ("Please say something here", GTK_FILE_CHOOSER_ACTION_OPEN)
        'GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
        gtk_widget_set_size_request(FileButton, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), FileButton, 50, 140)
        'gtk_color_button_set_title(GTK_FILE_CHOOSER_BUTTON(FileButton), "Choose File")
DIM AS GtkWidget PTR FontButton = gtk_font_button_new ()
        gtk_widget_set_size_request(FontButton, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), FontButton, 50, 180)
        'gtk_color_button_set_title(GTK_FONT_BUTTON(FontButton), "Choose Font")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR label = gtk_label_new_with_mnemonic ("LABELABELLABELABELLABELABELLABELABEL")
        gtk_widget_set_size_request(label, 150, 15)
        gtk_fixed_put(GTK_FIXED(fixed), label, 10, 350)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
g_signal_connect(G_OBJECT(button1), "clicked", G_CALLBACK (@Dialog1), win)
g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK (@Dialog2), win)
g_signal_connect(G_OBJECT(button3), "clicked", G_CALLBACK (@Dialog3), win)

g_signal_connect(G_OBJECT(button111), "clicked", G_CALLBACK (@show_info), win)
g_signal_connect(G_OBJECT(button222), "clicked", G_CALLBACK (@show_error), win)
g_signal_connect(G_OBJECT(button333), "clicked", G_CALLBACK (@show_question), win)
g_signal_connect(G_OBJECT(button444), "clicked", G_CALLBACK (@show_warning), win)

g_signal_connect(G_OBJECT(buttonColorData), "clicked", G_CALLBACK (@ColorDataDump), ColorButton)
g_signal_connect(G_OBJECT(buttonFileData), "clicked", G_CALLBACK (@FileDataDump), FileButton)
g_signal_connect(G_OBJECT(buttonFontData), "clicked", G_CALLBACK (@FontDataDump), FontButton)

g_signal_connect(G_OBJECT(showColorbutton4), "clicked", G_CALLBACK (@show_ColorDialog), label)
g_signal_connect(G_OBJECT(showFilebutton5), "clicked", G_CALLBACK (@show_FileDialog), label)
g_signal_connect(G_OBJECT(showFontbutton6), "clicked", G_CALLBACK (@show_FontDialog), label)

g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK (@gtk_main_quit), NULL)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
gtk_widget_show_all(win)
gtk_main()
END 0


I don't understand the meaning of the ChooserDataPrint buttons.
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

Postby vladimir777 » Sep 19, 2011 22:53

It print values-data for button on the left side

I add code for "color data chooser print" FIRST ONE
----------------------------------------------------------------------------
I in gtk3 I can not read the other two

Code: Select all

#LIBPATH "C:\opt\GTK-3.0.9\lib"

#INCLUDE ONCE "TJF/gtk.bi" ' to compile against GTK3
'#INCLUDE ONCE "gtk/gtk.bi" ' to compile against GTK-2.06.1 (original FB)

Dim Shared KOLOR As GdkColor

#DEFINE NULL 0

SUB show_info CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  DIM dialog AS GtkWidget PTR = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Download Completed", "title")
  gtk_window_set_title(GTK_WINDOW(dialog), "Information")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
END SUB
SUB show_error CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  DIM dialog AS GtkWidget PTR = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error loading file")
  gtk_window_set_title(GTK_WINDOW(dialog), "Error")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
END SUB
SUB show_question CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
PRINT "how do i read answer"
  DIM dialog AS GtkWidget PTR = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are you sure to quit?")
  gtk_window_set_title(GTK_WINDOW(dialog), "Question")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
END SUB
SUB show_warning CDECL(BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  DIM dialog AS GtkWidget PTR = gtk_message_dialog_new(GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Unallowed operation")
  gtk_window_set_title(GTK_WINDOW(dialog), "Warning")
  gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(dialog)
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog1 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
PRINT "ok "
DIM s AS STRING
DIM dialog AS GtkWidget PTR = gtk_message_dialog_new( GTK_WINDOW(www), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, STRPTR( s ))
gtk_dialog_run( GTK_DIALOG( dialog ) )
gtk_widget_destroy( dialog )
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog2 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
PRINT "This is OK"
DIM s AS STRING
DIM filename AS STRING
filename="FN"
DIM errno AS INTEGER
errno = 1167
DIM dialog AS GtkWidget PTR = gtk_message_dialog_new (GTK_WINDOW(www),  GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error loading file '%s': %s", filename, g_strerror (errno))
gtk_dialog_run( GTK_DIALOG( dialog ) )
gtk_widget_destroy( dialog )
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB Dialog3 CDECL (BYVAL widget AS GtkWidget PTR, BYVAL www AS GtkWidget PTR)
  VAR dialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new())
#IFDEF __gtkversion_bi__
    gtk_about_dialog_set_name(dialog, "GTK DIALOGS")
#ELSE
    gtk_about_dialog_set_program_name(dialog, "GTK DIALOGS")
#ENDIF
  gtk_about_dialog_set_version(dialog, "0.9")
  gtk_about_dialog_set_copyright(dialog, "vladimir777")
  gtk_about_dialog_set_comments(dialog, "An excelent example for GTK DIalogs")
  gtk_about_dialog_set_website(dialog, "http://www.freebasic.net")

  VAR pixbuf = gdk_pixbuf_new_from_file("GtkDialog.png", NULL)
  IF pixbuf THEN gtk_about_dialog_set_logo(dialog, pixbuf)

  VAR r = gtk_dialog_run(GTK_DIALOG(dialog))
  gtk_widget_destroy(GTK_WIDGET(dialog))
  IF pixbuf THEN g_object_unref(pixbuf)
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_ColorDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
  VAR dialog = gtk_color_selection_dialog_new("Color")
 

'gtk_color_selection_set_has_palette (gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog)), TRUE)
'warninng
 
 
 
 
 
 
  IF gtk_dialog_run(GTK_DIALOG(dialog)) = GTK_RESPONSE_OK THEN

  ' RESPONSE_HELP        Returned by Help buttons in GTK+ dialogs.
  ' -10        Gtk::RESPONSE_APPLY        Returned by Apply buttons in GTK+ dialogs.
  ' -9        Gtk::RESPONSE_NO        Returned by No buttons in GTK+ dialogs.
  ' -8        Gtk::RESPONSE_YES        Returned by Yes buttons in GTK+ dialogs.
  ' -7        Gtk::RESPONSE_CLOSE        Returned by Close buttons in GTK+ dialogs.
  ' -6        Gtk::RESPONSE_CANCEL        Returned by Cancel buttons in GTK+ dialogs.
  ' -5        Gtk::RESPONSE_OK        Returned by OK buttons in GTK+ dialogs.
  ' -4        Gtk::RESPONSE_DELETE_EVENT        Returned if the dialog is deleted.
  ' -3        Gtk::RESPONSE_ACCEPT        Generic response id, not used by GTK+ dialogs.
  ' -2        Gtk::RESPONSE_REJECT        Generic response id, not used by GTK+ dialogs.
  ' -1        Gtk::RESPONSE_NONE

    DIM AS GdkColor colour
#IFDEF __gtkversion_bi__
    VAR colsel = GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel
#ELSE
    VAR colsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog))
#ENDIF
    gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colsel), @colour)
    gtk_widget_modify_fg(label, GTK_STATE_NORMAL, @colour)
  END IF

  gtk_widget_destroy(dialog)
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_FileDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
  VAR chooser = gtk_file_chooser_dialog_new("TITLE", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, _
    "Get it", 1, "I don't know", 2, "No, nothing", 3, 0)
  SELECT CASE AS CONST gtk_dialog_run(GTK_DIALOG(chooser))
  CASE 1 : gtk_label_set_text(GTK_LABEL(label), !"OK, you got:\n" & _
             *gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)))
  CASE 2 : gtk_label_set_text(GTK_LABEL(label), "OK, you're unsure.")
  CASE ELSE : gtk_label_set_text(GTK_LABEL(label), "Nothing? That's boring!")
  END SELECT
  gtk_widget_destroy( chooser )
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB show_FontDialog CDECL (BYVAL widget AS GtkWidget PTR, BYVAL label AS GtkWidget PTR)
  VAR dialog = gtk_font_selection_dialog_new("Select Font")
  VAR result = gtk_dialog_run(GTK_DIALOG(dialog))

  IF (result = GTK_RESPONSE_OK ORELSE result = GTK_RESPONSE_APPLY) THEN
    VAR fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog))
    VAR font_desc = pango_font_description_from_string(fontname)

    gtk_widget_modify_font(label, font_desc)
    gtk_label_set_text(GTK_LABEL(label), fontname)
    g_free(fontname)
    pango_font_description_free(font_desc)
  END IF
  gtk_widget_destroy(dialog)
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB ColorDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
        PRINT "== COLOR BUTTON DATA =="
        'print gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER(pr1))
      gtk_color_button_get_color (GTK_COLOR_BUTTON(pr1), @KOLOR)
      
      print "R:", KOLOR.red
      print "G:", KOLOR.green
      print "B:", KOLOR.blue
      
      
END SUB

SUB FileDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
        PRINT "== FILE BUTTON DATA =="
        'print gtk_file_chooser_get_current_folder_file (GTK_COLOR_CHOOSER(pr1))
END SUB

SUB FontDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
        PRINT "== FONT BUTTON DATA =="
        'print gtk_f_chooser_get_current_folder_file (GTK_FONT_CHOOSER(pr1))
END SUB
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
gtk_init(@__FB_ARGC__, @__FB_ARGV__)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR win = gtk_window_new(GTK_WINDOW_TOPLEVEL)
        gtk_window_set_title(GTK_WINDOW(win), "DIALOG DEMO")
        gtk_widget_set_size_request(win, 700, 450)
        gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER)
DIM AS GtkWidget PTR fixed = gtk_fixed_new()
        gtk_container_add(GTK_CONTAINER(win), fixed)

DIM AS GtkWidget PTR button1 = gtk_button_new_with_label("Dialog 1")
        gtk_widget_set_size_request(button1, 80, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button1, 50, 10)
DIM AS GtkWidget PTR button2 = gtk_button_new_with_label("Dialog 2")
        gtk_widget_set_size_request(button2, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button2, 150, 10)
DIM AS GtkWidget PTR button3 = gtk_button_new_with_label("About")
        gtk_widget_set_size_request(button3, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button3, 350, 10)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR button111 = gtk_button_new_with_label("INFO")
        gtk_widget_set_size_request(button111, 100, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button111, 50, 50)
DIM AS GtkWidget PTR button222 = gtk_button_new_with_label("ERROR")
        gtk_widget_set_size_request(button222, 100, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button222, 160, 50)
DIM AS GtkWidget PTR button333 = gtk_button_new_with_label("QUESTION")
        gtk_widget_set_size_request(button333, 100, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button333, 280, 50)
DIM AS GtkWidget PTR button444 = gtk_button_new_with_label("WARNING")
        gtk_widget_set_size_request(button444, 100, 30)
        gtk_fixed_put(GTK_FIXED(fixed), button444, 400, 50)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR showColorbutton4 = gtk_button_new_with_label("Color Dialog")
        gtk_widget_set_size_request(showColorbutton4, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), showColorbutton4, 500, 100)
DIM AS GtkWidget PTR showFilebutton5 = gtk_button_new_with_label("File Dialog")
        gtk_widget_set_size_request(showFilebutton5, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), showFilebutton5, 500, 140)
DIM AS GtkWidget PTR showFontbutton6 = gtk_button_new_with_label("Font Dialog")
        gtk_widget_set_size_request(showFontbutton6, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), showFontbutton6, 500, 180)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR buttonColorData = gtk_button_new_with_label("Color Chooser Data Print")
        gtk_widget_set_size_request(buttonColorData, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), buttonColorData, 250, 100)
DIM AS GtkWidget PTR buttonFileData = gtk_button_new_with_label("File Chooser Data Print")
        gtk_widget_set_size_request(buttonFileData, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), buttonFileData, 250, 140)
DIM AS GtkWidget PTR buttonFontData = gtk_button_new_with_label("Font Chooser Data Print")
        gtk_widget_set_size_request(buttonFontData, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), buttonFontData, 250, 180)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
KOLOR.red=&Hff * &H100 : KOLOR.Green=0: KOLOR.blue=0: KOLOR.pixel=32
DIM AS GtkWidget PTR ColorButton = gtk_color_button_new ()
'DIM AS GtkWidget PTR ColorButton = gtk_color_button_new_with_color (@KOLOR)
gtk_color_button_set_color (GTK_COLOR_BUTTON(ColorButton), @KOLOR)
        gtk_widget_set_size_request(ColorButton, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), ColorButton, 50, 100)
        gtk_color_button_set_title(GTK_COLOR_BUTTON(ColorButton), "Choose Color")
DIM AS GtkWidget PTR FileButton = gtk_file_chooser_button_new ("Please say something here", GTK_FILE_CHOOSER_ACTION_OPEN)
      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (FileButton), "d:\start")
        'GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
        gtk_widget_set_size_request(FileButton, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), FileButton, 50, 140)
        'gtk_color_button_set_title(GTK_FILE_CHOOSER_BUTTON(FileButton), "Choose File")
DIM AS GtkWidget PTR FontButton = gtk_font_button_new ()
        gtk_widget_set_size_request(FontButton, 180, 30)
        gtk_fixed_put(GTK_FIXED(fixed), FontButton, 50, 180)
        gtk_font_button_set_title(GTK_FONT_BUTTON(FontButton), "Choose Font")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM AS GtkWidget PTR label = gtk_label_new_with_mnemonic ("LABELABELLABELABELLABELABELLABELABEL")
        gtk_widget_set_size_request(label,350, 15)
        gtk_fixed_put(GTK_FIXED(fixed), label, 10, 350)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
g_signal_connect(G_OBJECT(button1), "clicked", G_CALLBACK (@Dialog1), win)
g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK (@Dialog2), win)
g_signal_connect(G_OBJECT(button3), "clicked", G_CALLBACK (@Dialog3), win)

g_signal_connect(G_OBJECT(button111), "clicked", G_CALLBACK (@show_info), win)
g_signal_connect(G_OBJECT(button222), "clicked", G_CALLBACK (@show_error), win)
g_signal_connect(G_OBJECT(button333), "clicked", G_CALLBACK (@show_question), win)
g_signal_connect(G_OBJECT(button444), "clicked", G_CALLBACK (@show_warning), win)

g_signal_connect(G_OBJECT(buttonColorData), "clicked", G_CALLBACK (@ColorDataDump), ColorButton)
g_signal_connect(G_OBJECT(buttonFileData), "clicked", G_CALLBACK (@FileDataDump), FileButton)
g_signal_connect(G_OBJECT(buttonFontData), "clicked", G_CALLBACK (@FontDataDump), FontButton)

g_signal_connect(G_OBJECT(showColorbutton4), "clicked", G_CALLBACK (@show_ColorDialog), label)
g_signal_connect(G_OBJECT(showFilebutton5), "clicked", G_CALLBACK (@show_FileDialog), label)
g_signal_connect(G_OBJECT(showFontbutton6), "clicked", G_CALLBACK (@show_FontDialog), label)

g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK (@gtk_main_quit), NULL)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
gtk_widget_show_all(win)
gtk_main()
END 0

TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Sep 20, 2011 6:22

vladimir777 wrote:I in gtk3 I can not read the other two

No difference between GTK2 and GTK3:

Code: Select all

SUB FileDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
  PRINT "== FILE BUTTON DATA =="
  ?"  Folder: "; *gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(pr1))
  ?"Filename: "; *gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pr1))
END SUB

SUB FontDataDump CDECL (BYVAL widget AS GtkWidget PTR, BYVAL pr1 AS GtkWidget PTR)
  PRINT "== FONT BUTTON DATA =="
  ?*gtk_font_button_get_font_name (GTK_FONT_BUTTON(pr1))
END SUB


BTW:
Do you know the online documentation for GTK2 and GTK3, available for different vesions?

I'm developing on LINUX and I use a tool called Devhelp. This tool shows the GNOME content offline (and it's connected with IDE and GUI designer -- mark the unclear function name or a part of it and get the desired help by a single keystroke).
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

SIGNALS FOR BUTTON DEMO - WORKS WELL

Postby vladimir777 » Sep 20, 2011 15:10

Thank you TJF!

I hope these examples will help other people too.

Here is one that works well and emonstrate signals for button

Code: Select all

#LIBPATH "C:\opt\GTK-3.0.9\lib"

#include once "TJF/gtk.bi"

#define NULL 0

SUB b4_clicked CDECL(BYVAL widget AS GtkWidget PTR, BYVAL lab AS GtkWidget PTR )
print "Clicked"
end sub

SUB b4_enter CDECL(BYVAL widget AS GtkWidget PTR, BYVAL lab AS GtkWidget PTR )
print "Enter"
end sub

SUB b4_leave CDECL(BYVAL widget AS GtkWidget PTR, BYVAL lab AS GtkWidget PTR )
print "LEAVE"
end sub

SUB b4_pressed CDECL(BYVAL widget AS GtkWidget PTR, BYVAL lab AS GtkWidget PTR )
print "PRESSED"
end sub

SUB b4_released CDECL(BYVAL widget AS GtkWidget PTR, BYVAL lab AS GtkWidget PTR )
print "RELEASED"
end sub

SUB b4_activate CDECL(BYVAL widget AS GtkWidget PTR, BYVAL lab AS GtkWidget PTR )
print "ACTIVATE"
end sub

gtk_init(@__FB_ARGC__, @__FB_ARGV__)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim As GtkWidget Ptr win = gtk_window_new(GTK_WINDOW_TOPLEVEL)
   gtk_window_set_title(GTK_WINDOW(win), "Close")
   gtk_widget_set_size_request(win, 550, 250)
   gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER)
Dim As GtkWidget Ptr fixed = gtk_fixed_new()
   gtk_container_add(GTK_CONTAINER(win), fixed)


   
Dim As GtkWidget Ptr button77 = gtk_volume_button_new ()
   gtk_widget_set_size_request(button77, 80, 35)
   gtk_fixed_put(GTK_FIXED(fixed), button77, 10, 10)   


   
   
Dim As GtkWidget Ptr button1 = gtk_button_new_from_stock(GTK_STOCK_CLOSE)
   gtk_widget_set_size_request(button1, 80, 35)
   gtk_fixed_put(GTK_FIXED(fixed), button1, 50, 90)
Dim As GtkWidget Ptr button2 = gtk_button_new_with_mnemonic ("Te_st1")
   gtk_widget_set_size_request(button2, 80, 35)
   gtk_fixed_put(GTK_FIXED(fixed), button2, 150, 90)   
Dim As GtkWidget Ptr button4 = gtk_button_new_from_stock(GTK_STOCK_EDIT)
   gtk_widget_set_size_request(button4, 80, 35)
   gtk_fixed_put(GTK_FIXED(fixed), button4, 250, 90)      



'gtk_button_set_image ()     add this
   
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
g_signal_connect(G_OBJECT(button1), "clicked", G_CALLBACK (@gtk_main_quit), NULL)

g_signal_connect(G_OBJECT(button4), "clicked", G_CALLBACK (@b4_clicked), NULL)
g_signal_connect(G_OBJECT(button4), "enter", G_CALLBACK (@b4_enter), NULL)
g_signal_connect(G_OBJECT(button4), "leave", G_CALLBACK (@b4_leave), NULL)
g_signal_connect(G_OBJECT(button4), "pressed", G_CALLBACK (@b4_pressed), NULL)
g_signal_connect(G_OBJECT(button4), "released", G_CALLBACK (@b4_released), NULL)
g_signal_connect(G_OBJECT(button4), "activate", G_CALLBACK (@b4_activate), NULL)  ' never use this

g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK (@gtk_main_quit), NULL)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''     
gtk_widget_show_all(win)
gtk_main()
END 0




/'
GTK_STOCK_ABOUT GTK_STOCK_ADD GTK_STOCK_APPLY GTK_STOCK_BOLD
GTK_STOCK_CANCEL GTK_STOCK_CAPS_LOCK_WARNING GTK_STOCK_CDROM
GTK_STOCK_CLEAR GTK_STOCK_CLOSE GTK_STOCK_COLOR_PICKER GTK_STOCK_CONVERT
GTK_STOCK_CONNECT

GTK_STOCK_COPY GTK_STOCK_CUT GTK_STOCK_DELETE
GTK_STOCK_DIALOG_AUTHENTICATION
GTK_STOCK_DIALOG_ERROR
GTK_STOCK_DIALOG_INFO
GTK_STOCK_DIALOG_QUESTION
GTK_STOCK_DIALOG_WARNING
GTK_STOCK_DIRECTORY
GTK_STOCK_DISCARD
GTK_STOCK_DISCONNECT
GTK_STOCK_DND drag and drop
GTK_STOCK_DND_MULTIPLE
GTK_STOCK_EDIT
GTK_STOCK_EXECUTE
GTK_STOCK_FILE
GTK_STOCK_FIND
GTK_STOCK_FIND_AND_REPLACE
GTK_STOCK_FLOPPY
GTK_STOCK_FULLSCREEN
GTK_STOCK_GOTO_BOTTOM
GTK_STOCK_GOTO_FIRST
GTK_STOCK_GOTO_LAST
GTK_STOCK_GOTO_TOP
GTK_STOCK_GO_BACK
GTK_STOCK_GO_DOWN
GTK_STOCK_GO_FORWARD
GTK_STOCK_GO_UP
GTK_STOCK_HARDDISK GTK_STOCK_HELP GTK_STOCK_HOME GTK_STOCK_INDENT
GTK_STOCK_INDEX GTK_STOCK_INFO GTK_STOCK_ITALIC GTK_STOCK_JUMP_TO
GTK_STOCK_JUSTIFY_CENTER GTK_STOCK_JUSTIFY_FILL GTK_STOCK_JUSTIFY_LEFT GTK_STOCK_JUSTIFY_RIGHT
GTK_STOCK_LEAVE_FULLSCREEN
GTK_STOCK_MEDIA_FORWARD GTK_STOCK_MEDIA_NEXT GTK_STOCK_MEDIA_PAUSE GTK_STOCK_MEDIA_PLAY GTK_STOCK_MEDIA_PREVIOUS
GTK_STOCK_MEDIA_RECORD GTK_STOCK_MEDIA_REWIND GTK_STOCK_MEDIA_STOP

GTK_STOCK_MISSING_IMAGE GTK_STOCK_NETWORK GTK_STOCK_NEW GTK_STOCK_NO
GTK_STOCK_OK GTK_STOCK_OPEN GTK_STOCK_ORIENTATION_LANDSCAPE GTK_STOCK_ORIENTATION_PORTRAIT
GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT
GTK_STOCK_PAGE_SETUP GTK_STOCK_PASTE GTK_STOCK_PREFERENCES GTK_STOCK_PRINT
GTK_STOCK_PRINT_ERROR GTK_STOCK_PRINT_PAUSED GTK_STOCK_PRINT_PREVIEW
GTK_STOCK_PRINT_REPORT GTK_STOCK_PRINT_WARNING GTK_STOCK_PROPERTIES
GTK_STOCK_QUIT GTK_STOCK_REDO GTK_STOCK_REFRESH GTK_STOCK_REMOVE
GTK_STOCK_REVERT_TO_SAVED GTK_STOCK_SAVE GTK_STOCK_SAVE_AS
GTK_STOCK_SELECT_ALL GTK_STOCK_SELECT_COLOR GTK_STOCK_SELECT_FONT GTK_STOCK_SORT_ASCENDING GTK_STOCK_SORT_DESCENDING
GTK_STOCK_SPELL_CHECK GTK_STOCK_STOP GTK_STOCK_STRIKETHROUGH
GTK_STOCK_UNDELETE GTK_STOCK_UNDERLINE GTK_STOCK_UNDO
GTK_STOCK_UNINDENT GTK_STOCK_YES GTK_STOCK_ZOOM_100 GTK_STOCK_ZOOM_FIT GTK_STOCK_ZOOM_IN GTK_STOCK_ZOOM_OUT

'/


Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 4 guests