Class: Context::Gtk::MainWindow

Inherits:
Gtk::Window
  • Object
show all
Includes:
Widget
Defined in:
lib/Context/Views/Gtk/Widgets/MainWindow.rb

Overview

A Gtk widget representing a main window. It is simply a Gtk::Window into which you can add new widgets. You must implement the following methods on the view that you pass to initialize:

close() -- closes the view.

Instance Attribute Summary

Attributes included from Widget

#gtkWidgetMainWindow

Instance Method Summary collapse

Methods included from Widget

#addToThisWidget, #afterWidgetIsAdded, #afterWidgetIsRemoved, #expandWidgetHeight, #expandWidgetHeight?, #expandWidgetWidth, #expandWidgetWidth?, #isAMainWindow, #isInTests?, #removeFromThisWidget, #setupWidget, #widgetWasAddedTo, #widgetWasRemovedFrom

Constructor Details

#initialize(title, view) ⇒ MainWindow

Create a main window with a given title corresponding to a Context::View.



15
16
17
18
19
20
21
22
# File 'lib/Context/Views/Gtk/Widgets/MainWindow.rb', line 15

def initialize(title, view)
    super(title)
    @view = view
    setupWidget
    isAMainWindow
    @closed = false
    connectSignals unless @view.nil?
end

Instance Method Details

#closeViewObject

Close the view. This is called when the destroy signal has been emitted. Note: the View must implement close()



50
51
52
# File 'lib/Context/Views/Gtk/Widgets/MainWindow.rb', line 50

def closeView
    @view.close
end

#connectSignalsObject

Connect the Gtk signals we care about.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/Context/Views/Gtk/Widgets/MainWindow.rb', line 25

def connectSignals
    signal_connect('destroy') do
        if !@closed
            closeView
        end
    end
    signal_connect('delete-event') do
        if !@closed
            closeView
        end
        true
    end
end

#explicitDestroyObject

Explicitly destroy the window through the code rather than having the window destroyed by pressing the close button.



42
43
44
45
# File 'lib/Context/Views/Gtk/Widgets/MainWindow.rb', line 42

def explicitDestroy
    @closed = true
    self.destroy
end

#gtkAddWidget(widget) ⇒ Object

Add a widget to this window.

Note that Gtk::Windows can only add a single item. If you want to add more items, you will have to make another widget (like a table or a vbox) and add it to this one.



61
62
63
# File 'lib/Context/Views/Gtk/Widgets/MainWindow.rb', line 61

def gtkAddWidget(widget)
    add(widget)
end

#gtkRemoveWidget(widget) ⇒ Object

Remove the contained widget from this window



66
67
68
# File 'lib/Context/Views/Gtk/Widgets/MainWindow.rb', line 66

def gtkRemoveWidget(widget)
    remove(widget)
end