show一下

软件和网站开发以及相关技术探讨
回复
gong
帖子: 439
注册时间: 2008-03-30 10:35
送出感谢: 1 次
接收感谢: 0

show一下

#1

帖子 gong » 2008-04-12 16:07

今天刚刚用ruby + glade 做得实验品。

感觉比用c, cpp简单多了。

很爽!! 特此分享。。。

Glade设计就省略掉。。

main.glade

代码: 全选

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Sat Apr 12 15:39:01 2008 -->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
    <property name="title" translatable="yes">ruby的GTK世界</property>
    <property name="window_position">GTK_WIN_POS_CENTER</property>
    <property name="default_width">170</property>
    <property name="default_height">170</property>
    <signal name="delete_event" handler="on_quit"/>
    <child>
      <widget class="GtkButton" id="button1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
        <property name="label" translatable="yes">button</property>
        <property name="response_id">0</property>
        <signal name="clicked" handler="on_button1_clicked"/>
      </widget>
    </child>
  </widget>
</glade-interface>


然后终端

ruby-glade-create-template main.glade > main.rb

产生ruby模板

代码: 全选

#!/usr/bin/env ruby
#
# This file is gererated by ruby-glade-create-template 1.1.4.
#
require 'libglade2'

class MainGlade
  include GetText

  attr :glade
 
  def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)
    bindtextdomain(domain, localedir, nil, "UTF-8")
    @glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}
    @window = @glade.get_widget("window1") //手工添加
    @button = @glade.get_widget("button1") //手工添加
    @window.show_all //手工添加
  end
 
  def on_button1_clicked(widget)
    @window.title=('你好ruby') //手工添加
    widget.label = 'ruby的GTK世界' //手工添加
  end
  def on_quit(widget, arg0)
    Gtk.main_quit //手工添加
  end
end

# Main program
if __FILE__ == $0
  # Set values as your own application.
  PROG_PATH = "main.glade"
  PROG_NAME = "ruby GTK world"
  MainGlade.new(PROG_PATH, nil, PROG_NAME)
  Gtk.main
end


基本就是这样弄的了。。其他的同理。。然后运行一下ruby ./main.rb
附件
Screenshot.png
头像
lovewine
帖子: 1233
注册时间: 2006-03-25 10:36
送出感谢: 0
接收感谢: 0
联系:

#2

帖子 lovewine » 2008-04-12 16:17

编程又有新天地了!
让自由的声音传传传传传传传传天下。。。
Spread the words of freedom.
回复

回到 “软件/网站开发”