changeset 0:87b46f01d08d

Initial commit
author unexist
date Sat, 12 Dec 2009 22:33:59 +0100
parents
children 60b9314c5115
files subtly.rb subtly/browser.rb subtly/gdk.rb subtly/glib.rb subtly/gtk.rb subtly/webkit.rb
diffstat 6 files changed, 517 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/subtly.rb	Sat Dec 12 22:33:59 2009 +0100
@@ -0,0 +1,17 @@
+#!/usr/bin/ruby
+##
+# @package subtly
+#
+# @file subtly
+# @author Christoph Kappel <unexist@dorfelite.net>
+# @version $Id$
+#
+# This program can be distributed under the terms of the GNU GPL.
+##
+ 
+require "subtly/browser"
+
+b = Subtly::Browser.new
+b.add_key(:OpenUri => "o")
+b.load("http://www.google.de")
+b.run
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/subtly/browser.rb	Sat Dec 12 22:33:59 2009 +0100
@@ -0,0 +1,55 @@
+ ##
+ # @package subtly
+ #
+ # @file Browser class
+ # @author Christoph Kappel <unexist@dorfelite.net>
+ # @version $Id$
+ #
+ # This program can be distributed under the terms of the GNU GPL.
+ ##
+ 
+require "subtly/glib"
+require "subtly/gtk"
+require "subtly/gdk"
+require "subtly/webkit"
+
+module Subtly
+  class Browser < Subtly::Gtk::Runner
+    attr_accessor :win, :scrolled, :label, :box, :view
+
+    def initialize
+      super
+
+      # Create widgets
+      @win      = Subtly::Gtk::Window.new
+      @scrolled = Subtly::Gtk::Scrolled.new
+      @label    = Subtly::Gtk::Label.new("subtly")
+      @box      = Subtly::Gtk::VBox.new(true, 0)
+      @view     = Subtly::Webkit::View.new
+
+      # Containers
+      @win.add(@box)
+      @scrolled.add(@view)
+
+      # Boxes
+      @box.add(@scrolled, true, true, 0)
+      @box.add(@label,    true, true, 0)
+
+      # Options
+      @win.default_size = [ 800, 600 ]
+      @win.title        = "Subtly"
+      @win.show_all
+
+      # Colors
+      #set_colors(@bar, "white", "black")
+    end
+
+    def load(uri)
+      @view.uri  = uri
+      @label.text = uri
+    end
+
+    def add_key(hash)
+    end
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/subtly/gdk.rb	Sat Dec 12 22:33:59 2009 +0100
@@ -0,0 +1,46 @@
+##
+# @package subtly
+#
+# @file Gdk bindings
+# @author Christoph Kappel <unexist@dorfelite.net>
+# @version $Id$
+#
+# This program can be distributed under the terms of the GNU GPL.
+##
+
+require "ffi"
+
+module Subtly
+  module Gdk
+    extend FFI::Library
+
+    ffi_lib("libgdk-x11-2.0")
+
+    ## thread_enter
+    # Enter protected area
+    ##
+   
+    attach_function(:thread_enter,
+      :gdk_threads_init, [ ], :void
+    )
+
+    ## thread_leave
+    # Leave protected area
+    ##  
+   
+    attach_function(:thread_leave,
+      :gdk_threads_enter, [ ], :void
+    )
+
+    ## parse_color
+    # Parse color name
+    #
+    # @param  [String,  #read]   Color name
+    # @param  [Pointer, #write]  Store color here
+    ##
+   
+    attach_function(:parse_color,
+      :gdk_color_parse, [ :string, :pointer ], :void
+    )
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/subtly/glib.rb	Sat Dec 12 22:33:59 2009 +0100
@@ -0,0 +1,29 @@
+##
+# @package subtly
+#
+# @file Glib bindings
+# @author Christoph Kappel <unexist@dorfelite.net>
+# @version $Id$
+#
+# This program can be distributed under the terms of the GNU GPL.
+##
+
+require "ffi"
+
+module Subtly
+  module Glib
+    extend FFI::Library
+
+    ffi_lib("libgthread-2.0")
+
+    ## thread_init
+    # Init thread system
+    #
+    # @param  [Pointer, #read]  Just don't use, #GThreadFunctions
+    ##
+
+    attach_function(:thread_init,
+      :g_thread_init, [ :pointer ], :void
+    )
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/subtly/gtk.rb	Sat Dec 12 22:33:59 2009 +0100
@@ -0,0 +1,314 @@
+##
+# @package subtly
+#
+# @file Gtk bindings
+# @author Christoph Kappel <unexist@dorfelite.net>
+# @version $Id$
+#
+# This program can be distributed under the terms of the GNU GPL.
+##
+
+require "ffi"
+require "subtly/glib"
+
+module Subtly
+  module Gtk
+    class Runner # {{{
+      extend FFI::Library
+
+      ffi_lib("libgtk-x11-2.0")    
+
+      def initialize
+        Subtly::Glib.thread_init(nil)
+        Subtly::Gtk::Runner.ffi_init(nil, nil)
+      end
+
+      def run
+        Subtly::Gtk::Runner.ffi_run
+      end
+
+      ## init
+      # Init Gtk system
+      #
+      # @param  [Pointer, #read]  Parent widget
+      ##
+
+      attach_function(:ffi_init,                   
+        :gtk_init, [ :pointer, :pointer ], :void
+      )
+
+      ## run
+      # Run Gtk main loop
+      ##
+
+      attach_function(:ffi_run,
+        :gtk_main, [ ], :void
+      )
+
+      ## quit
+      # Quit Gtk main loop
+      ##
+
+      attach_function(:ffi_quit,
+        :gtk_main_quit, [ ], :void
+      )
+    end # }}}
+
+    class Widget # {{{
+      extend FFI::Library
+
+      ffi_lib("libgtk-x11-2.0")
+
+      # States
+      enum(:state,
+      [
+        :normal, 1,
+        :active,
+        :prelight,
+        :selected,
+        :insensitive
+      ])
+      
+      ## set_fg
+      # Set foreground color of widget
+      #
+      # @param  [Pointer, #read]  Widget to set color
+      # @param  [State,   #read]  Widget state
+      # @param  [Pointer, #read]  Color to set
+      ##
+
+      attach_function(:set_fg,
+        :gtk_widget_modify_fg, [ :pointer, :state, :pointer ], :void
+      )
+
+      ## set_fg
+      # Set background color of widget
+      #
+      # @param  [Pointer, #read]  Widget to set color
+      # @param  [State,   #read]  Widget state
+      # @param  [Pointer, #read]  Color to set
+      ##
+
+      attach_function(:set_bg,
+        :gtk_widget_modify_bg, [ :pointer, :state, :pointer ], :void
+      )
+    end # }}}
+
+    class Window # {{{
+      attr_accessor :widget
+
+      extend FFI::Library
+
+      ffi_lib("libgtk-x11-2.0")
+
+      def initialize
+        @widget = Subtly::Gtk::Window.ffi_new(0)
+      end
+
+      def title=(str)
+        Subtly::Gtk::Window.ffi_set_title(@widget, str)
+      end
+
+      def default_size=(array)
+        Subtly::Gtk::Window.ffi_set_size(@widget, array[0], array[1])
+      end
+
+      def show_all
+        Subtly::Gtk::Window.ffi_show_all(@widget)
+      end
+
+      def add(widget)
+        Subtly::Gtk::Window.ffi_add(@widget, widget.to_wid)
+      end
+
+      def to_wid
+        @widget
+      end
+
+      ## ffi_new
+      # Create window
+      #
+      # @param  [Fixnum, #read]  Window type, #GtkWindowType
+      # @return [Pointer] Return the new widget
+      ##
+     
+      attach_function(:ffi_new,
+        :gtk_window_new, [ :int ], :pointer
+      )
+
+      ## ffi_set_title
+      # Set window title
+      #
+      # @param  [Pointer, #read]  Window to set title
+      # @param  [String,  #read]  Window title
+      ##
+
+      attach_function(:ffi_set_title,
+        :gtk_window_set_title, [:pointer, :string], :void
+      )
+
+      ## ffi_set_size
+      # Set default size of widget
+      #
+      # @param  [Pointer, #read]  Widget to set size
+      # @param  [Fixnum,  #read]  Width of the widget
+      # @param  [Fixnum,  #read]  Height of the widget
+      ##
+
+      attach_function(:ffi_set_size,
+        :gtk_window_set_default_size, [ :pointer, :int, :int ], :void
+      )      
+
+      ## ffi_show_all
+      # Show all child widgets
+      #
+      # @param  [Pointer, #read]  Parent widget
+      ##
+
+      attach_function(:ffi_show_all,
+        :gtk_widget_show_all, [ :pointer ], :void
+      )
+
+      ## ffi_add_container
+      # Add widget to container
+      #
+      # @param  [Pointer, #read]  Container widget
+      # @param  [Pointer, #read]  Widget to add
+      ##
+
+      attach_function(:ffi_add,
+        :gtk_container_add, [ :pointer, :pointer ], :void
+      )
+    end # }}}
+
+    class VBox # {{{
+      attr_accessor :widget
+
+      extend FFI::Library
+
+      ffi_lib("libgtk-x11-2.0")
+
+      def initialize(homogenous, spacing)
+        @widget = Subtly::Gtk::VBox.ffi_new(homogenous, spacing)
+      end
+
+      def add(widget, expand, fill, padding)
+        Subtly::Gtk::VBox.ffi_add(@widget, widget.to_wid, expand, fill, padding)
+      end
+
+      def to_wid
+        @widget
+      end
+
+      ## create_vbox
+      # Create vbox widget
+      #
+      # @param  [Bool,   #read]  Homogeneous or not
+      # @param  [Fixnum, #read]  Default space between children
+      # @return [Pointer] Return the new widget
+      ##
+
+      attach_function(:ffi_new,
+        :gtk_vbox_new, [ :bool, :int ], :pointer
+      )
+
+      ## ffi_add
+      # Add widget to box
+      #
+      # @param  [Pointer, #read]  Box widget
+      # @param  [Pointer, #read]  Widget to add
+      # @param  [Bool,    #read]  Expand widget
+      # @param  [Bool,    #read]  Fill widget
+      # @param  [Fixnum,  #read]  Padding of children
+      ##
+
+      attach_function(:ffi_add,
+        :gtk_box_pack_start, [:pointer, :pointer, :bool, :bool, :int], :void
+      )      
+    end # }}}
+
+    class Label # {{{
+      attr_accessor :widget
+
+      extend FFI::Library
+
+      ffi_lib("libgtk-x11-2.0")
+
+      def initialize(str)
+        @widget = Subtly::Gtk::Label.ffi_new(str)
+      end
+
+      def text=(str)
+        Subtly::Gtk::Label.ffi_set_text(@widget, str)
+      end
+
+      def to_wid
+        @widget
+      end
+    
+      ## create_label
+      # Create label widget
+      # 
+      # @param  [String, #read]  String to display
+      # @return [Pointer] Return the new widget
+      ##
+
+      attach_function(:ffi_new,
+        :gtk_label_new, [ :string ], :pointer
+      )
+
+      ## set_text
+      # Set widget label text
+      # @param  [Pointer, #read]  Widget to set text
+      # @param  [String,  #read]  String to set
+      ##
+
+      attach_function(:ffi_set_text,
+        :gtk_label_set_text, [ :pointer, :string ], :void
+      )
+    end # }}}
+
+    class Scrolled # {{{
+      attr_accessor :widget
+
+      extend FFI::Library
+
+      ffi_lib("libgtk-x11-2.0")
+
+      def initialize
+        @widget = Subtly::Gtk::Scrolled.ffi_new(nil, nil)
+      end
+
+      def add(widget)
+        Subtly::Gtk::Window.ffi_add(@widget, widget.to_wid)
+      end
+
+      def to_wid
+        @widget
+      end
+
+      ## ffi_new
+      # Create scrolled window
+      #
+      # @param  [Pointer, #read]  Horizontal adjustment, #GtkAdjustment
+      # @param  [Pointer, #read]  Vertical adjustment, #GtkAdjustment
+      # @return [Pointer] Return the new widget
+      ##
+      
+      attach_function(:ffi_new,
+        :gtk_scrolled_window_new, [ :pointer, :pointer ], :pointer
+      )
+
+      ## ffi_add
+      # Add widget to container
+      #
+      # @param  [Pointer, #read]  Container widget
+      # @param  [Pointer, #read]  Widget to add
+      ##
+
+      attach_function(:ffi_add,
+        :gtk_container_add, [ :pointer, :pointer ], :void
+      )      
+    end # }}}
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/subtly/webkit.rb	Sat Dec 12 22:33:59 2009 +0100
@@ -0,0 +1,56 @@
+##
+# @package browser
+#
+# @file Webkit bindings
+# @author Christoph Kappel <unexist@dorfelite.net>
+# @version $Id$
+#
+# This program can be distributed under the terms of the GNU GPL.
+##
+
+require "ffi"
+
+module Subtly
+  module Webkit
+    class View # {{{
+      attr_accessor :widget
+
+      extend FFI::Library
+
+      ffi_lib("libwebkit-1.0")
+
+      def initialize
+        @widget = Subtly::Webkit::View.ffi_new
+      end
+
+      def uri=(uri)
+        Subtly::Webkit::View.ffi_load_uri(@widget, uri)
+      end
+      
+      def to_wid
+        @widget
+      end
+
+      ## ffi_new
+      # Create webkit view
+      #
+      # @return [Pointer] Return the new view
+      ##
+
+      attach_function(:ffi_new,
+        :webkit_web_view_new, [ ], :pointer
+      )
+
+      ## load_uri
+      # Load given uri in view
+      #
+      # @param  [Pointer, #read]  Webkit view, #GtkWidget
+      # @param  [String, #read]   Uri to load
+      ##
+
+      attach_function(:ffi_load_uri,
+        :webkit_web_view_load_uri, [ :pointer, :string ], :void
+      )
+    end # }}}
+  end
+end