Class: Shoes::Swt::App

Inherits:
Object
  • Object
show all
Includes:
Common::Container, Common::Clickable
Defined in:
shoes-swt/lib/shoes/swt/app.rb

Overview

Shoes::App.new creates a new Shoes application window! The default window is a [flow]

Instance Attribute Summary collapse

Attributes included from Common::Clickable

#pass_coordinates

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::Clickable

#click, #pass_coordinates?, #register_click, #release

Constructor Details

#initialize(dsl) ⇒ App

Returns a new instance of App.



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
55
56
57
58
59
# File 'shoes-swt/lib/shoes/swt/app.rb', line 26

def initialize(dsl)
  if self.class.main_app_closed?
    Shoes.logger.error <<~EOS
      Sorry! You can't start another Shoes.app at after the main one has already
      finished like that! If you need multiple windows, try it more like this:

          Shoes.app do
            para "first!"
            Shoes.app do
              para "second!"
            end
          end
EOS
    exit 1
  end

  @dsl = dsl

  ::Swt::Widgets::Display.app_name = @dsl.app_title

  ::Shoes::Swt::App.setup_system_colors
  ::Shoes::Swt::Font.setup_fonts

  @background = Color.new(@dsl.opts[:background] ||
                         ::Shoes::COLORS.fetch(:system_background))
  @started = false
  initialize_shell
  initialize_real
  ::Shoes::Swt.register self
  attach_event_listeners
  initialize_scroll_bar

  @redrawing_aspect = RedrawingAspect.new self, Shoes.display
end

Instance Attribute Details

#click_listenerObject (readonly)

Returns the value of attribute click_listener.



24
25
26
# File 'shoes-swt/lib/shoes/swt/app.rb', line 24

def click_listener
  @click_listener
end

#dslObject (readonly)

Returns the value of attribute dsl.



24
25
26
# File 'shoes-swt/lib/shoes/swt/app.rb', line 24

def dsl
  @dsl
end

#realObject (readonly)

Returns the value of attribute real.



24
25
26
# File 'shoes-swt/lib/shoes/swt/app.rb', line 24

def real
  @real
end

#shellObject (readonly)

Returns the value of attribute shell.



24
25
26
# File 'shoes-swt/lib/shoes/swt/app.rb', line 24

def shell
  @shell
end

Class Method Details

.main_app_closed?Boolean

Because SWT shutdown is hard to reverse, we only let you do it once and warn you if you try to run again afterward.

Returns:

  • (Boolean)


200
201
202
# File 'shoes-swt/lib/shoes/swt/app.rb', line 200

def self.main_app_closed?
  @main_app_closed ||= false
end

.mark_main_app_closedObject



204
205
206
# File 'shoes-swt/lib/shoes/swt/app.rb', line 204

def self.mark_main_app_closed
  @main_app_closed = true
end

.setup_system_colorsObject



186
187
188
189
190
191
192
193
194
195
196
# File 'shoes-swt/lib/shoes/swt/app.rb', line 186

def self.setup_system_colors
  # Skip it if we've already loaded the color!
  return if ::Shoes::COLORS[:system_background]

  # just one color for now
  background_color = Shoes.display.getSystemColor(::Swt::SWT::COLOR_WIDGET_BACKGROUND)
  ::Shoes::DSL.define_shoes_color(:system_background,
                                  background_color.red,
                                  background_color.green,
                                  background_color.blue)
end

Instance Method Details

#add_key_listener(listener) ⇒ Object



170
171
172
# File 'shoes-swt/lib/shoes/swt/app.rb', line 170

def add_key_listener(listener)
  @key_listeners[listener.class] << listener
end

#appShoes::Swt::App

Returns Self.

Returns:



82
83
84
# File 'shoes-swt/lib/shoes/swt/app.rb', line 82

def app
  self
end

#clickable_elementsObject



154
155
156
# File 'shoes-swt/lib/shoes/swt/app.rb', line 154

def clickable_elements
  @click_listener.clickable_elements
end

#clipboardObject

Java doesn’t like ruby-style accessors here for some reason



134
135
136
# File 'shoes-swt/lib/shoes/swt/app.rb', line 134

def clipboard
  ::Swt::Clipboard.new(Shoes.display).getContents ::Swt::TextTransfer.getInstance
end

#clipboard=(str) ⇒ Object



138
139
140
141
142
143
144
# File 'shoes-swt/lib/shoes/swt/app.rb', line 138

def clipboard=(str)
  ::Swt::Clipboard.new(Shoes.display).setContents(
    [str].to_java,
    [::Swt::TextTransfer.getInstance].to_java(::Swt::TextTransfer),
    ::Swt::DND::DND::CLIPBOARD
  )
end

#disposed?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'shoes-swt/lib/shoes/swt/app.rb', line 98

def disposed?
  @shell.disposed? || @real.disposed?
end

#flushObject



120
121
122
# File 'shoes-swt/lib/shoes/swt/app.rb', line 120

def flush
  @real.layout if @dsl.top_slot
end

#focusObject



102
103
104
# File 'shoes-swt/lib/shoes/swt/app.rb', line 102

def focus
  @shell.force_active
end

#fullscreenObject



150
151
152
# File 'shoes-swt/lib/shoes/swt/app.rb', line 150

def fullscreen
  @shell.full_screen
end

#fullscreen=(state) ⇒ Object



146
147
148
# File 'shoes-swt/lib/shoes/swt/app.rb', line 146

def fullscreen=(state)
  @shell.full_screen = state
end

#gutterObject

This represents the space (potentially) occupied by a vertical scrollbar. Since the scrollbar may not be visible at the time this method is called, we don’t rely on its reported value.



165
166
167
168
# File 'shoes-swt/lib/shoes/swt/app.rb', line 165

def gutter
  # 16
  @shell.vertical_bar.size.x
end

#heightObject



90
91
92
# File 'shoes-swt/lib/shoes/swt/app.rb', line 90

def height
  shell.client_area.height
end

#main_app?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'shoes-swt/lib/shoes/swt/app.rb', line 116

def main_app?
  ::Shoes::Swt.main_app.equal? self
end

#openObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'shoes-swt/lib/shoes/swt/app.rb', line 61

def open
  # If something called quit during the app block's initial evaluation
  # we might already be disposed of, in which case get out of here!
  return if ::Shoes::Swt.main_app.disposed? || @shell.disposed?

  @shell.pack
  force_shell_size
  @shell.open
  @started = true
  self.fullscreen = true if dsl.start_as_fullscreen?
  flush
  ::Swt.event_loop { ::Shoes::Swt.apps.all?(&:disposed?) } if main_app?
end

#open?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'shoes-swt/lib/shoes/swt/app.rb', line 94

def open?
  !disposed?
end

#quitObject



75
76
77
78
79
# File 'shoes-swt/lib/shoes/swt/app.rb', line 75

def quit
  @image.dispose
  @background.dispose
  @shell.dispose
end

#redraw(left = nil, top = nil, width = nil, height = nil, all = true) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'shoes-swt/lib/shoes/swt/app.rb', line 106

def redraw(left = nil, top = nil, width = nil, height = nil, all = true)
  return if @real.disposed?

  if left.nil? || top.nil? || width.nil? || height.nil?
    @real.redraw
  else
    @real.redraw(left, top, width, height, all)
  end
end

#remove_key_listener(listener) ⇒ Object



174
175
176
# File 'shoes-swt/lib/shoes/swt/app.rb', line 174

def remove_key_listener(listener)
  @key_listeners[listener.class].delete(listener)
end

#scroll_topObject



124
125
126
# File 'shoes-swt/lib/shoes/swt/app.rb', line 124

def scroll_top
  @real.location.y
end

#scroll_top=(n) ⇒ Object



128
129
130
131
# File 'shoes-swt/lib/shoes/swt/app.rb', line 128

def scroll_top=(n)
  @real.setLocation 0, -n
  @shell.vertical_bar.selection = n
end

#started?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'shoes-swt/lib/shoes/swt/app.rb', line 158

def started?
  @started
end

#wait_until_closedObject

For use from modal Shoes windows, keeps pumping UI messages but hangs on from executing other Shoes code until we’re done.



180
181
182
183
184
# File 'shoes-swt/lib/shoes/swt/app.rb', line 180

def wait_until_closed
  until @shell.isDisposed
    ::Swt.display.sleep unless ::Swt.display.readAndDispatch
  end
end

#widthObject



86
87
88
# File 'shoes-swt/lib/shoes/swt/app.rb', line 86

def width
  shell.client_area.width
end