Permalink
Browse files

Merge branch 'gui'

  • Loading branch information...
mohawkjohn committed Sep 19, 2011
2 parents 1a75207 + 5773336 commit c0fe25d4529ba8373ad2a07e5ad36743e440ce3a
View
6 .rspec
@@ -0,0 +1,6 @@
+--colour
+--format
+profile
+--timeout
+20
+--diff
View
28 Gemfile
@@ -0,0 +1,28 @@
+# -*- ruby -*-
+
+# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
+
+source :gemcutter
+
+gem "distribution", ">=0.4.0"
+gem "green_shoes", ">=1.0.282" #:path => "/home/jwoods/green_shoes" #:git => "git://github.com/ashbb/green_shoes.git"
+gem "statsample", ">=1.1.0"
+gem "gsl", "~>1.14.5"
+gem "rsvg2", "~>1.0.0"
+gem "rubyvis", ">=0.4.0"
+
+gem "hoe", "~>2.12", :group => [:development, :test]
+gem "rdoc", ">=0", :group => [:development, :test]
+gem "rspec", ">=2.0", :group => [:development, :test]
+gem "haml", ">=0", :group => [:development, :test]
+gem "coderay", ">=0", :group => [:development, :test]
+gem "nokogiri", ">=0", :group => [:development, :test]
+gem "RedCloth", ">=0", :group => [:development, :test]
+gem "shoulda", "~>2.11", :group => [:development, :test]
+gem "gtksourceview2", ">=0", :group => [:development, :test]
+gem "hoe-gemspec", "~>1.0", :group => [:development, :test]
+gem "hoe-bundler", "~>1.1", :group => [:development, :test]
+gem "minitest", "~>2.0", :group => [:development, :test]
+gem "hoe", "~>2.12", :group => [:development, :test]
+
+# vim: syntax=ruby
View
@@ -1,10 +1,15 @@
.autotest
History.txt
Manifest.txt
-README.txt
+readme.md
Rakefile
lib/sciruby.rb
lib/sciruby/validation.rb
lib/sciruby/recommend.rb
+lib/sciruby/plotter.rb
+lib/sciruby/editor.rb
+lib/ext/shoes.rb
+bin/sciruby-plotter
+static/sciruby-icon.png
test/test_recommend.rb
test/helpers_tests.rb
View
@@ -4,6 +4,7 @@
$:.unshift(File.dirname(__FILE__)+'/lib/')
require 'rubygems'
+require 'rdoc/task'
require 'sciruby'
require 'hoe'
@@ -35,28 +36,95 @@ task :console do
sh "irb -rubygems -I lib -r sciruby.rb"
end
+desc "Start the plotter without the console"
+task :plotter, [:script] => [] do |t,args|
+ if args.script.empty?
+ raise ArgumentError, "Need a script, e.g.: rake plotter[script.rb]"
+ else
+ sh "ruby -rubygems -I lib -r sciruby.rb -e 'SciRuby::Plotter.new(\"#{args.script}\")'"
+ end
+end
+
+desc "Start the plotter without the console"
+task :editor do
+ sh "ruby -rubygems -I lib -r sciruby.rb -e 'SciRuby::Editor.new'"
+end
+
task :release do
system %{git push origin master}
end
h = Hoe.spec 'sciruby' do
self.version = SciRuby::VERSION
+ self.require_ruby_version ">=1.9"
self.developer('SciRuby Development Team', 'sciruby-dev@googlegroups.com')
- self.extra_deps = {'distribution' => "~> 0.4.0",
- 'statsample' => "~> 1.1.0",
+ self.extra_deps = {'distribution' => ">=0.4.0",
+ 'green_shoes' => ">=1.0.282",
+ 'statsample' => ">=1.1.0",
'gsl' => "~> 1.14.5",
- 'rubyvis' => '~> 0.4.0' }.to_a
+ 'rsvg2' => '~> 1.0.0',
+ 'rubyvis' => '>=0.4.0' }.to_a
+
self.extra_dev_deps = {'hoe' => "~> 2.12",
+ 'rdoc' => ">=0",
+ 'rspec' => ">=2.0",
+ 'haml' => ">=0", # for Rubyvis
+ 'coderay' => ">=0", # for Rubyvis
+ 'nokogiri' => ">=0", # for Rubyvis
+ 'RedCloth' => ">=0", # for Rubyvis
+ 'gtksourceview2' => ">=0", # for editor
'shoulda' => "~> 2.11",
'hoe-gemspec' => "~> 1.0",
'hoe-bundler' => "~> 1.1",
'minitest' => "~> 2.0" }.to_a
- # self.rubyforge_name = 'scirubyx' # if different than 'sciruby'
+ #self.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
+
+ self.post_install_message = <<-EOF
+***********************************************************
+Welcome to SciRuby: Tools for Scientific Computing in Ruby!
+
+ *** WARNING ***
+Please be aware that SciRuby is in ALPHA status. If you're
+thinking of using SciRuby to write mission critical code,
+such as for driving a car or flying a space shuttle, you
+may wish to choose other software (for now).
+
+In order to leverage the GUI features, you will need to
+install gtk2 and optionally gtksourceview2:
+
+ $ gem install gtk2 gtksourceview2
+
+You will probably first need to install the headers for
+a number of required packages. In Ubuntu, use:
+
+ $ sudo apt-get install libgtk2.0-dev libgtksourceview2-dev \
+ librsvg2-dev libcairo2-dev
+
+If you have trouble with Green Shoes, you should look at
+the Green Shoes wiki:
+
+http://github.com/ashbb/green_shoes/wiki
+
+For Mac OSX Green Shoes:
+
+https://github.com/ashbb/green_shoes/wiki/Building-Green-Shoes-on-OSX
+
+More explicit instructions for SciRuby should be available
+at our website, sciruby.com, or through our mailing list
+(which can also be found on our website).
+
+Thanks for installing SciRuby! Happy hypothesis testing!
+
+***********************************************************
+ EOF
+
+ self.need_rdoc = false
+
end
-Rake::RDocTask.new(:docs) do |rd|
+RDoc::Task.new(:docs) do |rd|
rd.main = h.readme_file
rd.options << '-d' if (`which dot` =~ /\/dot/) unless
ENV['NODOT'] || Hoe::WINDOZE
@@ -96,4 +164,12 @@ task :publish_docs => [:clean, :docs] do
sh %{rsync #{h.rsync_args} #{local_dir}/ #{host}:#{remote_dir}}
end
+require 'rspec/core/rake_task'
+namespace :spec do
+ desc "Run all specs"
+ RSpec::Core::RakeTask.new
+ # options in .rspec in package root
+end
+
+
# vim: syntax=ruby
View
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'sciruby'
+
+STDERR.puts "RUBY_VERSION = #{RUBY_VERSION}"
+
+if ARGV.size == 0
+ STDERR.puts "sciruby-plotter: missing plot script"
+ STDERR.puts "Usage: sciruby-plotter myscript.rb"
+ exit false
+end
+
+SciRuby::Plotter.new ARGV.first
View
@@ -0,0 +1,131 @@
+require "green_shoes"
+
+class Shoes
+ class App
+ # This has been integrated into Green Shoes in the repo, but is not yet in the current gem.
+ # Creates an edit_box for source code editing, using gtksourceview2.
+ def code_box args={}
+ require 'gtksourceview2'
+ args = basic_attributes args
+
+ args[:width] = 400 if args[:width].zero?
+ args[:height] = 300 if args[:height].zero?
+
+ (change_proc = args[:change]; args.delete :change) if args[:change]
+ sv = Gtk::SourceView.new
+ sv.show_line_numbers = true
+ sv.insert_spaces_instead_of_tabs = true
+ sv.smart_home_end = Gtk::SourceView::SMART_HOME_END_ALWAYS
+ sv.tab_width = 2
+ sv.buffer.text = args[:text].to_s
+ sv.buffer.language = Gtk::SourceLanguageManager.new.get_language('ruby')
+ sv.buffer.highlight_syntax = true
+ sv.modify_font(Pango::FontDescription.new(args[:font])) if args[:font]
+
+ cb = Gtk::ScrolledWindow.new
+ cb.set_size_request args[:width], args[:height]
+ cb.set_policy Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC
+ cb.set_shadow_type Gtk::SHADOW_IN
+ cb.add sv
+
+ sv.buffer.signal_connect "changed" do
+ yield @_cb
+ end if block_given?
+
+ @canvas.put cb, args[:left], args[:top]
+
+ cb.show_all
+ args[:real], args[:app], args[:textview] = cb, self, sv
+ @_cb = CodeBox.new(args).tap{|s| s.change &change_proc}
+ end
+
+
+ # Helper function for image() [with no name provided]. Currently only understands SVGs. Converts whatever it's given to
+ # the format needed by Gtk::Image.new().
+ #
+ # Arguments:
+ # * :data can be a string (e.g., for an SVG), an RSVG::Handle, a Gdk::Pixbuf, or even a Gtk::Image. If it can't tell which, it'll try
+ # calling the pixbuf() method on :data, or just returning it as is.
+ # * :format, when it works, will specify the content-type of :data when that is not implicit in the class of :data. For example, if
+ # :data is a string, :format might be :svg.
+ def image_handle args={}
+ if args[:data].is_a?(String)
+ raise(NotImplementedError, "Currently only RSVG::Handle is implemented.") if args.has_key?(:format) && args[:format] != :svg
+ RSVG::Handle.new_from_data(args[:data]).tap{|s|s.close}.pixbuf
+ elsif args[:data].is_a?(RSVG::Handle)
+ args[:data].pixbuf
+ elsif args[:data].is_a?(Gdk::Pixbuf) || args[:data].is_a?(Gtk::Image)
+ args[:data]
+ else
+ # Unknown format. Try asking for a pixbuf, otherwise just assume it's already a pixbuf.
+ args[:data].respond_to?(:pixbuf) ? args[:data].pixbuf : args[:data]
+ end
+ end
+
+
+ # Improvement on Green Shoes' image function: accepts already-loaded images, such as those you might
+ # create in-app. This has mostly been merged into green shoes, but that version is buggy.
+ def image name, args={}
+ # Handle case where no name is given -- typically, :data argument will be set.
+ if name.is_a?(Hash)
+ args = name
+ name = nil
+ raise(ArgumentError, ":data must be set if no name given") unless args.has_key?(:data)
+ end
+
+ args = basic_attributes args
+ args[:full_width] = args[:full_height] = 0
+ (click_proc = args[:click]; args.delete :click) if args[:click]
+
+ if name.nil?
+ img = Gtk::Image.new image_handle(args)
+
+ args[:full_width], args[:full_height] = img.size_request if (!args[:width].zero? or !args[:height].zero?)
+ downloading = false
+
+ elsif name =~ /^(http|https):\/\//
+ tmpname = File.join(Dir.tmpdir, "__green_shoes_#{Time.now.to_f}.png")
+ d = download name, save: tmpname
+ img = Gtk::Image.new File.join(DIR, '../static/downloading.png')
+ downloading = true
+ else
+ img = Gtk::Image.new name
+ downloading = false
+ end
+
+ if (!args[:width].zero? or !args[:height].zero?) and !downloading
+ args[:full_width], args[:full_height] = imagesize(name) unless name.nil?
+ args[:width] = args[:full_width] if args[:width].zero?
+ args[:height] = args[:full_height] if args[:height].zero?
+ img = Gtk::Image.new img.pixbuf.scale(args[:width], args[:height])
+ end
+ @canvas.put img, args[:left], args[:top]
+ img.show_now
+ @canvas.remove img if args[:hidden]
+ args[:real], args[:app], args[:path] = img, self, name
+ Image.new(args).tap do |s|
+ @dics.push([s, d, tmpname]) if downloading
+ s.click &click_proc if click_proc
+ end
+ end
+
+
+ def icon filename=nil
+ filename.nil? ? win.icon : win.icon = filename
+ end
+
+ class << self
+ def default_icon= filename
+ Gtk::Window.set_default_icon(filename)
+ end
+ end
+ end
+
+ class CodeBox < EditBox; end
+end
+
+module SciRuby
+ ICON_PATH = File.join(DIR, '..', 'static', 'sciruby-icon.png')
+end
+
+Shoes::App.default_icon = SciRuby::ICON_PATH
View
@@ -24,9 +24,23 @@
# Specific notices will be placed where they are appropriate.
#
+require "rubygems"
+require "bundler/setup"
+
module SciRuby
- VERSION = '0.1.2'
+ VERSION = '0.1.3'
+ DIR = Pathname.new(__FILE__).realpath.dirname.to_s
+
+ class << self
+ def plot script # &panel
+ SciRuby::Plotter.new script
+ end
+ end
- autoload(:Recommend, 'sciruby/recommend')
- autoload(:Validation, 'sciruby/validation')
+ autoload(:Plotter, File.join(DIR, 'sciruby', 'plotter'))
+ autoload(:Editor, File.join(DIR, 'sciruby', 'editor'))
+ autoload(:Recommend, File.join(DIR, 'sciruby', 'recommend'))
+ autoload(:Validation, File.join(DIR, 'sciruby', 'validation'))
end
+
+autoload(:Shoes, File.join(SciRuby::DIR, 'ext', 'shoes'))
Oops, something went wrong.

0 comments on commit c0fe25d

Please sign in to comment.