Esempio n. 1
0
    def __init__(self, parent=None, path=None, *args, **kwargs):

        # Initialize the Frame base class.
        Tkinter.Frame.__init__(self, parent, *args, **kwargs)

        # Create the main menubar.
        self._createMenubar()

        # Read the model file (if specified).
        if path:
            sourceLibraryDocument = SourceLibraryDocument(path=path)
        else:
            sourceLibraryDocument = SourceLibraryDocument()

        # Create and grid the source library document editor component.
        sourceLibraryDocumentEditor = \
            SourceLibraryDocumentEditor(self, sourceLibraryDocument,
                                        borderwidth = 2, relief = 'ridge')
        sourceLibraryDocumentEditor.grid(row=0, column=0)
        self._sourceLibraryDocumentEditor = sourceLibraryDocumentEditor

        # Save the path to the document.
        self._path = path

        # set default ROI center to 0,0
        self.ROI_ra = -1
        self.ROI_dec = 0
        self.catParams = None
        self.docLock = thread.allocate_lock()
        self.ds9 = DS9Connector(self._sourceLibraryDocumentEditor)
        self._sourceLibraryDocumentEditor.setDS9Connector(self.ds9)
    def get(self):
        """Return the contents of the editor.

        Parameters:

        self: This object.

        Return value:

        Copy of SourceLibraryDocument being edited.

        Description:

        Return a new SourceLibraryDocument containing the current
        state of the editor.
        """

        # Fetch the contents of the SourceLibrary editor.
        sourceLibrary = self._sourceLibraryEditor.get()

        # Create a new SourceLibraryDocument with the current values.
        sourceLibraryDocument = SourceLibraryDocument(sourceLibrary)

        # Return the new SourceLibraryDocument.
        return sourceLibraryDocument
    def __init__(self,
                 parent=None,
                 sourceLibraryDocument=None,
                 *args,
                 **kwargs):
        """Initialize this object.

        Parameters:

        self: This object.

        parent: (tkinter.Frame) Parent object for this widget.

        sourceLibraryDocument: (SourceLibraryDocument) Object to edit.
        """

        # Initialize the parent class. Note that this class does NOT
        # derive from ElementEditor.
        tkinter.Frame.__init__(self, parent, *args, **kwargs)

        # Create widgets.
        self._makeWidgets()

        # Populate the editor.
        if sourceLibraryDocument is None:
            sourceLibraryDocument = SourceLibraryDocument()
        self.set(sourceLibraryDocument)
        self.commit()
Esempio n. 4
0
    def _open(self, path):
        """
        Open the specified document.
        """
        assert path is not None

        # Open the specified document.
        try:
            sourceLibraryDocument = SourceLibraryDocument(path=path)
            self._sourceLibraryDocumentEditor.set(sourceLibraryDocument)
            self._sourceLibraryDocumentEditor.commit()
            self._path = path
            self.master.title('ModelEditor (%s)' % self._path)
        except ExpatError as e:
            showwarning("XML error!", "In " + path + ": " + str(e))
Esempio n. 5
0
    def _new(self):
        """
        Create a new, blank document and use it to initialize the editor.
        """

        # Create a new, blank SourceLibraryDocument.
        sourceLibraryDocument = SourceLibraryDocument()

        # Populate the editor with the blank document.
        self._sourceLibraryDocumentEditor.set(sourceLibraryDocument)

        # Commit the new document.
        self._sourceLibraryDocumentEditor.commit()

        # Clear the document path.
        self._path = None

        # Change the window title to reflect the new path.
        self.master.title('ModelEditor (%s)' % self._path)
    # Create the root window.
    root = tkinter.Tk()
    Pmw.initialise(root)
    root.title('SourceLibraryDocumentEditor test')

    # Create a 2-source library.
    from Source import Source
    source1 = Source(name='Source 1')
    source2 = Source(name='Source 2')

    # Create a SourceLibraryDocument from the 2 sources.
    from SourceLibrary import SourceLibrary
    sourceLibrary = SourceLibrary(title='2 sources',
                                  sources=[source1, source2])
    sourceLibraryDocument = SourceLibraryDocument(sourceLibrary = \
                                                  sourceLibrary)

    # Create and grid the editor, a button to commit changes, and a
    # button to dump its contents.
    sourceLibraryDocumentEditor = \
        SourceLibraryDocumentEditor(root, sourceLibraryDocument)
    sourceLibraryDocumentEditor.grid(row=0, column=0)
    commitButton = tkinter.Button(root,
                                  text='Commit',
                                  command=sourceLibraryDocumentEditor.commit)
    commitButton.grid(row=0, column=1)
    resetButton = tkinter.Button(root,
                                 text='Reset',
                                 command=sourceLibraryDocumentEditor.reset)
    resetButton.grid(row=0, column=2)
    printButton = tkinter.Button(root, text = 'Print',