Commit 24b77c58 authored by sumpfralle's avatar sumpfralle

r685@erker: lars | 2010-02-18 22:43:33 +0100

 allow arbitrary sorting of processing config templates


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@143 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 1a73f35f
...@@ -76,8 +76,11 @@ feedrate: 200 ...@@ -76,8 +76,11 @@ feedrate: 200
material_allowance: 0 material_allowance: 0
overlap: 20 overlap: 20
step_down: 1.0 step_down: 1.0
# default sort weight is low (thus new items will appear above the defaults)
sort_weight: 0
[Rough] [Rough]
sort_weight: 90
cutter_shape: CylindricalCutter cutter_shape: CylindricalCutter
path_generator: PushCutter path_generator: PushCutter
path_postprocessor: PolygonCutter path_postprocessor: PolygonCutter
...@@ -85,12 +88,14 @@ tool_radius: 1.0 ...@@ -85,12 +88,14 @@ tool_radius: 1.0
[Semi-finish] [Semi-finish]
sort_weight: 91
cutter_shape: ToroidalCutter cutter_shape: ToroidalCutter
path_generator: PushCutter path_generator: PushCutter
path_postprocessor: ContourCutter path_postprocessor: ContourCutter
tool_radius: 0.5 tool_radius: 0.5
[Finish] [Finish]
sort_weight: 92
cutter_shape: SphericalCutter cutter_shape: SphericalCutter
path_generator: DropCutter path_generator: DropCutter
path_postprocessor: ZigZagCutter path_postprocessor: ZigZagCutter
...@@ -113,7 +118,7 @@ tool_radius: 0.1 ...@@ -113,7 +118,7 @@ tool_radius: 0.1
"speed": float, "speed": float,
"feedrate": float, "feedrate": float,
"material_allowance": float, "material_allowance": float,
"overlap": int, "overlap": float,
"step_down": float, "step_down": float,
} }
...@@ -122,9 +127,13 @@ tool_radius: 0.1 ...@@ -122,9 +127,13 @@ tool_radius: 0.1
self.config = None self.config = None
self.reset() self.reset()
def reset(self): def reset(self, config_text=None):
self.config = ConfigParser.SafeConfigParser() self.config = ConfigParser.SafeConfigParser()
self.config.readfp(StringIO.StringIO(self.DEFAULT_CONFIG)) if config_text is None:
config_text = StringIO.StringIO(self.DEFAULT_CONFIG)
else:
config_text = StringIO.StringIO(config_text)
self.config.readfp(config_text)
def load_file(self, filename): def load_file(self, filename):
try: try:
...@@ -137,7 +146,7 @@ tool_radius: 0.1 ...@@ -137,7 +146,7 @@ tool_radius: 0.1
def load_from_string(self, config_text): def load_from_string(self, config_text):
input_text = StringIO.StringIO(config_text) input_text = StringIO.StringIO(config_text)
try: try:
self.config.readfp(input_text) self.reset(input_text)
except ConfigParser.ParsingError, err_msg: except ConfigParser.ParsingError, err_msg:
print sys.stderr, "Failed to parse config data: %s" % str(err_msg) print sys.stderr, "Failed to parse config data: %s" % str(err_msg)
return False return False
...@@ -170,7 +179,18 @@ tool_radius: 0.1 ...@@ -170,7 +179,18 @@ tool_radius: 0.1
self.settings.set(key, value) self.settings.set(key, value)
def get_config_list(self): def get_config_list(self):
return self.config.sections() items = self.config.sections()[:]
# sort the list according to "sort_weight"
def cmp(sec1, sec2):
diff = int(self.config.get(sec1, "sort_weight")) - int(self.config.get(sec2, "sort_weight"))
if diff < 0:
return -1
elif diff == 0:
return 0
else:
return 1
items.sort(cmp)
return items
def store_config(self, section="DEFAULT"): def store_config(self, section="DEFAULT"):
if not self.config.has_section(section): if not self.config.has_section(section):
......
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