Skip to content

Commit

Permalink
This commit was manufactured by cvs2svn to create tag 'start'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown Author committed Feb 25, 2003
1 parent ec23f07 commit 42abc2f
Show file tree
Hide file tree
Showing 17 changed files with 2,139 additions and 0 deletions.
Binary file added gtk/sample/gtk-demo/alphatest.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
187 changes: 187 additions & 0 deletions gtk/sample/gtk-demo/appwindow.rb
@@ -0,0 +1,187 @@
# $Id: appwindow.rb,v 1.1 2003/02/25 15:07:22 kzys Exp $
=begin
= Application main window
Demonstrates a typical application window, with menubar, toolbar, statusbar.
=end
require 'common'
require 'gdk_pixbuf2'

module Demo
class AppWindow < BasicWindow
def initialize
register_stock_icons

## Create toplevel window
super('Application Window')

table = Gtk::Table.new(1, 4, false)
add(table)

## Create the menubar
accel_group = Gtk::AccelGroup.new
add_accel_group(accel_group)

item_factory = Gtk::ItemFactory.new(Gtk::ItemFactory::TYPE_MENU_BAR,
'<main>', accel_group)
# create menu items
menuitem_cb = proc do |data, widget|
# TODO: Show item-factory's path to menu item
dialog = Gtk::MessageDialog.new(self,
Gtk::Dialog::DESTROY_WITH_PARENT,
Gtk::MessageDialog::INFO,
Gtk::MessageDialog::BUTTONS_CLOSE,
"You selected or toggled the menu item \"#{Gtk::ItemFactory.path_from_widget(widget)}\"")

# Close dialog on user response
dialog.signal_connect('response') do |widget, data|
widget.destroy
end

dialog.show
end

menu_items = [
["/_File"],
["/_File/_New",
"<StockItem>", "<control>N", Gtk::Stock::NEW, menuitem_cb],
["/_File/_Open",
"<StockItem>", "<control>O", Gtk::Stock::OPEN, menuitem_cb],
["/File/_Save",
"<StockItem>", "<control>S", Gtk::Stock::SAVE, menuitem_cb],
["/File/Save _As...",
"<StockItem>", nil, Gtk::Stock::SAVE, menuitem_cb],
["/File/sep1",
"<Separator>", nil, nil, menuitem_cb],
["/File/Quit",
"<StockItem>", "<control>Q", Gtk::Stock::QUIT, menuitem_cb],

["/_Preferences"],
["/_Preferences/_Color"],
["/_Preferences/Color/_Red",
"<RadioItem>", nil, nil, menuitem_cb],
["/_Preferences/Color/_Green",
"/Preferences/Color/Red", nil, nil, menuitem_cb],
["/_Preferences/Color/_Blue",
"/Preferences/Color/Red", nil, nil, menuitem_cb],

["/Preferences/_Shape"],
["/Preferences/Shape/_Square",
"<RadioItem>", nil, nil, menuitem_cb],
["/Preferences/Shape/_Rectangle",
"/Preferences/Shape/Square", nil, nil, menuitem_cb],
["/Preferences/Shape/_Oval",
"/Preferences/Shape/Square", nil, nil, menuitem_cb],

# If you wanted this to be right justified you would use
# "<LastBranch>", not "<Branch>". Right justified help menu
# items are generally considered a bad idea now days.
["/_Help"],
["/Help/_About", "<Item>", nil, nil, menuitem_cb],
]
item_factory.create_items(menu_items)

table.attach(item_factory.get_widget('<main>'),
# X direction # Y direction
0, 1, 0, 1,
Gtk::EXPAND | Gtk::FILL, 0,
0, 0)

## Create the toolbar
toolbar = Gtk::Toolbar.new
# toolbar.set_toolbar_style(Gtk::Toolbar::BOTH)
toolbar.insert(-1,
Gtk::Stock::OPEN,
"This is a demo button with an 'open' icon",
nil, -1) do toolbar_cb end
toolbar.insert(-1,
Gtk::Stock::QUIT,
"This is a demo button with an 'quit' icon",
nil, -1) do toolbar_cb end
toolbar.append_space
toolbar.insert(-1,
:demo_gtk_logo,
"This is a demo button with an 'gtk' icon",
nil) do toolbar_cb end
table.attach(toolbar,
# X direction # Y direction
0, 1, 1, 2,
Gtk::EXPAND | Gtk::FILL, 0,
0, 0)

## Create document
sw = Gtk::ScrolledWindow.new
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
sw.shadow_type = Gtk::SHADOW_IN
table.attach(sw,
# X direction # Y direction
0, 1, 2, 3,
Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL,
0, 0)

set_default_size(200, 200)

contents = Gtk::TextView.new
sw.add(contents)

## Create statusbar
statusbar = Gtk::Statusbar.new
table.attach(statusbar,
# X direction # Y direction
0, 1, 3, 4,
Gtk::EXPAND | Gtk::FILL, 0,
0, 0)

# Show text widget info in the statusbar
buffer = contents.buffer
buffer.signal_connect('changed') do |buffer|
update_statusbar(buffer, statusbar)
end
# cursor moved
buffer.signal_connect('mark_set') do |buffer, iter, mark|
update_statusbar(buffer, statusbar)
end
end

def toolbar_cb(*args)
dialog = Gtk::MessageDialog.new(self,
Gtk::Dialog::DESTROY_WITH_PARENT,
Gtk::MessageDialog::INFO,
Gtk::MessageDialog::BUTTONS_CLOSE,
"You selected a toolbar button")

# Close dialog on user response
dialog.signal_connect('response') do |widget, data|
widget.destroy
end

dialog.show
end

def update_statusbar(buffer, statusbar)
statusbar.pop(0)

iter = buffer.get_iter_at_mark(buffer.get_mark('insert'))

statusbar.push(0,
"Cursor at row #{iter.line} column #{iter.line_offset} - #{buffer.char_count} chars in document")
end

def register_stock_icons
# Register our stock items
Gtk::Stock.add(:demo_gtk_logo, '_GTK!')

# Add out custom icon factory to the list of defaults
factory = Gtk::IconFactory.new
factory.add_default

filename = Demo.find_file('gtk-logo-rgb.gif')
pixbuf = Gdk::Pixbuf.new(filename)

transparent = pixbuf.add_alpha(true, 0xff, 0xff, 0xff)

icon_set = Gtk::IconSet.new(transparent)
factory.add('demo_gtk_logo', icon_set)
end
end
end
81 changes: 81 additions & 0 deletions gtk/sample/gtk-demo/button_box.rb
@@ -0,0 +1,81 @@
# $Id: button_box.rb,v 1.1 2003/02/25 15:07:22 kzys Exp $
=begin
= Button Boxes
The Button Box widgets are used to arrange buttons with padding.
=end
require 'common'

module Demo
class ButtonBox < BasicWindow
def initialize
super('Button Boxes')
set_border_width(10)

main_vbox = Gtk::VBox.new(false, 0)
add(main_vbox)

frame_horiz = Gtk::Frame.new('Horizontal Button Boxes')
main_vbox.pack_start(frame_horiz, true, true, 10)

vbox = Gtk::VBox.new(false, 0)
vbox.set_border_width(10)
frame_horiz.add(vbox)

vbox.pack_start(create_bbox(true, 'Spread', 40, Gtk::ButtonBox::SPREAD),
true, true, 0)

vbox.pack_start(create_bbox(true, 'Edge', 40, Gtk::ButtonBox::EDGE),
true, true, 5)

vbox.pack_start(create_bbox(true, 'Start', 40, Gtk::ButtonBox::START),
true, true, 5)

vbox.pack_start(create_bbox(true, 'End', 40, Gtk::ButtonBox::END),
true, true, 5)

frame_vert = Gtk::Frame.new('Vertical Button Boxes')
main_vbox.pack_start(frame_vert, true, true, 10)

hbox = Gtk::HBox.new(false, 0)
hbox.set_border_width(10)
frame_vert.add(hbox)

hbox.pack_start(create_bbox(false, 'Spread', 30, Gtk::ButtonBox::SPREAD),
true, true, 0)

hbox.pack_start(create_bbox(false, 'Edge', 30, Gtk::ButtonBox::EDGE),
true, true, 5)

hbox.pack_start(create_bbox(false, 'Start', 30, Gtk::ButtonBox::START),
true, true, 5)

hbox.pack_start(create_bbox(false, 'End', 30, Gtk::ButtonBox::END),
true, true, 5)

end

def create_bbox(horizontal, title, spacing, layout)
frame = Gtk::Frame.new(title)

bbox = if horizontal
Gtk::HButtonBox.new
else
Gtk::VButtonBox.new
end

bbox.set_border_width(5)
frame.add(bbox)

bbox.layout_style = layout
bbox.set_spacing(spacing)

[Gtk::Stock::OK, Gtk::Stock::CANCEL, Gtk::Stock::HELP].each do |stock|
button = Gtk::Button.new(stock)
bbox.add(button)
end

return frame
end
end
end
81 changes: 81 additions & 0 deletions gtk/sample/gtk-demo/colorsel.rb
@@ -0,0 +1,81 @@
# $Id: colorsel.rb,v 1.1 2003/02/25 15:07:22 kzys Exp $
=begin
= Color Selector
GtkColorSelection lets the user choose a color. GtkColorSelectionDialog is
a prebuilt dialog containing a GtkColorSelection.
=end
require 'common'

module Demo
class ColorSel < BasicWindow
def initialize
super('Color Selection')

@color = Gdk::Color.new(0, 0, 65535)

set_border_width(8)

vbox = Gtk::VBox.new(false, 0)
vbox.set_border_width(8)
add(vbox)

## Create the color swatch area
@frame = Gtk::Frame.new
@frame.set_shadow_type(Gtk::SHADOW_IN)
vbox.pack_start(@frame, true, true, 0)

@da = Gtk::DrawingArea.new

@da.signal_connect('expose_event') do |widget, event|
if widget.window
style = widget.style

widget.window.draw_rectangle(style.bg_gc(Gtk::STATE_NORMAL),
true,
event.area.x, event.area.y,
event.area.width, event.area.height)
end
end

# set a minimum size
@da.set_size_request(200, 200)
# set the color
@da.modify_bg(Gtk::STATE_NORMAL, @color)

@frame.add(@da)

alignment = Gtk::Alignment.new(1.0, 0.5, 0.0, 0.0)

button = Gtk::Button.new('_Change the above color', true)
alignment.add(button)

vbox.pack_start(alignment, false, false, 0)

button.signal_connect('clicked') do
change_color_callback
end
end

def change_color_callback
dialog = Gtk::ColorSelectionDialog.new('Changing color')

dialog.set_transient_for(self)

colorsel = dialog.colorsel

colorsel.set_previous_color(@color)
colorsel.set_current_color(@color)
colorsel.set_has_palette(true)

response = dialog.run

if response == Gtk::Dialog::RESPONSE_OK
@color = colorsel.current_color
@da.modify_bg(Gtk::STATE_NORMAL, @color)
end

dialog.destroy
end
end
end
34 changes: 34 additions & 0 deletions gtk/sample/gtk-demo/common.rb
@@ -0,0 +1,34 @@
# $Id: common.rb,v 1.1 2003/02/25 15:07:22 kzys Exp $
require 'gtk2'

module Demo
def self.find_file(basename)
%w(. /usr/share/gtk-2.0/demo).each do |dirname|
path = File.join(dirname, basename)
if File.exist?(path)
return path
end
end
raise Exception
end

class BasicWindow < Gtk::Window
def initialize(title = nil)
puts "#{self.class}#initialize"

super(Gtk::Window::TOPLEVEL)
if title
set_title("#{title} in Ruby/GTK")
end

signal_connect("delete_event") do |widget, event|
quit
end
end

def quit
hide
true
end
end
end

0 comments on commit 42abc2f

Please sign in to comment.