Commit 4dd43c97 authored by sumpfralle's avatar sumpfralle

added automatic preferences load/save during startup/exit of the program

 * the preferences file is written to ~/.pycam/preferences.conf (*nix) resp. below APP_DATA (Windows)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@285 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 94e0fa35
Version 0.2.3 - UNRELEASED
* GUI change: tool and process settings can be combined into tasks
* added export of EMC tool definitions
* store configured settings to a file in the user's home directory
* fixed "overlap" calculation
* added a warning dialog (GUI) for missing dependencies during startup (especially useful for Windows)
* improved GUI for model scaling
......
This diff is collapsed.
......@@ -3,12 +3,40 @@ import StringIO
import sys
import os
GET_INDEX = 0
SET_INDEX = 1
VALUE_INDEX = 2
CONFIG_DIR = "pycam"
def get_config_dirname():
try:
from win32com.shell import shellcon, shell
homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
config_dir = os.path.join(homedir, CONFIG_DIR)
except ImportError: # quick semi-nasty fallback for non-windows/win32com case
homedir = os.path.expanduser("~")
# hide the config directory for unixes
config_dir = os.path.join(homedir, "." + CONFIG_DIR)
if not os.path.isdir(config_dir):
try:
os.makedirs(config_dir)
except OSError:
config_dir = None
return config_dir
def get_config_filename(filename=None):
if filename is None:
filename = "preferences.conf"
config_dir = get_config_dirname()
if config_dir is None:
return None
else:
return os.path.join(config_dir, filename)
class Settings:
GET_INDEX = 0
SET_INDEX = 1
VALUE_INDEX = 2
def __init__(self):
self.items = {}
self.values = {}
......@@ -17,35 +45,39 @@ class Settings:
self.items[key] = [None, None, None]
self.define_get_func(key, get_func)
self.define_set_func(key, set_func)
self.items[key][VALUE_INDEX] = None
self.items[key][self.VALUE_INDEX] = None
def define_get_func(self, key, get_func=None):
if not self.items.has_key(key):
return
if get_func is None:
get_func = lambda: self.items[key][VALUE_INDEX]
self.items[key][GET_INDEX] = get_func
get_func = lambda: self.items[key][self.VALUE_INDEX]
self.items[key][self.GET_INDEX] = get_func
def define_set_func(self, key, set_func=None):
if not self.items.has_key(key):
return
def default_set_func(value):
self.items[key][VALUE_INDEX] = value
self.items[key][self.VALUE_INDEX] = value
if set_func is None:
set_func = default_set_func
self.items[key][SET_INDEX] = set_func
self.items[key][self.SET_INDEX] = set_func
def get(self, key, default=None):
if self.items.has_key(key):
return self.items[key][GET_INDEX]()
return self.items[key][self.GET_INDEX]()
else:
return default
def set(self, key, value):
if not self.items.has_key(key):
self.add_item(key)
self.items[key][SET_INDEX](value)
self.items[key][VALUE_INDEX] = value
self.items[key][self.SET_INDEX](value)
self.items[key][self.VALUE_INDEX] = value
def has_key(self, key):
""" expose the "has_key" function of the items list """
return self.items.has_key(key)
def __str__(self):
result = {}
......@@ -54,7 +86,7 @@ class Settings:
return str(result)
class SettingsFileManager:
class ProcessSettings:
DEFAULT_CONFIG = """
[ToolDefault]
......
......@@ -10,9 +10,9 @@
<menuitem action="Quit"/>
</menu>
<menu action="SettingsMenu">
<menuitem action="LoadSettings"/>
<menuitem action="SaveSettings"/>
<menuitem action="SaveAsSettings"/>
<menuitem action="LoadTaskSettings"/>
<menuitem action="SaveTaskSettings"/>
<menuitem action="SaveAsTaskSettings"/>
<separator />
<menuitem action="ExportEMCToolDefinition"/>
<separator />
......
......@@ -614,6 +614,7 @@
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Scale the model along all axes proportionally.</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
......@@ -2178,19 +2179,19 @@ This combination is added to the above task list.</property>
<property name="tooltip">Write all current toolpaths to a file.</property>
<property name="stock_id">gtk-execute</property>
</object>
<object class="GtkAction" id="LoadSettings">
<property name="label">_Load Settings</property>
<property name="tooltip">Loads a set of processing templates from a file.</property>
<object class="GtkAction" id="LoadTaskSettings">
<property name="label">_Load Task Settings</property>
<property name="tooltip">Load tool, process and task definitions from a file.</property>
<property name="stock_id">gtk-open</property>
</object>
<object class="GtkAction" id="SaveSettings">
<property name="label">_Save Settings</property>
<property name="tooltip">Save the currently visible set of processing templates to a file.</property>
<object class="GtkAction" id="SaveTaskSettings">
<property name="label">_Save Task Settings</property>
<property name="tooltip">Save the tool, process and task definitions.</property>
<property name="stock_id">gtk-save</property>
</object>
<object class="GtkAction" id="SaveAsSettings">
<property name="label">Save Settings _as ...</property>
<property name="tooltip">Save the currently visible set of processing templates to a new file.</property>
<object class="GtkAction" id="SaveAsTaskSettings">
<property name="label">Save Task Settings _as ...</property>
<property name="tooltip">Save the tool, process and task definitions to a new file.</property>
<property name="stock_id">gtk-save-as</property>
</object>
<object class="GtkAction" id="GeneralSettings">
......@@ -2223,7 +2224,7 @@ This combination is added to the above task list.</property>
</object>
<object class="GtkDialog" id="GeneralSettingsWindow">
<property name="border_width">5</property>
<property name="title" translatable="yes">PyCAM Settings</property>
<property name="title" translatable="yes">PyCAM Preferences</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">normal</property>
<child internal-child="vbox">
......@@ -2796,7 +2797,18 @@ This combination is added to the above task list.</property>
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
<object class="GtkButton" id="ResetPreferencesButton">
<property name="label">gtk-revert-to-saved</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>
<child>
<object class="GtkButton" id="CloseSettingsWindow">
......@@ -2822,6 +2834,7 @@ This combination is added to the above task list.</property>
</object>
</child>
<action-widgets>
<action-widget response="0">ResetPreferencesButton</action-widget>
<action-widget response="0">CloseSettingsWindow</action-widget>
</action-widgets>
</object>
......
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