Commit 58ed1d98 authored by Guillaume Seguin's avatar Guillaume Seguin

Fix #510: add setting validator for color options

parent 088d0cc5
...@@ -36,7 +36,7 @@ from . import printcore ...@@ -36,7 +36,7 @@ from . import printcore
from .utils import install_locale, setup_logging, \ from .utils import install_locale, setup_logging, \
iconfile, configfile, format_time, format_duration, \ iconfile, configfile, format_time, format_duration, \
hexcolor_to_float, parse_temperature_report, \ hexcolor_to_float, parse_temperature_report, \
prepare_command prepare_command, check_rgb_color, check_rgba_color
install_locale('pronterface') install_locale('pronterface')
try: try:
...@@ -123,7 +123,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -123,7 +123,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self._add_settings(size) self._add_settings(size)
for field in dir(self.settings): for field in dir(self.settings):
if field.startswith("_gcview_color_") and not field.endswith("_cb"): if field.startswith("_gcview_color_"):
cleanname = field[1:] cleanname = field[1:]
color = hexcolor_to_float(getattr(self.settings, cleanname), 4) color = hexcolor_to_float(getattr(self.settings, cleanname), 4)
setattr(self, cleanname, list(color)) setattr(self, cleanname, list(color))
...@@ -815,14 +815,14 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -815,14 +815,14 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
self.settings._add(FloatSpinSetting("preview_extrusion_width", 0.5, 0, 10, _("Preview extrusion width"), _("Width of Extrusion in Preview"), "UI"), self.update_gviz_params) self.settings._add(FloatSpinSetting("preview_extrusion_width", 0.5, 0, 10, _("Preview extrusion width"), _("Width of Extrusion in Preview"), "UI"), self.update_gviz_params)
self.settings._add(SpinSetting("preview_grid_step1", 10., 0, 200, _("Fine grid spacing"), _("Fine Grid Spacing"), "UI"), self.update_gviz_params) self.settings._add(SpinSetting("preview_grid_step1", 10., 0, 200, _("Fine grid spacing"), _("Fine Grid Spacing"), "UI"), self.update_gviz_params)
self.settings._add(SpinSetting("preview_grid_step2", 50., 0, 200, _("Coarse grid spacing"), _("Coarse Grid Spacing"), "UI"), self.update_gviz_params) self.settings._add(SpinSetting("preview_grid_step2", 50., 0, 200, _("Coarse grid spacing"), _("Coarse Grid Spacing"), "UI"), self.update_gviz_params)
self.settings._add(StringSetting("bgcolor", "#FFFFFF", _("Background color"), _("Pronterface background color"), "Colors"), self.reload_ui) self.settings._add(StringSetting("bgcolor", "#FFFFFF", _("Background color"), _("Pronterface background color"), "Colors"), self.reload_ui, validate = check_rgb_color)
self.settings._add(StringSetting("gcview_color_background", "#FAFAC7FF", _("3D view background color"), _("Color of the 3D view background"), "Colors"), self.update_gcview_colors) self.settings._add(StringSetting("gcview_color_background", "#FAFAC7FF", _("3D view background color"), _("Color of the 3D view background"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
self.settings._add(StringSetting("gcview_color_travel", "#99999999", _("3D view travel moves color"), _("Color of travel moves in 3D view"), "Colors"), self.update_gcview_colors) self.settings._add(StringSetting("gcview_color_travel", "#99999999", _("3D view travel moves color"), _("Color of travel moves in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
self.settings._add(StringSetting("gcview_color_tool0", "#FF000099", _("3D view print moves color"), _("Color of print moves with tool 0 in 3D view"), "Colors"), self.update_gcview_colors) self.settings._add(StringSetting("gcview_color_tool0", "#FF000099", _("3D view print moves color"), _("Color of print moves with tool 0 in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
self.settings._add(StringSetting("gcview_color_tool1", "#4F0CE599", _("3D view tool 1 moves color"), _("Color of print moves with tool 1 in 3D view"), "Colors"), self.update_gcview_colors) self.settings._add(StringSetting("gcview_color_tool1", "#4F0CE599", _("3D view tool 1 moves color"), _("Color of print moves with tool 1 in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
self.settings._add(StringSetting("gcview_color_printed", "#33BF0099", _("3D view printed moves color"), _("Color of printed moves in 3D view"), "Colors"), self.update_gcview_colors) self.settings._add(StringSetting("gcview_color_printed", "#33BF0099", _("3D view printed moves color"), _("Color of printed moves in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
self.settings._add(StringSetting("gcview_color_current", "#00E5FFCC", _("3D view current layer moves color"), _("Color of moves in current layer in 3D view"), "Colors"), self.update_gcview_colors) self.settings._add(StringSetting("gcview_color_current", "#00E5FFCC", _("3D view current layer moves color"), _("Color of moves in current layer in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
self.settings._add(StringSetting("gcview_color_current_printed", "#196600CC", _("3D view printed current layer moves color"), _("Color of already printed moves from current layer in 3D view"), "Colors"), self.update_gcview_colors) self.settings._add(StringSetting("gcview_color_current_printed", "#196600CC", _("3D view printed current layer moves color"), _("Color of already printed moves from current layer in 3D view"), "Colors"), self.update_gcview_colors, validate = check_rgba_color)
self.settings._add(StaticTextSetting("note1", _("Note:"), _("Changing most settings here will require restart to get effect"), group = "UI")) self.settings._add(StaticTextSetting("note1", _("Note:"), _("Changing most settings here will require restart to get effect"), group = "UI"))
recentfilessetting = StringSetting("recentfiles", "[]") recentfilessetting = StringSetting("recentfiles", "[]")
recentfilessetting.hidden = True recentfilessetting.hidden = True
......
...@@ -185,6 +185,18 @@ def hexcolor_to_float(color, components): ...@@ -185,6 +185,18 @@ def hexcolor_to_float(color, components):
return tuple(round(float(int(color[i:i + ndigits], 16)) / div, 2) return tuple(round(float(int(color[i:i + ndigits], 16)) / div, 2)
for i in range(0, numel, ndigits)) for i in range(0, numel, ndigits))
def check_rgb_color(color):
if len(color[1:]) % 3 != 0:
ex = ValueError(_("Color must be specified as #RGB"))
ex.from_validator = True
raise ex
def check_rgba_color(color):
if len(color[1:]) % 4 != 0:
ex = ValueError(_("Color must be specified as #RGBA"))
ex.from_validator = True
raise ex
tempreport_exp = re.compile("([TB]\d*):([-+]?\d*\.?\d*)(?: ?\/)?([-+]?\d*\.?\d*)") tempreport_exp = re.compile("([TB]\d*):([-+]?\d*\.?\d*)(?: ?\/)?([-+]?\d*\.?\d*)")
def parse_temperature_report(report): def parse_temperature_report(report):
matches = tempreport_exp.findall(report) matches = tempreport_exp.findall(report)
......
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