mecamira / dxf2gcode

Automatically exported from code.google.com/p/dxf2gcode
0 stars 0 forks source link

Fix for 'QString' object has no attribute 'decode' #51

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run dxf2gcode.py svn rev. 522
2. Open .dxf file

The file is not loaded and in console there is a message:

Traceback (most recent call last):
  File "./dxf2gcode.py", line 241, in showDialog
    self.loadFile(self.filename)
  File "./dxf2gcode.py", line 684, in loadFile
    filename = str(filename.decode("utf-8"))
AttributeError: 'QString' object has no attribute 'decode'

Attached patch can fix this problem.

Original issue reported on code.google.com by alyoshi...@gmail.com on 14 Jul 2014 at 7:29

Attachments:

GoogleCodeExporter commented 9 years ago
But it is stil failed to load file with non ASCII name, e.g. "fräsen_test_02 
2004.dxf":

Traceback (most recent call last):
  File "./dxf2gcode.py", line 241, in showDialog
    self.loadFile(self.filename)
  File "./dxf2gcode.py", line 684, in loadFile
    filename = str(filename).decode("utf-8")
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 
45: ordinal not in range(128)

Original comment by alyoshi...@gmail.com on 14 Jul 2014 at 7:51

GoogleCodeExporter commented 9 years ago
Point one has been fixed already. The Problem with non ASCII Names works for me 
in Windows. Linux i can not test.

Original comment by christian.kohloeffel on 4 Feb 2015 at 1:30

GoogleCodeExporter commented 9 years ago
svn551 in Linux with system locale (LANG=C) can't open 
Ellipsenbögen_Block_gedreht.dxf with GUI message box: "File not found. Please 
verify the correct file name was given."

With Russian locale and same file also can't open, but no GUI message box, only 
traceback:

Traceback (most recent call last):
  File "dxf2gcode.py", line 245, in showDialog
    self.loadFile(self.filename)
  File "dxf2gcode.py", line 707, in loadFile
    filename = str(filename).decode("utf-8")
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 
56: ordinal not in range(128)

Original comment by alyoshi...@gmail.com on 4 Feb 2015 at 6:43

GoogleCodeExporter commented 9 years ago
Just tried another way of Encoding. This all is a bit tricky since you can load 
files view QTGUI and directly specify them with the call of dxf2gcode.py. Which 
way are you trying? 
Can you Exchange the file with the attached one and try again?

Original comment by christian.kohloeffel on 6 Feb 2015 at 1:48

Attachments:

GoogleCodeExporter commented 9 years ago
I am loading file via GUI. Will try with replaced file and report.

Original comment by alyoshi...@gmail.com on 6 Feb 2015 at 2:08

GoogleCodeExporter commented 9 years ago
It works with replaced file via GUI, but from command line:

./dxf2gcode.py ../dxf/Ellipsenbögen_Block_kopiert.dxf 
DEBUG      root            <module>   1039:  - locale: ru_RU
DEBUG      PostPro.PostProcessorConfig load_config 200 :  - read existing 
varspace 
'/home/asv/projects/cnc/dxf2gcode-read-only/source/postpro_config/postpro_config
.cfg'
DEBUG      root            <module>   1069:  - Started with following options 
ArgumentParser(prog='dxf2gcode.py', usage=None, description=None, version=None, 
formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', 
add_help=True)
Traceback (most recent call last):
  File "./dxf2gcode.py", line 1084, in <module>
    window.loadFile(options.filename)
  File "./dxf2gcode.py", line 726, in loadFile
    logger.info(self.tr('Loading file: %s') % filename)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: 
ordinal not in range(128)

Original comment by alyoshi...@gmail.com on 6 Feb 2015 at 5:42

GoogleCodeExporter commented 9 years ago
I tried to fix that too. Same procedure. However this may be a cannot fix 
Problem due to different codings of Linux / Windows in different countries:

Line 1086:     window.loadFile(options.filename.decode("cp1252"))

I learned the coding cp1252 is the Standard western Coding, for russia i don't 
know if it's the same.

Original comment by christian.kohloeffel on 6 Feb 2015 at 7:48

Attachments:

GoogleCodeExporter commented 9 years ago
> Line 1086:     window.loadFile(options.filename.decode("cp1252"))

"UTF-8" here works for me, probably because $LANG is ru_RU.UTF-8

The problem 1/2 now with File/Reload File if file is loaded from CLI:

Traceback (most recent call last):
  File "./dxf2gcode.py", line 255, in reloadFile
    logger.info(self.tr("Reloading file: %s") % self.filename)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: 
ordinal not in range(128)
DEBUG      root            closeEvent 1007:  - exiting

Problem 2/2 with File/Reload File if file is loaded via GUI:

Traceback (most recent call last):
  File "./dxf2gcode.py", line 259, in reloadFile
    self.loadFile(self.filename)
  File "./dxf2gcode.py", line 712, in loadFile
    (name, ext) = os.path.splitext(filename)
  File "/usr/lib/python2.7/posixpath.py", line 105, in splitext
    return genericpath._splitext(p, sep, altsep, extsep)
  File "/usr/lib/python2.7/genericpath.py", line 91, in _splitext
    sepIndex = p.rfind(sep)
AttributeError: 'QString' object has no attribute 'rfind'

Original comment by alyoshi...@gmail.com on 7 Feb 2015 at 8:05

GoogleCodeExporter commented 9 years ago
I changed again. Hope this works now. I had the same issues already and fixed 
it without updating here, sorry.

Original comment by christian.kohloeffel on 8 Feb 2015 at 12:10

Attachments:

GoogleCodeExporter commented 9 years ago
This dxf2gcode.py is exactly as in svn552.  All works if cp1252 is replaced
with UTF-8.

Original comment by alyoshi...@gmail.com on 8 Feb 2015 at 7:44