Commit c901eec2 authored by sumpfralle's avatar sumpfralle

fixed code-style issues


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@501 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent c9ae4ffc
This diff is collapsed.
...@@ -43,7 +43,6 @@ import math ...@@ -43,7 +43,6 @@ import math
import time import time
import logging import logging
import datetime import datetime
import re
import os import os
import sys import sys
...@@ -1358,7 +1357,7 @@ class ProjectGui: ...@@ -1358,7 +1357,7 @@ class ProjectGui:
self.model.export(comment=self.get_meta_data()).write(fi) self.model.export(comment=self.get_meta_data()).write(fi)
fi.close() fi.close()
except IOError, err_msg: except IOError, err_msg:
log.error("Failed to save model file") log.error("Failed to save model file: %s" % err_msg)
else: else:
self.add_to_recent_file_list(filename) self.add_to_recent_file_list(filename)
...@@ -1564,7 +1563,7 @@ class ProjectGui: ...@@ -1564,7 +1563,7 @@ class ProjectGui:
out.write(text) out.write(text)
out.close() out.close()
except IOError, err_msg: except IOError, err_msg:
log.error("Failed to save EMC tool file") log.error("Failed to save EMC tool file: %s" % err_msg)
else: else:
self.add_to_recent_file_list(filename) self.add_to_recent_file_list(filename)
...@@ -1684,7 +1683,6 @@ class ProjectGui: ...@@ -1684,7 +1683,6 @@ class ProjectGui:
return self.gui.get_object("boundary_%s_%s" % ("xyz"[index], side)) return self.gui.get_object("boundary_%s_%s" % ("xyz"[index], side))
# disable each zero-dimension in relative margin mode # disable each zero-dimension in relative margin mode
if current_type == Bounds.TYPE_RELATIVE_MARGIN: if current_type == Bounds.TYPE_RELATIVE_MARGIN:
low, high = current_settings.get_bounds()
model_dims = (self.model.maxx - self.model.minx, model_dims = (self.model.maxx - self.model.minx,
self.model.maxy - self.model.miny, self.model.maxy - self.model.miny,
self.model.maxz - self.model.minz) self.model.maxz - self.model.minz)
...@@ -1799,9 +1797,9 @@ class ProjectGui: ...@@ -1799,9 +1797,9 @@ class ProjectGui:
self.gui.get_object(value).set_active(True) self.gui.get_object(value).set_active(True)
set_path_generator(settings["path_generator"]) set_path_generator(settings["path_generator"])
# path direction # path direction
def set_path_direction(input): def set_path_direction(direction):
for obj, value in (("PathDirectionX", "x"), ("PathDirectionY", "y"), ("PathDirectionXY", "xy")): for obj, value in (("PathDirectionX", "x"), ("PathDirectionY", "y"), ("PathDirectionXY", "xy")):
if value == input: if value == direction:
self.gui.get_object(obj).set_active(True) self.gui.get_object(obj).set_active(True)
return return
set_path_direction(settings["path_direction"]) set_path_direction(settings["path_direction"])
...@@ -1953,12 +1951,9 @@ class ProjectGui: ...@@ -1953,12 +1951,9 @@ class ProjectGui:
@gui_activity_guard @gui_activity_guard
def save_task_settings_file(self, widget=None, filename=None): def save_task_settings_file(self, widget=None, filename=None):
no_dialog = False
if callable(filename): if callable(filename):
filename = filename() filename = filename()
if isinstance(filename, basestring): if not isinstance(filename, basestring):
no_dialog = True
else:
# we open a dialog # we open a dialog
filename = self.get_filename_via_dialog("Save settings to ...", filename = self.get_filename_via_dialog("Save settings to ...",
mode_load=False, type_filter=FILTER_CONFIG) mode_load=False, type_filter=FILTER_CONFIG)
...@@ -2008,7 +2003,7 @@ class ProjectGui: ...@@ -2008,7 +2003,7 @@ class ProjectGui:
@progress_activity_guard @progress_activity_guard
def update_toolpath_simulation(self, widget=None, toolpath=None): def update_toolpath_simulation(self, widget=None, toolpath=None):
import pycam.Simulation.ODEBlocks import pycam.Simulation.ODEBlocks as ODEBlocks
# get the currently selected toolpath, if none is give # get the currently selected toolpath, if none is give
if toolpath is None: if toolpath is None:
toolpath_index = self._treeview_get_active_index(self.toolpath_table, self.toolpath) toolpath_index = self._treeview_get_active_index(self.toolpath_table, self.toolpath)
...@@ -2029,9 +2024,8 @@ class ProjectGui: ...@@ -2029,9 +2024,8 @@ class ProjectGui:
/ (bounding_box["maxy"] - bounding_box["miny"]) / (bounding_box["maxy"] - bounding_box["miny"])
x_steps = int(math.sqrt(grid_size) * proportion) x_steps = int(math.sqrt(grid_size) * proportion)
y_steps = int(math.sqrt(grid_size) / proportion) y_steps = int(math.sqrt(grid_size) / proportion)
simulation_backend = pycam.Simulation.ODEBlocks.ODEBlocks( simulation_backend = ODEBlocks.ODEBlocks(toolpath.get_tool_settings(),
toolpath.get_tool_settings(), toolpath.get_bounding_box(), toolpath.get_bounding_box(), x_steps=x_steps, y_steps=y_steps)
x_steps=x_steps, y_steps=y_steps)
self.settings.set("simulation_object", simulation_backend) self.settings.set("simulation_object", simulation_backend)
# disable the simulation widget (avoids confusion regarding "cancel") # disable the simulation widget (avoids confusion regarding "cancel")
if not widget is None: if not widget is None:
...@@ -2240,10 +2234,10 @@ class ProjectGui: ...@@ -2240,10 +2234,10 @@ class ProjectGui:
file_filter.add_pattern(ext) file_filter.add_pattern(ext)
dialog.add_filter(file_filter) dialog.add_filter(file_filter)
# add filter for all files # add filter for all files
filter = gtk.FileFilter() ext_filter = gtk.FileFilter()
filter.set_name("All files") ext_filter.set_name("All files")
filter.add_pattern("*") ext_filter.add_pattern("*")
dialog.add_filter(filter) dialog.add_filter(ext_filter)
done = False done = False
while not done: while not done:
dialog.set_filter(dialog.list_filters()[0]) dialog.set_filter(dialog.list_filters()[0])
...@@ -2343,7 +2337,7 @@ class ProjectGui: ...@@ -2343,7 +2337,7 @@ class ProjectGui:
destination.close() destination.close()
log.info("GCode file successfully written: %s" % str(filename)) log.info("GCode file successfully written: %s" % str(filename))
except IOError, err_msg: except IOError, err_msg:
log.error("Failed to save toolpath file") log.error("Failed to save toolpath file: %s" % err_msg)
else: else:
self.add_to_recent_file_list(filename) self.add_to_recent_file_list(filename)
...@@ -2367,6 +2361,6 @@ class ProjectGui: ...@@ -2367,6 +2361,6 @@ class ProjectGui:
if __name__ == "__main__": if __name__ == "__main__":
gui = ProjectGui() gui = ProjectGui()
if len(sys.argv) > 1: if len(sys.argv) > 1:
gui.open(sys.argv[1]) gui.load_model_file(sys.argv[1])
gui.mainloop() gui.mainloop()
...@@ -37,7 +37,8 @@ def get_config_dirname(): ...@@ -37,7 +37,8 @@ def get_config_dirname():
from win32com.shell import shellcon, shell from win32com.shell import shellcon, shell
homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0) homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
config_dir = os.path.join(homedir, CONFIG_DIR) config_dir = os.path.join(homedir, CONFIG_DIR)
except ImportError: # quick semi-nasty fallback for non-windows/win32com case except ImportError:
# quick semi-nasty fallback for non-windows/win32com case
homedir = os.path.expanduser("~") homedir = os.path.expanduser("~")
# hide the config directory for unixes # hide the config directory for unixes
config_dir = os.path.join(homedir, "." + CONFIG_DIR) config_dir = os.path.join(homedir, "." + CONFIG_DIR)
...@@ -343,7 +344,8 @@ process: 3 ...@@ -343,7 +344,8 @@ process: 3
return False return False
return True return True
def write_to_file(self, filename, tools=None, processes=None, bounds=None, tasks=None): def write_to_file(self, filename, tools=None, processes=None, bounds=None,
tasks=None):
text = self.get_config_text(tools, processes, bounds, tasks) text = self.get_config_text(tools, processes, bounds, tasks)
try: try:
fi = open(filename, "w") fi = open(filename, "w")
...@@ -398,19 +400,23 @@ process: 3 ...@@ -398,19 +400,23 @@ process: 3
value_type = self.SETTING_TYPES[key] value_type = self.SETTING_TYPES[key]
raw = value_type == str raw = value_type == str
try: try:
value_raw = self.config.get(current_section_name, key, raw=raw) value_raw = self.config.get(current_section_name, key,
raw=raw)
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
try: try:
value_raw = self.config.get(prefix + self.DEFAULT_SUFFIX, key, raw=raw) value_raw = self.config.get(
prefix + self.DEFAULT_SUFFIX, key, raw=raw)
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
value_raw = None value_raw = None
if not value_raw is None: if not value_raw is None:
try: try:
if value_type == object: if value_type == object:
# try to get the referenced object # try to get the referenced object
value = self._get_category_items(key)[int(value_raw)] value = self._get_category_items(key)[
int(value_raw)]
elif value_type == bool: elif value_type == bool:
if value_raw.lower() in ("1", "true", "yes", "on"): if value_raw.lower() in (
"1", "true", "yes", "on"):
value = True value = True
else: else:
value = False value = False
...@@ -446,7 +452,8 @@ process: 3 ...@@ -446,7 +452,8 @@ process: 3
else: else:
return str(value_type(value)) return str(value_type(value))
def get_config_text(self, tools=None, processes=None, bounds=None, tasks=None): def get_config_text(self, tools=None, processes=None, bounds=None,
tasks=None):
def get_dictionary_of_bounds(b): def get_dictionary_of_bounds(b):
""" this function should be the inverse operation of """ this function should be the inverse operation of
'_get_bounds_instance_from_dict' '_get_bounds_instance_from_dict'
...@@ -487,7 +494,7 @@ process: 3 ...@@ -487,7 +494,7 @@ process: 3
for key in self.CATEGORY_KEYS[type_name]: for key in self.CATEGORY_KEYS[type_name]:
try: try:
values = [item[key] for item in type_list] values = [item[key] for item in type_list]
except KeyError, err_msg: except KeyError:
values = None values = None
# check if there are values and if they all have the same value # check if there are values and if they all have the same value
if values and (values.count(values[0]) == len(values)): if values and (values.count(values[0]) == len(values)):
...@@ -590,7 +597,8 @@ class ToolpathSettings: ...@@ -590,7 +597,8 @@ class ToolpathSettings:
high = (self.bounds["maxx"], self.bounds["maxy"], self.bounds["maxz"]) high = (self.bounds["maxx"], self.bounds["maxy"], self.bounds["maxz"])
return Bounds(Bounds.TYPE_CUSTOM, low, high) return Bounds(Bounds.TYPE_CUSTOM, low, high)
def set_tool(self, index, shape, tool_radius, torus_radius=None, speed=0.0, feedrate=0.0): def set_tool(self, index, shape, tool_radius, torus_radius=None, speed=0.0,
feedrate=0.0):
self.tool_settings = {"id": index, self.tool_settings = {"id": index,
"shape": shape, "shape": shape,
"tool_radius": tool_radius, "tool_radius": tool_radius,
...@@ -668,14 +676,14 @@ class ToolpathSettings: ...@@ -668,14 +676,14 @@ class ToolpathSettings:
(self.support_grid, "SupportGrid"), (self.support_grid, "SupportGrid"),
(self.process_settings, "Process")): (self.process_settings, "Process")):
for key, value_type in self.SECTIONS[section].items(): for key, value_type in self.SECTIONS[section].items():
raw_value = config.get(section, key, None) value_raw = config.get(section, key, None)
if raw_value is None: if value_raw is None:
continue continue
elif value_type == bool: elif value_type == bool:
value = value_raw.lower() in ("1", "true", "yes", "on") value = value_raw.lower() in ("1", "true", "yes", "on")
else: else:
try: try:
value = value_type(raw_value) value = value_type(value_raw)
except ValueError: except ValueError:
log.warn("Settings: Ignored invalid setting " \ log.warn("Settings: Ignored invalid setting " \
"(%s -> %s): %s" % (section, key, value_raw)) "(%s -> %s): %s" % (section, key, value_raw))
......
This diff is collapsed.
...@@ -21,7 +21,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -21,7 +21,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
import pycam.Utils.log import pycam.Utils.log
# Tkinter is used for "EmergencyDialog" below - but we will try to import it carefully # Tkinter is used for "EmergencyDialog" below - but we will try to import it
# carefully.
#import Tkinter #import Tkinter
import sys import sys
import os import os
...@@ -149,13 +150,14 @@ class EmergencyDialog: ...@@ -149,13 +150,14 @@ class EmergencyDialog:
import Tkinter import Tkinter
except ImportError: except ImportError:
# tk is not installed # tk is not installed
log.warn("Failed to show error dialog due to a missing Tkinter Python package.") log.warn("Failed to show error dialog due to a missing Tkinter " \
+ "Python package.")
return return
try: try:
root = Tkinter.Tk() root = Tkinter.Tk()
except Tkinter.TclError, err_msg: except Tkinter.TclError, err_msg:
log.info("Failed to create error dialog window (%s). " % str(err_msg) \ log.info(("Failed to create error dialog window (%s). Probably " \
+ "Probably you are running PyCAM from a terminal.") + "you are running PyCAM from a terminal.") % err_msg)
return return
root.title(title) root.title(title)
root.bind("<Return>", self.finish) root.bind("<Return>", self.finish)
......
...@@ -75,7 +75,7 @@ class ODEBlocks: ...@@ -75,7 +75,7 @@ class ODEBlocks:
or (location_start.y > location_end.y): or (location_start.y > location_end.y):
swap = location_start swap = location_start
location_start = location_end location_start = location_end
location_end = location_start location_end = swap
cutter_body = ode.Body(self.world) cutter_body = ode.Body(self.world)
cutter_shape, cutter_position_func = self.cutter.get_shape("ODE") cutter_shape, cutter_position_func = self.cutter.get_shape("ODE")
self.space.add(cutter_shape) self.space.add(cutter_shape)
......
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