druzy-little_frame 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/druzy/little_frame/file_chooser.rb +140 -0
- data/lib/druzy/little_frame/version.rb +5 -0
- data/lib/druzy/little_frame.rb +8 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e9569942fc071035573b5f7ed5309f7c554a141a
|
4
|
+
data.tar.gz: 355c0801fe0c52e40c0a62fbe07fb6f41058991c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 56bd35b913c62d0893459b038b88d8daee07a2814d2cefa436649bd64d6c6af9db02e12d0836d134800b1ae404717c22d5d744b8ee58a235a7e9acffd5365799
|
7
|
+
data.tar.gz: d803c786dd4fd5c746661646b445af9bb7d17324dbe4229294907974939ddbc85a9b3f4576a1a392836a0b8a5b604ed6ba26c8a5cde6769df7105ee91bf178a9
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'druzy/mvc'
|
2
|
+
require 'gtk3'
|
3
|
+
|
4
|
+
module Druzy
|
5
|
+
module LittleFrame
|
6
|
+
|
7
|
+
class FileChooser < Druzy::MVC::Controller
|
8
|
+
def initialize(args)
|
9
|
+
if (args[:model]==nil)
|
10
|
+
initialize(:model => FileChooserModel.new(args))
|
11
|
+
else
|
12
|
+
super(args[:model])
|
13
|
+
add_view(FileChooserView.new(self))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def notify_action(view,action,args={})
|
18
|
+
if action == :destroy
|
19
|
+
@model.result = :cancel
|
20
|
+
view.close
|
21
|
+
elsif action == :open_clicked
|
22
|
+
@model.files = args[:files]
|
23
|
+
@model.result = :open
|
24
|
+
view.close
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def result
|
29
|
+
if @model.result == nil
|
30
|
+
@model.stopped_thread=Thread.current
|
31
|
+
Thread.stop
|
32
|
+
end
|
33
|
+
|
34
|
+
return @model.result
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
class FileChooserModel < Druzy::MVC::Model
|
41
|
+
attr_accessor :files, :result, :stopped_thread, :filters_mime_type
|
42
|
+
|
43
|
+
def initialize(args)
|
44
|
+
if args[:filter_mime_type] != nil
|
45
|
+
initialize(:filters_mime_type => [args[:filter_mime_type]])
|
46
|
+
|
47
|
+
else
|
48
|
+
super()
|
49
|
+
@files = nil
|
50
|
+
@result = nil
|
51
|
+
@stopped_thread = nil
|
52
|
+
@filters_mime_type=args[:filters_mime_type]
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def result=(result)
|
58
|
+
@result = result
|
59
|
+
if @stopped_thread != nil
|
60
|
+
@stopped_thread.wakeup
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
class FileChooserView < Druzy::MVC::View
|
67
|
+
def initialize(controller)
|
68
|
+
super(controller)
|
69
|
+
Gtk.init
|
70
|
+
@window =Gtk::Window.new
|
71
|
+
@window.signal_connect('destroy') do
|
72
|
+
Thread.new do
|
73
|
+
@controller.notify_action(self,:destroy)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
@open = Gtk::Button.new(:label => "Ouvrir")
|
78
|
+
@open.signal_connect("clicked") do
|
79
|
+
Thread.new do
|
80
|
+
@controller.notify_action(self,:open_clicked, :files => @chooser.filenames)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
@cancel = Gtk::Button.new(:label => "Annuler")
|
85
|
+
@cancel.signal_connect("clicked") do
|
86
|
+
Thread.new do
|
87
|
+
@controller.notify_action(self,:destroy)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
@chooser = Gtk::FileChooserWidget.new(Gtk::FileChooser::Action::OPEN)
|
92
|
+
@chooser.select_multiple = true
|
93
|
+
for filter in @controller.model.filters_mime_type
|
94
|
+
f=Gtk::FileFilter.new
|
95
|
+
f.add_mime_type(filter)
|
96
|
+
f.name = filter
|
97
|
+
@chooser.add_filter(f)
|
98
|
+
end
|
99
|
+
|
100
|
+
@main_vbox = Gtk::Box.new(:vertical,0)
|
101
|
+
|
102
|
+
@button_hbox = Gtk::Box.new(:horizontal,0)
|
103
|
+
|
104
|
+
#ajout des composants
|
105
|
+
@window.add(@main_vbox)
|
106
|
+
|
107
|
+
@main_vbox.pack_start(@chooser)
|
108
|
+
@main_vbox.pack_start(@button_hbox, :expand => false, :padding => 20)
|
109
|
+
|
110
|
+
@button_hbox.pack_end(@open, :expand => false, :padding => 20)
|
111
|
+
@button_hbox.pack_end(@cancel, :expand => false)
|
112
|
+
|
113
|
+
|
114
|
+
Thread.new do
|
115
|
+
Gtk.main
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def display
|
120
|
+
@window.show_all
|
121
|
+
end
|
122
|
+
|
123
|
+
def close
|
124
|
+
Gtk.main_quit
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
if __FILE__ == $0
|
132
|
+
chooser = Druzy::LittleFrame::FileChooser.new(:filters_mime_type => ["video/*","image/*"])
|
133
|
+
chooser.display_views
|
134
|
+
|
135
|
+
if chooser.result == :open
|
136
|
+
puts chooser.model.files
|
137
|
+
end
|
138
|
+
Thread.list.each {|t| t.join if t!=Thread.main}
|
139
|
+
|
140
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: druzy-little_frame
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Le Greneur
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: druzy-mvc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gtk3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- jonathan.legreneur@free.fr
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/druzy/little_frame.rb
|
77
|
+
- lib/druzy/little_frame/file_chooser.rb
|
78
|
+
- lib/druzy/little_frame/version.rb
|
79
|
+
homepage: https://github.com/druzy/ruby-druzy-little_frame
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.5.1
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: some little frame like filechooser
|
103
|
+
test_files: []
|