Commit b840cc29 authored by sumpfralle's avatar sumpfralle

moved part of the GCode settings to separate plugins


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1193 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 13608b72
<?xml version="1.0"?>
<interface>
<!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="GCodePreferencesWindow">
<property name="border_width">5</property>
<property name="type_hint">normal</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkNotebook" id="GCodePrefsNotebook">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tab_pos">left</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="CloseButton">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">CloseButton</action-widget>
</action-widgets>
</object>
<object class="GtkHButtonBox" id="PreferencesControls">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="PreferencesButton">
<property name="label">gtk-preferences</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
</interface>
......@@ -244,78 +244,7 @@
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkTable" id="table14">
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">2</property>
<child>
<object class="GtkLabel" id="GCodeFilenameExtensionLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Custom GCode filename extension:</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="GCodeFilenameExtension">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Select a file extension to be used when storing GCode files.
Leave this field empty if you are satisfied with the default: "ngc".
This is just a convenience setting. The "Export Toolpath" dialog
still allows you to choose the file extension freely.</property>
<property name="invisible_char">&#x25CF;</property>
<property name="width_chars">6</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="SafetyHeightControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Rapid moves are allowed at this z-level.
This should be clearly above the stock material.
Choose a small value to minimize rapid moves up and down.</property>
<property name="invisible_char">&#x25CF;</property>
<property name="adjustment">SafetyHeightValue</property>
<property name="digits">1</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="SafetyHeightLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Safety Height:</property>
</object>
<packing>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
<placeholder/>
</child>
<child>
<object class="GtkExpander" id="expander3">
......
......@@ -51,6 +51,20 @@ def _output_conversion(func):
class InputBaseClass(object):
def connect(self, signal, handler, control=None):
if not handler:
return
if control is None:
control = self.get_widget()
if not hasattr(self, "_handler_ids"):
self._handler_ids = []
self._handler_ids.append(control.connect(signal, handler))
def destroy(self):
while hasattr(self, "_handler_ids") and self._handler_ids:
self.get_widget().disconnect(self._handler_ids.pop())
self.get_widget().destroy()
def get_widget(self):
return self.control
......@@ -73,8 +87,7 @@ class InputNumber(InputBaseClass):
step_incr=increment)
self.control = gtk.SpinButton(adjustment, digits=digits)
self.control.set_value(start)
if change_handler:
self.control.connect("changed", change_handler)
self.connect("changed", change_handler)
@_output_conversion
def get_value(self):
......@@ -85,6 +98,22 @@ class InputNumber(InputBaseClass):
self.control.set_value(value)
class InputString(InputBaseClass):
def __init__(self, start="", max_length=32, change_handler=None):
self.control = gtk.Entry(max_length)
self.control.set_text(start)
self.connect("changed", change_handler)
@_output_conversion
def get_value(self):
return self.control.get_text()
@_input_conversion
def set_value(self, value):
self.control.set_text(value)
class InputChoice(InputBaseClass):
def __init__(self, choices, change_handler=None):
......@@ -98,8 +127,7 @@ class InputChoice(InputBaseClass):
self.control.pack_start(renderer)
self.control.set_attributes(renderer, text=0)
self.control.set_active(0)
if change_handler:
self.control.connect("changed", change_handler)
self.connect("changed", change_handler)
@_output_conversion
def get_value(self):
......@@ -172,8 +200,7 @@ class InputTable(InputChoice):
self._selection = self._treeview.get_selection()
self._selection.set_mode(gtk.SELECTION_MULTIPLE)
self.control.show_all()
if change_handler:
self._selection.connect("changed", change_handler)
self.connect("changed", change_handler, self._selection)
def get_value(self):
model, rows = self._selection.get_selected_rows()
......@@ -195,8 +222,7 @@ class InputCheckBox(InputBaseClass):
def __init__(self, start=False, change_handler=None):
self.control = gtk.CheckButton()
self.control.set_active(start)
if change_handler:
self.control.connect("toggled", change_handler)
self.connect("toggled", change_handler)
@_output_conversion
def get_value(self):
......
......@@ -441,7 +441,6 @@ class ProjectGui(object):
add_preferences_item, clear_preferences)
for obj_name, label, priority in (
("GeneralSettingsPrefTab", "General", -50),
("GCodePrefTab", "GCode", 10),
("ProgramsPrefTab", "Programs", 50)):
obj = self.gui.get_object(obj_name)
obj.unparent()
......@@ -527,21 +526,6 @@ class ProjectGui(object):
self.settings.register_event("gui-disable", disable_gui)
self.settings.register_event("gui-enable", enable_gui)
# gcode settings
gcode_minimum_step_x = self.gui.get_object("GCodeMinimumStep_x")
self.settings.add_item("gcode_minimum_step_x",
gcode_minimum_step_x.get_value, gcode_minimum_step_x.set_value)
gcode_minimum_step_y = self.gui.get_object("GCodeMinimumStep_y")
self.settings.add_item("gcode_minimum_step_y",
gcode_minimum_step_y.get_value, gcode_minimum_step_y.set_value)
gcode_minimum_step_z = self.gui.get_object("GCodeMinimumStep_z")
self.settings.add_item("gcode_minimum_step_z",
gcode_minimum_step_z.get_value, gcode_minimum_step_z.set_value)
gcode_safety_height = self.gui.get_object("SafetyHeightControl")
self.settings.add_item("gcode_safety_height",
gcode_safety_height.get_value, gcode_safety_height.set_value)
gcode_spindle_delay = self.gui.get_object("GCodeSpindleDelay")
self.settings.add_item("gcode_spindle_delay",
gcode_spindle_delay.get_value, gcode_spindle_delay.set_value)
for objname, setting in (
("GCodeTouchOffOnStartup", "touch_off_on_startup"),
("GCodeTouchOffOnToolChange", "touch_off_on_tool_change")):
......@@ -580,9 +564,6 @@ class ProjectGui(object):
touch_off_pause = self.gui.get_object("TouchOffPauseExecution")
self.settings.add_item("touch_off_pause_execution",
touch_off_pause.get_active, touch_off_pause.set_active)
# redraw the toolpath if safety height changed
gcode_safety_height.connect("value-changed", lambda widget:
self.settings.emit_event("visual-item-updated"))
gcode_path_mode = self.gui.get_object("GCodeCornerStyleControl")
self.settings.add_item("gcode_path_mode", gcode_path_mode.get_active,
gcode_path_mode.set_active)
......@@ -602,10 +583,6 @@ class ProjectGui(object):
gcode_start_stop_spindle.get_active,
gcode_start_stop_spindle.set_active)
gcode_start_stop_spindle.connect("toggled", self.update_gcode_controls)
gcode_filename_extension = self.gui.get_object("GCodeFilenameExtension")
self.settings.add_item("gcode_filename_extension",
gcode_filename_extension.get_text,
gcode_filename_extension.set_text)
# configure locations of external programs
for auto_control_name, location_control_name, browse_button, key in (
("ExternalProgramInkscapeAuto",
......
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
import pycam.Gui.ControlsGTK
class GCodePreferences(pycam.Plugins.PluginBase):
DEPENDS = []
CATEGORIES = ["GCode"]
UI_FILE = "gcode_preferences.ui"
def setup(self):
if self.gui:
import gtk
notebook = self.gui.get_object("GCodePrefsNotebook")
def clear_preferences():
for child in notebook.get_children():
notebook.remove(child)
def add_preferences_item(item, name):
if not isinstance(item, gtk.Frame):
# create a simple default frame if none was given
frame = gtk.Frame(name)
frame.get_label_widget().set_markup("<b>%s</b>" % name)
frame.set_shadow_type(gtk.SHADOW_NONE)
align = gtk.Alignment()
align.set_padding(5, 0, 12, 0)
frame.add(align)
frame.show()
item.unparent()
align.add(item)
align.show()
item = frame
notebook.append_page(item, gtk.Label(name))
notebook.show_all()
self.core.register_ui_section("gcode_preferences",
add_preferences_item, clear_preferences)
general_widget = pycam.Gui.ControlsGTK.ParameterSection()
general_widget.widget.show()
self.core.register_ui_section("gcode_general_parameters",
general_widget.add_widget, general_widget.clear_widgets)
self.core.register_ui("gcode_preferences", "General",
general_widget.widget)
self.core.register_ui("toolpath_handling", "Settings",
self.gui.get_object("PreferencesControls"))
self.gui.get_object("PreferencesButton").connect("clicked",
self._toggle_window, True)
self.gui.get_object("CloseButton").connect("clicked",
self._toggle_window, False)
self.window = self.gui.get_object("GCodePreferencesWindow")
self.window.connect("delete-event", self._toggle_window, False)
return True
def teardown(self):
if self.gui:
self._toggle_window(False)
def _toggle_window(self, *args):
status = args[-1]
if status:
self.window.show()
else:
self.window.hide()
# don't destroy the window
return True
class GCodeSafetyHeight(pycam.Plugins.PluginBase):
DEPENDS = ["GCodePreferences"]
CATEGORIES = ["GCode"]
def setup(self):
self.safety_height = pycam.Gui.ControlsGTK.InputNumber(digits=0,
change_handler=lambda *args: \
self.core.emit_event("visual-item-updated"))
self.core.register_ui("gcode_general_parameters", "Safety Height",
self.safety_height.get_widget(), weight=20)
# TODO: this should be done via parameter groups based on postprocessors
self.safety_height.get_widget().show()
self.core.add_item("gcode_safety_height",
self.safety_height.get_value, self.safety_height.set_value)
return True
def teardown(self):
self.core.add_item("gcode_safety_height", lambda value: None,
lambda: None)
self.safety_height.destroy()
class GCodeFilenameExtension(pycam.Plugins.PluginBase):
DEPENDS = ["GCodePreferences"]
CATEGORIES = ["GCode"]
def setup(self):
self.filename_extension = pycam.Gui.ControlsGTK.InputString(
max_length=6)
self.core.register_ui("gcode_general_parameters",
"Custom GCode filename extension",
self.filename_extension.get_widget(), weight=80)
# TODO: this should be done via parameter groups based on postprocessors
self.filename_extension.get_widget().show()
self.core.add_item("gcode_filename_extension",
self.filename_extension.get_value,
self.filename_extension.set_value)
return True
def teardown(self):
self.core.add_item("gcode_filename_extension", lambda value: None,
lambda: None)
self.filename_extension.destroy()
class GCodeStepWidth(pycam.Plugins.PluginBase):
DEPENDS = ["GCodePreferences"]
CATEGORIES = ["GCode"]
def setup(self):
table = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui("gcode_preferences", "Step precision",
table.widget)
self.core.register_ui_section("gcode_step_width",
table.add_widget, table.clear_widgets)
for key in "xyz":
control = pycam.Gui.ControlsGTK.InputNumber(digits=8, start=0.0001,
increment=0.00005)
self.core.add_item("gcode_minimum_step_%s" % key,
control.get_value, control.set_value)
self.core.register_ui("gcode_step_width", key.upper(),
control.get_widget(), weight="xyz".index(key))
# TODO: this should be done via parameter groups based on postprocessors
control.get_widget().show()
return True
class GCodeSpindle(pycam.Plugins.PluginBase):
DEPENDS = ["GCodePreferences"]
CATEGORIES = ["GCode"]
def setup(self):
table = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui("gcode_preferences", "Spindle control",
table.widget)
self.core.register_ui_section("gcode_spindle",
table.add_widget, table.clear_widgets)
self.spindle_delay = pycam.Gui.ControlsGTK.InputNumber(digits=1)
self.core.register_ui("gcode_spindle",
"Delay (in seconds) after start/stop",
self.spindle_delay.get_widget(), weight=20)
# TODO: this should be done via parameter groups based on postprocessors
self.spindle_delay.get_widget().show()
self.core.add_item("gcode_spindle_delay",
self.spindle_delay.get_value,
self.spindle_delay.set_value)
......@@ -108,7 +108,7 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
CATEGORIES = ["Tool", "Parameter"]
def setup(self):
self.control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=100000,
self.control = pycam.Gui.ControlsGTK.InputNumber(lower=1, upper=500000,
digits=0, change_handler=lambda widget=None: \
self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "spindle_speed",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment