Commit 5d5cd99a1c1efaf0ffb78b152f96c66ac44cfd60
1 parent
275f57c0
Exists in
master
and in
6 other branches
FIX: Taiwan error open DICOM (problem caracter code with vtk), temporary fix
Showing
1 changed file
with
17 additions
and
14 deletions
Show diff stats
invesalius/data/vtk_utils.py
... | ... | @@ -22,7 +22,7 @@ import vtk |
22 | 22 | import wx.lib.pubsub as ps |
23 | 23 | |
24 | 24 | import constants as const |
25 | -from gui.dialogs import ProgressDialog | |
25 | +from gui.dialogs import ProgressDialog | |
26 | 26 | |
27 | 27 | # If you are frightened by the code bellow, or think it must have been result of |
28 | 28 | # an identation error, lookup at: |
... | ... | @@ -45,36 +45,36 @@ def ShowProgress(number_of_filters = 1, |
45 | 45 | last_obj_progress = [0] |
46 | 46 | if (dialog_type == "ProgressDialog"): |
47 | 47 | dlg = ProgressDialog(100) |
48 | - | |
48 | + | |
49 | 49 | |
50 | 50 | # when the pipeline is larger than 1, we have to consider this object |
51 | 51 | # percentage |
52 | 52 | ratio = (100.0 / number_of_filters) |
53 | - | |
53 | + | |
54 | 54 | def UpdateProgress(obj, label=""): |
55 | 55 | """ |
56 | 56 | Show progress on GUI according to pipeline execution. |
57 | 57 | """ |
58 | 58 | # object progress is cummulative and is between 0.0 - 1.0 |
59 | - # is necessary verify in case is sending the progress | |
59 | + # is necessary verify in case is sending the progress | |
60 | 60 | #represented by number in case multiprocess, not vtk object |
61 | 61 | if isinstance(obj, float) or isinstance(obj, int): |
62 | 62 | obj_progress = obj |
63 | 63 | else: |
64 | 64 | obj_progress = obj.GetProgress() |
65 | - | |
65 | + | |
66 | 66 | # as it is cummulative, we need to compute the diference, to be |
67 | 67 | # appended on the interface |
68 | 68 | if obj_progress < last_obj_progress[0]: # current obj != previous obj |
69 | 69 | difference = obj_progress # 0 |
70 | 70 | else: # current obj == previous obj |
71 | 71 | difference = obj_progress - last_obj_progress[0] |
72 | - | |
72 | + | |
73 | 73 | last_obj_progress[0] = obj_progress |
74 | 74 | |
75 | 75 | # final progress status value |
76 | 76 | progress[0] = progress[0] + ratio*difference |
77 | - | |
77 | + | |
78 | 78 | # Tell GUI to update progress status value |
79 | 79 | if (dialog_type == "GaugeProgress"): |
80 | 80 | ps.Publisher().sendMessage('Update status in GUI', |
... | ... | @@ -82,12 +82,12 @@ def ShowProgress(number_of_filters = 1, |
82 | 82 | else: |
83 | 83 | if (int(progress[0]) == 99): |
84 | 84 | progress[0] = 100 |
85 | - | |
85 | + | |
86 | 86 | if not(dlg.Update(progress[0],label)): |
87 | 87 | dlg.Close() |
88 | - | |
88 | + | |
89 | 89 | return progress[0] |
90 | - | |
90 | + | |
91 | 91 | return UpdateProgress |
92 | 92 | |
93 | 93 | class Text(object): |
... | ... | @@ -133,7 +133,10 @@ class Text(object): |
133 | 133 | # With some encoding in some dicom fields (like name) raises a |
134 | 134 | # UnicodeEncodeError because they have non-ascii characters. To avoid |
135 | 135 | # that we encode in utf-8. |
136 | - self.mapper.SetInput(value.encode("cp1252")) | |
136 | + try: | |
137 | + self.mapper.SetInput(value.encode("latin-1")) | |
138 | + except(UnicodeEncodeError): | |
139 | + self.mapper.SetInput(value.encode("utf-8")) | |
137 | 140 | |
138 | 141 | def SetPosition(self, position): |
139 | 142 | self.actor.GetPositionCoordinate().SetValue(position[0], |
... | ... | @@ -178,11 +181,11 @@ class TextZero(object): |
178 | 181 | property.SetColor(const.TEXT_COLOUR) |
179 | 182 | self.property = property |
180 | 183 | |
181 | - actor = vtk.vtkTextActor() | |
184 | + actor = vtk.vtkTextActor() | |
182 | 185 | actor.GetTextProperty().ShallowCopy(property) |
183 | - actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() | |
186 | + actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() | |
184 | 187 | actor.PickableOff() |
185 | - self.actor = actor | |
188 | + self.actor = actor | |
186 | 189 | |
187 | 190 | def SetColour(self, colour): |
188 | 191 | self.property.SetColor(colour) | ... | ... |