Skip to content

Gmoccapy fix various (localization) bugs #3500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions lib/python/gladevcp/calculatorwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Calculator( Gtk.Box ):

def __init__( self, *a, **kw ):
Gtk.Box.__init__( self, *a, **kw )
self.allow_dot_and_comma = False
self.preset_value = None
self.eval_string = ""
self.font = "sans 12"
Expand Down Expand Up @@ -170,19 +171,19 @@ def get_preset_value( self ):

def compute( self ):
qualified = ''
# print"string:",self.eval_string
temp = self.eval_string.strip( " " ).replace("Pi", "math.pi")
if self.allow_dot_and_comma: temp = temp.replace(",", ".")
# this loop adds only spaces around the mentioned operators
for i in( '-', '+', '/', '*', 'math.pi', '(', ')' ):
new = " %s " % i
temp = temp.replace( i, new )
for i in temp.split():
# print ( "i in compute = ", i )
try:
i = str( locale.atof( i ) )
# print ( "converted i in compute = ", i )
except:
pass
if not self.allow_dot_and_comma:
try:
# convert to decimal dot format
i = str( locale.atof( i ) )
except:
pass
if i.isdigit():
qualified = qualified + str( float( i ) )
else:
Expand All @@ -194,18 +195,16 @@ def compute( self ):
b = str( eval( qualified ) )
except:
b = "Error"
print("Calculator widget error, string:", self.eval_string, sys.exc_info()[0])
self.eval_string = ''
else : self.eval_string = b
# if locale.localeconv()["decimal_point" = comma ,
# we have to replace the internal dot by a comma,
# otherwise it will be interpreted as an thousend separator
try:
b = locale.format_string( "%f", float( b ) ).rstrip( "0" )
if b[-1] == locale.localeconv()["decimal_point"]:
b = b.rstrip( locale.localeconv()["decimal_point"] )
except:
b = "Error"
if not self.allow_dot_and_comma:
try:
b = locale.format_string( "%f", float( b ) ).rstrip( "0" )
if b[-1] == locale.localeconv()["decimal_point"]:
b = b.rstrip( locale.localeconv()["decimal_point"] )
else:
self.eval_string = b
except:
b = "Error"
self.entry.set_text( b )
self.entry.set_position(len(self.eval_string))

Expand Down
8 changes: 3 additions & 5 deletions lib/python/gladevcp/offsetpage_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,13 @@ def reload_offsets(self):
else:
tmpl = self.imperial_text_template

degree_tmpl = "%11.2f"

# fill each row of the liststore from the offsets arrays
for row, i in enumerate([tool, g28, g30, g92]):
for column in range(0, 11):
if column > 8:
self.store[row][column + 1] = " " # Blank R column
else:
self.store[row][column + 1] = locale.format_string(tmpl, i[column])
self.store[row][column + 1] = tmpl % i[column]
# set the current system's label's color - to make it stand out a bit
if self.store[row][0] == self.current_system:
if isinstance(self.foreground_color, str):
Expand All @@ -226,7 +224,7 @@ def reload_offsets(self):

for row, i in enumerate([g54, g55, g56, g57, g58, g59, g59_1, g59_2, g59_3]):
for column in range(0, 10):
self.store[row+4][column + 1] = locale.format_string(tmpl, i[column])
self.store[row+4][column + 1] = tmpl % i[column]
# set the current system's label's color - to make it stand out a bit
if self.store[row+4][0] == self.current_system:
if isinstance(self.foreground_color, str):
Expand Down Expand Up @@ -387,7 +385,7 @@ def system_to_p(system):

# set the text in the table
try:
self.store[row][col] = locale.format_string("%10.4f", locale.atof(new_text))
self.store[row][col] = "%10.4f" % locale.atof(new_text)
except Exception as error:
print('new_text: ', new_text, error)
print(_("offsetpage widget error: unrecognized float input"))
Expand Down
1 change: 1 addition & 0 deletions src/emc/usr_intf/gmoccapy/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def entry_dialog(self, caller, data = None, header = _("Enter value") , label =
label.modify_font(Pango.FontDescription("sans 20"))
label.set_margin_top(15)
calc = gladevcp.Calculator()
calc.allow_dot_and_comma = True
content_area = dialog.get_content_area()
content_area.pack_start(child=label, expand=False, fill=False, padding=0)
content_area.add(calc)
Expand Down
4 changes: 2 additions & 2 deletions src/emc/usr_intf/gmoccapy/gmoccapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def excepthook(exc_type, exc_obj, exc_tb):
ALERT_ICON = "dialog_warning"
INFO_ICON = "dialog_information"

AXISLIST = ['offset', 'X', 'Y', 'Z', 'A', 'B', 'C', 'U', 'V', 'W', 'name']
AXISLIST = ['offset', 'X', 'Y', 'Z', 'A', 'B', 'C', 'U', 'V', 'W', 'Rot', 'name']

class gmoccapy(object):
def __init__(self, argv):
Expand Down Expand Up @@ -2275,7 +2275,7 @@ def _init_offsetpage(self):
names.append([system, name])
self.widgets.offsetpage1.set_names(names)
for col, name in enumerate(AXISLIST):
if col > 9:break
if col > 10:break
temp = self.widgets.offsetpage1.wTree.get_object("cell_%s" % name)
temp.connect('editing-started', self.on_offset_col_edit_started, col)

Expand Down
Loading