root/branch/umitweb-ng/umitInventory/TLGraphPreferences.py @ 4721

Revision 4721, 17.3 kB (checked in by rcarvalho, 4 years ago)

Merged revisions 4095-4099 via svnmerge from
http://svn.umitproject.org/svnroot/umit/trunk

........

r4095 | getxsick | 2009-02-17 17:58:22 -0300 (Ter, 17 Fev 2009) | 1 line


test CIA

........

r4096 | getxsick | 2009-02-17 18:17:28 -0300 (Ter, 17 Fev 2009) | 1 line


remove xxx file from tests

........

r4097 | luis | 2009-02-17 18:28:51 -0300 (Ter, 17 Fev 2009) | 1 line


Updated licence copyrights using -> find . -path '*/.svn' -prune -o -type f -print0 | xargs -0 sed -i -e 's/2007 Insecure.Com LLC./2007 Adriano Monteiro Marques/'

........

r4098 | gpolo | 2009-02-17 18:43:12 -0300 (Ter, 17 Fev 2009) | 1 line


float support is deprecated for WaitForSingleObject?

........

r4099 | gpolo | 2009-02-17 18:48:49 -0300 (Ter, 17 Fev 2009) | 1 line


Adjusted umit_scheduler to run as a Windows service under py2exe

........

Line 
1# Copyright (C) 2007 Adriano Monteiro Marques
2#
3# Authors: Guilherme Polo <ggpolo@gmail.com>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18# USA
19
20import os
21import gtk
22
23from umitCore.I18N import _
24from umitCore.Paths import Path
25
26from higwidgets.higwindows import HIGWindow
27from higwidgets.higboxes import HIGVBox, HIGHBox, hig_box_space_holder
28from higwidgets.higlabels import HIGEntryLabel
29from higwidgets.higbuttons import HIGButton
30
31profiles = [
32    _("Custom"), _("Standard"), _("Best Performance"),
33    _("Best Visual")
34    ]
35
36pixmaps_dir = Path.pixmaps_dir
37
38if pixmaps_dir:
39    logo = os.path.join(pixmaps_dir, 'wizard_logo.png')
40else:
41    logo = None
42
43class GraphPreferences(HIGWindow):
44    """
45    Graph Preferences Editor
46    """
47
48    def __init__(self, daddy=None):
49        HIGWindow.__init__(self)
50
51        self.daddy = daddy # TLGraphToolbar instance
52        self.wtitle = _("Graph Preferences Editor")
53
54        # header
55        self.title_markup = "<span size='16500' weight='heavy'>%s</span>"
56        self.ttitle = HIGEntryLabel("")
57        self.ttitle.set_line_wrap(False)
58        self.ttitle.set_markup(self.title_markup % self.wtitle)
59        self.umit_logo = gtk.Image()
60        self.umit_logo.set_from_file(logo)
61        # profiles
62        self.graph_profile_lbl = HIGEntryLabel(_("Profile"))
63        self.graph_profile = gtk.combo_box_new_text()
64        # horizontal divisors/balloons
65        self.hdivs_lbl = HIGEntryLabel(_("Horizontal divisors"))
66        self.hdivs = gtk.SpinButton(gtk.Adjustment(value=5, lower=2, upper=10,
67            step_incr=1), 1)
68        # arc drawing
69        self.draw_arc_lbl = HIGEntryLabel('')
70        self.draw_arc_lbl.set_markup(_("<b>Points higlight</b>"))
71        self.draw_arc_onsel = gtk.RadioButton(label=_("On Selection"))
72        self.draw_arc_always = gtk.RadioButton(self.draw_arc_onsel,
73            label=_("Always"))
74        self.draw_arc_bounds = gtk.RadioButton(label=_("Boundary points only"))
75        self.draw_arc_allpts = gtk.RadioButton(self.draw_arc_bounds,
76            label=_("Every point"))
77        self.balloons = gtk.CheckButton(_("Show balloons on selection"))
78        # vertical divisors
79        self.draw_vertdiv = gtk.CheckButton(_("Draw vertical lines"))
80        self.draw_vertdiv_dash = gtk.RadioButton(label=_("Dashed"))
81        self.draw_vertdiv_solid = gtk.RadioButton(self.draw_vertdiv_dash,
82            label=_("Solid"))
83        # background fill
84        self.bg_gradient = gtk.CheckButton(_("Gradient background"))
85        self.bg_gradient_vert = gtk.RadioButton(label=_("Vertical gradient"))
86        self.bg_gradient_horiz = gtk.RadioButton(self.bg_gradient_vert,
87            label=_("Horizontal gradient"))
88        # selection fill
89        self.selection_fill = gtk.CheckButton(_("On selection do "
90            "progressive fill"))
91        self.selection_fill_solid = gtk.RadioButton(label=_("Solid fill"))
92        self.selection_fill_gradient = gtk.RadioButton(
93            self.selection_fill_solid, label=_("Gradient fill"))
94        # bottom buttons
95        self.help = HIGButton(stock=gtk.STOCK_HELP)
96        self.help.connect('clicked', self._show_help)
97        self.apply = HIGButton(stock=gtk.STOCK_APPLY)
98        self.apply.connect('clicked', self._save_pref)
99        self.cancel = HIGButton(stock=gtk.STOCK_CANCEL)
100        self.cancel.connect('clicked', self._exit)
101        self.ok = HIGButton(stock=gtk.STOCK_OK)
102        self.ok.connect('clicked', self._save_pref_and_leave)
103
104
105        self.append_profiles()
106        start_profile = self.load_options_from_graph()
107        self.setup_controls(None, start_profile)
108
109        self.__do_connects()
110        self.__set_props()
111        self.__do_layout()
112
113
114    def append_profiles(self):
115        """
116        Write profiles to combobox.
117        """
118        for p in profiles:
119            self.graph_profile.append_text(p)
120
121        self.graph_profile.set_active(1)
122
123
124    def graph_attrs(self):
125        """
126        Tuple of attributes in graph.
127        """
128        return (
129            "hdivisors", "draw_arcs_always", "draw_every_arc",
130            "show_balloons", "draw_dashed_vert", "draw_solid_vert",
131            "gradient_fill", "gradient_direction", "selection_effect",
132            "selection_gradient" )
133
134
135    def load_options_from_graph(self):
136        """
137        Load startup graph settings.
138        """
139        # horizontal divisors
140        hdivs = self.daddy.graph_attr("hdivisors") + 1
141        # arcs
142        draw_arcs_always = int(self.daddy.graph_attr("draw_arcs_always"))
143        draw_every_arc = int(self.daddy.graph_attr("draw_every_arc"))
144        # balloons
145        balloons = self.daddy.graph_attr("show_balloons")
146        # vertical lines
147        vert_enabled = True
148        if self.daddy.graph_attr("draw_dashed_vert"):
149            vert_line = 0
150        elif self.daddy.graph_attr("draw_solid_vert"):
151            vert_line = 1
152        else:
153            vert_line = -1
154            vert_enabled = False
155        # widget background
156        gradient_bg = True and self.daddy.graph_attr("gradient_fill")
157        if not gradient_bg:
158            gradient_bg_dir = -1
159        else:
160            gradient_bg_dir = int(self.daddy.graph_attr("gradient_direction"))
161        # selection
162        selection_effect = True and self.daddy.graph_attr("selection_effect")
163        selection_fill = int(self.daddy.graph_attr("selection_gradient"))
164
165        profile = {"Startup": (
166            hdivs, draw_arcs_always, draw_every_arc,
167            balloons, vert_enabled, vert_line,
168            gradient_bg, gradient_bg_dir,
169            selection_effect, selection_fill)}
170
171        return profile
172
173
174    def setup_controls(self, event, startup=None):
175        """
176        Enable/Disable controls.
177        """
178        opt_profiles = (
179            _("Standard"), _("Best Performance"), _("Best Visual")
180            )
181
182        profile = self.graph_profile.get_active_text()
183        indx_active = self.graph_profile.get_active()
184        if not profile in opt_profiles: # custom
185            return
186
187        # dict with default values for each option in this window.
188        profiles_d = {
189            _("Standard"): (5, 0, 1, True, False, -1, False, -1, True, 0),
190            _("Best Performance"): (3, 0, 0, True, False, -1, False, -1,
191                False, 0),
192            _("Best Visual"): (5, 0, 1, True, True, 0, True, 0, True, 1)
193            }
194
195        if startup:
196            found_profile = False
197            for p, values in profiles_d.items():
198                if startup["Startup"] == values:
199                    index_profile = profiles.index(p)
200                    self.graph_profile.set_active(index_profile)
201                    indx_active = self.graph_profile.get_active()
202                    profile = p
203                    found_profile = True
204                    break
205
206            if not found_profile: # custom
207                indx_active = 0
208                profile = _("Custom")
209                self.graph_profile.set_active(indx_active)
210                temp = { }
211                temp[_("Custom")] = startup["Startup"]
212                profiles_d.update(temp)
213
214
215        controls = (self.hdivs, (self.draw_arc_onsel, self.draw_arc_always),
216                    (self.draw_arc_bounds, self.draw_arc_allpts),
217                    self.balloons, self.draw_vertdiv, (self.draw_vertdiv_dash,
218                    self.draw_vertdiv_solid), self.bg_gradient,
219                    (self.bg_gradient_vert, self.bg_gradient_horiz),
220                    self.selection_fill, (self.selection_fill_solid,
221                    self.selection_fill_gradient))
222
223        for indx, control in enumerate(controls):
224            value = profiles_d[profile][indx]
225
226            if value >= 2: # it is spinbutton
227                control.set_value(float(value))
228            elif type(value) == type(True): # checkbutton
229                control.set_active(value)
230            elif value != -1: # radiobutton
231                control[value].set_active(True)
232
233
234        checkbtns = (self.draw_vertdiv, self.bg_gradient)
235        methods = (self._vertdiv_changed, self._bgfill_changed)
236
237        for indx, checkbtn in enumerate(checkbtns):
238            methods[indx](checkbtn.get_active(), indx_active)
239
240        return True
241
242
243    def _vertdiv_changed(self, event, custom=0):
244        """
245        Vertical divisors enabled/disabled.
246        """
247        status = self.get_status(event)
248
249        self.draw_vertdiv_dash.set_sensitive(status)
250        self.draw_vertdiv_solid.set_sensitive(status)
251
252        self.graph_profile.set_active(custom)
253
254
255    def _bgfill_changed(self, event, custom=0):
256        """
257        Gradient background fill enabled/disabled.
258        """
259        status = self.get_status(event)
260
261        self.bg_gradient_vert.set_sensitive(status)
262        self.bg_gradient_horiz.set_sensitive(status)
263
264        self.graph_profile.set_active(custom)
265
266
267    def get_status(self, event):
268        """
269        Get event status.
270        """
271        if type(event) == type(True):
272            status = event # event generated by profile change
273        else:
274            status = event.get_active() # event generated by mouse click
275
276        return status
277
278
279    def _show_help(self, event):
280        """
281        Show help for Graph Preferences.
282        """
283
284
285    def _save_pref(self, event):
286        """
287        Save preferences.
288        """
289        profile = self.graph_profile.get_active_text()
290
291        cmds = {
292            _("Standard"): "standard_mode",
293            _("Best Performance"): "speedup_performance",
294            _("Best Visual"): "best_visual" }
295
296        if profile != _("Custom"):
297            self.daddy.change_graph_mode = cmds[profile]
298            return
299
300        controls = (self.hdivs, self.draw_arc_always, self.draw_arc_allpts,
301                    self.balloons, (self.draw_vertdiv, self.draw_vertdiv_dash,
302                    self.draw_vertdiv_solid), self.bg_gradient,
303                    self.bg_gradient_horiz, self.selection_fill,
304                    self.selection_fill_gradient)
305
306        indx = 0
307        for control in controls:
308            if type(control) == type(tuple()): # group of controls
309                enable = True
310                if not control[0].get_active():
311                    enable = False
312
313                for c in control[1:]:
314                    if enable == False:
315                        self.daddy.change_graph_attr = (
316                            self.graph_attrs()[indx], False)
317                    else:
318                        self.daddy.change_graph_attr = (
319                            self.graph_attrs()[indx], c.get_active())
320                    indx += 1
321
322                continue
323
324            elif hasattr(control, "get_active"): # radio/checkbutton
325                self.daddy.change_graph_attr = (
326                    self.graph_attrs()[indx], control.get_active())
327                   
328            elif hasattr(control, "set_width_chars"): # spinbutton
329                nhdiv = int(control.get_text())
330                self.daddy.change_graph_attr = self.graph_attrs()[indx], nhdiv
331
332            indx += 1
333
334        self.daddy.update_graph()
335
336
337    def _save_pref_and_leave(self, event):
338        """
339        Saves preferences and close window.
340        """
341        self._save_pref(None)
342        self._exit(None)
343
344
345    def _exit(self, event):
346        """
347        Close window.
348        """
349        self.destroy()
350
351
352    def __do_connects(self):
353        """
354        Connect signals.
355        """
356        self.hdivs.connect('value-changed',
357            lambda c: self.graph_profile.set_active(0))
358
359        self.draw_arc_always.connect('clicked',
360            lambda c: self.graph_profile.set_active(0))
361        self.draw_arc_bounds.connect('clicked',
362            lambda c: self.graph_profile.set_active(0))
363        self.draw_arc_allpts.connect('clicked',
364            lambda c: self.graph_profile.set_active(0))
365        self.balloons.connect('toggled',
366            lambda c: self.graph_profile.set_active(0))
367
368        self.draw_vertdiv.connect('toggled', self._vertdiv_changed)
369        self.draw_vertdiv_dash.connect('clicked',
370            lambda c: self.graph_profile.set_active(0))
371        self.draw_vertdiv_solid.connect('clicked',
372            lambda c: self.graph_profile.set_active(0))
373
374        self.bg_gradient.connect('toggled', self._bgfill_changed)
375        self.bg_gradient_vert.connect('clicked',
376            lambda c: self.graph_profile.set_active(0))
377        self.bg_gradient_horiz.connect('clicked',
378            lambda c: self.graph_profile.set_active(0))
379
380        self.selection_fill.connect('toggled',
381            lambda c: self.graph_profile.set_active(0))
382        self.selection_fill_solid.connect('clicked',
383            lambda c: self.graph_profile.set_active(0))
384        self.selection_fill_gradient.connect('clicked',
385            lambda c: self.graph_profile.set_active(0))
386
387        self.graph_profile.connect('changed', self.setup_controls)
388
389
390    def __set_props(self):
391        """
392        Set window properties.
393        """
394        self.set_title(self.wtitle)
395
396
397    def __do_layout(self):
398        """
399        Layout widgets in window.
400        """
401
402        def left_padding(widget):
403            """
404            Add left padding for a widget.
405            """
406            left_padding_align = gtk.Alignment(0.5, 0.5, 1, 1)
407            left_padding_align.set_padding(0, 0, 12, 0)
408            left_padding_align.add(widget)
409            return left_padding_align
410
411
412        main_vbox = HIGVBox()
413        main_vbox.set_border_width(5)
414        main_vbox.set_spacing(12)
415        header_hbox = HIGHBox()
416        profile_hbox = HIGHBox()
417        hdivs_hbox = HIGHBox()
418        arcdraw_vbox = HIGVBox()
419        vdivs_vbox = HIGVBox()
420        bgfill_vbox = HIGVBox()
421        selectfill_vbox = HIGVBox()
422        btns_hbox = HIGHBox()
423
424        # header
425        header_hbox._pack_expand_fill(self.ttitle)
426        header_hbox._pack_noexpand_nofill(self.umit_logo)
427
428        # profiles
429        profile_hbox._pack_noexpand_nofill(self.graph_profile_lbl)
430        profile_hbox._pack_noexpand_nofill(self.graph_profile)
431
432        # horizontal divisors
433        hdivs_hbox._pack_noexpand_nofill(self.hdivs_lbl)
434        hdivs_hbox._pack_noexpand_nofill(self.hdivs)
435
436        # arc drawing
437        arcdraw_vbox._pack_noexpand_nofill(self.draw_arc_lbl)
438
439        arcdraw_when = HIGHBox()
440        arcdraw_when._pack_noexpand_nofill(self.draw_arc_onsel)
441        arcdraw_when._pack_noexpand_nofill(self.draw_arc_always)
442
443        arcdraw_where = HIGHBox()
444        arcdraw_where._pack_noexpand_nofill(self.draw_arc_bounds)
445        arcdraw_where._pack_noexpand_nofill(self.draw_arc_allpts)
446
447        arcdraw_vbox._pack_noexpand_nofill(left_padding(arcdraw_when))
448        arcdraw_vbox._pack_noexpand_nofill(left_padding(arcdraw_where))
449        arcdraw_vbox._pack_noexpand_nofill(left_padding(self.balloons))
450
451        # vertical divisors
452        vdivs_vbox._pack_noexpand_nofill(self.draw_vertdiv)
453
454        vdivs_kind = HIGHBox()
455        vdivs_kind._pack_noexpand_nofill(self.draw_vertdiv_dash)
456        vdivs_kind._pack_noexpand_nofill(self.draw_vertdiv_solid)
457
458        vdivs_vbox._pack_noexpand_nofill(left_padding(vdivs_kind))
459
460        # background fill
461        bgfill_vbox._pack_noexpand_nofill(self.bg_gradient)
462
463        bgfill_gtype = HIGHBox()
464        bgfill_gtype._pack_noexpand_nofill(self.bg_gradient_vert)
465        bgfill_gtype._pack_noexpand_nofill(self.bg_gradient_horiz)
466
467        bgfill_vbox._pack_noexpand_nofill(left_padding(bgfill_gtype))
468
469        # selection fill
470        selectfill_vbox._pack_noexpand_nofill(self.selection_fill)
471
472        selectfill_kind = HIGHBox()
473        selectfill_kind._pack_noexpand_nofill(self.selection_fill_solid)
474        selectfill_kind._pack_noexpand_nofill(self.selection_fill_gradient)
475
476        selectfill_vbox._pack_noexpand_nofill(left_padding(selectfill_kind))
477
478        # bottom buttons
479        btns_hbox.set_homogeneous(True)
480        btns_hbox._pack_expand_fill(self.help)
481        btns_hbox._pack_expand_fill(hig_box_space_holder())
482        btns_hbox._pack_expand_fill(self.apply)
483        btns_hbox._pack_expand_fill(self.cancel)
484        btns_hbox._pack_expand_fill(self.ok)
485
486
487        main_vbox._pack_noexpand_nofill(header_hbox)
488        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
489        main_vbox._pack_noexpand_nofill(profile_hbox)
490        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
491        main_vbox._pack_noexpand_nofill(hdivs_hbox)
492        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
493        main_vbox._pack_noexpand_nofill(arcdraw_vbox)
494        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
495        main_vbox._pack_noexpand_nofill(vdivs_vbox)
496        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
497        main_vbox._pack_noexpand_nofill(bgfill_vbox)
498        main_vbox._pack_noexpand_nofill(gtk.HSeparator())
499        main_vbox._pack_noexpand_nofill(selectfill_vbox)
500        main_vbox.pack_end(btns_hbox, False, False, 0)
501        main_vbox.pack_end(gtk.HSeparator(), False, False, 0)
502        self.add(main_vbox)
Note: See TracBrowser for help on using the browser.