Sha256: 8434909598a7fb489298301391768a6277c5598d10a3413b40918d71e623d0f4

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

require 'gtk2'

module Context::Gtk

    # 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.
    class MainWindow < Gtk::Window
        include Context::Gtk::Widget
        # Create a main window with a given title corresponding to
        # a Context::View.
        def initialize(title, view)
            super(title)
            @view = view
            setupWidget
            isAMainWindow
            @closed = false
            connectSignals unless @view.nil?
        end

        # Connect the Gtk signals we care about.
        def connectSignals
            signal_connect('destroy') do
                if !@closed
                    closeView
                end
            end
            signal_connect('delete-event') do
                if !@closed
                    closeView
                end
                true
            end
        end
        
        # Explicitly destroy the window through the code rather
        # than having the window destroyed by pressing the close
        # button.
        def explicitDestroy
            @closed = true
            self.destroy
        end
        
        # Close the view. This is called when the destroy
        # signal has been emitted.
        # Note: the View *must* implement close()
        def closeView
            @view.close
        end

        # Context::Gtk::Widget requirements

        # 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.
        def gtkAddWidget(widget)
            add(widget)
        end

        # Remove the contained widget from this window
        def gtkRemoveWidget(widget)
            remove(widget)
        end
    end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
jldrill-0.5.1.7 lib/Context/Views/Gtk/Widgets/MainWindow.rb
context-0.0.22 lib/Context/Views/Gtk/Widgets/MainWindow.rb