FlatCAM Application

App

class FlatCAM.App

The main application class. The constructor starts the GUI.

disable_plots(except_current=False)

Disables all plots with exception of the current object if specified.

Parameters:except_current – Wether to skip the current object.
Rtype except_current:
 boolean
Returns:None
file_chooser_action(on_success)

Opens the file chooser and runs on_success on a separate thread upon completion of valid file choice.

Parameters:on_success (func) – A function to run upon completion of a valid file selection. Takes 2 parameters: The app instance and the filename. Note that it is run on a separate thread, therefore it must take the appropriate precautions when accessing shared resources.
Returns:None
file_chooser_save_action(on_success)

Opens the file chooser and runs on_success upon completion of valid file choice.

Parameters:on_success – A function to run upon selection of a filename. Takes 2 parameters: The instance of the application (App) and the chosen filename. This gets run immediately in the same thread.
Returns:None
get_eval(widget_name)

Runs eval() on the on the text entry of name ‘widget_name’ and returns the results.

Parameters:widget_name (str) – Name of Gtk.Entry
Returns:Depends on contents of the entry text.
get_radio_value(radio_set)

Returns the radio_set[key] of the radiobutton whose name is key is active.

Parameters:radio_set (dict) – A dictionary containing widget_name: value pairs.
Returns:radio_set[key]
info(text)

Show text on the status bar. This method is thread safe.

Parameters:text (str) – Text to display.
Returns:None
load_defaults()

Loads the aplication’s default settings from defaults.json into self.defaults.

Returns:None
new_object(kind, name, initialize)

Creates a new specalized FlatCAMObj and attaches it to the application, this is, updates the GUI accordingly, any other records and plots it. This method is thread-safe.

Parameters:
  • kind (str) – The kind of object to create. One of ‘gerber’, ‘excellon’, ‘cncjob’ and ‘geometry’.
  • name (str) – Name for the object.
  • initialize (function) – Function to run after creation of the object but before it is attached to the application. The function is called with 2 parameters: the new object and the App instance.
Returns:

None

Return type:

None

on_about(widget)

Opens the ‘About’ dialog box.

Parameters:widget – Ignored.
Returns:None
on_activate_name(entry)

Hitting ‘Enter’ after changing the name of an item updates the item dictionary and re-builds the item list.

Parameters:entry – The widget from which this was called.
Returns:None
on_canvas_configure(widget, event)

Called whenever the canvas changes size. The axes are updated such as to use the whole canvas.

Parameters:
  • widget – Ignored.
  • event – Ignored.
Returns:

None

on_cb_plot_toggled(widget)

Callback for toggling the “Plot” checkbox. Re-plots.

Parameters:widget – Ignored.
Returns:None
on_clear_plots(widget)

Callback for toolbar button. Clears all plots.

Parameters:widget – The widget from which this was called.
Returns:None
on_click_over_plot(event)

Callback for the mouse click event over the plot. This event is generated by the Matplotlib backend and has been registered in self.__init__(). For details, see: http://matplotlib.org/users/event_handling.html

Default actions are:

  • Copy coordinates to clipboard. Ex.: (65.5473, -13.2679)
Parameters:event – Contains information about the event, like which button was clicked, the pixel coordinates and the axes coordinates.
Returns:None
on_closewindow(param)

Callback for closing the main window.

Parameters:param – Whatever is passed by the event. Ignore.
Returns:None
on_cncjob_exportgcode(widget)

Called from button on CNCjob form to save the G-Code from the object.

Parameters:widget – The widget from which this was called.
Returns:None
on_create_aligndrill(widget)

Creates alignment holes Excellon object. Creates mirror duplicates of the specified holes around the specified axis.

Parameters:widget – Ignored.
Returns:None
on_create_mirror(widget)

Creates a mirror image of an object to be used as a bottom layer.

Parameters:widget – Ignored.
Returns:None
on_delete(widget)

Delete the currently selected FlatCAMObj.

Parameters:widget – The widget from which this was called. Ignored.
Returns:None
on_entry_eval_activate(widget)

Called when an entry is activated (eg. by hitting enter) if set to do so. Its text is eval()’d and set to the returned value. The current object is updated.

Parameters:widget
Returns:
on_eval_update(widget)

Modifies the content of a Gtk.Entry by running eval() on its contents and puting it back as a string.

Parameters:widget – The widget from which this was called.
Returns:None
on_excellon_tool_choose(widget)

Callback for button on Excellon form to open up a window for selecting tools.

Parameters:widget – The widget from which this was called.
Returns:None
on_file_new(param)

Callback for menu item File->New. Returns the application to its startup state. This method is thread-safe.

Parameters:param – Whatever is passed by the event. Ignore.
Returns:None
on_file_openproject(param)

Callback for menu item File->Open Project. Opens a file chooser and calls self.open_project() after successful selection of a filename.

Parameters:param – Ignored.
Returns:None
on_file_savedefaults(param)

Callback for menu item File->Save Defaults. Saves application default options self.defaults to defaults.json.

Parameters:param – Ignored.
Returns:None
on_file_saveproject(param)

Callback for menu item File->Save Project. Saves the project to self.project_filename or calls self.on_file_saveprojectas() if set to None. The project is saved by calling self.save_project().

Parameters:param – Ignored.
Returns:None
on_file_saveprojectas(param)

Callback for menu item File->Save Project As... Opens a file chooser and saves the project to the given file via self.save_project().

Parameters:param – Ignored.
Returns:None
on_file_saveprojectcopy(param)

Callback for menu item File->Save Project Copy... Opens a file chooser and saves the project to the given file via self.save_project. It does not update self.project_filename so subsequent save requests are done on the previous known filename.

Parameters:param – Ignore.
Returns:None
on_fileopenexcellon(param)

Callback for menu item File->Open Excellon. Defines a function that is then passed to self.file_chooser_action(). It requests the creation of a FlatCAMExcellon object and updates the progress bar throughout the process.

Parameters:param – Ignore
Returns:None
on_fileopengcode(param)

Callback for menu item File->Open G-Code. Defines a function that is then passed to self.file_chooser_action(). It requests the creation of a FlatCAMCNCjob object and updates the progress bar throughout the process.

Parameters:param – Ignore
Returns:None
on_fileopengerber(param)

Callback for menu item File->Open Gerber. Defines a function that is then passed to self.file_chooser_action(). It requests the creation of a FlatCAMGerber object and updates the progress bar throughout the process.

Parameters:param – Ignore
Returns:None
on_filequit(param)

Callback for menu item File->Quit. Closes the application.

Parameters:param – Whatever is passed by the event. Ignore.
Returns:None
on_generate_cncjob(widget)

Callback for button on geometry form to generate CNC job.

Parameters:widget – The widget from which this was called.
Returns:None
on_generate_excellon_cncjob(widget)

Callback for button active/click on Excellon form to create a CNC Job for the Excellon file.

Parameters:widget – Ignored
Returns:None
on_generate_gerber_bounding_box(widget)

Callback for request from the Gerber form to generate a bounding box for the geometry in the object. Creates a FlatCAMGeometry with the bounding box. The box can have rounded corners if specified in the form.

Parameters:widget – Ignored.
Returns:None
on_generate_isolation(widget)

Callback for button on Gerber form to create isolation routing geometry.

Parameters:widget – The widget from which this was called.
Returns:None
on_generate_paintarea(widget)

Callback for button on geometry form. Subscribes to the “Click on plot” event and continues after the click. Finds the polygon containing the clicked point and runs clear_poly() on it, resulting in a new FlatCAMGeometry object.

Parameters:widget – The widget from which this was called.
Returns:None
on_gerber_generate_cutout(widget)

Callback for button on Gerber form to create geometry with lines for cutting off the board.

Parameters:widget – The widget from which this was called.
Returns:None
on_gerber_generate_noncopper(widget)

Callback for button on Gerber form to create a geometry object with polygons covering the area without copper or negative of the Gerber.

Parameters:widget – The widget from which this was called.
Returns:None
on_key_over_plot(event)

Callback for the key pressed event when the canvas is focused. Keyboard shortcuts are handled here. So far, these are the shortcuts:

Key Action
‘1’ Zoom-fit. Fits the axes limits to the data.
‘2’ Zoom-out.
‘3’ Zoom-in.
‘m’ Toggle on-off the measuring tool.
Parameters:event – Ignored.
Returns:None
on_mouse_move_over_plot(event)

Callback for the mouse motion event over the plot. This event is generated by the Matplotlib backend and has been registered in self.__init__(). For details, see: http://matplotlib.org/users/event_handling.html

Parameters:event – Contains information about the event.
Returns:None
on_offset_object(widget)

Offsets the object’s geometry by the vector specified in the form. Re-plots.

Parameters:widget – Ignored
Returns:None
on_options_app2object(param)

Callback for Options->Transfer Options->App=>Object. Copies options from application defaults to the currently selected object.

Parameters:param – Ignored.
Returns:None
on_options_app2project(param)

Callback for Options->Transfer Options->App=>Project. Copies options from application defaults to project defaults.

Parameters:param – Ignored.
Returns:None
on_options_combo_change(widget)

Called when the combo box to choose between application defaults and project option changes value. The corresponding variables are copied to the UI.

Parameters:widget – The widget from which this was called. Ignore.
Returns:None
on_options_object2app(param)

Callback for Options->Transfer Options->Object=>App. Copies options from the currently selected object to application defaults.

Parameters:param – Ignored.
Returns:None
on_options_object2project(param)

Callback for Options->Transfer Options->Object=>Project. Copies options from the currently selected object to project defaults.

Parameters:param – Ignored.
Returns:None
on_options_project2app(param)

Callback for Options->Transfer Options->Project=>App. Copies options from project defaults to application defaults.

Parameters:param – Ignored.
Returns:None
on_options_project2object(param)

Callback for Options->Transfer Options->Project=>Object. Copies options from project defaults to the currently selected object.

Parameters:param – Ignored.
Returns:None
on_options_update(widget)

Called whenever a value in the options/defaults form changes. All values are updated. Can be inhibited by setting self.options_update_ignore = True, which may be necessary when updating the UI from code and not by the user.

Parameters:widget – The widget from which this was called. Ignore.
Returns:None
on_row_activated(widget, path, col)

Callback for selection activation (Enter or double-click) on the Project list. Switches the notebook page to the object properties form. Calls self.notebook.set_current_page(1).

Parameters:
  • widget – Ignored.
  • path – Ignored.
  • col – Ignored.
Returns:

None

on_scale_object(widget)

Callback for request to change an objects geometry scale. The object is re-scaled and replotted.

Parameters:widget – Ignored.
Returns:None
on_toggle_pointbox(widget)

Callback for radio selection change between point and box in the Double-sided PCB tool. Updates the UI accordingly.

Parameters:widget – Ignored.
Returns:None
on_toggle_units(widget)

Callback for the Units radio-button change in the Options tab. Changes the application’s default units or the current project’s units. If changing the project’s units, the change propagates to all of the objects in the project.

Parameters:widget – Ignored.
Returns:None
on_toolbar_replot(widget)

Callback for toolbar button. Re-plots all objects.

Parameters:widget – The widget from which this was called.
Returns:None
on_tools_doublesided(param)

Callback for menu item Tools->Double Sided PCB Tool. Launches the tool placing its UI in the “Tool” tab in the notebook.

Parameters:param – Ignored.
Returns:None
on_update_plot(widget)

Callback for button on form for all kinds of objects. Re-plots the current object only.

Parameters:widget – The widget from which this was called. Ignored.
Returns:None
on_zoom_fit(event)

Callback for zoom-out request. This can be either from the corresponding toolbar button or the ‘1’ key when the canvas is focused. Calls self.adjust_axes() with axes limits from the geometry bounds of all objects.

Parameters:event – Ignored.
Returns:None
on_zoom_in(event)

Callback for zoom-in request. This can be either from the corresponding toolbar button or the ‘3’ key when the canvas is focused. Calls self.zoom().

Parameters:event – Ignored.
Returns:None
on_zoom_out(event)

Callback for zoom-out request. This can be either from the corresponding toolbar button or the ‘2’ key when the canvas is focused. Calls self.zoom().

Parameters:event – Ignored.
Returns:None
open_project(filename)

Loads a project from the specified file.

Parameters:filename (str) – Name of the file from which to load.
Returns:None
options2form()

Sets the ‘Project Options’ or ‘Application Defaults’ form with values from self.options or self.defaults.

Returns:None
Return type:None
plot_all()

Re-generates all plots from all objects.

Returns:None
populate_objects_combo(combo)

Populates a Gtk.Comboboxtext with the list of the object in the project.

Parameters:combo (str or Gtk.ComboBoxText) – Name or instance of the comboboxtext.
Returns:None
read_form()

Reads the options form into self.defaults/self.options.

Returns:None
Return type:None
read_form_item(name, dest)

Reads the value of a form item in the defaults/options form and saves it to the corresponding dictionary.

Parameters:
  • name (str) – Name of the form item. A key in self.defaults or self.options.
  • dest (dict) – Dictionary to which to save the value.
Returns:

None

save_project(filename)

Saves the current project to the specified file.

Parameters:filename (str) – Name of the file in which to save.
Returns:None
set_form_item(name, value)

Sets a form item ‘name’ in the GUI with the given ‘value’. The syntax of form names in the GUI is <kind>_app_<name>, where kind is one of: rb (radio button), cb (check button), entry_eval or entry_text (entry), combo (combo box). name is whatever name it’s been given. For self.defaults, name is a key in the dictionary.

Parameters:
  • name (str) – Name of the form field.
  • value (Depends on field kind.) – The value to set the form field to.
Returns:

None

set_progress_bar(percentage, text='')

Sets the application’s progress bar to a given frac_digits and text.

Parameters:
  • percentage (float) – The frac_digits (0.0-1.0) of the progress.
  • text (str) – Text to display on the progress bar.
Returns:

None

setup_component_editor()

Initial configuration of the component editor. Creates a page titled “Selection” on the notebook on the left side of the main window.

Returns:None
setup_obj_classes()

Sets up application specifics on the FlatCAMObj class.

Returns:None
version_check(*args)

Checks for the latest version of the program. Alerts the user if theirs is outdated. This method is meant to be run in a saeparate thread.

Returns:None

PlotCanvas

class FlatCAM.PlotCanvas(container)

Class handling the plotting area in the application.

adjust_axes(xmin, ymin, xmax, ymax)

Adjusts all axes while maintaining the use of the whole canvas and an aspect ratio to 1:1 between x and y axes. The parameters are an original request that will be modified to fit these restrictions.

Parameters:
  • xmin (float) – Requested minimum value for the X axis.
  • ymin (float) – Requested minimum value for the Y axis.
  • xmax (float) – Requested maximum value for the X axis.
  • ymax (float) – Requested maximum value for the Y axis.
Returns:

None

auto_adjust_axes(*args)

Calls adjust_axes() using the extents of the base axes.

:rtype : None :return: None

clear()

Clears axes and figure.

Returns:None
connect(event_name, callback)

Attach an event handler to the canvas through the native GTK interface.

Parameters:
  • event_name (str) – Name of the event
  • callback (function) – Function to call
Returns:

Nothing

mpl_connect(event_name, callback)

Attach an event handler to the canvas through the Matplotlib interface.

Parameters:
  • event_name (str) – Name of the event
  • callback (func) – Function to call
Returns:

Connection id

Return type:

int

mpl_disconnect(cid)

Disconnect callback with the give id. :param cid: Callback id. :return: None

new_axes(name)

Creates and returns an Axes object attached to this object’s Figure.

Parameters:name – Unique label for the axes.
Returns:Axes attached to the figure.
Return type:Axes
on_key_down(event)
Parameters:event
Returns:
on_key_up(event)
Parameters:event
Returns:
on_mouse_move(event)

Mouse movement event hadler.

Parameters:event – Contains information about the event.
Returns:None
on_scroll(canvas, event)

Scroll event handler.

Parameters:
  • canvas – The widget generating the event. Ignored.
  • event – Event object containing the event information.
Returns:

None

zoom(factor, center=None)

Zooms the plot by factor around a given center point. Takes care of re-drawing.

Parameters:
  • factor (float) – Number by which to scale the plot.
  • center (list) – Coordinates [x, y] of the point around which to scale the plot.
Returns:

None

ObjectCollection

class FlatCAM.ObjectCollection
append(obj, active=False)

Add a FlatCAMObj the the collection. This method is thread-safe.

Parameters:
  • obj (FlatCAMObj) – FlatCAMObj to append
  • active (bool) – If it is to become the active object after appending
Returns:

None

change_name(old_name, new_name)

Changes the name of FlatCAMObj named old_name to new_name.

Parameters:
  • old_name (str) – Name of the object to change.
  • new_name (str) – New name.
Returns:

True if name change succeeded, False otherwise. Will fail if no object with old_name is found.

Return type:

bool

get_bounds()

Finds coordinates bounding all objects in the collection.

Returns:[xmin, ymin, xmax, ymax]
Return type:list
get_by_name(name)

Fetches the FlatCAMObj with the given name.

Parameters:name (str) – The name of the object.
Returns:The requested object or None if no such object.
Return type:FlatCAMObj or None
get_list()

Returns a list with all FlatCAMObj.

Returns:List with all FlatCAMObj.
Return type:list
get_names()

Gets a list of the names of all objects in the collection.

Returns:List of names.
Return type:list
on_list_selection_change(selection)

Callback for change in selection on the objects’ list. Instructs the new selection to build the UI for its options.

Parameters:selection – Ignored.
Returns:None
on_row_activated(*args)

Does nothing right now. :param args: Ignored. :return: None

set_active(name)

Sets an object as the active object in the program. Same as set_list_selection().

Parameters:name (str) – Name of the object.
Returns:None
set_list_selection(name)

Sets which object should be selected in the list.

Parameters:name – Name of the object.
Rtype name:str
Returns:None

Measurement

class FlatCAM.Measurement(container, plotcanvas, update=None)