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.



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

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()



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

def closeView
    @view.close
end

#connectSignalsObject

Connect the Gtk signals we care about.



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

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.



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

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.



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

def gtkAddWidget(widget)
    add(widget)
end

#gtkRemoveWidget(widget) ⇒ Object

Remove the contained widget from this window



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

def gtkRemoveWidget(widget)
    remove(widget)
end

#showBusy(bool) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/Context/Views/Gtk/Widgets/MainWindow.rb', line 71

def showBusy(bool)
    if bool
        self.window.set_cursor(Gdk::Cursor.new(Gdk::Cursor::WATCH))
    else
        self.window.set_cursor(nil)
    end
    Gdk::flush
end