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

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

Add section

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
200class CommandPageNotebook(TwiceCommand, Command):
201    '''
202    Add Page at Notebook or Remove
203    '''
204    def __init__(self, notebook, page, number, profilecore, state):
205        TwiceCommand.__init__(self, state)
206        Command.__init__(self, _('Add/Remove Page'))
207        self._notebook = notebook
208        self._page = page
209        self._number = number
210        self._profilecore = profilecore
211    def _create_label(self):
212        pass
213   
214    def _add_page(self):
215        label = self._create_label()
216        self._notebook.insert_page(self._page, label, self._number)
217       
218    _execute_1 = _add_page
219    def _remove_page(self):
220        self._notebook.remove_page(self._number)
221   
222    _execute_2 = _remove_page
223   
224class CommandMovePage(TwiceCommand, Command):
225    '''
226    move page
227    '''
228    def __init__(self, notebook, number,profilecore, state):
229        '''
230        @param number: number of num pages to move ; default should be 1
231        @type number: Integer
232        '''
233       
234        TwiceCommand.__init__(self, state)
235        Command.__init__(self, _('Move Page'))
236        self._notebook = notebook
237        self._page = self._notebook.get_nth_page(self._notebook.get_current_page())
238        self._number = number
239        self._profilecore = profilecore
240    def _move_left(self):
241        log.debug("move left")
242        self._notebook.reorder_child(self._page,self._notebook.get_current_page()-self._number )
243        name = self._page.get_name()
244        if name != None :
245            self._profilecore.move_section_left(name)
246       
247       
248    _execute_1 = _move_left
249    def _move_right(self):
250        log.debug("move right")
251        self._notebook.reorder_child(self._page,self._notebook.get_current_page()+self._number )
252        name = self._page.get_name()
253        if name != None :
254            self._profilecore.move_section_right(name)
255    _execute_2 = _move_right
256
257
258
259class CommandMove(TwiceCommand, Command):
260    '''
261    Move items to down or up
262    #Trick:
263    - Add other colums to save row and do a swap. Use a temporary widget.
264    '''
265    def __init__(self, widget_container, widget, coords , profilecore,  state):
266        TwiceCommand.__init__(self, state)
267        Command.__init__(self, _('Move item'))
268        self._parent = widget_container
269        self._section_name = widget_container.get_name()
270        self._table = widget_container.get_table()
271        self._move = widget
272        self._coords = coords
273        self._profilecore = profilecore
274        self._x, self._y = self._coords[widget]
275        self._name = widget.get_name()
276       
277       
278       
279    def _determine_child(self, list, num): 
280        result = None 
281        x, y = self._coords[self._move]
282        x = x + num
283        y = y + num
284        for i in list : 
285            x_tmp, y_tmp = self._coords[i]
286            if x_tmp == x and y_tmp == y  :
287                result= i
288                break 
289        return result
290    def _get_next(self):
291         
292        childs = self._table.get_children()
293        return self._determine_child(childs, 1)
294    def _get_prev(self): 
295       
296        childs = self._table.get_children()
297        childs.reverse()
298        return self._determine_child(childs,-1) 
299    def _swap(self, widget1, widget2):
300        x1, y1 = self._coords[widget1]
301        x2, y2 = self._coords[widget2]
302        list_vp = []
303        if widget1.is_voidplace():
304            widget1.unload_voidplace()
305            list_vp.append(widget1)
306           
307        if widget2.is_voidplace():
308            list_vp.append(widget2)
309            widget2.unload_voidplace()
310
311       
312        widget1.set_select(False)
313        widget2.set_select(False)
314        w_tmp = gtk.Label('tmp')
315        self._table.attach(w_tmp, 1,2, x1, y1)
316        self._table.remove(widget1)
317        self._table.attach(widget1, 0,2, x2, y2)
318        self._table.remove(widget2)
319        self._table.attach(widget2, 0,2, x1, y1)
320        self._table.remove(w_tmp)
321       
322        self._coords[widget1] = [x2, y2]
323        self._coords[widget2] = [x1,y1]
324        #self._move = widget2
325        for i in list_vp:
326            i.do_voidplace()
327            #i.do_resize_voidplace()
328           
329           
330    def _move_up(self):
331       
332        widget_swap = self._get_prev()
333        self._profilecore.move_option_up(self._section_name, 
334                                         self._name,
335                                         widget_swap.get_name())
336        self._swap(self._move, widget_swap)
337        #widget_swap.do_resize_voidplace()
338        self._parent.send_signal()
339        self._move.do_draw()
340        log.debug('<<< Moving item up')
341    _execute_1 = _move_up
342   
343    def _move_down(self):
344       
345        widget_swap = self._get_next()
346        self._profilecore.move_option_down(self._section_name, 
347                                           self._name, 
348                                           widget_swap.get_name())
349        self._swap( widget_swap, self._move)
350        #x, y = self._coords[widget_swap]
351        #self._move.set_select(False)
352        #widget_swap.set_select(False)
353
354        #w_tmp = gtk.Label('tmp')
355        #self._table.attach(w_tmp, 1,2, x, y)
356        #self._table.remove(widget_swap)
357        #self._table.attach(widget_swap, 0,2, self._x, self._x+1)
358        #self._table.remove(self._move)
359       
360        #self._table.attach(self._move, 0,2, x, y)
361        #self._table.remove(w_tmp)
362       
363        #self._coords[widget_swap] = [self._x, self._y]
364        #self._coords[self._move] = [x,y]
365        self._parent.send_signal()
366        self._move.do_draw()
367        log.debug('<<< Moving item down')
368       
369    _execute_2 = _move_down
370
371
372class CommandAddRemoveOption(TwiceCommand, Command):
373    '''
374    Add or Remove Option from BoxEditable
375    ###
376    trik : state is a inicial value if it is remove or add.
377    '''
378    def __init__(self, widget_container, widget_option, state):
379        TwiceCommand.__init__(self, state)
380        Command.__init__(self, _('Add/Remove Option'))
381        self._widget = widget_container
382        self._widget_option = widget_option
383       
384   
385    def _add_option(self):
386       
387        widget_option = self._widget_option
388        widget = self._widget
389        childs = widget.get_children()
390        widget.remove(childs[0])
391        widget.unload_voidplace()
392        for k in widget_option:
393            widget.pack_start(k)
394        #widget_option.show() # XXX - may be need
395       
396        log.debug('Adding option')
397    _execute_1 = _add_option
398    def _remove_option(self):
399       
400        widget = self._widget
401        childs = widget.get_children()
402        for i in childs:
403            widget.remove(i)
404        t = gtk.Label('-')
405        t.set_size_request(-1, 23)
406        t.show()
407       
408        widget.pack_start(t)
409        widget.do_voidplace()
410        log.debug('Removing option, Adding Void Place')
411    _execute_2 = _remove_option
412
413
414class BoxEditable(HIGVBox):
415    def __init__(self, section_name, profile, listoptions, notebook_parent):
416        """
417        A Box Editable contains a options of each tab
418        @param section_name: section name <tab>
419        @type section_name: str
420        @param profile: A class that view and modify xml file
421        @type profile: ProfileCore
422        """
423           
424        HIGVBox.__init__(self)
425        self._coords = {}
426        self._parent = notebook_parent
427        self._last = None 
428        #Profile Core do a manage at profile_editor.xml file
429        self._profilecore = None 
430       
431        self._profile = profile
432        self._listoptions = listoptions
433        self._table = HIGTable()
434        self._section_name = section_name
435        self._options = self._profile.get_section(section_name)
436        self._table.set_border_width(3)
437        c = self.get_colormap()
438        color = c.alloc_color(0,0,0)   
439        self._table.modify_fg(gtk.STATE_NORMAL,color )
440        self._fill_table()
441       
442        box_tmp = HIGVBox()
443        box_tmp.pack_start(self._table, False, False)
444        self._sw = HIGScrolledWindow()
445        #self._sw.set_size_request(400,200)
446        vp = gtk.Viewport()
447        vp.add(box_tmp)
448        vp.set_shadow_type(gtk.SHADOW_NONE)
449        self._sw.add(vp)
450        self.pack_start(self._sw, True, True)
451        self._old_selected = None 
452        self._x = 0
453        self._y = 0 
454       
455       
456        self.connect('button-press-event', self._bp)
457    #Private API
458    def _bp(self, widget,event):
459        pass
460           
461
462    def _fill_table(self):
463        k = 0
464        for i in self._options:
465            t = SpecialHBox()
466            type = i.get_type()
467            if type== 'option_check':
468               
469                name_option = i.get_option()
470                hint = self._listoptions.get_hint(name_option)
471                tmp_widget = OptionCheckIcon(i.get_label(),name_option,hint)
472                t.pack_start(tmp_widget)
473                arg_type = self._listoptions.get_arg_type(name_option)
474                if arg_type!= '':
475                    additional = type_mapping[arg_type]()
476                    t.pack_start(additional)
477               
478            elif type == 'option_list': 
479                eventbox = gtk.EventBox()
480                label = HIGEntryLabel(i.get_label())
481               
482                eventbox.add(label)
483                tmp_widget = OptionList()
484                for j in i.get_option_list():
485                    d = {}
486                    d['name'] = j
487                    tmp_widget.append(d)
488                t.pack_start(eventbox)         
489                t.pack_start(tmp_widget)
490                #t.drag_source_set(gtk.gdk.BUTTON1_MASK |
491                                                  #gtk.gdk.BUTTON3_MASK,
492                                                  #target,
493                                                  #gtk.gdk.ACTION_COPY |
494                                                  #gtk.gdk.ACTION_MOVE)
495                #t.connect('drag_data_get', self.source_drag_data_get)
496           
497            #XXX : I think that is very important ( I only comment to get focus)
498            t.set_flags( t.flags() |  gtk.CAN_FOCUS)
499            t.connect('button-press-event', self._button_press_event)
500            t.connect('key-press-event', self._key_press_event)
501            t.set_name(i.get_label())
502            t.connect('drag_data_received', self.drag_received)
503            t.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
504                                gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
505           
506            self._table.attach(t, 0,2, k,k+1)
507            self._coords[t] = [k, k+1]
508            self._x = k
509            self._y = k+1
510            k =k +1
511            self._last = t
512       
513   
514       
515    def _key_press_event(self, widget, event):
516        print "key pressed"
517        _keyval = gtk.gdk.keyval_name(event.keyval)
518        if _keyval == "Delete" and self._old_selected!=None :
519            if not widget.is_voidplace(): 
520                # remove widgets like checkbuttons or others and put voidplace
521                childs = widget.get_children()
522                cmd = CommandAddRemoveOption(widget,childs, False)
523                widget.set_select(False)
524                command_manager.add_command(cmd)
525                log.debug(' Remove Widgets like CheckButtons or others and put voidplace')
526               
527            else:
528                # remove voidplace and delete the widget from table/box
529                #XXX
530                cmd = CommandAddRemoveVoidplace(self, 
531                                                widget, self._coords, False)
532                #widget.unload_voidplace()
533                command_manager.add_command(cmd)
534                log.debug('Remove voidplace and delete the widget from table')
535               
536        #self._table.remove(widget)
537        #childs = self._table.get_children()
538        #for i in childs:
539            #if i.is_voidplace():
540                #i.do_resize_voidplace()
541    def _button_press_event(self,widget, event):
542        widget.set_select(True) 
543        self._parent.select(False)
544        if widget == self._old_selected :
545            log.debug('Do nothing')
546            if widget.is_voidplace():
547                widget.do_draw()
548            widget.grab_focus()
549            return 
550        widget.do_draw()
551        if self._old_selected != None:
552            self._old_selected.set_select(False)
553        log.debug('drawing')
554        self._old_selected = widget
555        widget.grab_focus()
556        self._parent.emit('changed', 'Options', self._parent.get_current_page())
557
558    #Public API
559    def get_name(self):
560        return self._section_name
561   
562    def can_move_up(self):
563       
564        widget = self._old_selected
565        x = 0 
566        if widget!= None :
567            x,y = self._coords[widget]
568        return x != 0
569    def can_move_down(self):
570       
571        widget = self._old_selected
572        y = len(self._coords)
573        if widget!= None :
574            x,y = self._coords[widget]
575        return y != (len(self._coords))
576    def send_signal(self):
577        self._parent.emit('changed', 'Options', self._parent.get_current_page())
578    def add_voidplace(self, position):
579        # Create SpecialHBox with Voidplace
580        t = SpecialHBox()
581        e = gtk.EventBox()
582        label = gtk.Label('-')
583        label.set_size_request(-1, 23)
584        e.add(label)
585        t.pack_start(e)
586        t.set_flags( t.flags() |  gtk.CAN_FOCUS)
587        t.connect('button-press-event', self._button_press_event)
588        t.connect('key-press-event', self._key_press_event)
589        t.connect('drag_data_received', self.drag_received)
590        t.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
591                            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
592        cmd = CommandVoidPlaceAttach(self, t, self._coords, True)
593        command_manager.add_command(cmd)
594       
595        #if position == -1 :
596            #x, y = self._x,self._y
597            #self._table.attach()
598        #else:
599            ## Choose the position
600            #pass
601   
602    def move_item_down(self):
603        '''
604        Move selected item to down
605        '''
606        assert self.can_move_down()
607       
608        cmd = CommandMove(self, self._old_selected, self._coords, self._profilecore, False)
609        command_manager.add_command(cmd)
610        self.send_signal()
611    def move_item_up(self):
612        '''
613        Move selected item to up
614        '''
615        assert self.can_move_up()
616       
617        cmd = CommandMove(self, self._old_selected, self._coords, self._profilecore, True)
618        command_manager.add_command(cmd)
619        self.send_signal()
620   
621   
622    def set_profile_core(self, profile_core):
623        self._profilecore = profile_core
624   
625    def option_builder(self, option_name, type):
626        '''
627        construct a widget with the name of the option
628        @return: A widget
629        @rtype: Widget like OptionCheck or others
630        '''
631        result = []
632        hint = self._listoptions.get_hint(option_name)
633        #label, option_name, hint
634        tmp_widget = OptionCheckIcon(option_name,option_name,hint) 
635        result.append(tmp_widget)
636        arg_type = self._listoptions.get_arg_type(option_name)
637        if arg_type!= '':
638            additional = type_mapping[arg_type]()
639            result.append(additional)
640        return result
641       
642       
643       
644       
645    def _is_widget(self, name):
646        return name[0:3] == '_wid'
647
648    def drag_received(self,w, context, x, y, data, info, time):
649        print "drag received"
650        option_name = data.data
651        if self._is_widget(option_name) or not  w.is_voidplace():
652            return
653       
654        arg_type = self._listoptions.get_arg_type(data.data)
655        widgets = self.option_builder(option_name, arg_type)
656       
657        #Remove child
658        childs = w.get_children()
659        w.remove(childs[0])
660        #Add
661        for child in widgets:
662            #t = gtk.Label('fsck')
663            w.pack_start(child)
664            child.show_all()
665       
666        w.unload_voidplace()
667    def get_table(self):
668        return self._table
669    def set_last(self, last):
670        self._last = last
671    def get_last(self):
672        return self._last
673    def source_drag_data_get(self, btn, context, selection_data, info, time):
674        selection_data.set(selection_data.target, 8, "I'm Data!")   
675
676class NotebookEditable(HIGNotebook):
677    '''
678    Editable Notebook to Edit Profile Editor
679    '''
680    __gsignals__ = {
681        'changed':  (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, 
682                     (gobject.TYPE_STRING,object))
683    }
684    def __init__(self, listoption, profilecore):
685        self._listoption = listoption
686        HIGNotebook.__init__(self)
687        self.sections_widgets = {}
688        self.sections_widgets_list = []
689        self.connect('key-press-event', self.on_key_press)
690        self.connect_after('switch-page', self.on_switch_page)
691        self._old_select = None 
692        self._profilecore = profilecore
693       
694        self._page_in = 0
695
696    def save(self):
697        self._profilecore.write_file(profile_editor)
698    def reset(self):
699        pass
700   
701    def load_data(self):
702        self.profile = CommandProfile()
703        options_used = {}
704       
705        self.constructor = CommandConstructor(options_used)
706        self.options = ProfileCore(profile_editor) 
707        i = 0
708        for tab in self.options.groups:
709            self.create_tab(tab, self.options.section_names[tab], 
710                            self.options.tabs[tab], i)
711            i = i+1 
712    def create_tab(self, tab_name, section_name, tab, number):
713        box = BoxEditable(tab_name, self.options, self._listoption, self)
714        box.set_profile_core(self._profilecore)
715        label = NotebookLabel(tab_name)
716        #eventbox = gtk.EventBox()
717
718        #eventbox.add(label)
719        label.set_flags( label.flags() |  gtk.CAN_FOCUS) 
720        label.connect('key-press-event', self.on_key_press)
721        label.connect('button-press-event', self.on_button_press) 
722
723       
724        label.connect('drag_data_received', self.label_drag_data_received)
725        label.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
726                            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
727        #eventbox.show_all()
728        label.show_all()
729        self.sections_widgets[label] = number
730        self.sections_widgets_list.append(label)
731        self.append_page(box, label)
732        #self.set_tab_reorderable(label, True)
733   
734    def select(self, value):
735        if self._old_select!=None:
736            self._old_select.set_select(value)
737            self._old_select=None
738   
739    def on_button_press(self, widget, event):
740        log.debug('Button press on Notebook')
741        if self._old_select != None:
742            self._old_select.set_select(False)
743        widget.set_select(True)
744        self._old_select = widget
745       
746        self.set_current_page(self.sections_widgets[widget])
747        #XXX - this focus owns drag-n-drop received :(
748        #widget.grab_focus()
749        self._page_in = self.get_current_page()
750        log.debug('<<< Setting page %s'%self._page_in)
751        return True
752    def put_on_page(self):
753        log.debug('<<< Put on page %s'%self._page_in)
754        self.set_current_page(self._page_in)
755    def on_switch_page(self, widget, event, page):
756        self.grab_focus()
757        self.emit('changed','Sections', page)
758    def on_key_press(self, widget, event):
759        _keyval = gtk.gdk.keyval_name(event.keyval)
760        log.debug('Key press event on NotebookEditable')
761        if self._old_select==None:
762            return
763
764        if _keyval == "Delete" :
765            if self._old_select.is_voidplace():
766                self._old_select.unload_voidplace()
767                label_tmp =self.get_tab_label(self.get_nth_page(
768                    self.get_current_page()))
769                num = self.sections_widgets[label_tmp]
770                del self.sections_widgets[label_tmp]
771                for i in range(num, len(self.sections_widgets)):
772                    print i
773                    widget_tmp = self.sections_widgets_list[i+1]
774                    self.sections_widgets[widget_tmp] = self.sections_widgets[widget_tmp] - 1 
775               
776                self.sections_widgets_list.pop(num)
777                self.remove_page(self.get_current_page())
778               
779
780               
781            else: 
782                cmd = CommandAddRemoveLabel(self._old_select, 
783                                            self._old_select.get_text(), False)
784                command_manager.add_command(cmd)
785        #else:
786            #self._old_select.unload_voidplace()
787    def label_drag_data_received(self, w, context, x, y, data, info, time):
788        print "received"
789
790        if data and data.format == 8:
791            print 'Received "%s" in label' % data.data
792            context.finish(True, False, time)
793            cmd = CommandAddRemoveLabel(self._old_select, 'New Label', True)
794            command_manager.add_command(cmd)
795           
796        #else:
797        #    context.finish(False, False, time)
798       
799    def can_move_right(self):
800        n = self.get_n_pages()
801        current = self.get_current_page()
802        return (n-1) != (current)
803    def can_move_left(self):   
804        current = self.get_current_page()
805        return current!= 0
806    def move_right(self):
807        cmd = CommandMovePage(self, 1, self._profilecore, False)
808        command_manager.add_command(cmd)
809        self.emit('changed','Sections', None)
810    def move_left(self):
811        cmd = CommandMovePage(self, 1, self._profilecore, True)
812        command_manager.add_command(cmd)
813        self.emit('changed','Sections', None)
814           
815   
816   
817class ProfileEdit(gtk.HBox):
818   
819    def __init__(self, listoption):
820        gtk.HBox.__init__(self)
821        self._toolbar = ToolBarInterface()
822        self._proprieties = None 
823        self._notebook_tools = None 
824        #MAIN SCROLLED
825        self._scroolledmain = HIGScrolledWindow()
826        #NOTEBOOKEDITABLE :
827        self._profilecore = ProfileCore(profile_editor)
828        self.notebook = NotebookEditable(listoption, self._profilecore)
829        self._toolbar.set_notebook(self.notebook)
830        self.notebook.connect_after('changed', self.update_toolbar)
831        self.notebook.load_data()
832        self.pack_start(self._toolbar.get_toolbar(), False, True,0)
833        self.pack_start(self._scroolledmain, True, True)
834        self._scroolledmain.add_with_viewport(self.notebook)
835        self.show_all()
836    def get_profilecore(self):
837        return self._profilecore
838    def set_notebook(self, notebook):
839        self._notebook_tools = notebook
840    def set_proprieties(self, proprieties):
841        self._proprieties = proprieties
842        proprieties.disable_all()
843    def update_toolbar(self, action, others, page):
844        #print action
845        #print others
846        #print page
847        boxeditable = self.get_box_editable()
848        self._toolbar.set_box_editable(boxeditable)
849        self._toolbar.update_toolbar()
850       
851        #Update Proprieties box
852        if self._notebook_tools != None: 
853            self._notebook_tools.set_current_page(2)
854       
855        if boxeditable._old_selected!= None :
856            #SpecialHBox - Item
857            self._proprieties.set_boxeditable(boxeditable)
858            self._proprieties.set_item(boxeditable._old_selected)
859           
860            log.debug('<<< SpecialHBox Item update')
861        elif self.notebook._old_select!= None:
862            #Notebook_Label
863            self._proprieties.set_notebooklabel(self.notebook._old_select)
864            log.debug('<<< NotebookLabel update')
865   
866    def get_box_editable(self):
867        current_page = self.notebook.get_current_page()
868        current_box = self.notebook.get_nth_page(current_page)
869        return current_box
870   
871    def save(self):
872        self._profilecore.write_file(profile_editor)
873        log.debug('<<< Saving to file %s ' % profile_editor)
874   
875    def create_events(self):
876        #....
877        pass
878
879       
Note: See TracBrowser for help on using the browser.