root/branch/k0p/umitInterfaceEditor/Profile.py @ 1357

Revision 1357, 25.3 kB (checked in by kop-labs, 6 years ago)

Fixed bug on swich page - number

Line 
1# Copyright (C) 2005 Insecure.Com LLC.
2#
3# Author: Luis A. Bastiao Silva <luis.kop@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 USA
18
19
20import gtk 
21
22import sys
23# Testing at devel
24from os.path import split, join
25
26from umitCore.Paths import Path
27#Path.set_umit_conf(join(split(__file__)[0], 'config', 'umit.conf'))
28#END DEV TEST
29options = Path.options
30profile_editor = Path.profile_editor
31#XXX This path is too wrong
32#sys.path.append("selectborder")
33from umitInterfaceEditor.selectborder.WrapperWidgets import NotebookLabel, SpecialHBox
34
35from higwidgets.higscrollers import HIGScrolledWindow
36from higwidgets.hignotebooks import HIGNotebook
37from higwidgets.higlabels import HIGSectionLabel, HIGEntryLabel
38
39from umitCore.NmapCommand import CommandConstructor
40from umitCore.UmitConf import Profile, CommandProfile
41from umitGUI.OptionBuilder import *
42from higwidgets.higboxes import HIGVBox
43from umitCore.Logging import log
44from umitCore.I18N import _
45from higwidgets.higtables import HIGTable
46import gobject
47
48
49
50TARGET_STRING = 0
51TARGET_ROOTWIN = 1
52
53target = [
54    ('STRING', 0, TARGET_STRING),
55    ('text/plain', 0, TARGET_STRING),
56    ('application/x-rootwin-drop', 0, TARGET_ROOTWIN)
57]
58
59#Global variables
60SPACE_TABLE = 6
61
62
63
64# XXX : Should be put in other file to using by OptionBuilder too
65type_mapping = { 
66    "str": OptionEntry,
67    "int": OptionIntSpin,
68    "float": OptionFloatSpin,
69    "level": OptionLevelSpin, 
70    "path": OptionFile,
71    "interface": OptionInterface, 
72    "scriptlist": OptionScriptList
73    }
74
75
76from ProfileCore import ProfileCore, ProfileOption
77from Command import Command, TwiceCommand, command_manager
78from Tools import ToolBarInterface
79
80#TODO :
81'''
82The list and dictionarie with the widgets of NotebookEditable with numbers
83of the pages should be a class to manage better the pages
84'''
85
86
87class CommandAddRemoveLabel(TwiceCommand, Command):
88    '''
89    Add or Remove Label from Title pages of NotebookEditable
90    ###
91    trik : state is a inicial value if it is remove or add.
92    '''
93    def __init__(self, widget, text, state):
94        TwiceCommand.__init__(self, state)
95        Command.__init__(self, _('Add Label'))
96        self._widget = widget
97        self._text = text
98       
99   
100    def _add_label(self):
101        self._widget.unload_voidplace()
102        self._widget.set_text(self._text) 
103        log.debug('Adding label')
104    _execute_1 = _add_label
105    def _remove_label(self):
106        self._widget.voidplace()
107        log.debug('Removing label, Adding Void Place')
108    _execute_2 = _remove_label
109
110
111class CommandAddRemoveVoidplace(TwiceCommand, Command):
112    '''
113    Add or Remove A voidplace on the Editor-Mode
114   
115    '''
116    def __init__(self, table, widget, coords, state): 
117        TwiceCommand.__init__(self, state)
118        Command.__init__(self, _('Add/Remove Voidplace'))
119        self._table = table.get_table()
120       
121        self._widget = widget
122        self._x,self._y = coords[widget] 
123        #self._spacing = self._table.get_row_spacing(self._x)
124        self._spacing = SPACE_TABLE
125    def _add(self):
126        if self._widget.is_voidplace():
127            self._widget.show_voidplace()
128       
129        #self._widget.do_draw()
130        self._widget.show()     
131        #self._table.attach(self._widget, 0,2,self._x,self._y)
132        self._table.set_row_spacing(self._x,self._spacing)
133        #self._widget.do_voidplace()
134        #self._widget.do_voidplace()
135
136        log.debug('CommandVoidplace: add voidplace')
137       
138    _execute_1 = _add
139    def _remove(self):
140       
141        if self._widget != None and self._widget.is_voidplace():
142            log.debug('CommandVoidplace: remove voidplace')
143            self._widget.hide_voidplace()
144            self._widget.set_select(False)
145            self._widget.hide()
146            self._table.set_row_spacing(self._x,0)
147           
148            #self._widget.unload_voidplace()
149            #self._table.remove(self._widget)
150           
151    _execute_2 = _remove
152   
153
154
155class CommandVoidPlaceAttach(TwiceCommand, Command):
156    '''
157    Add a new widget (voidplace) at the last position
158   
159    '''
160    def __init__(self,table, widget, coords, state):
161        self._last = table.get_last()
162        self._box = table
163        x, y = coords[self._last] 
164        coords[widget] = [+1 , y+1]
165        TwiceCommand.__init__(self, state)
166        Command.__init__(self, _('Add/Remove Voidplace'))
167        self._table = table.get_table()
168        self._box.set_last(widget)
169        self._widget = widget
170        self._x,self._y = coords[widget] 
171        self._coords = coords
172        #self._spacing = self._table.get_row_spacing(x-1)
173        self._spacing = SPACE_TABLE
174    def _attach(self):
175        self._table.resize(self._y, 2)
176        log.debug('<<< Attach Add Voidplace')
177        self._table.set_row_spacing(self._x,self._spacing)
178
179        self._table.attach(self._widget, 0, 2, self._x, self._y)
180        self._widget.show_all()
181        self._widget.do_voidplace()
182       
183
184       
185       
186    _execute_1 = _attach
187    def _unattach(self):
188        #if self._widget != None and self._widget.is_voidplace():
189            #log.debug('<<< remove voidplace unattach')
190            #self._widget.hide_voidplace()
191            #self._widget.set_select(False)
192            #self._widget.hide()
193            #self._table.set_row_spacing(self._x,0)
194        self._widget.unload_voidplace()
195        self._table.remove(self._widget)
196        del self._coords[self._widget]
197    _execute_2 = _unattach
198   
199   
200
201
202class CommandPageNotebook(TwiceCommand, Command):
203    '''
204    Add Page at Notebook or Remove
205    '''
206    def __init__(self, notebook, page, number, profilecore, state):
207        TwiceCommand.__init__(self, state)
208        Command.__init__(self, _('Add/Remove Page'))
209        self._notebook = notebook
210        self._page = page
211        self._number = number
212        self._profilecore = profilecore
213    def _create_label(self):
214        pass
215   
216    def _add_page(self):
217        label = self._create_label()
218        self._notebook.insert_page(self._page, label, self._number)
219       
220    _execute_1 = _add_page
221    def _remove_page(self):
222        self._notebook.remove_page(self._number)
223   
224    _execute_2 = _remove_page
225   
226class CommandMovePage(TwiceCommand, Command):
227    '''
228    move page
229    '''
230    def __init__(self, notebook, number,profilecore, state):
231        '''
232        @param number: number of num pages to move ; default should be 1
233        @type number: Integer
234        '''
235       
236        TwiceCommand.__init__(self, state)
237        Command.__init__(self, _('Move Page'))
238        self._notebook = notebook
239        self._page = self._notebook.get_nth_page(self._notebook.get_current_page())
240        self._number = number
241        self._profilecore = profilecore
242    def _move_left(self):
243        log.debug("move left")
244        self._notebook.reorder_child(self._page,self._notebook.get_current_page()-self._number )
245        name = self._page.get_name()
246        if name != None :
247            self._profilecore.move_section_left(name)
248       
249       
250    _execute_1 = _move_left
251    def _move_right(self):
252        log.debug("move right")
253        self._notebook.reorder_child(self._page,self._notebook.get_current_page()+self._number )
254        name = self._page.get_name()
255        if name != None :
256            self._profilecore.move_section_right(name)
257    _execute_2 = _move_right
258
259
260
261class CommandMove(TwiceCommand, Command):
262    '''
263    Move items to down or up
264    #Trick:
265    - Add other colums to save row and do a swap. Use a temporary widget.
266    '''
267    def __init__(self, widget_container, widget, coords , profilecore,  state):
268        TwiceCommand.__init__(self, state)
269        Command.__init__(self, _('Move item'))
270        self._parent = widget_container
271        self._section_name = widget_container.get_name()
272        self._table = widget_container.get_table()
273        self._move = widget
274        self._coords = coords
275        self._profilecore = profilecore
276        self._x, self._y = self._coords[widget]
277        self._name = widget.get_name()
278       
279       
280       
281    def _determine_child(self, list, num): 
282        result = None 
283        x, y = self._coords[self._move]
284        x = x + num
285        y = y + num
286        for i in list : 
287            x_tmp, y_tmp = self._coords[i]
288            if x_tmp == x and y_tmp == y  :
289                result= i
290                break 
291        return result
292    def _get_next(self):
293         
294        childs = self._table.get_children()
295        return self._determine_child(childs, 1)
296    def _get_prev(self): 
297       
298        childs = self._table.get_children()
299        childs.reverse()
300        return self._determine_child(childs,-1) 
301    def _swap(self, widget1, widget2):
302        x1, y1 = self._coords[widget1]
303        x2, y2 = self._coords[widget2]
304        list_vp = []
305        if widget1.is_voidplace():
306            widget1.unload_voidplace()
307            list_vp.append(widget1)
308           
309        if widget2.is_voidplace():
310            list_vp.append(widget2)
311            widget2.unload_voidplace()
312
313       
314        widget1.set_select(False)
315        widget2.set_select(False)
316        w_tmp = gtk.Label('tmp')
317        self._table.attach(w_tmp, 1,2, x1, y1)
318        self._table.remove(widget1)
319        self._table.attach(widget1, 0,2, x2, y2)
320        self._table.remove(widget2)
321        self._table.attach(widget2, 0,2, x1, y1)
322        self._table.remove(w_tmp)
323       
324        self._coords[widget1] = [x2, y2]
325        self._coords[widget2] = [x1,y1]
326        #self._move = widget2
327        for i in list_vp:
328            i.do_voidplace()
329            #i.do_resize_voidplace()
330           
331           
332    def _move_up(self):
333       
334        widget_swap = self._get_prev()
335        self._profilecore.move_option_up(self._section_name, 
336                                         self._name,
337                                         widget_swap.get_name())
338        self._swap(self._move, widget_swap)
339        #widget_swap.do_resize_voidplace()
340        self._parent.send_signal()
341        self._move.do_draw()
342        log.debug('<<< Moving item up')
343    _execute_1 = _move_up
344   
345    def _move_down(self):
346       
347        widget_swap = self._get_next()
348        self._profilecore.move_option_down(self._section_name, 
349                                           self._name, 
350                                           widget_swap.get_name())
351        self._swap( widget_swap, self._move)
352        #x, y = self._coords[widget_swap]
353        #self._move.set_select(False)
354        #widget_swap.set_select(False)
355
356        #w_tmp = gtk.Label('tmp')
357        #self._table.attach(w_tmp, 1,2, x, y)
358        #self._table.remove(widget_swap)
359        #self._table.attach(widget_swap, 0,2, self._x, self._x+1)
360        #self._table.remove(self._move)
361       
362        #self._table.attach(self._move, 0,2, x, y)
363        #self._table.remove(w_tmp)
364       
365        #self._coords[widget_swap] = [self._x, self._y]
366        #self._coords[self._move] = [x,y]
367        self._parent.send_signal()
368        self._move.do_draw()
369        log.debug('<<< Moving item down')
370       
371    _execute_2 = _move_down
372
373
374class CommandAddRemoveOption(TwiceCommand, Command):
375    '''
376    Add or Remove Option from BoxEditable
377    ###
378    trik : state is a inicial value if it is remove or add.
379    '''
380    def __init__(self, widget_container, widget_option, state):
381        TwiceCommand.__init__(self, state)
382        Command.__init__(self, _('Add/Remove Option'))
383        self._widget = widget_container
384        self._widget_option = widget_option
385       
386   
387    def _add_option(self):
388       
389        widget_option = self._widget_option
390        widget = self._widget
391        childs = widget.get_children()
392        widget.remove(childs[0])
393        widget.unload_voidplace()
394        for k in widget_option:
395            widget.pack_start(k)
396        #widget_option.show() # XXX - may be need
397       
398        log.debug('Adding option')
399    _execute_1 = _add_option
400    def _remove_option(self):
401       
402        widget = self._widget
403        childs = widget.get_children()
404        for i in childs:
405            widget.remove(i)
406        t = gtk.Label('-')
407        t.set_size_request(-1, 23)
408        t.show()
409       
410        widget.pack_start(t)
411        widget.do_voidplace()
412        log.debug('Removing option, Adding Void Place')
413    _execute_2 = _remove_option
414
415
416class BoxEditable(HIGVBox):
417    def __init__(self, section_name, profile, listoptions, notebook_parent):
418        """
419        A Box Editable contains a options of each tab
420        @param section_name: section name <tab>
421        @type section_name: str
422        @param profile: A class that view and modify xml file
423        @type profile: ProfileCore
424        """
425           
426        HIGVBox.__init__(self)
427        self._coords = {}
428        self._parent = notebook_parent
429        self._last = None 
430        #Profile Core do a manage at profile_editor.xml file
431        self._profilecore = None 
432       
433        self._profile = profile
434        self._listoptions = listoptions
435        self._table = HIGTable()
436        self._section_name = section_name
437        self._options = self._profile.get_section(section_name)
438        self._table.set_border_width(3)
439        c = self.get_colormap()
440        color = c.alloc_color(0,0,0)   
441        self._table.modify_fg(gtk.STATE_NORMAL,color )
442        self._fill_table()
443       
444        box_tmp = HIGVBox()
445        box_tmp.pack_start(self._table, False, False)
446        self._sw = HIGScrolledWindow()
447        #self._sw.set_size_request(400,200)
448        vp = gtk.Viewport()
449        vp.add(box_tmp)
450        vp.set_shadow_type(gtk.SHADOW_NONE)
451        self._sw.add(vp)
452        self.pack_start(self._sw, True, True)
453        self._old_selected = None 
454        self._x = 0
455        self._y = 0 
456       
457       
458        self.connect('button-press-event', self._bp)
459    #Private API
460    def _bp(self, widget,event):
461        pass
462           
463
464    def _fill_table(self):
465        k = 0
466        for i in self._options:
467            t = SpecialHBox()
468            type = i.get_type()
469            if type== 'option_check':
470               
471                name_option = i.get_option()
472                hint = self._listoptions.get_hint(name_option)
473                tmp_widget = OptionCheckIcon(i.get_label(),name_option,hint)
474                t.pack_start(tmp_widget)
475                arg_type = self._listoptions.get_arg_type(name_option)
476                if arg_type!= '':
477                    additional = type_mapping[arg_type]()
478                    t.pack_start(additional)
479               
480            elif type == 'option_list': 
481                eventbox = gtk.EventBox()
482                label = HIGEntryLabel(i.get_label())
483               
484                eventbox.add(label)
485                tmp_widget = OptionList()
486                for j in i.get_option_list():
487                    d = {}
488                    d['name'] = j
489                    tmp_widget.append(d)
490                t.pack_start(eventbox)         
491                t.pack_start(tmp_widget)
492                #t.drag_source_set(gtk.gdk.BUTTON1_MASK |
493                                                  #gtk.gdk.BUTTON3_MASK,
494                                                  #target,
495                                                  #gtk.gdk.ACTION_COPY |
496                                                  #gtk.gdk.ACTION_MOVE)
497                #t.connect('drag_data_get', self.source_drag_data_get)
498           
499            #XXX : I think that is very important ( I only comment to get focus)
500            t.set_flags( t.flags() |  gtk.CAN_FOCUS)
501            t.connect('button-press-event', self._button_press_event)
502            t.connect('key-press-event', self._key_press_event)
503            t.set_name(i.get_label())
504            t.connect('drag_data_received', self.drag_received)
505            t.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
506                                gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
507           
508            self._table.attach(t, 0,2, k,k+1)
509            self._coords[t] = [k, k+1]
510            self._x = k
511            self._y = k+1
512            k =k +1
513            self._last = t
514       
515   
516       
517    def _key_press_event(self, widget, event):
518        print "key pressed"
519        _keyval = gtk.gdk.keyval_name(event.keyval)
520        if _keyval == "Delete" and self._old_selected!=None :
521            if not widget.is_voidplace(): 
522                # remove widgets like checkbuttons or others and put voidplace
523                childs = widget.get_children()
524                cmd = CommandAddRemoveOption(widget,childs, False)
525                widget.set_select(False)
526                command_manager.add_command(cmd)
527                log.debug(' Remove Widgets like CheckButtons or others and put voidplace')
528               
529            else:
530                # remove voidplace and delete the widget from table/box
531                #XXX
532                cmd = CommandAddRemoveVoidplace(self, 
533                                                widget, self._coords, False)
534                #widget.unload_voidplace()
535                command_manager.add_command(cmd)
536                log.debug('Remove voidplace and delete the widget from table')
537               
538        #self._table.remove(widget)
539        #childs = self._table.get_children()
540        #for i in childs:
541            #if i.is_voidplace():
542                #i.do_resize_voidplace()
543    def _button_press_event(self,widget, event):
544        widget.set_select(True) 
545        self._parent.select(False)
546        if widget == self._old_selected :
547            log.debug('Do nothing')
548            if widget.is_voidplace():
549                widget.do_draw()
550            widget.grab_focus()
551            return 
552        widget.do_draw()
553        if self._old_selected != None:
554            self._old_selected.set_select(False)
555        log.debug('drawing')
556        self._old_selected = widget
557        widget.grab_focus()
558        self._parent.emit('changed', 'Options', self._parent.get_current_page())
559
560    #Public API
561    def get_name(self):
562        return self._section_name
563   
564    def can_move_up(self):
565       
566        widget = self._old_selected
567        x = 0 
568        if widget!= None :
569            x,y = self._coords[widget]
570        return x != 0
571    def can_move_down(self):
572       
573        widget = self._old_selected
574        y = len(self._coords)
575        if widget!= None :
576            x,y = self._coords[widget]
577        return y != (len(self._coords))
578    def send_signal(self):
579        self._parent.emit('changed', 'Options', self._parent.get_current_page())
580    def add_voidplace(self, position):
581        # Create SpecialHBox with Voidplace
582        t = SpecialHBox()
583        e = gtk.EventBox()
584        label = gtk.Label('-')
585        label.set_size_request(-1, 23)
586        e.add(label)
587        t.pack_start(e)
588        t.set_flags( t.flags() |  gtk.CAN_FOCUS)
589        t.connect('button-press-event', self._button_press_event)
590        t.connect('key-press-event', self._key_press_event)
591        t.connect('drag_data_received', self.drag_received)
592        t.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
593                            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
594        cmd = CommandVoidPlaceAttach(self, t, self._coords, True)
595        command_manager.add_command(cmd)
596       
597        #if position == -1 :
598            #x, y = self._x,self._y
599            #self._table.attach()
600        #else:
601            ## Choose the position
602            #pass
603   
604    def move_item_down(self):
605        '''
606        Move selected item to down
607        '''
608        assert self.can_move_down()
609       
610        cmd = CommandMove(self, self._old_selected, self._coords, self._profilecore, False)
611        command_manager.add_command(cmd)
612        self.send_signal()
613    def move_item_up(self):
614        '''
615        Move selected item to up
616        '''
617        assert self.can_move_up()
618       
619        cmd = CommandMove(self, self._old_selected, self._coords, self._profilecore, True)
620        command_manager.add_command(cmd)
621        self.send_signal()
622   
623   
624    def set_profile_core(self, profile_core):
625        self._profilecore = profile_core
626   
627    def option_builder(self, option_name, type):
628        '''
629        construct a widget with the name of the option
630        @return: A widget
631        @rtype: Widget like OptionCheck or others
632        '''
633        result = []
634        hint = self._listoptions.get_hint(option_name)
635        #label, option_name, hint
636        tmp_widget = OptionCheckIcon(option_name,option_name,hint) 
637        result.append(tmp_widget)
638        arg_type = self._listoptions.get_arg_type(option_name)
639        if arg_type!= '':
640            additional = type_mapping[arg_type]()
641            result.append(additional)
642        return result
643       
644       
645       
646       
647    def _is_widget(self, name):
648        return name[0:3] == '_wid'
649
650    def drag_received(self,w, context, x, y, data, info, time):
651        print "drag received"
652        option_name = data.data
653        if self._is_widget(option_name) or not  w.is_voidplace():
654            return
655       
656        arg_type = self._listoptions.get_arg_type(data.data)
657        widgets = self.option_builder(option_name, arg_type)
658       
659        #Remove child
660        childs = w.get_children()
661        w.remove(childs[0])
662        #Add
663        for child in widgets:
664            #t = gtk.Label('fsck')
665            w.pack_start(child)
666            child.show_all()
667       
668        w.unload_voidplace()
669    def get_table(self):
670        return self._table
671    def set_last(self, last):
672        self._last = last
673    def get_last(self):
674        return self._last
675    def source_drag_data_get(self, btn, context, selection_data, info, time):
676        selection_data.set(selection_data.target, 8, "I'm Data!")   
677
678class NotebookEditable(HIGNotebook):
679    '''
680    Editable Notebook to Edit Profile Editor
681    '''
682    __gsignals__ = {
683        'changed':  (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, 
684                     (gobject.TYPE_STRING,object))
685    }
686    def __init__(self, listoption, profilecore):
687        self._listoption = listoption
688        HIGNotebook.__init__(self)
689        self.sections_widgets = {}
690        self.sections_widgets_list = []
691        self.connect('key-press-event', self.on_key_press)
692        self.connect_after('switch-page', self.on_switch_page)
693        self._old_select = None 
694        self._profilecore = profilecore
695       
696        self._page_in = 0
697
698    def save(self):
699        self._profilecore.write_file(profile_editor)
700    def reset(self):
701        pass
702   
703    def load_data(self):
704        self.profile = CommandProfile()
705        options_used = {}
706       
707        self.constructor = CommandConstructor(options_used)
708        self.options = ProfileCore(profile_editor) 
709        i = 0
710        for tab in self.options.groups:
711            self.create_tab(tab, self.options.section_names[tab], 
712                            self.options.tabs[tab], i)
713            i = i+1 
714    def create_tab(self, tab_name, section_name, tab, number):
715        box = BoxEditable(tab_name, self.options, self._listoption, self)
716        box.set_profile_core(self._profilecore)
717        label = NotebookLabel(tab_name)
718        #eventbox = gtk.EventBox()
719
720        #eventbox.add(label)
721        label.set_flags( label.flags() |  gtk.CAN_FOCUS) 
722        label.connect('key-press-event', self.on_key_press)
723        label.connect('button-press-event', self.on_button_press) 
724
725       
726        label.connect('drag_data_received', self.label_drag_data_received)
727        label.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
728                            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
729        #eventbox.show_all()
730        label.show_all()
731        self.sections_widgets[label] = number
732        self.sections_widgets_list.append(label)
733        self.append_page(box, label)
734        #self.set_tab_reorderable(label, True)
735   
736    def select(self, value):
737        if self._old_select!=None:
738            self._old_select.set_select(value)
739            self._old_select=None
740   
741    def on_button_press(self, widget, event):
742        log.debug('Button press on Notebook')
743        if self._old_select != None:
744            self._old_select.set_select(False)
745        widget.set_select(True)
746        self._old_select = widget
747       
748        self.set_current_page(self.sections_widgets[widget])
749        #XXX - this focus owns drag-n-drop received :(
750        #widget.grab_focus()
751        self._page_in = self.get_current_page()
752        log.debug('<<< Setting page %s'%self._page_in)
753        return True
754    def put_on_page(self):
755        log.debug('<<< Put on page %s'%self._page_in)
756        self.set_current_page(self._page_in)
757    def on_switch_page(self, widget, event, page):
758       
759        self.grab_focus()
760        self.emit('changed','Sections', page)
761
762   
763    def on_key_press(self, widget, event):
764        _keyval = gtk.gdk.keyval_name(event.keyval)
765        log.debug('Key press event on NotebookEditable')
766        if self._old_select==None:
767            return
768
769        if _keyval == "Delete" :
770            if self._old_select.is_voidplace():
771                self._old_select.unload_voidplace()
772                label_tmp =self.get_tab_label(self.get_nth_page(
773                    self.get_current_page()))
774                num = self.sections_widgets[label_tmp]
775                del self.sections_widgets[label_tmp]
776                for i in range(num, len(self.sections_widgets)):
777                    print i
778                    widget_tmp = self.sections_widgets_list[i+1]
779                    self.sections_widgets[widget_tmp] = self.sections_widgets[widget_tmp] - 1 
780               
781                self.sections_widgets_list.pop(num)
782                self.remove_page(self.get_current_page())
783               
784
785               
786            else: 
787                cmd = CommandAddRemoveLabel(self._old_select, 
788                                            self._old_select.get_text(), False)
789                command_manager.add_command(cmd)
790        #else:
791            #self._old_select.unload_voidplace()
792    def label_drag_data_received(self, w, context, x, y, data, info, time):
793        print "received"
794
795        if data and data.format == 8:
796            print 'Received "%s" in label' % data.data
797            context.finish(True, False, time)
798            cmd = CommandAddRemoveLabel(self._old_select, 'New Label', True)
799            command_manager.add_command(cmd)
800           
801        #else:
802        #    context.finish(False, False, time)
803       
804    def can_move_right(self):
805        n = self.get_n_pages()
806        current = self.get_current_page()
807        return (n-1) != (current)
808    def can_move_left(self):   
809        current = self.get_current_page()
810        return current!= 0
811    def move_right(self):
812        cmd = CommandMovePage(self, 1, self._profilecore, False)
813        command_manager.add_command(cmd)
814        self.emit('changed','Sections', None)
815    def move_left(self):
816        cmd = CommandMovePage(self, 1, self._profilecore, True)
817        command_manager.add_command(cmd)
818        self.emit('changed','Sections', None)
819           
820   
821   
822class ProfileEdit(gtk.HBox):
823   
824    def __init__(self, listoption):
825        gtk.HBox.__init__(self)
826        self._toolbar = ToolBarInterface()
827        self._proprieties = None 
828        self._notebook_tools = None 
829        #MAIN SCROLLED
830        self._scroolledmain = HIGScrolledWindow()
831        #NOTEBOOKEDITABLE :
832        self._profilecore = ProfileCore(profile_editor)
833        self.notebook = NotebookEditable(listoption, self._profilecore)
834        self._toolbar.set_notebook(self.notebook)
835        self.notebook.connect_after('changed', self.update_toolbar)
836        self.notebook.load_data()
837        self.pack_start(self._toolbar.get_toolbar(), False, True,0)
838        self.pack_start(self._scroolledmain, True, True)
839        self._scroolledmain.add_with_viewport(self.notebook)
840        self.show_all()
841    def get_profilecore(self):
842        return self._profilecore
843    def set_notebook(self, notebook):
844        self._notebook_tools = notebook
845    def set_proprieties(self, proprieties):
846        self._proprieties = proprieties
847        proprieties.disable_all()
848    def update_toolbar(self, action, others, page):
849        #print action
850        #print others
851        #print page
852        boxeditable = self.get_box_editable()
853        self._toolbar.set_box_editable(boxeditable)
854        self._toolbar.update_toolbar()
855       
856        #Update Proprieties box
857        if self._notebook_tools != None: 
858            self._notebook_tools.set_current_page(2)
859       
860        if boxeditable._old_selected!= None :
861            #SpecialHBox - Item
862            self._proprieties.set_boxeditable(boxeditable)
863            self._proprieties.set_item(boxeditable._old_selected)
864           
865            log.debug('<<< SpecialHBox Item update')
866        elif self.notebook._old_select!= None:
867            #Notebook_Label
868            self._proprieties.set_notebooklabel(self.notebook._old_select)
869            log.debug('<<< NotebookLabel update')
870   
871    def get_box_editable(self):
872        current_page = self.notebook.get_current_page()
873        current_box = self.notebook.get_nth_page(current_page)
874        return current_box
875   
876    def save(self):
877        self._profilecore.write_file(profile_editor)
878        log.debug('<<< Saving to file %s ' % profile_editor)
879   
880    def create_events(self):
881        #....
882        pass
883
884       
Note: See TracBrowser for help on using the browser.