Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 8 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
2 .gitignore
@@ -2,5 +2,5 @@
*.xpm
*.gz
.rvmrc
-doc
+.yardoc
ruby-gtk2-1.0.0
View
12 lib/gtk_app.rb
@@ -12,23 +12,29 @@ module GtkApp
autoload :SignalSupport, "#{lib}/gtk_app/signal_support"
autoload :TextBuffer, "#{lib}/gtk_app/text_buffer"
autoload :Observer, "#{lib}/gtk_app/observer"
+ autoload :Drawer, "#{lib}/gtk_app/drawer"
autoload :Version, "#{lib}/gtk_app/version"
+ # Start the main Gtk loop.
def self.run
Gtk::main
end
+ # Stop the main Gtk loop.
def self.quit
Gtk::main_quit
end
+ # Run a single iteration of the main loop while there are pending events
+ # without blocking.
def self.refresh
Gtk::main_iteration_do(false) while Gtk::events_pending?
end
- # @param [Fixnum] time_in_milliseconds
- # @param [Object] controller
- # @param [String] callback
+ # Establish a controller method to be invoked at regular intervals.
+ # @param [Fixnum] time_in_milliseconds Time between calls to the receiver method.
+ # @param [Object] controller The class in which the method exists.
+ # @param [String] callback Receiver method name.
def self.add_timeout(time_in_milliseconds, controller, callback)
GLib::Timeout.add(time_in_milliseconds){ controller.method(:"#{callback}") }
end
View
8 lib/gtk_app/controller.rb
@@ -3,14 +3,18 @@ class Controller
include GtkApp::Helpers
include GtkApp::SignalSupport
- attr_accessor :model, :view
+ # @attribute [rw] model
+ attr_accessor :model
+ # @attr_accessor [rw] view
+ attr_accessor :view
def initialize(&block)
instance_eval(&block) if block_given?
-
+
establish_signal_connections
end
+ # @param [Boolean] with_validations
def quit(with_validations=true)
# TODO: if with_validations
# end
View
36 lib/gtk_app/drawer.rb
@@ -0,0 +1,36 @@
+module GtkApp
+class Drawer < Gtk::Window
+ attr_reader :parent
+
+ def initialize(parent, view)#, builder_file)
+ @parent = parent
+ # super(controller, builder_file)
+ super(Gtk::Window::POPUP)
+ p view.objects
+ add_child(view, view.vboxMain)
+
+ # TODO: normalize the following setup
+ decorated = false
+ # app_paintable = true
+ resizable = true
+ visible = true
+
+ setup_signals
+ show_all # TODO: replace with slide out/in methods
+ end
+
+ private
+
+ def setup_signals
+ @parent.signal_connect('configure-event') do |_window, event|
+ align_to(event.x, event.y, event.width, event.height)
+ end
+ end
+
+ def align_to(x, y, w, h)
+ resize(size[0], h)
+ move(x+w, y)
+ end
+
+end
+end
View
11 lib/gtk_app/helpers.rb
@@ -4,9 +4,14 @@ module Helpers
def log
GtkApp.logger
end
-
- # def config
- # end
+
+ class Array
+
+ def extract_options!
+ last.is_a?(Hash) && last.extractable_options? ? pop : {}
+ end
+
+ end
end
end
View
8 lib/gtk_app/text_buffer.rb
@@ -52,11 +52,15 @@ def redo
place_cursor(s_iter)
end
end
-
+
+ # Retrieve the word at the current cursor position
+ # @return [String] The word.
def word_at_cursor
get_text(*word_bounds).strip
end
+ # Determine the boudaries of the word at the current cursor position.
+ # @return [Array] The start and end iter.
def word_bounds
iter = get_iter_at_offset(cursor_position)
s_iter, e_iter = iter.clone, iter.clone
@@ -74,7 +78,7 @@ def check_spelling(word=nil, s_iter=nil, e_iter=nil)
format(:spell_error, s, e)
end
end
-
+
# Does the
# Gtk::TextTagTable[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ATextTagTable]
# contain any 'spell_error' tags?
View
15 lib/gtk_app/view.rb
@@ -7,10 +7,13 @@ class View < Gtk::Builder
# @param [String] builder_file Path the Gtk builder file
def initialize(controller, builder_file, *args)
super()
+ # options = args.extract_options!
self.add_from_file(builder_file)
self.connect_signals { |handler| controller.method(handler) }
+
+ # self.title = options[:title] if options.key?(:title)
end
-
+
def method_missing(id, *args, &block)
method_name = id.to_s
@@ -46,7 +49,11 @@ def method_missing(id, *args, &block)
nil,
lambda do |row|
iter = widget.model.append
- row.each_with_index { |v,i| iter[i] = v }
+ if row.is_a?(Gtk::TreeIter)
+ (0..model.n_columns).each { |i| iter[i] = row[i] }
+ else
+ row.each_with_index { |v,i| iter[i] = v }
+ end
iter
end ]
else
@@ -56,13 +63,13 @@ def method_missing(id, *args, &block)
lambda { |text| widget.text = ("#{widget.text}" << text) } ]
else [nil, nil, nil]; end
end
-
+
class_eval do
define_method(:"#{widget_name}", lambda { widget })
define_method(:"#{widget_name}!", bang_proc) if bang_proc
define_method(:"#{widget_name}=", equal_proc) if equal_proc
end
-
+
widget.class_eval do
define_method("<<", append_proc)
end if append_proc
View
13 lib/gtk_app/view_helpers.rb
@@ -1,6 +1,7 @@
module GtkApp
module ViewHelpers
+ # Simple way to setup a listview.
# @param [Symbol] Widget name
# @param [Hash]
# @param [Hash] options
@@ -11,29 +12,32 @@ module ViewHelpers
# @yieldparam [String] header Column header text
# @yieldparam [Gtk::TreeViewColumn] column The current column
# @yieldparam [Gtk::CellRenderer] renderer Current column cell renderer
+ # @raise [ExceptionClass] If an unhandled column data type is provided, an
+ # exception is raised.
+ # @example Build a simple listview.
+ # @view.build_listview(:listThings, {id: Integer, name: String})
def build_listview(widget_name, columns, options={}, &block)
list = self.send(:"#{widget_name}")
list.model = Gtk::ListStore.new(*columns.values)
columns.each_with_index do |keyval, index|
header, data_type = keyval
renderer, attrs = case "#{data_type}".to_sym
when :String, :Integer
- [Gtk::CellRendererText.new, :text => index]
+ [Gtk::CellRendererText.new, text: index]
when :TrueClass
toggle = Gtk::CellRendererToggle.new
toggle.signal_connect('toggled') do |widget, path|
iter = list.model.get_iter(path)
iter[index] = !iter[index]
end
- [toggle, :active => index]
+ [toggle, active: index]
when :'Gtk::ListStore'
_renderer = Gtk::CellRendererCombo.new
model = Gtk::ListStore.new(String)
_renderer.signal_connect("edited") do |cell, path, text|
model.get_iter(path)[index] = text
end
- [_renderer, :text_column => 0, :model => model, :text => index,
- :editable => index]
+ [_renderer, text_column: 0, model: model, text: index, editable: index]
else
raise("GtkApp::View##{__method__} does not know how to handle " +
"'#{data_type}' data types.")
@@ -64,6 +68,7 @@ def sensitize(*widgets)
def desensitize(*widgets)
widgets.each { |w| self["#{w}"].sensitive = false }
end
+
end
end
View
39 test/drawer.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkVBox" id="vboxMain">
+ <property name="width_request">200</property>
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <child>
+ <object class="GtkViewport" id="viewport1">
+ <property name="visible">True</property>
+ <property name="resize_mode">queue</property>
+ <child>
+ <object class="GtkTreeView" id="treeviewFiles">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+</interface>
View
2 test/test_application.rb
@@ -113,7 +113,7 @@ def find
fancy_buffer = GtkApp::TextBuffer.new
fancy_buffer.text = File.read(File.dirname(__FILE__) + '/test.txt')
@view.txtView.buffer = fancy_buffer
-
+ GtkApp::Drawer.new(@view.main_window, GtkApp::View.new(self, "./drawer.ui"))
end
GtkApp.run

No commit comments for this range

Something went wrong with that request. Please try again.