gtk2_expander_settings 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "gtk2"
7
+ gem "knjrbfw"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rspec", "~> 2.8.0"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", ">= 1.0.0"
15
+ gem "jeweler", "~> 1.8.4"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ atk (1.1.5)
5
+ glib2 (>= 1.1.5)
6
+ cairo (1.12.2)
7
+ pkg-config
8
+ datet (0.0.19)
9
+ diff-lcs (1.1.3)
10
+ gdk_pixbuf2 (1.1.5)
11
+ glib2 (>= 1.1.5)
12
+ git (1.2.5)
13
+ glib2 (1.1.5)
14
+ pkg-config
15
+ gtk2 (1.1.5)
16
+ atk (>= 1.1.5)
17
+ gdk_pixbuf2 (>= 1.1.5)
18
+ pango (>= 1.1.5)
19
+ http2 (0.0.10)
20
+ jeweler (1.8.4)
21
+ bundler (~> 1.0)
22
+ git (>= 1.2.5)
23
+ rake
24
+ rdoc
25
+ json (1.7.5)
26
+ knjrbfw (0.0.91)
27
+ datet
28
+ http2
29
+ php4r
30
+ tsafe
31
+ wref
32
+ pango (1.1.5)
33
+ cairo (>= 1.10.0)
34
+ glib2 (>= 1.1.5)
35
+ php4r (0.0.3)
36
+ datet
37
+ http2
38
+ pkg-config (1.1.4)
39
+ rake (0.9.2.2)
40
+ rdoc (3.12)
41
+ json (~> 1.4)
42
+ rspec (2.8.0)
43
+ rspec-core (~> 2.8.0)
44
+ rspec-expectations (~> 2.8.0)
45
+ rspec-mocks (~> 2.8.0)
46
+ rspec-core (2.8.0)
47
+ rspec-expectations (2.8.0)
48
+ diff-lcs (~> 1.1.2)
49
+ rspec-mocks (2.8.0)
50
+ tsafe (0.0.11)
51
+ wref (0.0.5)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler (>= 1.0.0)
58
+ gtk2
59
+ jeweler (~> 1.8.4)
60
+ knjrbfw
61
+ rdoc (~> 3.12)
62
+ rspec (~> 2.8.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Kasper Johansen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = gtk2_expander_settings
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to gtk2_expander_settings
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Kasper Johansen. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "gtk2_expander_settings"
18
+ gem.homepage = "http://github.com/kaspernj/gtk2_expander_settings"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A library for remembering expander-settings using a database for the gtk2-extension in Ruby.}
21
+ gem.description = %Q{A library for remembering expander-settings using a database for the gtk2-extension in Ruby.}
22
+ gem.email = "k@spernj.org"
23
+ gem.authors = ["Kasper Johansen"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "gtk2_expander_settings #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gtk2_expander_settings}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kasper Johansen"]
12
+ s.date = %q{2012-08-31}
13
+ s.description = %q{A library for remembering expander-settings using a database for the gtk2-extension in Ruby.}
14
+ s.email = %q{k@spernj.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "gtk2_expander_settings.gemspec",
29
+ "lib/gtk2_expander_settings.rb",
30
+ "spec/gtk2_expander_settings_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/kaspernj/gtk2_expander_settings}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.6.2}
37
+ s.summary = %q{A library for remembering expander-settings using a database for the gtk2-extension in Ruby.}
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<gtk2>, [">= 0"])
44
+ s.add_runtime_dependency(%q<knjrbfw>, [">= 0"])
45
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
46
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
49
+ else
50
+ s.add_dependency(%q<gtk2>, [">= 0"])
51
+ s.add_dependency(%q<knjrbfw>, [">= 0"])
52
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<gtk2>, [">= 0"])
59
+ s.add_dependency(%q<knjrbfw>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
61
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
62
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,65 @@
1
+ #A class that helps saving and restoring settings for expanders using a database.
2
+ class Gtk2_expander_settings
3
+ ALLOWED_ARGS = [:db, :expander, :name]
4
+ DB_SCHEMA = {
5
+ "tables" => {
6
+ "Gtk2_expander_settings" => {
7
+ "columns" => [
8
+ {"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
9
+ {"name" => "name", "type" => "varchar"},
10
+ {"name" => "expanded", "type" => "enum", "maxlength" => "'0','1'"},
11
+ {"name" => "saved", "type" => "enum", "maxlength" => "'0','1'"}
12
+ ],
13
+ "indexes" => ["name"]
14
+ }
15
+ }
16
+ }
17
+
18
+ def initialize(args)
19
+ #Load arguments and database.
20
+ args.each do |key, val|
21
+ raise "Invalid argument: '#{key}'." if !ALLOWED_ARGS.include?(key)
22
+ end
23
+
24
+ @db, @expander, @name = args[:db], args[:expander], args[:name]
25
+
26
+ Knj::Db::Revision.new.init_db("db" => @db, "schema" => DB_SCHEMA)
27
+
28
+ #Load or initialize saved data in database.
29
+ if @data = @db.single(:Gtk2_expander_settings, :name => @name)
30
+ @id = @data[:id]
31
+ else
32
+ @id = @db.insert(:Gtk2_expander_settings, {:name => @name, :saved => 0}, :return_id => true)
33
+ @data = @db.single(:Gtk2_expander_settings, :id => @id)
34
+ end
35
+
36
+ #Restore saved value. Use timeouts to give window time to initialize first (to load code that may effect the expander like in OpenAll-Time-Applet).
37
+ if @data[:saved].to_i == 1
38
+ if @data[:expanded].to_i == 1 and !@expander.expanded?
39
+ Gtk.timeout_add(25) do
40
+ @expander.activate
41
+ false
42
+ end
43
+ elsif @data[:expanded].to_i == 0 and @expander.expanded?
44
+ Gtk.timeout_add(25) do
45
+ @expander.activate
46
+ false
47
+ end
48
+ end
49
+ end
50
+
51
+ #Connect signals in order to save new values.
52
+ @expander.signal_connect_after("activate", &self.method(:on_expander_activated))
53
+ end
54
+
55
+ #Called after the expander is activated.
56
+ def on_expander_activated(*args)
57
+ if @expander.expanded?
58
+ exp_val = 1
59
+ else
60
+ exp_val = 0
61
+ end
62
+
63
+ @db.update(:Gtk2_expander_settings, {:expanded => exp_val, :saved => 1}, {:id => @id})
64
+ end
65
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Gtk2ExpanderSettings" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'gtk2_expander_settings'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gtk2_expander_settings
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Kasper Johansen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-08-31 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: gtk2
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: knjrbfw
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.8.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rdoc
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: "3.12"
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: bundler
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 1.0.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: jeweler
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.8.4
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ description: A library for remembering expander-settings using a database for the gtk2-extension in Ruby.
83
+ email: k@spernj.org
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ files:
92
+ - .document
93
+ - .rspec
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ - Rakefile
99
+ - VERSION
100
+ - gtk2_expander_settings.gemspec
101
+ - lib/gtk2_expander_settings.rb
102
+ - spec/gtk2_expander_settings_spec.rb
103
+ - spec/spec_helper.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/kaspernj/gtk2_expander_settings
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3313718296616835424
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: "0"
128
+ requirements: []
129
+
130
+ rubyforge_project:
131
+ rubygems_version: 1.6.2
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: A library for remembering expander-settings using a database for the gtk2-extension in Ruby.
135
+ test_files: []
136
+