rgw 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ #encoding: UTF-8
2
+
3
+ =begin
4
+ RadioRevealer is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public
6
+ License as published by the Free Software Foundation; either
7
+ version 2.1 of the License, or (at your option) any later version.
8
+
9
+ RadioRevealer is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with RadioRevealer; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ Copyright 2014 Detlef Reichl detlef!reichl()gmx!org
19
+ =end
20
+
21
+ module Rgw
22
+ class RadioRevealer < Gtk::Box
23
+ self.type_register
24
+ self.signal_new :revealed, GLib::Signal::RUN_FIRST, nil, GLib::Type['void'], Integer
25
+ def signal_do_revealed foo; end
26
+
27
+ def initialize
28
+ super(:orientation => :vertical)
29
+
30
+ @radioGroup = nil
31
+ @revealers = []
32
+ @revealerButtons = []
33
+ @lastRevealed = nil
34
+ end
35
+
36
+
37
+ def create_entry head, child=nil
38
+ button = nil
39
+ label = nil
40
+ if head.is_a? Gtk::Widget
41
+ label = head
42
+ else
43
+ label = create_group_label head
44
+ end
45
+
46
+ if @radioGroup.nil?
47
+ button = Gtk::RadioButton.new
48
+ @radioGroup = button
49
+ else
50
+ button = Gtk::RadioButton.new @radioGroup
51
+ end
52
+ @revealerButtons << button
53
+ button.add label
54
+
55
+ pack_start button, :expand => false, :fill => false, :padding => 6
56
+ button.signal_connect(:toggled) do |btn|
57
+ @revealerButtons.each_with_index do |widget, idx|
58
+ if widget.active?
59
+ if idx != @lastRevealed
60
+ @revealers[@lastRevealed].reveal_child = false unless @lastRevealed.nil?
61
+ @revealers[idx].reveal_child = true
62
+ @lastRevealed = idx
63
+ signal_emit :revealed, idx
64
+ end
65
+ break
66
+ end
67
+ end
68
+ end
69
+ rev = Gtk::Revealer.new
70
+ @revealers << rev
71
+ pack_start rev, :expand => false, :fill => false, :padding => 6
72
+
73
+ rev.add child unless child.nil?
74
+
75
+ if @revealers.length() == 1
76
+ rev.reveal_child = true
77
+ @lastRevealed = 0
78
+ end
79
+ end
80
+
81
+
82
+ def set_child idx, child
83
+ raise ArguentError, "invalid index %i" % idx.to_i unless (0..@revealers.length).cover?(idx)
84
+ @revealers[idx].remove @revealers[idx].child unless @revealers[idx].child.nil?
85
+ @revealers[idx].add child
86
+ end
87
+
88
+
89
+ def set_activate idx
90
+ raise ArguentError, "invalid index %i" % idx.to_i unless (0..@revealers.length).cover?(idx)
91
+ @revealerButtons[idx].active = true
92
+ end
93
+ alias_method :active=, :set_activate
94
+
95
+
96
+ def active
97
+ idx
98
+ end
99
+
100
+
101
+ def create_group_label text
102
+ label = Gtk::Label.new.set_xalign(0.04)
103
+ label.markup = '<span size="large" weight="bold">' + text + '</span>'
104
+ label
105
+ end
106
+
107
+
108
+ end
109
+ end
@@ -0,0 +1,129 @@
1
+ #encoding: UTF-8
2
+
3
+ =begin
4
+ RestrictedEntry is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public
6
+ License as published by the Free Software Foundation; either
7
+ version 2.1 of the License, or (at your option) any later version.
8
+
9
+ RestrictedEntry is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with RestrictedEntry; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ Copyright 2014 Detlef Reichl detlef!reichl()gmx!org
19
+ =end
20
+
21
+
22
+ require 'i18n-toolbox'
23
+
24
+ # Rgw::RestrictionEntry is a specialized Gtk::Entry, that can be restricted so that only valid
25
+ # Numerics can be entered. For this the locale under which the program runs is taken into account.
26
+ # Also the range of the input can be limited. For numerics it will limit the number range, for
27
+ # strings the length of the in put.
28
+
29
+ module Rgw
30
+ class RestrictedEntry < Gtk::Entry
31
+ alias_method :text_parent, :text
32
+ # Initialize a new Rgw::RestrictedEntry object
33
+ def initialize
34
+ super()
35
+ @restriction = :none
36
+ @lcNumeric = I18nToolbox::LcNumeric.new
37
+ @beepOnError = true
38
+ @isValid = false
39
+ @range = nil
40
+
41
+ @matchInteger = Regexp.new /[0-9-]/
42
+ @matchFloat = Regexp.new /[0-9#{@lcNumeric.delimiter.chr}-]/
43
+ @matchFloatString = Regexp.new /^\-?[0-9]*#{@lcNumeric.delimiter.chr}{,1}[0-9]*$/
44
+
45
+ signal_connect(:insert_text) {|wid, str| signal_emit_stop :insert_text unless chr_valid? str}
46
+ signal_connect_after(:insert_text) {str_valid?}
47
+ signal_connect_after(:delete_text) {str_valid?}
48
+ end
49
+
50
+
51
+ # Sets the restriction to the entry. Only characters which match the selected type will show
52
+ # up in the entry.
53
+ #
54
+ # @param rest [:integer, :float, :none] The entry will be limited to characters to display
55
+ # Integers (:integer), Floats (:float) or has no restriction (:none)
56
+ def restriction=(rest)
57
+ raise ArgumentError, "invalid type %s for restriction" % rest.class.to_s unless rest.is_a? Symbol
58
+ raise ArgumentError, "invalid restriction %s" % rest.to_s unless [:integer, :float, :none].include? rest
59
+ @restriction = rest
60
+ end
61
+
62
+
63
+ # Set the range of valid values for the entry
64
+ #
65
+ # param rg [Range] for a restriction of :integer or :float the range gives the minimum and
66
+ # maximum values, which are allowed.
67
+ # for a restriction of :none the range gives the minimum or maximum length of the
68
+ # inserted string
69
+ def range=(rg)
70
+ raise ArgumentError, "invalid type %s for range" % rg.class.to_s unless rg.is_a? Range
71
+ raise ArgumentError, "range has to be numeric" unless rg.first.is_a? Numeric and rg.last.is_a? Numeric
72
+ raise ArgumentError, "range start has to be positive for none-restrictions" if @restriction == :none and rg.first < 0
73
+ @range = rg
74
+ end
75
+
76
+
77
+ # Enables to beep if the string does not represent a valid number, i.e. has two decimal
78
+ # points or is empty
79
+ #
80
+ # @param beep [true, false] if beeping should be enabled
81
+ def beep_on_error=(beep)
82
+ @beepOnError = beep == true
83
+ end
84
+
85
+
86
+ # Returns the text of the entry
87
+ #
88
+ # @return [String, nil] Returns the string, if it is valid or nil if it is not.
89
+ def text
90
+ return super() if str_valid?
91
+ nil
92
+ end
93
+
94
+
95
+ private
96
+ # Checks if the text in the entry is a valid numeric representation
97
+ def str_valid?
98
+ txt = self.text_parent
99
+ if @restriction == :none
100
+ unless @range.nil?
101
+ @isValid = @range.cover? txt.length
102
+ else
103
+ @isValid = true
104
+ end
105
+ else
106
+ @isValid = 0 < txt.length
107
+ @isValid &= @matchFloatString =~ txt
108
+ @isValid &= @range.cover? @lcNumeric.to_f txt unless @range.nil?
109
+ end
110
+ @isValid ? set_secondary_icon_stock('') : set_secondary_icon_stock('gtk-dialog-warning')
111
+ Gdk.beep if !@isValid and @beepOnError
112
+ @isValid
113
+ end
114
+
115
+
116
+ # Checks if a single character is valid for the selected restriction
117
+ def chr_valid? str
118
+ return true if @restriction == :none
119
+
120
+ if @restriction == :integer
121
+ return @matchInteger =~ str
122
+ end
123
+
124
+ if @restriction == :float
125
+ return @matchFloat =~ str
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,78 @@
1
+ # encoding: UTF-8
2
+
3
+ =begin
4
+ SyncedSpinButton is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public
6
+ License as published by the Free Software Foundation; either
7
+ version 2.1 of the License, or (at your option) any later version.
8
+
9
+ SyncedSpinButton is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with SyncedSpinButton; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ Copyright 2014 Detlef Reichl detlef!reichl()gmx!org
19
+ =end
20
+
21
+ module Rgw
22
+ PIXMAP_PATH = File.expand_path(File.dirname(__FILE__) + '/../data/pixmaps/') + '/'
23
+ class SyncedSpinButton < Gtk::Box
24
+ self.type_register
25
+ self.signal_new :value1_changed, GLib::Signal::RUN_FIRST, nil, GLib::Type['void'], Object
26
+ self.signal_new :value2_changed, GLib::Signal::RUN_FIRST, nil, GLib::Type['void'], Object
27
+ def signal_do_value1_changed foo; end
28
+ def signal_do_value2_changed foo; end
29
+
30
+
31
+ def initialize min, max, step, locked
32
+ super(:orientation => :horizontal)
33
+ @locked = locked
34
+
35
+ @s1 = Gtk::SpinButton.new min, max, step
36
+ @s2 = Gtk::SpinButton.new min, max, step
37
+
38
+ @s1.signal_connect(:value_changed) do
39
+ signal_emit :value1_changed, @s1.value
40
+ next unless @locked
41
+ @s2.value = @s1.value if @s2.value != @s1.value
42
+ end
43
+
44
+ @s2.signal_connect(:value_changed) do
45
+ signal_emit :value2_changed, @s2.value
46
+ next unless @locked
47
+ @s1.value = @s2.value if @s1.value != @s2.value
48
+ end
49
+
50
+ lb = Gtk::ToggleButton.new
51
+ lb.active = @locked
52
+ img = Gtk::Image.new(:file => Rgw::PIXMAP_PATH + (locked ? 'lock16.png' : 'unlock16.png'))
53
+ lb << img
54
+ lb.signal_connect(:toggled) do
55
+ @locked = lb.active?
56
+ img.file = @locked ? Rgw::PIXMAP_PATH + 'lock16.png' : PIXMAP_PATH + 'unlock16.png'
57
+ @s2.value = @s1.value if @locked
58
+ end
59
+
60
+ pack_start @s1, :expand => true, :fill => true, :padding => 0
61
+ pack_start lb, :expand => false, :fill => false, :padding => 0
62
+ pack_start @s2, :expand => true, :fill => true, :padding => 0
63
+ end
64
+
65
+
66
+ def set_values v1, v2
67
+ raise RangeError, 'value 1 out of range' if v1 < @s1.range.min or v1 > @s1.range.max
68
+ raise RangeError, 'value 2 out of range' if v2 < @s2.range.min or v1 > @s2.range.max
69
+ @s1.value = v1
70
+ @s2.value = v2
71
+ end
72
+
73
+
74
+ def get_values
75
+ [@s1.value, @s2.value]
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,129 @@
1
+ #encoding: UTF-8
2
+
3
+ =begin
4
+ Types is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public
6
+ License as published by the Free Software Foundation; either
7
+ version 2.1 of the License, or (at your option) any later version.
8
+
9
+ Types is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with Types; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ Copyright 2014 Detlef Reichl detlef!reichl()gmx!org
19
+ =end
20
+
21
+
22
+ # this are some extension to standard types
23
+
24
+ class Float
25
+ def near f
26
+ self * 1.000000001 > f and self * 0.999999999 < f
27
+ end
28
+ end
29
+
30
+
31
+ class Numeric
32
+ def min a
33
+ self <= a ? self : a
34
+ end
35
+
36
+
37
+ def max a
38
+ self >= a ? self : a
39
+ end
40
+
41
+
42
+ def in a, b
43
+ a.min(b) < self && self < a.max(b)
44
+ end
45
+
46
+
47
+ def clamp min, max
48
+ s = self.max(min)
49
+ s.min(max)
50
+ end
51
+ end
52
+
53
+
54
+ class Fifo < Array
55
+ def initialize l
56
+ raise ArgumentError, "length has to be >= 1" if l.to_i < 1
57
+ @lng = l.to_i
58
+ super()
59
+ end
60
+
61
+ def push item
62
+ super
63
+ self.delete_at(0) if self.length > @lng
64
+ end
65
+
66
+ def max
67
+ @lng
68
+ end
69
+
70
+ def resize l
71
+ @lng = l
72
+ while(self.length > @lng)
73
+ self.delete_at(0)
74
+ end
75
+ end
76
+
77
+ alias << push
78
+ end
79
+
80
+
81
+ class Rectangle
82
+ def initialize x=0.0, y=0.0, w=0.0, h=0.0
83
+ @x = x
84
+ @y = y
85
+ @width = w
86
+ @height = h
87
+ end
88
+ attr_reader :x, :y, :width, :height
89
+
90
+ def x=(x)
91
+ raise ArgumentError, 'invallid type for pos x' unless x.is_a? Numeric
92
+ @x = x.to_f
93
+ end
94
+
95
+
96
+ def y=(y)
97
+ raise ArgumentError, 'invallid type for pos y' unless y.is_a? Numeric
98
+ @y = y.to_f
99
+ end
100
+
101
+
102
+ def width=(w)
103
+ raise ArgumentError, 'invallid type for width' unless w.is_a? Numeric
104
+ raise ArgumentError, 'width has to be >= 0' unless w >= 0.0
105
+ @width = w.to_f
106
+ end
107
+
108
+
109
+ def height=(h)
110
+ raise ArgumentError, 'invallid type for height' unless h.is_a? Numeric
111
+ raise ArgumentError, 'height has to be >= 0' unless h >= 0.0
112
+ @height = h.to_f
113
+ end
114
+
115
+
116
+ def in x, y
117
+ x >= @x and x <= @x + @width and y >= @y and y <= @y + @height
118
+ end
119
+
120
+
121
+ def grow!(val)
122
+ @x -= val
123
+ @y -= val
124
+ @width += (val * 2.0)
125
+ @height += (val * 2.0)
126
+ end
127
+ end
128
+
129
+
@@ -0,0 +1,3 @@
1
+ module Rgw
2
+ VERSION = [0, 5, 0]
3
+ end