Module: Gtk3App
- Defined in:
- lib/gtk3app.rb,
lib/gtk3app/program.rb,
lib/gtk3app/widgets.rb
Overview
This Gem
Defined Under Namespace
Classes: AppMenu, EventImage, Menu, MenuItem, YesNoDialog
Constant Summary collapse
- VERSION =
'5.4.230109'
Class Method Summary collapse
- .about! ⇒ Object
- .ensure_keywords(kw) ⇒ Object
- .finalize(&block) ⇒ Object
- .fs! ⇒ Object
- .help! ⇒ Object
- .install(kw) ⇒ Object
- .logo_press_event(&block) ⇒ Object
- .minime! ⇒ Object
- .quit! ⇒ Object
- .raise_argument_error(kw) ⇒ Object
-
.run(**kw) ⇒ Object
Gtk3App.run(version:String?, help:String?, klass:(Class | Module)?), appdir:String?, appname:String?, config:Hash?).
- .transient(window) ⇒ Object
Class Method Details
.about! ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/gtk3app/program.rb', line 91 def about! about = Such::AboutDialog.new :about_dialog transient about about.set_logo @pixbuf about.run about.destroy end |
.ensure_keywords(kw) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gtk3app/program.rb', line 66 def ensure_keywords(kw) raise_argument_error(kw) if kw.keys.any?{![:version,:help,:klass,:appdir,:appname,:config].include?_1} klass = kw[:klass] kw[:version] ||= (klass and defined? klass::VERSION)? klass::VERSION : (defined? ::VERSION)? ::VERSION : VERSION kw[:help] ||= (klass and defined? klass::HELP)? klass::HELP : (defined? ::HELP)? ::HELP : HELP kw[:appname] ||= klass&.name&.downcase || File.basename($0) kw[:config] ||= klass::CONFIG if klass and defined? klass::CONFIG end |
.finalize(&block) ⇒ Object
150 151 152 |
# File 'lib/gtk3app/program.rb', line 150 def finalize(&block) @finalize = block end |
.fs! ⇒ Object
86 87 88 89 |
# File 'lib/gtk3app/program.rb', line 86 def fs! @fs ? @main.unfullscreen : @main.fullscreen @fs = !@fs end |
.help! ⇒ Object
99 100 101 |
# File 'lib/gtk3app/program.rb', line 99 def help! system(@@CONFIG[:Open], @@CONFIG[:HelpFile]) end |
.install(kw) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/gtk3app/program.rb', line 156 def install(kw) stub = UserSpace.new parser:RBON, appname:'gtk3app', config:"config-#{VERSION.semantic(0..1)}" stub.configures @@CONFIG # :klass and :config flags user wants xdg maintainance. # :appname, :appdir, and :version are sanity checks. if [:klass,:config,:appname,:appdir,:version].all?{kw[_1]} app = UserSpace.new parser:RBON, # Will be a subdirectory in gtk3app: appname:"gtk3app/#{kw[:appname]}", appdir:kw[:appdir], config:"config-#{kw[:version].semantic(0..1)}" app.configures kw[:config] end # Pad-up klass::CONFIG and switch to it: if cfg = kw[:config] @@CONFIG.each do |k,v| if cfg.key? k $stderr.puts "Overriding Gtk3App::CONFIG[#{k}]" if $VERBOSE else cfg[k]=v end end @@CONFIG = cfg end end |
.logo_press_event(&block) ⇒ Object
82 83 84 |
# File 'lib/gtk3app/program.rb', line 82 def logo_press_event(&block) @logo_press_event = block end |
.minime! ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gtk3app/program.rb', line 103 def minime! if @minime @minime = false unless @options.notoggle @main.set_decorated true unless @options.notdecorated @main.set_keep_above false end @stage. true @toolbar. true if @options.minime? @stage.show @toolbar.show end else @minime = true unless @options.notoggle @main.set_decorated false unless @options.notdecorated @main.set_keep_above true end @stage. false @toolbar. false if @options.minime? @stage.hide @toolbar.hide end @main.resize 1,1 end end |
.quit! ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/gtk3app/program.rb', line 133 def quit! ursure = Gtk3App::YesNoDialog.new :quit_ursure! transient ursure return true unless ursure.ok? @finalize.call if @finalize Gtk.main_quit return false rescue # finalize raised exception $!.puts dialog = Such::MessageDialog.new transient dialog dialog.set_text $!. dialog.run dialog.destroy return true end |
.raise_argument_error(kw) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/gtk3app/program.rb', line 56 def raise_argument_error(kw) $stderr.puts <<~SIGNATURE Expected Signature: Gtk3App.run(version:String?, help:String?, klass:Class?, appdir:String?, :appname:String? config:Hash?) SIGNATURE raise ArgumentError, kw.inspect end |
.run(**kw) ⇒ Object
Gtk3App.run(version:String?, help:String?,
klass:(Class | Module)?), appdir:String?, appname:String?,
config:Hash?)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gtk3app/program.rb', line 6 def run(**kw) # :appdir must be evaluated here, else breaks UserSpace's heuristics kw[:appdir] ||= UserSpace.appdir ensure_keywords(kw) @options = HelpParser[kw[:version], kw[:help]] install(kw) Such::Thing.configure @@CONFIG @main = Such::Window.new :main! do |*_,e,signal| case signal when 'key-press-event' if e.keyval==@@CONFIG[:AppMenu] @appmenu. @logo, Gdk::Gravity::NORTH_WEST,Gdk::Gravity::NORTH_WEST end when 'delete-event' quit! end end @main.set_decorated false if @options.notdecorated vbox = Such::Box.new @main, [:vertical] hbox = Such::Box.new vbox, [:horizontal] size = @@CONFIG[:LogoSize] @pixbuf = GdkPixbuf::Pixbuf.new(file: @@CONFIG[:Logo]).scale(size,size) @logo = Gtk3App::EventImage.new hbox, [pixbuf:@pixbuf] @appmenu = Gtk3App::AppMenu.new(@logo, :app_menu!) do |,*e,signal| case signal when 'activate' send .key when 'button_press_event' @logo_press_event.call(e[0].) if @logo_press_event end end @stage = Such::Expander.new vbox, :stage! @toolbar = Such::Expander.new hbox, :toolbar! if block_given? yield(@stage, @toolbar, @options) else kw[:klass]&.new(@stage, @toolbar, @options) end @minime = @fs = false @main.show_all Gtk.main end |
.transient(window) ⇒ Object
78 79 80 |
# File 'lib/gtk3app/program.rb', line 78 def transient(window) window.transient_for = @main end |