libguib 1.1.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.
data/libguib.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "libguib"
3
+ spec.version = "1.1.0"
4
+ spec.authors = ["Meinrad Recheis aka Henon", "Lars Kanis"]
5
+ spec.email = ["meinrad.recheis@gmail.com", "lars@greiz-reinsdorf.de"]
6
+
7
+ spec.summary = "Helper library for foxGUIb"
8
+ spec.description = "Helper library for the Fox GUI builder"
9
+ spec.homepage = "https://github.com/larskanis/foxGUIb"
10
+ spec.license = "LGPL-2.1"
11
+
12
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
13
+ spec.bindir = "exe"
14
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.required_ruby_version = [">= 2.5", "< 4.0"]
18
+
19
+ spec.add_runtime_dependency "fxruby", "~> 1.6.0"
20
+
21
+ spec.add_development_dependency "bundler", ">= 1.11", "<= 3.0"
22
+ spec.add_development_dependency "rake", "~> 13.0"
23
+ end
data/readme.txt ADDED
@@ -0,0 +1,14 @@
1
+ libGUIb is the foxGUIb library required by the foxGUIb editor and all pieces of generated code.
2
+ it includes the FX API which is a facade of the FXRuby API. foxGUIb is an interactive gui builder
3
+ for fxruby. fxruby is the ruby binding of the Fox Toolkit.
4
+
5
+ libGUIb and foxGUIb are copyrighted by Meinrad Recheis aka Henon. (c) 2006
6
+
7
+
8
+ INSTALLATION:
9
+
10
+ To install libGUIb execute the file install.rb like this:
11
+
12
+ # ruby install.rb
13
+
14
+ LICENSE: LGPL
data/src/Container.rb ADDED
@@ -0,0 +1,103 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ if __FILE__ == $0
4
+ Dir.chdir ".."
5
+ require "FX"
6
+ end
7
+
8
+ module FX
9
+ class Container < FX::VerticalFrame
10
+ attr_reader :header, :hsep
11
+
12
+ def initialize(parent)
13
+ super
14
+ boxMinusPNG_Str =
15
+ "9805e474d0a0a1a0000000d09484442500000090000000904030000010568bb25b000000704794d4" +
16
+ "54704d50016041822c41f2b600000090078495370000b0210000b021102ddde7cf000000407614d4" +
17
+ "1400001bf8b0cf16500000009005c44554484848ffffff0000003e75793f000000229444144587ad" +
18
+ "3606082062011a404cc82801c0402828c024a80221c2c28288584000525c10091d50980600000000" +
19
+ "9454e444ea240628"
20
+ boxPlusPNG_Str =
21
+ "9805e474d0a0a1a0000000d09484442500000090000000904030000010568bb25b000000704794d4" +
22
+ "54704d50016041c0ef71bcab00000090078495370000b0210000b021102ddde7cf000000407614d4" +
23
+ "1400001bf8b0cf16500000009005c44554484848ffffff0000003e75793f000000729444144587ad" +
24
+ "3606082062011a404cc8a801c0402828c024a8022142c2802a91505119840a8000c25a100daa1682" +
25
+ "d9000000009454e444ea240628"
26
+ self.padLeft = 0
27
+ self.frameStyle = 12288
28
+ self.layoutHints = Fox::LAYOUT_FILL_X
29
+ self.padRight = 0
30
+ @openIcon = Icon.LoadFromString boxMinusPNG_Str
31
+ @closedIcon = Icon.LoadFromString boxPlusPNG_Str
32
+ FX::Label.new(self) { |w|
33
+ @header = w
34
+ w.layoutHints = Fox::LAYOUT_FILL_X
35
+ w.iconPosition = Fox::ICON_BEFORE_TEXT
36
+ w.justify = Fox::JUSTIFY_LEFT
37
+ w.icon = @openIcon.img
38
+ @open = true
39
+ }
40
+ FX::HorizontalSeparator.new(self) { |w|
41
+ @hsep = w
42
+ w.padLeft = 0
43
+ w.padRight = 0
44
+ }
45
+ @header.connect(SEL_LEFTBUTTONPRESS) {
46
+ if @open
47
+ close_body
48
+ else
49
+ open_body
50
+ end
51
+ }
52
+ end
53
+
54
+ def close_body
55
+ @open = false
56
+ @header.icon = @closedIcon.img
57
+ children.each { |ch|
58
+ next if ch == @header
59
+ ch.hide
60
+ }
61
+ if layoutHints & LAYOUT_FILL_Y == LAYOUT_FILL_Y
62
+ self.layoutHints -= LAYOUT_FILL_Y
63
+ @fill_y = true
64
+ else
65
+ @fill_y = false
66
+ end
67
+ recalc
68
+ end
69
+
70
+ def open_body
71
+ @open = true
72
+ @header.icon = @openIcon.img
73
+ children.each { |ch|
74
+ next if ch == @header
75
+ ch.show
76
+ }
77
+ self.layoutHints |= LAYOUT_FILL_Y if @fill_y
78
+ recalc
79
+ end
80
+
81
+ def title=(text)
82
+ @header.text = text
83
+ end
84
+
85
+ def title
86
+ @header.text
87
+ end
88
+ end
89
+ end
90
+ # unit test
91
+ if __FILE__ == $0
92
+ app = App.new
93
+ mw = MainWindow.new app
94
+ w = Container.new mw
95
+ # ~ w.header.iconPosition=ICON_AFTER_TEXT
96
+ w.layoutHints = LAYOUT_FIX_WIDTH
97
+ w.width = 150
98
+ w.header.text = "header"
99
+ Button.new w
100
+ mw.show(0)
101
+ app.create
102
+ app.run
103
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ require "_guib_FileSelector"
4
+
5
+ class FileSelector
6
+ def init
7
+ @title = "File Dialog"
8
+ @relative_path = false
9
+ @filename = ""
10
+
11
+ @directory = Dir.getwd
12
+ @dialog = Fox::FXFileDialog.new(@topwin, @title)
13
+ @patterns = ["All Files (*)"]
14
+ @currentPattern = 0
15
+ @browse.connect(Fox::SEL_COMMAND, method(:onBrowse))
16
+ end
17
+ attr_accessor :directory, :patterns, :currentPattern, :title, :filename, :relative_path
18
+ attr_accessor :onNewFilenameBlock
19
+ def description=text
20
+ @label.text = text
21
+ end
22
+
23
+ def description
24
+ @label.text
25
+ end
26
+
27
+ def onBrowse(*args)
28
+ @dialog.title = @title
29
+ @dialog.directory = @directory
30
+ @dialog.patternList = @patterns
31
+ @currentPattern = 0 if @currentPattern >= @patterns.size
32
+ @dialog.currentPattern = @currentPattern
33
+ @dialog.filename = filename.to_s
34
+ if @dialog.execute != 0
35
+ @filename = @textfield.text = if @relative_path
36
+ rel_path(Dir.getwd, @dialog.filename)
37
+ else
38
+ @dialog.filename
39
+ end
40
+ @onNewFilenameBlock.call if @onNewFilenameBlock.respond_to? :call
41
+ end
42
+ end
43
+ end
Binary file
@@ -0,0 +1,37 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ require "relative-path"
4
+ class PathSelector
5
+ def init
6
+ @title = "Directory Dialog"
7
+ @relative_path = false
8
+ @directory = Dir.getwd
9
+ update(@directory)
10
+ @dialog = FXDirDialog.new(@topwin, @title)
11
+ @browse.connect(SEL_COMMAND, method(:onBrowse))
12
+ end
13
+ attr_accessor :directory, :title, :filename, :relative_path
14
+ def description=text
15
+ @label.text = text
16
+ end
17
+
18
+ def description
19
+ @label.text
20
+ end
21
+
22
+ def onBrowse(*args)
23
+ @dialog.title = @title
24
+ @dialog.directory = @directory
25
+ if @dialog.execute != 0
26
+ update(@dialog.directory)
27
+ end
28
+ end
29
+
30
+ def update(path)
31
+ @directory = @textfield.text = if @relative_path
32
+ rel_path(Dir.getwd, path)
33
+ else
34
+ path
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ class PathSelector
4
+ def initialize(parent)
5
+ construct_widget_tree(parent)
6
+ init if respond_to? :init
7
+ end
8
+
9
+ def construct_widget_tree(parent)
10
+ @topwin =
11
+ FX::HorizontalFrame.new(parent) { |w|
12
+ @PathSelector = w
13
+ w.padLeft = 0
14
+ w.frameStyle = 0
15
+ w.padRight = 0
16
+ w.hSpacing = 2
17
+ w.height = 21
18
+ w.layoutHints = 1024
19
+ FX::Label.new(@PathSelector) { |w|
20
+ @label = w
21
+ w.text = "Path:"
22
+ w.width = 30
23
+ w.x = 0
24
+ }
25
+ FX::TextField.new(@PathSelector) { |w|
26
+ @textfield = w
27
+ w.width = 291
28
+ w.y = 0
29
+ w.layoutHints = 1024
30
+ w.x = 32
31
+ }
32
+ FX::Button.new(@PathSelector) { |w|
33
+ @browse = w
34
+ w.text = "Browse..."
35
+ w.padLeft = 4
36
+ w.width = 59
37
+ w.padRight = 4
38
+ w.y = 0
39
+ w.x = 325
40
+ }
41
+ }
42
+ end
43
+ attr_accessor :topwin,
44
+ :PathSelector,
45
+ :label,
46
+ :textfield,
47
+ :browse,
48
+ :__foxGUIb__last__
49
+ end
50
+ s = "PathSelector-extension.rb"
51
+ require s if File.exist?(s)
52
+ # unit test
53
+ if __FILE__ == $0
54
+ Dir.chdir ".."
55
+ require "FX"
56
+ app = App.new
57
+ mw = MainWindow.new app
58
+ w = PathSelector.new mw
59
+ mw.show(0)
60
+ app.create
61
+ app.run
62
+ end
Binary file
data/src/__FX__.rb ADDED
@@ -0,0 +1,17 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ require "fox16"
4
+
5
+ require "relative-path"
6
+ require "app"
7
+ require "fxbase"
8
+ require "fxobjects"
9
+ require "main-window"
10
+ require "middle-right-mouse"
11
+ require "FileSelector"
12
+ require "PathSelector"
13
+ require "Container"
14
+ require "radio_matrix"
15
+ require "table"
16
+ require "style"
17
+ require "dcwindow"
@@ -0,0 +1,60 @@
1
+ class FileSelector
2
+ def initialize(parent)
3
+ construct_widget_tree(parent)
4
+ init if respond_to? :init
5
+ end
6
+
7
+ def construct_widget_tree(parent)
8
+ @topwin =
9
+ FX::HorizontalFrame.new(parent) { |w|
10
+ @FileSelector = w
11
+ w.padLeft = 0
12
+ w.frameStyle = 0
13
+ w.padRight = 0
14
+ w.hSpacing = 2
15
+ w.height = 21
16
+ w.layoutHints = 1024
17
+ FX::Label.new(@FileSelector) { |w|
18
+ @label = w
19
+ w.text = "File:"
20
+ w.width = 24
21
+ w.x = 0
22
+ }
23
+ FX::TextField.new(@FileSelector) { |w|
24
+ @textfield = w
25
+ w.width = 297
26
+ w.y = 0
27
+ w.layoutHints = 1024
28
+ w.x = 26
29
+ }
30
+ FX::Button.new(@FileSelector) { |w|
31
+ @browse = w
32
+ w.text = "Browse..."
33
+ w.padLeft = 4
34
+ w.width = 59
35
+ w.padRight = 4
36
+ w.y = 0
37
+ w.x = 325
38
+ }
39
+ }
40
+ end
41
+ attr_accessor :topwin,
42
+ :FileSelector,
43
+ :label,
44
+ :textfield,
45
+ :browse,
46
+ :__foxGUIb__last__
47
+ end
48
+ # ~ s='FileSelector-extension.rb'
49
+ # ~ require s if File.exist?(s)
50
+ # unit test
51
+ if __FILE__ == $0
52
+ Dir.chdir ".."
53
+ require "FX"
54
+ app = App.new
55
+ mw = MainWindow.new app
56
+ w = FileSelector.new mw
57
+ mw.show(0)
58
+ app.create
59
+ app.run
60
+ end
data/src/app.rb ADDED
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ module FX
4
+ class App < Fox::FXApp
5
+ def initialize a = "", b = ""
6
+ super
7
+ @created = false
8
+ $app = $fxapp = self
9
+ # $fxtooltip=FXTooltip.new $fxapp
10
+ end
11
+
12
+ def create(*args)
13
+ super
14
+ @created = true
15
+ end
16
+
17
+ def created?
18
+ @created
19
+ end
20
+ end
21
+ end # FX
data/src/dcwindow.rb ADDED
@@ -0,0 +1,88 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ require "event_listener"
4
+ require "fxbase"
5
+ module FX
6
+ # adding support for variable origin to DC, which allows drawing with relative coordinates
7
+ class DCWindow < Fox::FXDCWindow
8
+ def initialize(*args)
9
+ super
10
+ setOrigin(0, 0)
11
+ end
12
+
13
+ def getOrigin
14
+ [@xOrigin, @yOrigin]
15
+ end
16
+
17
+ def setOrigin x = 0, y = 0
18
+ @xOrigin = x
19
+ @yOrigin = y
20
+ @originStack = [x, y]
21
+ end
22
+
23
+ def pushOrigin x = 0, y = 0
24
+ @xOrigin += x
25
+ @yOrigin += y
26
+ @originStack.push [@xOrigin, @yOrigin]
27
+ end
28
+
29
+ def popOrigin
30
+ @originStack.pop if @originStack.size > 1
31
+ @xOrigin, @yOrigin = @originStack.last
32
+ end
33
+
34
+ def drawText x, y, text, bg = false
35
+ if bg
36
+ drawImageText(@xOrigin + x, @yOrigin + y, text)
37
+ else
38
+ super(@xOrigin + x, @yOrigin + y, text)
39
+ end
40
+ end
41
+
42
+ def drawImageText x, y, text
43
+ super(@xOrigin + x, @yOrigin + y, text)
44
+ end
45
+
46
+ def drawLine x, y, x1, y1
47
+ super(@xOrigin + x, @yOrigin + y, @xOrigin + x1, @yOrigin + y1)
48
+ end
49
+
50
+ def fillRectangle x, y, w, h
51
+ super(@xOrigin + x, @yOrigin + y, w, h)
52
+ end
53
+
54
+ def drawRectangle x, y, w, h
55
+ super(@xOrigin + x, @yOrigin + y, w, h)
56
+ end
57
+ end
58
+
59
+ class DrawingCanvas < Canvas
60
+ __sends__ :event_draw
61
+ def initialize parent
62
+ super(parent, Fox::LAYOUT_FILL_X | Fox::LAYOUT_FILL_Y)
63
+ @stdFont = Fox::FXFont.new($fxapp, "[helvetica] 90 700 1 1 0 0")
64
+ @stdFont.create
65
+ connect(Fox::SEL_PAINT) { |sender, sel, event|
66
+ resize parent.width, parent.height if width != parent.width or height != parent.height
67
+ dc = DCWindow.new self
68
+ dc.font = @stdFont
69
+ event_draw(dc, event, self)
70
+ dc.end
71
+ }
72
+ end
73
+ end
74
+ end
75
+ if __FILE__ == $0
76
+ $stdout.sync = true
77
+ include FX
78
+ app = App.new
79
+ mw = MainWindow.new app
80
+ canvas = DrawingCanvas.new mw
81
+ canvas.on_draw { |dc, event, c|
82
+ dc.fillRectangle 0, 0, canvas.width, canvas.height
83
+ }
84
+ mw.resize 400, 300
85
+ mw.show
86
+ app.create
87
+ app.run
88
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ class Module
4
+ def __sends__ *args
5
+ args.each { |arg|
6
+ class_eval <<-CEEND, __FILE__, __LINE__ + 1
7
+ def on_#{arg}(&callback)
8
+ @#{arg}_observers ||= {}
9
+ @#{arg}_observers[caller[0]]=callback
10
+ return caller[0]
11
+ end
12
+ def del_#{arg}(id)
13
+ @#{arg}_observers ||= {}
14
+ return @#{arg}_observers.delete( id)
15
+ end
16
+ private
17
+ def #{arg} *the_args
18
+ @#{arg}_observers ||= {}
19
+ @#{arg}_observers.each { |caller, cb|
20
+ cb.call *the_args
21
+ }
22
+ end
23
+ CEEND
24
+ }
25
+ end
26
+ end
27
+
28
+ # MAKE_CUTOFF
29
+
30
+ if __FILE__ == $0
31
+ class TextBox
32
+ __sends__ "text_changed", "key_pressed"
33
+
34
+ def initialize txt = ""
35
+ @txt = txt
36
+ end
37
+
38
+ def txt= txt
39
+ @txt = txt
40
+ text_changed
41
+ end
42
+
43
+ def key_press key
44
+ key_pressed key
45
+ end
46
+ end
47
+
48
+ box = TextBox.new
49
+ text_changed_id = box.on_text_changed { puts "Text changed!" }
50
+ 5.times { |i|
51
+ box.on_key_pressed { |k| puts "(#{i}) Key pressed: #{k}" }
52
+ }
53
+
54
+ box.txt = "New text!"
55
+ box.del_text_changed(text_changed_id)
56
+ box.txt = "New text!"
57
+
58
+ box.key_press "j"
59
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright (c) 2004-2006 by Henon (meinrad dot recheis at gmail dot com)
2
+
3
+ require "fxruby"
4
+ require "__FX__"
5
+ # include Fox
6
+
7
+ widgets = Fox.constants.find_all { |c|
8
+ begin
9
+ c.to_s =~ /^FX/ and Object.const_get(c).ancestors.include? FXWindow
10
+ rescue
11
+ # puts "!"+c
12
+ end
13
+ }
14
+ puts "Found #{widgets.size} Fox Widgets."
15
+ puts
16
+ widgets.sort.each { |wclass|
17
+ have = FX.constants.include?(wclass.gsub(/^FX/, ""))
18
+ print "<code>" if have
19
+ print "#{wclass}"
20
+ print "</code>" if have
21
+ puts "<br>"
22
+ }