Commit 08a3b8ee995367325e153c0f1dbc35898a57292e

Authored by Thiago Franco de Moraes
1 parent 327cd317
Exists in master

Coding style improvements in preferences

Showing 1 changed file with 91 additions and 49 deletions   Show diff stats
invesalius/gui/preferences.py
1   -import wx
2 1 import invesalius.constants as const
3   -from wx.lib.pubsub import pub as Publisher
4 2 import invesalius.session as ses
  3 +import wx
5 4 from invesalius.gui.language_dialog import ComboBoxLanguage
6   -ID = wx.NewId()
  5 +from wx.lib.pubsub import pub as Publisher
7 6  
8 7 try:
9 8 from agw import flatnotebook as fnb
  9 +
10 10 AGW = 1
11   -except ImportError: # if it's not there locally, try the wxPython lib.
  11 +except ImportError: # if it's not there locally, try the wxPython lib.
12 12 import wx.lib.agw.flatnotebook as fnb
13   - AGW = 0
14 13  
15   -class Preferences(wx.Dialog):
  14 + AGW = 0
16 15  
17   - def __init__( self, parent, id = ID, title = _("Preferences"), size=wx.DefaultSize,\
18   - pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
19 16  
20   - wx.Dialog.__init__(self, parent, id, title, pos, size, style)
  17 +class Preferences(wx.Dialog):
  18 + def __init__(
  19 + self,
  20 + parent,
  21 + id_=-1,
  22 + title=_("Preferences"),
  23 + size=wx.DefaultSize,
  24 + pos=wx.DefaultPosition,
  25 + style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  26 + ):
  27 +
  28 + wx.Dialog.__init__(self, parent, id_, title, pos, size, style)
21 29  
22 30 sizer = wx.BoxSizer(wx.VERTICAL)
23 31  
... ... @@ -28,7 +36,7 @@ class Preferences(wx.Dialog):
28 36 else:
29 37 self.book = fnb.FlatNotebook(self, wx.ID_ANY, agwStyle=bookStyle)
30 38  
31   - sizer.Add(self.book, 1, wx.EXPAND|wx.ALL)
  39 + sizer.Add(self.book, 1, wx.EXPAND | wx.ALL)
32 40  
33 41 self.pnl_viewer2d = Viewer2D(self)
34 42 self.pnl_viewer3d = Viewer3D(self)
... ... @@ -40,11 +48,16 @@ class Preferences(wx.Dialog):
40 48 # self.book.AddPage(self.pnl_surface, _("Surface creation"))
41 49 self.book.AddPage(self.pnl_language, _("Language"))
42 50  
43   - line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
44   - sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
  51 + line = wx.StaticLine(self, -1, size=(20, -1), style=wx.LI_HORIZONTAL)
  52 + sizer.Add(line, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)
45 53  
46 54 btnsizer = self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL)
47   - sizer.Add(btnsizer, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP|wx.BOTTOM, 5)
  55 + sizer.Add(
  56 + btnsizer,
  57 + 0,
  58 + wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP | wx.BOTTOM,
  59 + 5,
  60 + )
48 61  
49 62 self.SetSizer(sizer)
50 63 sizer.Fit(self)
... ... @@ -52,7 +65,7 @@ class Preferences(wx.Dialog):
52 65 self.__bind_events()
53 66  
54 67 def __bind_events(self):
55   - Publisher.subscribe(self.LoadPreferences, 'Load Preferences')
  68 + Publisher.subscribe(self.LoadPreferences, "Load Preferences")
56 69  
57 70 def GetPreferences(self):
58 71 values = {}
... ... @@ -62,41 +75,47 @@ class Preferences(wx.Dialog):
62 75 values.update(lang)
63 76 values.update(viewer)
64 77 values.update(viewer2d)
65   -
  78 +
66 79 return values
67 80  
68 81 def LoadPreferences(self):
69 82 se = ses.Session()
70   -
71   - values = {const.RENDERING:se.rendering,
72   - const.SURFACE_INTERPOLATION:se.surface_interpolation,
73   - const.LANGUAGE:se.language,
74   - const.SLICE_INTERPOLATION: se.slice_interpolation,
75   - }
  83 +
  84 + values = {
  85 + const.RENDERING: se.rendering,
  86 + const.SURFACE_INTERPOLATION: se.surface_interpolation,
  87 + const.LANGUAGE: se.language,
  88 + const.SLICE_INTERPOLATION: se.slice_interpolation,
  89 + }
76 90  
77 91 self.pnl_viewer2d.LoadSelection(values)
78 92 self.pnl_viewer3d.LoadSelection(values)
79 93 self.pnl_language.LoadSelection(values)
80 94  
81 95  
82   -
83 96 class Viewer3D(wx.Panel):
84   -
85 97 def __init__(self, parent):
86 98  
87 99 wx.Panel.__init__(self, parent)
88 100  
89   -
90 101 box_visualization = wx.StaticBox(self, -1, _("Surface"))
91 102 bsizer = wx.StaticBoxSizer(box_visualization, wx.VERTICAL)
92 103  
93 104 lbl_inter = wx.StaticText(self, -1, _("Interpolation "))
94   - bsizer.Add(lbl_inter, 0, wx.TOP|wx.LEFT, 10)
  105 + bsizer.Add(lbl_inter, 0, wx.TOP | wx.LEFT, 10)
95 106  
96   - rb_inter = self.rb_inter = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize,
97   - ['Flat','Gouraud','Phong'], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
  107 + rb_inter = self.rb_inter = wx.RadioBox(
  108 + self,
  109 + -1,
  110 + "",
  111 + wx.DefaultPosition,
  112 + wx.DefaultSize,
  113 + ["Flat", "Gouraud", "Phong"],
  114 + 3,
  115 + wx.RA_SPECIFY_COLS | wx.NO_BORDER,
  116 + )
98 117  
99   - bsizer.Add(rb_inter, 0, wx.TOP|wx.LEFT, 0)
  118 + bsizer.Add(rb_inter, 0, wx.TOP | wx.LEFT, 0)
100 119  
101 120 box_rendering = wx.StaticBox(self, -1, _("Volume rendering"))
102 121 bsizer_ren = wx.StaticBoxSizer(box_rendering, wx.VERTICAL)
... ... @@ -104,22 +123,31 @@ class Viewer3D(wx.Panel):
104 123 lbl_rendering = wx.StaticText(self, -1, _("Rendering"))
105 124 bsizer_ren.Add(lbl_rendering, 0, wx.TOP | wx.LEFT, 10)
106 125  
107   - rb_rendering = self.rb_rendering = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize,
108   - ['CPU', _(u'GPU (NVidia video cards only)')], 2, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
  126 + rb_rendering = self.rb_rendering = wx.RadioBox(
  127 + self,
  128 + -1,
  129 + "",
  130 + wx.DefaultPosition,
  131 + wx.DefaultSize,
  132 + ["CPU", _(u"GPU (NVidia video cards only)")],
  133 + 2,
  134 + wx.RA_SPECIFY_COLS | wx.NO_BORDER,
  135 + )
109 136  
110 137 bsizer_ren.Add(rb_rendering, 0, wx.TOP | wx.LEFT, 0)
111 138 border = wx.BoxSizer(wx.VERTICAL)
112   - border.Add(bsizer, 50, wx.EXPAND|wx.ALL, 10)
113   - border.Add(bsizer_ren, 50, wx.EXPAND|wx.ALL, 10)
  139 + border.Add(bsizer, 50, wx.EXPAND | wx.ALL, 10)
  140 + border.Add(bsizer_ren, 50, wx.EXPAND | wx.ALL, 10)
114 141 self.SetSizer(border)
115 142  
116 143 border.Fit(self)
117 144  
118   -
119 145 def GetSelection(self):
120 146  
121   - options = {const.RENDERING:self.rb_rendering.GetSelection(),
122   - const.SURFACE_INTERPOLATION:self.rb_inter.GetSelection()}
  147 + options = {
  148 + const.RENDERING: self.rb_rendering.GetSelection(),
  149 + const.SURFACE_INTERPOLATION: self.rb_inter.GetSelection(),
  150 + }
123 151  
124 152 return options
125 153  
... ... @@ -132,7 +160,6 @@ class Viewer3D(wx.Panel):
132 160  
133 161  
134 162 class Viewer2D(wx.Panel):
135   -
136 163 def __init__(self, parent):
137 164  
138 165 wx.Panel.__init__(self, parent)
... ... @@ -141,23 +168,30 @@ class Viewer2D(wx.Panel):
141 168 bsizer = wx.StaticBoxSizer(box_visualization, wx.VERTICAL)
142 169  
143 170 lbl_inter = wx.StaticText(self, -1, _("Interpolated "))
144   - bsizer.Add(lbl_inter, 0, wx.TOP|wx.LEFT, 10)
  171 + bsizer.Add(lbl_inter, 0, wx.TOP | wx.LEFT, 10)
145 172  
146   - rb_inter = self.rb_inter = wx.RadioBox(self, -1, "", wx.DefaultPosition, wx.DefaultSize,
147   - [_('Yes'), _('No')], 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
  173 + rb_inter = self.rb_inter = wx.RadioBox(
  174 + self,
  175 + -1,
  176 + "",
  177 + wx.DefaultPosition,
  178 + wx.DefaultSize,
  179 + [_("Yes"), _("No")],
  180 + 3,
  181 + wx.RA_SPECIFY_COLS | wx.NO_BORDER,
  182 + )
148 183  
149   - bsizer.Add(rb_inter, 0, wx.TOP|wx.LEFT, 0)
  184 + bsizer.Add(rb_inter, 0, wx.TOP | wx.LEFT, 0)
150 185  
151 186 border = wx.BoxSizer(wx.VERTICAL)
152   - border.Add(bsizer, 50, wx.EXPAND|wx.ALL, 10)
  187 + border.Add(bsizer, 50, wx.EXPAND | wx.ALL, 10)
153 188 self.SetSizer(border)
154 189  
155 190 border.Fit(self)
156 191  
157   -
158 192 def GetSelection(self):
159 193  
160   - options = {const.SLICE_INTERPOLATION:self.rb_inter.GetSelection()}
  194 + options = {const.SLICE_INTERPOLATION: self.rb_inter.GetSelection()}
161 195  
162 196 return options
163 197  
... ... @@ -167,7 +201,6 @@ class Viewer2D(wx.Panel):
167 201  
168 202  
169 203 class Language(wx.Panel):
170   -
171 204 def __init__(self, parent):
172 205  
173 206 wx.Panel.__init__(self, parent)
... ... @@ -178,19 +211,23 @@ class Language(wx.Panel):
178 211 box = wx.StaticBox(self, -1, _("Language"))
179 212 bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
180 213  
181   - text = wx.StaticText(self, -1, _("Language settings will be applied \n the next time InVesalius starts."))
  214 + text = wx.StaticText(
  215 + self,
  216 + -1,
  217 + _("Language settings will be applied \n the next time InVesalius starts."),
  218 + )
182 219 bsizer.Add(cmb_lang, 0, wx.EXPAND)
183 220 bsizer.AddSpacer(5)
184 221 bsizer.Add(text, 0, wx.EXPAND)
185 222  
186 223 border = wx.BoxSizer()
187   - border.Add(bsizer, 1, wx.EXPAND|wx.ALL, 20)
  224 + border.Add(bsizer, 1, wx.EXPAND | wx.ALL, 20)
188 225 self.SetSizerAndFit(border)
189 226  
190 227 def GetSelection(self):
191 228 selection = self.cmb_lang.GetSelection()
192 229 locales = self.lg.GetLocalesKey()
193   - options = {const.LANGUAGE:locales[selection]}
  230 + options = {const.LANGUAGE: locales[selection]}
194 231 return options
195 232  
196 233 def LoadSelection(self, values):
... ... @@ -200,11 +237,16 @@ class Language(wx.Panel):
200 237 self.cmb_lang.SetSelection(int(selection))
201 238  
202 239  
203   -
204 240 class SurfaceCreation(wx.Panel):
205 241 def __init__(self, parent):
206 242 wx.Panel.__init__(self, parent)
207   - self.rb_fill_border = wx.RadioBox(self, -1, _("Fill border holes"), choices=[_('Yes'), _('No')], style=wx.RA_SPECIFY_COLS | wx.NO_BORDER)
  243 + self.rb_fill_border = wx.RadioBox(
  244 + self,
  245 + -1,
  246 + _("Fill border holes"),
  247 + choices=[_("Yes"), _("No")],
  248 + style=wx.RA_SPECIFY_COLS | wx.NO_BORDER,
  249 + )
208 250  
209 251 sizer = wx.BoxSizer(wx.VERTICAL)
210 252 sizer.Add(self.rb_fill_border)
... ...