The document module¶
This module provides functions for working with documents. Most of the module-level
functions are used for creating instances of the Document object.
-
document.find_by_filename(filename)¶ Finds a document with the given filename from the open documents.
Parameters: filename – Filename of Documentto find.Returns: A Documentinstance for the found document orNone.
-
document.get_current()¶ Gets the currently active document.
Returns: A Documentinstance for the currently active document orNoneif no documents are open.
-
document.get_from_page(page_num)¶ Gets a document based on it’s
gtk.Notebookpage number.Parameters: page_num – The tab number of the document in the documents notebook. Returns: A Documentinstance for the corresponding document orNoneif no document matched.
-
document.index(index)¶ Gets a document based on its index in Geany’s documents array.
Parameters: index – The index of the document in Geany’s documents array. Returns: A Documentinstance for the corresponding document orNoneif not document matched, or the document that matched isn’t valid.
-
document.new_file([filename=None[, filetype=None[, text=None]]])¶ Creates a document file.
Parameters: - filename – The documents filename, or
Nonefor untitled. - filetype – The documents filetype or
Noneto auto-detect it from filename (if it’s notNone) - text – Initial text to put in the new document or
Noneto leave it blank
Returns: A
Documentinstance for the new document.- filename – The documents filename, or
-
document.open_file(filename[, read_only=False[, filetype=None[, forced_enc=None]]])¶ Open an existing document file.
Parameters: - filename – Filename of the document to open.
- read_only – Whether to open the document in read-only mode.
- filetype – Filetype to open the document as or
Noneto detect it automatically. - forced_enc – The file encoding to use or
Noneto auto-detect it.
Returns: A
Documentinstance for the opened document orNoneif it couldn’t be opened.
-
document.open_files(filenames, read_only=False, filetype="", forced_enc="")¶ Open multiple files. This actually calls
open_file()once for each filename in filenames.Parameters: - filenames – List of filenames to open.
- read_only – Whether to open the document in read-only mode.
- filetype – Filetype to open the document as or
Noneto detect it automatically. - forced_enc – The file encoding to use or
Noneto auto-detect it.
-
document.remove_page(page_num)¶ Remove a document from the documents array based on it’s page number in the documents notebook.
Parameters: page_num – The tab number of the document in the documents notebook. Returns: Trueif the document was actually removed orFalseotherwise.
-
document.get_documents_list()¶ Get a list of open documents.
Returns: A list of Documentinstances, one for each open document.
Document Objects¶
-
class
document.Document¶ The main class holding information about a specific document. Unless otherwise noted, the attributes are read-only properties.
-
basename_for_display¶ The last part of the filename for this document, possibly truncated to a maximum length in case the filename is very long.
-
notebook_page¶ The page number in the
gtk.Notebookcontaining documents.
-
status_color¶ Gets the status color of the document, or
Noneif the default widget coloring should be used. The color is red if the document has changes, green if it’s read-only orNoneif the document is unmodified but writable. The value is a tuple of the RGB values for red, green, and blue respectively.
-
encoding¶ The encoding of this document. Must be a valid string representation of an encoding. This property is read-write.
-
file_type¶ The file type of this document as a
Filetypeinstance. This property is read-write.
-
text_changed¶ Whether this document’s text has been changed since it was last saved.
-
file_name¶ The file name of this document.
-
has_bom¶ Indicates whether the document’s file has a byte-order-mark.
Indicates whether this document supports source code symbols (tags) to show in the sidebar.
-
index¶ Index of the document in Geany’s documents array.
-
is_valid¶ Indicates whether this document is active and all properties are set correctly.
-
read_only¶ Whether the document is in read-only mode.
-
real_path¶ The link-dereferenced, locale-encoded file name for this document.
-
editor¶ The
Editorinstance associated with this document.
-
close()¶ Close this document.
Returns: Trueif the document was closed,Falseotherwise.
-
reload([forced_enc=None])¶ Reloads this document.
Parameters: forced_enc – The encoding to use when reloading this document or Noneto auto-detect it.Returns: Trueif the document was actually reloaded orFalseotherwise.
-
rename(new_filename)¶ Rename this document to a new file name. Only the file on disk is actually renamed, you still have to call
save_as()to change the document object. It also stops monitoring for file changes to prevent receiving too many file change events while renaming. File monitoring is setup again insave_as().Parameters: new_filename – The new filename to rename to.
-
save([force=False])¶ Saves this documents file on disk.
Saving may include replacing tabs by spaces, stripping trailing spaces and adding a final new line at the end of the file, depending on user preferences. Then, the document-before-save signal is emitted, allowing plugins to modify the document before it’s saved, and the data is actually written to disk. The file type is set again or auto-detected if it wasn’t set yet. Afterwards, the document-save signal is emitted for plugins. If the file is not modified, this method does nothing unless force is set to
True.Note: You should ensure that
file_nameis notNonebefore calling this; otherwise calldialogs.show_save_as().Parameters: force – Whether to save the document even if it’s not modified. Returns: Trueif the file was saved orFalseif the file could not or should not be saved.
-
save_as(new_filename)¶ Saves the document with a new filename, detecting the filetype.
Parameters: new_filename – The new filename. Returns: Trueif the file was saved orFalseif it could not be saved.
-