Macro Python Assistant Window: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
Line 56: Line 56:
* Reduce multiple blank lines to single blank lines<br>- compacts the text by removing multiple blank lines
* Reduce multiple blank lines to single blank lines<br>- compacts the text by removing multiple blank lines
* Alter GUI settings<br>-
* Alter GUI settings<br>-
* Close window<br>- the PAW window is closed and the contents writen out to the persistent storage file<br><bold>Note</bold>: there is no Dialog asking about saving, it is done automatically
* Close window<br>-


==User Interface==
==User Interface==

Revision as of 15:20, 21 January 2015

File:Macro Python Assistant Window Macro Python Assistant Window

Description
This macro provides a cut/copy/paste workspace for Python code, it is segmented so different sections can be selected and it is persistent between FreeCAD sessions.

Author: Piffpoof
Author
Piffpoof
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

One of Python's powerful aspects is the Python Console which serves both as an output device and a dynamic interpreter of source code. The Python Assistant Window (subsequently referred to as 'PAW') provides additional functionality to the Python Console.

File:PythonAssistantWindowScreenShanpshot.jpg

Description

As a modern development environment, Python has a lot of advantages over older languages and their development environments. One large benefit is the Python Console where code can be interactively entered and the results received. Those results can then be copied and used to either build up Python source code (in a source editor) or pasted back into the Python Console in an altered form to receive further output. This is a very powerful method of developing code.

As powerful as it may be, two readily apparent shortcomings with the Python Console are:

  • the console is of limited size and the results of your work from 20 minutes ago may be scrolled far off the screen, they are not lost but they are awkward to retrieve
  • the console is cleared each time you quite your FreeCAD session, the console is empty (aside from the Python startup message) next time you start FreeCAD

The PAW provides the following:

  • it is persistent between FreeCAD sessions, things will not "disappear" from it unless the user removes them
  • it has a contextual menu that allows the following:
    • the standard editing operands: Copy & Paste & Select All
    • Copy a selection to the Python Console
    • Copy the complete contents of the PAW to the Python Console
    • Append the contents of the Python Console to the PAW
    • insert textual markers that facilitate management of the text
    • selection between any two consecutive markers
    • remove the prefix ">>> " which the Python Console uses to denote output
    • reduce multiple blank lines to single blank lines
    • personalise the working environment by managing the PAW (as well as the main FreeCAD window) by a slider-based GUI

Installation

All the code for pythonAssistantWindow.FCMacro is in one macro. So installation is comprised of copying the code to the appropriate Macro directory and invoking dumpObject from the Macro menu. Alternatively it may be run from the console.

A global variable within FreeCAD is used to coordinate the persistent storage.

A text file in the "UserAppData" directory is used to store the textual contents of the PAW between FreeCAD sessions.

Usage

The PAW is best used as a button on a toolbar. It can be run from the Macro Menu or the code pasted onto the Python Console but the latter two options really detract from it's ease of use.

When FreeCAD is started there will be no sign of the PAW, other than a button on a toolbar. Clicking the button will cause:

  • the PAW to open in the lower right corner
    • the default settings are for the about 1/3 of the screen width to be dedicated to the PAW with the remainder being used by the main FreeCAD window, the height of the PAW will be about 1/3 of the window height
  • the contents of the PAW when it last ran will appear in the window - there should be no difference from the last time it was used
    • if the PAW has not run before then the contents will be empty
  • if the PAW is already open but hidden by other windows then it will be raised to the top so that it becomes visible
  • closing the PAW will cause the contents to be written to file and the window will close - there is no Dialog asking whether to save or not

Most of the functionality for the PAW is provided by the contextual menu, the options are:

  • Copy
    - provide the standard Copy function
  • Copy selection to console
    - the current selection is copied to the end of the Python Console
  • Copy contents to console
    - the complete contents of the PAW is copied to the end of the Python Console
  • Paste
    - provide the standard Paste function
  • Append contents of Python Console to PAW
    - the copies of the Python Console are placed at the end of the PAW - note that the contents of the Python Console may be a mixture of Python Code, output from Python Code, error message text, output from any part of FreeCAD
  • Select between Markers
    - markers are used to divide up the text of the PAW into sections, once the contents are in sections then a section can be selected individually and worked with (e.g. Copy, Copy to the Python Console, Delete). The intention of Markers is to allow separate and unrelated sequences of Python statement to exist in the PAW, and then be managed and worked with individually.
  • Select all
    - provide the standard Select All function
  • Clear
    - provide the standard Clear function where all the text in the PAW is deleted
  • Insert marker
    - insert a textual Marker at the current cursor location
  • Remove ">>> "
    - after Python Console output is copied to the PAW, any lines which were output from executed Python commands will be prefixed with ">>> ", this option removed those prefixes so the output can be used as context free data
  • Reduce multiple blank lines to single blank lines
    - compacts the text by removing multiple blank lines
  • Alter GUI settings
    -
  • Close window
    - the PAW window is closed and the contents writen out to the persistent storage file
    <bold>Note</bold>: there is no Dialog asking about saving, it is done automatically

User Interface

The user interface is a simple text editing window, there is one button to start the PAW and a contextual menu of options to beform on the text in the text editing window. The options are described in the Usage section.

Options

About the only option for the PAW is the ability to alter it's display size and shape in accordance with the size and shape fo the main FreeCAD window. There are 3 constant values in the Python code which initial size and placement of the PAW.

Remarks

Links

none (so far)

Script

not here yet, coming soon