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
import time
import logging
import datetime
import re
import os
import sys
......@@ -969,7 +968,7 @@ class ProjectGui:
# the "delete-event" issues the additional "event" argument
state = event
if state is None:
state = not self._preferences_window_visible
state = not self._preferences_window_visible
if state:
if self._preferences_window_position:
self.preferences_window.move(*self._preferences_window_position)
......@@ -1358,7 +1357,7 @@ class ProjectGui:
self.model.export(comment=self.get_meta_data()).write(fi)
fi.close()
except IOError, err_msg:
log.error("Failed to save model file")
log.error("Failed to save model file: %s" % err_msg)
else:
self.add_to_recent_file_list(filename)
......@@ -1564,7 +1563,7 @@ class ProjectGui:
out.write(text)
out.close()
except IOError, err_msg:
log.error("Failed to save EMC tool file")
log.error("Failed to save EMC tool file: %s" % err_msg)
else:
self.add_to_recent_file_list(filename)
......@@ -1684,7 +1683,6 @@ class ProjectGui:
return self.gui.get_object("boundary_%s_%s" % ("xyz"[index], side))
# disable each zero-dimension in relative margin mode
if current_type == Bounds.TYPE_RELATIVE_MARGIN:
low, high = current_settings.get_bounds()
model_dims = (self.model.maxx - self.model.minx,
self.model.maxy - self.model.miny,
self.model.maxz - self.model.minz)
......@@ -1799,9 +1797,9 @@ class ProjectGui:
self.gui.get_object(value).set_active(True)
set_path_generator(settings["path_generator"])
# path direction
def set_path_direction(input):
def set_path_direction(direction):
for obj, value in (("PathDirectionX", "x"), ("PathDirectionY", "y"), ("PathDirectionXY", "xy")):
if value == input:
if value == direction:
self.gui.get_object(obj).set_active(True)
return
set_path_direction(settings["path_direction"])
......@@ -1953,12 +1951,9 @@ class ProjectGui:
@gui_activity_guard
def save_task_settings_file(self, widget=None, filename=None):
no_dialog = False
if callable(filename):
filename = filename()
if isinstance(filename, basestring):
no_dialog = True
else:
if not isinstance(filename, basestring):
# we open a dialog
filename = self.get_filename_via_dialog("Save settings to ...",
mode_load=False, type_filter=FILTER_CONFIG)
......@@ -2008,7 +2003,7 @@ class ProjectGui:
@progress_activity_guard
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
if toolpath is None:
toolpath_index = self._treeview_get_active_index(self.toolpath_table, self.toolpath)
......@@ -2029,9 +2024,8 @@ class ProjectGui:
/ (bounding_box["maxy"] - bounding_box["miny"])
x_steps = int(math.sqrt(grid_size) * proportion)
y_steps = int(math.sqrt(grid_size) / proportion)
simulation_backend = pycam.Simulation.ODEBlocks.ODEBlocks(
toolpath.get_tool_settings(), toolpath.get_bounding_box(),
x_steps=x_steps, y_steps=y_steps)
simulation_backend = ODEBlocks.ODEBlocks(toolpath.get_tool_settings(),
toolpath.get_bounding_box(), x_steps=x_steps, y_steps=y_steps)
self.settings.set("simulation_object", simulation_backend)
# disable the simulation widget (avoids confusion regarding "cancel")
if not widget is None:
......@@ -2240,10 +2234,10 @@ class ProjectGui:
file_filter.add_pattern(ext)
dialog.add_filter(file_filter)
# add filter for all files
filter = gtk.FileFilter()
filter.set_name("All files")
filter.add_pattern("*")
dialog.add_filter(filter)
ext_filter = gtk.FileFilter()
ext_filter.set_name("All files")
ext_filter.add_pattern("*")
dialog.add_filter(ext_filter)
done = False
while not done:
dialog.set_filter(dialog.list_filters()[0])
......@@ -2343,7 +2337,7 @@ class ProjectGui:
destination.close()
log.info("GCode file successfully written: %s" % str(filename))
except IOError, err_msg:
log.error("Failed to save toolpath file")
log.error("Failed to save toolpath file: %s" % err_msg)
else:
self.add_to_recent_file_list(filename)
......@@ -2367,6 +2361,6 @@ class ProjectGui:
if __name__ == "__main__":
gui = ProjectGui()
if len(sys.argv) > 1:
gui.open(sys.argv[1])
gui.load_model_file(sys.argv[1])
gui.mainloop()
......@@ -37,7 +37,8 @@ def get_config_dirname():
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
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)
......@@ -343,7 +344,8 @@ process: 3
return False
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)
try:
fi = open(filename, "w")
......@@ -398,19 +400,23 @@ process: 3
value_type = self.SETTING_TYPES[key]
raw = value_type == str
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:
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:
value_raw = None
if not value_raw is None:
try:
if value_type == 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:
if value_raw.lower() in ("1", "true", "yes", "on"):
if value_raw.lower() in (
"1", "true", "yes", "on"):
value = True
else:
value = False
......@@ -446,7 +452,8 @@ process: 3
else:
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):
""" this function should be the inverse operation of
'_get_bounds_instance_from_dict'
......@@ -487,7 +494,7 @@ process: 3
for key in self.CATEGORY_KEYS[type_name]:
try:
values = [item[key] for item in type_list]
except KeyError, err_msg:
except KeyError:
values = None
# check if there are values and if they all have the same value
if values and (values.count(values[0]) == len(values)):
......@@ -590,7 +597,8 @@ class ToolpathSettings:
high = (self.bounds["maxx"], self.bounds["maxy"], self.bounds["maxz"])
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,
"shape": shape,
"tool_radius": tool_radius,
......@@ -668,14 +676,14 @@ class ToolpathSettings:
(self.support_grid, "SupportGrid"),
(self.process_settings, "Process")):
for key, value_type in self.SECTIONS[section].items():
raw_value = config.get(section, key, None)
if raw_value is None:
value_raw = config.get(section, key, None)
if value_raw is None:
continue
elif value_type == bool:
value = value_raw.lower() in ("1", "true", "yes", "on")
else:
try:
value = value_type(raw_value)
value = value_type(value_raw)
except ValueError:
log.warn("Settings: Ignored invalid setting " \
"(%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/>.
"""
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 sys
import os
......@@ -149,13 +150,14 @@ class EmergencyDialog:
import Tkinter
except ImportError:
# 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
try:
root = Tkinter.Tk()
except Tkinter.TclError, err_msg:
log.info("Failed to create error dialog window (%s). " % str(err_msg) \
+ "Probably you are running PyCAM from a terminal.")
log.info(("Failed to create error dialog window (%s). Probably " \
+ "you are running PyCAM from a terminal.") % err_msg)
return
root.title(title)
root.bind("<Return>", self.finish)
......
......@@ -75,7 +75,7 @@ class ODEBlocks:
or (location_start.y > location_end.y):
swap = location_start
location_start = location_end
location_end = location_start
location_end = swap
cutter_body = ode.Body(self.world)
cutter_shape, cutter_position_func = self.cutter.get_shape("ODE")
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