Skip to content

Commit

Permalink
Add a high-level interface for GtkAssistant, with example, and fix ar…
Browse files Browse the repository at this point in the history
…gument error in hl window.
  • Loading branch information
jtappin committed Jan 7, 2013
1 parent b1a397a commit 71fd043
Show file tree
Hide file tree
Showing 8 changed files with 843 additions and 3 deletions.
5 changes: 5 additions & 0 deletions examples/CMakeLists.txt
Expand Up @@ -72,6 +72,10 @@ target_link_libraries(gtkbuilder2 gtk-fortran_static ${GTK_LIBRARIES})
# This test is excluded because the directories don't match up.
# add_test(gtkbuilder2 gtkbuilder2)

add_executable(hl_assistant "hl_assistant.f90")
target_link_libraries(hl_assistant gtk-fortran_static ${GTK_LIBRARIES})
add_test(hl_assistant ./hl_assistant)

add_executable(hl_cairo1 "hl_cairo1.f90")
target_link_libraries(hl_cairo1 gtk-fortran_static ${GTK_LIBRARIES})
add_test(hl_cairo1 ./hl_cairo1)
Expand Down Expand Up @@ -194,6 +198,7 @@ if (INSTALL_EXAMPLES)
"${CMAKE_CURRENT_SOURCE_DIR}/gtkbuilder.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/gtkbuilder2.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/gtkbuilder.glade"
"${CMAKE_CURRENT_SOURCE_DIR}/hl_assistant.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/hl_cairo1.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/hl_cairo_clock.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/hl_choosers.f90"
Expand Down
189 changes: 189 additions & 0 deletions examples/hl_assistant.f90
@@ -0,0 +1,189 @@
! Copyright (C) 2012
! Free Software Foundation, Inc.

! This file is part of the gtk-fortran gtk+ Fortran Interface library.

! This is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 3, or (at your option)
! any later version.

! This software is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.

! Under Section 7 of GPL version 3, you are granted additional
! permissions described in the GCC Runtime Library Exception, version
! 3.1, as published by the Free Software Foundation.

! You should have received a copy of the GNU General Public License along with
! this program; see the files COPYING3 and COPYING.RUNTIME respectively.
! If not, see <http://www.gnu.org/licenses/>.
!
! gfortran -g hl_assistant.f90 `pkg-config --cflags --libs gtk-2-fortran`
! Contributed by James Tappin.

! Based on the C example given in"
! https://www.linuxquestions.org/linux/articles/Technical/New_GTK_Widgets_GtkAssistant

module as_handlers
use gtk_hl
use gtk_sup
use iso_c_binding

!********************************
! Gtk modules for hl_assistant.f90
use g, only: g_usleep

use gtk, only: gtk_alignment_new, gtk_container_add, gtk_entry_get_text, &
& gtk_events_pending, gtk_label_new, gtk_main, gtk_main_iteration, &
& gtk_main_quit, gtk_toggle_button_get_active, gtk_widget_destroy, &
& gtk_widget_set_sensitive, gtk_widget_show_all, gtk_init, TRUE, FALSE, &
& GTK_ASSISTANT_PAGE_CONTENT, GTK_ASSISTANT_PAGE_INTRO, &
& GTK_ASSISTANT_PAGE_CONFIRM, GTK_ASSISTANT_PAGE_PROGRESS


implicit none

type(c_ptr) :: asstnt

contains
subroutine destroy_asstnt(widget, gdata) bind(c)
type(c_ptr), value :: widget, gdata

print *, "Exit called"
call gtk_widget_destroy(asstnt)
call gtk_main_quit ()
end subroutine destroy_asstnt

subroutine asstnt_close(widget, gdata) bind(c)
type(c_ptr), value :: widget, gdata

print *, "Completed"
call gtk_widget_destroy(widget)
call gtk_main_quit ()
end subroutine asstnt_close

subroutine name_enter(widget, data) bind(c)
type(c_ptr), value :: widget, data

type(c_ptr) :: ctext, page, ebox
character(len=100) :: ftext
if (c_associated(data)) then
ebox = data
else
ebox = widget
end if

ctext = gtk_entry_get_text(ebox)
call c_f_string(ctext, ftext)
print *, "Entered name as:",trim(ftext)

page = hl_gtk_assistant_get_current_page(asstnt)
call hl_gtk_assistant_set_page_complete(asstnt, &
& f_c_logical(len_trim(ftext) > 0))
end subroutine name_enter

subroutine check_tog(widget, data) bind(c)
type(c_ptr), value :: widget, data

call hl_gtk_assistant_set_page_complete(asstnt, &
& gtk_toggle_button_get_active(widget))

end subroutine check_tog

subroutine start_pb(widget, data) bind(c)
type(c_ptr), value :: widget, data

integer(kind=c_int) :: i, iev
type(c_ptr) :: page

call gtk_widget_set_sensitive(widget, FALSE)

page = hl_gtk_assistant_get_current_page(asstnt)
do i = 1, 10

do
if (.not. c_f_logical(gtk_events_pending ())) exit
iev = gtk_main_iteration ()
end do

call g_usleep(500000_c_long)
call hl_gtk_progress_bar_set(data, i, 10_c_int, string=TRUE)
end do
call hl_gtk_assistant_set_page_complete(asstnt, TRUE)

end subroutine start_pb
end module as_handlers

program hl_assistant

use as_handlers
implicit none

type(c_ptr) :: page, junk, jb, algn, ebox, pbar

call gtk_init()

asstnt = hl_gtk_assistant_new(title="GtkAssistant Example"//c_null_char, &
& destroy=c_funloc(destroy_asstnt), wsize=[450_c_int, 300_c_int], &
& close=c_funloc(asstnt_close))


! Intro page
junk = gtk_label_new("This is an example of a GtkAssistant"//c_new_line// &
& "by clicking the forward button,"//c_new_line// &
& " you can continue to the next section!"//c_null_char);

call hl_gtk_assistant_add_page(asstnt, junk, GTK_ASSISTANT_PAGE_INTRO, &
& page_title="Introduction"//c_null_char)

! Name entry
algn = gtk_alignment_new(0.5_c_float, 0.5_c_float, 1.0_c_float, 0._c_float)
jb = hl_gtk_box_new(horizontal=TRUE, spacing=5)
call gtk_container_add(algn, jb)
junk = gtk_label_new("Your name:"//c_null_char)
call hl_gtk_box_pack(jb, junk, expand=FALSE)

ebox = hl_gtk_entry_new(editable=TRUE, activate=c_funloc(name_enter))
call hl_gtk_box_pack(jb, ebox)
junk = hl_gtk_button_new("Apply"//c_null_char, clicked=c_funloc(name_enter), &
& data=ebox)
call hl_gtk_box_pack(jb, junk, expand=FALSE)

call hl_gtk_assistant_add_page(asstnt, algn, GTK_ASSISTANT_PAGE_CONTENT)

! Check button

junk = hl_gtk_check_button_new("Click to continue"//c_null_char, &
&toggled = c_funloc(check_tog))
call hl_gtk_assistant_add_page(asstnt, junk, GTK_ASSISTANT_PAGE_CONTENT, &
& page_title="Click the Check Button"//c_null_char)

! Progress

algn = gtk_alignment_new(0.5_c_float, 0.5_c_float, 1.0_c_float, 0._c_float)
jb = hl_gtk_box_new(horizontal=TRUE)
call gtk_container_add(algn, jb)
pbar = hl_gtk_progress_bar_new()
call hl_gtk_box_pack(jb, pbar)

junk = hl_gtk_button_new("Click to start"//c_null_char, &
& clicked=c_funloc(start_pb), data=pbar)
call hl_gtk_box_pack(jb, junk, expand=false)
call hl_gtk_assistant_add_page(asstnt, algn, GTK_ASSISTANT_PAGE_PROGRESS, &
& page_title="Applying"//c_null_char)

! Confirmation page

junk = gtk_label_new ("Text has been entered in the label and"//c_new_line// &
& "the combo box is clicked. If you are done, then"//c_new_line// &
& "it is time to leave!"//c_null_char)
call hl_gtk_assistant_add_page(asstnt, junk, GTK_ASSISTANT_PAGE_CONFIRM, &
& page_title = "Completed?"//c_null_char)

call gtk_widget_show_all(asstnt)
call gtk_main()

end program hl_assistant
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -45,6 +45,7 @@ set(sources
"gtk-hl-progress.f90"
"gtk-hl-accelerator.f90"
"gtk-hl-infobar.f90"
"gtk-hl-assistant.f90"
"gtk-hl-misc.f90"
"gtk-draw-hl.f90"
"gtk-sup.f90"
Expand Down Expand Up @@ -135,6 +136,7 @@ install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/gtk_hl_progress.mod"
"${CMAKE_CURRENT_BINARY_DIR}/gtk_hl_accelerator.mod"
"${CMAKE_CURRENT_BINARY_DIR}/gtk_hl_infobar.mod"
"${CMAKE_CURRENT_BINARY_DIR}/gtk_hl_assistant.mod"
"${CMAKE_CURRENT_BINARY_DIR}/gtk_hl_misc.mod"
"${CMAKE_CURRENT_BINARY_DIR}/gtk_draw_hl.mod"
"${CMAKE_CURRENT_BINARY_DIR}/gdk_pixbuf_hl.mod"
Expand Down

0 comments on commit 71fd043

Please sign in to comment.