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

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

Add section

RevLine 
[1071]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
[1047]20import gtk 
[1049]21
22import sys
[1050]23# Testing at devel
24from os.path import split, join
25
26from umitCore.Paths import Path
[1345]27#Path.set_umit_conf(join(split(__file__)[0], 'config', 'umit.conf'))
[1050]28#END DEV TEST
29options = Path.options
30profile_editor = Path.profile_editor
[1088]31#XXX This path is too wrong
[1338]32#sys.path.append("selectborder")
33from umitInterfaceEditor.selectborder.WrapperWidgets import NotebookLabel, SpecialHBox
[1340]34
[1049]35from higwidgets.higscrollers import HIGScrolledWindow
36from higwidgets.hignotebooks import HIGNotebook
[1050]37from higwidgets.higlabels import HIGSectionLabel, HIGEntryLabel
[1047]38
[1050]39from umitCore.NmapCommand import CommandConstructor
40from umitCore.UmitConf import Profile, CommandProfile
41from umitGUI.OptionBuilder import *
42from higwidgets.higboxes import HIGVBox
[1075]43from umitCore.Logging import log
44from umitCore.I18N import _
[1113]45from higwidgets.higtables import HIGTable
[1207]46import gobject
[1048]47
[1330]48
49
[1076]50TARGET_STRING = 0
51TARGET_ROOTWIN = 1
[1049]52
[1076]53target = [
54    ('STRING', 0, TARGET_STRING),
55    ('text/plain', 0, TARGET_STRING),
56    ('application/x-rootwin-drop', 0, TARGET_ROOTWIN)
57]
[1058]58
[1330]59#Global variables
60SPACE_TABLE = 6
[1113]61
[1162]62
[1330]63
[1162]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
[1113]76from ProfileCore import ProfileCore, ProfileOption
[1075]77from Command import Command, TwiceCommand, command_manager
[1207]78from Tools import ToolBarInterface
[1058]79
[1264]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'''
[1210]85
[1264]86
[1075]87class CommandAddRemoveLabel(TwiceCommand, Command):
88    '''
89    Add or Remove Label from Title pages of NotebookEditable
[1088]90    ###
91    trik : state is a inicial value if it is remove or add.
[1075]92    '''
93    def __init__(self, widget, text, state):
[1092]94        TwiceCommand.__init__(self, state)
[1075]95        Command.__init__(self, _('Add Label'))
96        self._widget = widget
[1076]97        self._text = text
[1088]98       
[1076]99   
[1075]100    def _add_label(self):
101        self._widget.unload_voidplace()
[1088]102        self._widget.set_text(self._text) 
103        log.debug('Adding label')
[1076]104    _execute_1 = _add_label
[1075]105    def _remove_label(self):
[1089]106        self._widget.voidplace()
[1088]107        log.debug('Removing label, Adding Void Place')
[1076]108    _execute_2 = _remove_label
[1058]109
[1301]110
[1181]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'))
[1322]119        self._table = table.get_table()
120       
[1181]121        self._widget = widget
122        self._x,self._y = coords[widget] 
[1330]123        #self._spacing = self._table.get_row_spacing(self._x)
124        self._spacing = SPACE_TABLE
[1181]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)
[1207]132        self._table.set_row_spacing(self._x,self._spacing)
[1181]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()
[1207]146            self._table.set_row_spacing(self._x,0)
[1181]147           
148            #self._widget.unload_voidplace()
149            #self._table.remove(self._widget)
150           
151    _execute_2 = _remove
152   
[1330]153
154
[1322]155class CommandVoidPlaceAttach(TwiceCommand, Command):
156    '''
157    Add a new widget (voidplace) at the last position
158   
159    '''
[1301]160    def __init__(self,table, widget, coords, state):
[1322]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] 
[1330]171        self._coords = coords
172        #self._spacing = self._table.get_row_spacing(x-1)
173        self._spacing = SPACE_TABLE
[1301]174    def _attach(self):
[1322]175        self._table.resize(self._y, 2)
[1330]176        log.debug('<<< Attach Add Voidplace')
[1322]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
[1301]187    def _unattach(self):
[1330]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]
[1322]197    _execute_2 = _unattach
[1181]198
[1301]199
[1241]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   
[1264]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
[1241]240    def _move_left(self):
[1353]241        log.debug("move left")
[1264]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       
[1241]248    _execute_1 = _move_left
249    def _move_right(self):
[1353]250        log.debug("move right")
[1264]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)
[1241]255    _execute_2 = _move_right
[1181]256
[1241]257
258
[1210]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    '''
[1230]265    def __init__(self, widget_container, widget, coords , profilecore,  state):
[1210]266        TwiceCommand.__init__(self, state)
267        Command.__init__(self, _('Move item'))
[1213]268        self._parent = widget_container
[1230]269        self._section_name = widget_container.get_name()
[1213]270        self._table = widget_container.get_table()
[1210]271        self._move = widget
272        self._coords = coords
[1230]273        self._profilecore = profilecore
[1210]274        self._x, self._y = self._coords[widget]
[1230]275        self._name = widget.get_name()
276       
277       
278       
[1213]279    def _determine_child(self, list, num): 
[1210]280        result = None 
[1213]281        x, y = self._coords[self._move]
282        x = x + num
283        y = y + num
[1210]284        for i in list : 
[1213]285            x_tmp, y_tmp = self._coords[i]
286            if x_tmp == x and y_tmp == y  :
287                result= i
[1210]288                break 
289        return result
[1230]290    def _get_next(self):
[1210]291         
292        childs = self._table.get_children()
[1213]293        return self._determine_child(childs, 1)
[1210]294    def _get_prev(self): 
295       
296        childs = self._table.get_children()
297        childs.reverse()
[1213]298        return self._determine_child(childs,-1) 
[1210]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)
[1207]314        w_tmp = gtk.Label('tmp')
[1210]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)
[1207]320        self._table.remove(w_tmp)
321       
[1210]322        self._coords[widget1] = [x2, y2]
323        self._coords[widget2] = [x1,y1]
[1213]324        #self._move = widget2
[1210]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()
[1230]333        self._profilecore.move_option_up(self._section_name, 
334                                         self._name,
335                                         widget_swap.get_name())
[1210]336        self._swap(self._move, widget_swap)
[1216]337        #widget_swap.do_resize_voidplace()
[1213]338        self._parent.send_signal()
[1333]339        self._move.do_draw()
[1210]340        log.debug('<<< Moving item up')
[1207]341    _execute_1 = _move_up
342   
343    def _move_down(self):
[1230]344       
345        widget_swap = self._get_next()
346        self._profilecore.move_option_down(self._section_name, 
347                                           self._name, 
348                                           widget_swap.get_name())
[1213]349        self._swap( widget_swap, self._move)
[1210]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]
[1213]365        self._parent.send_signal()
[1333]366        self._move.do_draw()
[1207]367        log.debug('<<< Moving item down')
368       
369    _execute_2 = _move_down
370
371
[1139]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    '''
[1156]378    def __init__(self, widget_container, widget_option, state):
[1139]379        TwiceCommand.__init__(self, state)
[1156]380        Command.__init__(self, _('Add/Remove Option'))
381        self._widget = widget_container
382        self._widget_option = widget_option
[1139]383       
384   
[1156]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('-')
[1241]405        t.set_size_request(-1, 23)
[1156]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
[1071]412
413
[1075]414class BoxEditable(HIGVBox):
[1210]415    def __init__(self, section_name, profile, listoptions, notebook_parent):
[1271]416        """
[1113]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
[1271]422        """
423           
[1113]424        HIGVBox.__init__(self)
[1181]425        self._coords = {}
[1210]426        self._parent = notebook_parent
[1322]427        self._last = None 
[1166]428        #Profile Core do a manage at profile_editor.xml file
429        self._profilecore = None 
[1322]430       
[1113]431        self._profile = profile
[1166]432        self._listoptions = listoptions
[1113]433        self._table = HIGTable()
[1230]434        self._section_name = section_name
[1113]435        self._options = self._profile.get_section(section_name)
[1156]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 )
[1113]440        self._fill_table()
[1116]441       
[1113]442        box_tmp = HIGVBox()
443        box_tmp.pack_start(self._table, False, False)
444        self._sw = HIGScrolledWindow()
[1116]445        #self._sw.set_size_request(400,200)
[1113]446        vp = gtk.Viewport()
447        vp.add(box_tmp)
448        vp.set_shadow_type(gtk.SHADOW_NONE)
449        self._sw.add(vp)
[1116]450        self.pack_start(self._sw, True, True)
451        self._old_selected = None 
[1139]452        self._x = 0
453        self._y = 0 
[1181]454       
[1322]455       
[1241]456        self.connect('button-press-event', self._bp)
[1114]457    #Private API
[1241]458    def _bp(self, widget,event):
[1301]459        pass
460           
461
[1114]462    def _fill_table(self):
[1113]463        k = 0
464        for i in self._options:
465            t = SpecialHBox()
[1115]466            type = i.get_type()
467            if type== 'option_check':
[1230]468               
[1167]469                name_option = i.get_option()
470                hint = self._listoptions.get_hint(name_option)
471                tmp_widget = OptionCheckIcon(i.get_label(),name_option,hint)
[1115]472                t.pack_start(tmp_widget)
[1181]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)
[1162]477               
[1115]478            elif type == 'option_list': 
479                eventbox = gtk.EventBox()
480                label = HIGEntryLabel(i.get_label())
[1230]481               
[1115]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)
[1116]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)
[1333]496           
497            #XXX : I think that is very important ( I only comment to get focus)
[1118]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)
[1230]501            t.set_name(i.get_label())
[1139]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           
[1113]506            self._table.attach(t, 0,2, k,k+1)
[1181]507            self._coords[t] = [k, k+1]
[1139]508            self._x = k
509            self._y = k+1
[1113]510            k =k +1
[1322]511            self._last = t
[1139]512       
[1322]513   
[1118]514       
515    def _key_press_event(self, widget, event):
516        print "key pressed"
[1139]517        _keyval = gtk.gdk.keyval_name(event.keyval)
[1230]518        if _keyval == "Delete" and self._old_selected!=None :
[1181]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)
[1198]523                widget.set_select(False)
[1181]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
[1322]530                cmd = CommandAddRemoveVoidplace(self, 
[1181]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               
[1139]536        #self._table.remove(widget)
[1207]537        #childs = self._table.get_children()
538        #for i in childs:
539            #if i.is_voidplace():
540                #i.do_resize_voidplace()
[1114]541    def _button_press_event(self,widget, event):
[1207]542        widget.set_select(True) 
[1230]543        self._parent.select(False)
[1116]544        if widget == self._old_selected :
[1181]545            log.debug('Do nothing')
[1198]546            if widget.is_voidplace():
547                widget.do_draw()
[1181]548            widget.grab_focus()
[1116]549            return 
[1114]550        widget.do_draw()
[1116]551        if self._old_selected != None:
552            self._old_selected.set_select(False)
[1114]553        log.debug('drawing')
[1116]554        self._old_selected = widget
[1118]555        widget.grab_focus()
[1210]556        self._parent.emit('changed', 'Options', self._parent.get_current_page())
[1207]557
[1166]558    #Public API
[1230]559    def get_name(self):
560        return self._section_name
[1207]561   
562    def can_move_up(self):
[1210]563       
564        widget = self._old_selected
565        x = 0 
566        if widget!= None :
567            x,y = self._coords[widget]
568        return x != 0
[1213]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())
[1301]578    def add_voidplace(self, position):
579        # Create SpecialHBox with Voidplace
580        t = SpecialHBox()
[1322]581        e = gtk.EventBox()
[1301]582        label = gtk.Label('-')
[1322]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)
[1301]593        command_manager.add_command(cmd)
[1213]594       
[1322]595        #if position == -1 :
596            #x, y = self._x,self._y
597            #self._table.attach()
598        #else:
599            ## Choose the position
600            #pass
[1301]601   
[1213]602    def move_item_down(self):
603        '''
604        Move selected item to down
605        '''
606        assert self.can_move_down()
607       
[1230]608        cmd = CommandMove(self, self._old_selected, self._coords, self._profilecore, False)
[1213]609        command_manager.add_command(cmd)
610        self.send_signal()
[1207]611    def move_item_up(self):
612        '''
[1213]613        Move selected item to up
[1207]614        '''
615        assert self.can_move_up()
[1213]616       
[1230]617        cmd = CommandMove(self, self._old_selected, self._coords, self._profilecore, True)
[1207]618        command_manager.add_command(cmd)
[1213]619        self.send_signal()
[1207]620   
621   
[1166]622    def set_profile_core(self, profile_core):
623        self._profilecore = profile_core
[1113]624   
[1166]625    def option_builder(self, option_name, type):
626        '''
627        construct a widget with the name of the option
[1199]628        @return: A widget
629        @rtype: Widget like OptionCheck or others
[1166]630        '''
[1199]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
[1166]641       
[1199]642       
643       
644       
645    def _is_widget(self, name):
646        return name[0:3] == '_wid'
[1075]647
[1166]648    def drag_received(self,w, context, x, y, data, info, time):
649        print "drag received"
[1199]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
[1166]658        childs = w.get_children()
659        w.remove(childs[0])
[1199]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()
[1213]667    def get_table(self):
668        return self._table
[1322]669    def set_last(self, last):
670        self._last = last
671    def get_last(self):
672        return self._last
[1166]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
[1049]676class NotebookEditable(HIGNotebook):
677    '''
678    Editable Notebook to Edit Profile Editor
679    '''
[1207]680    __gsignals__ = {
681        'changed':  (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, 
682                     (gobject.TYPE_STRING,object))
683    }
[1230]684    def __init__(self, listoption, profilecore):
[1166]685        self._listoption = listoption
[1049]686        HIGNotebook.__init__(self)
[1050]687        self.sections_widgets = {}
[1241]688        self.sections_widgets_list = []
[1156]689        self.connect('key-press-event', self.on_key_press)
[1264]690        self.connect_after('switch-page', self.on_switch_page)
[1052]691        self._old_select = None 
[1230]692        self._profilecore = profilecore
[1357]693       
694        self._page_in = 0
[1050]695
[1166]696    def save(self):
697        self._profilecore.write_file(profile_editor)
[1050]698    def reset(self):
699        pass
700   
701    def load_data(self):
702        self.profile = CommandProfile()
703        options_used = {}
[1049]704       
[1050]705        self.constructor = CommandConstructor(options_used)
[1113]706        self.options = ProfileCore(profile_editor) 
[1050]707        i = 0
708        for tab in self.options.groups:
[1092]709            self.create_tab(tab, self.options.section_names[tab], 
710                            self.options.tabs[tab], i)
[1050]711            i = i+1 
712    def create_tab(self, tab_name, section_name, tab, number):
[1210]713        box = BoxEditable(tab_name, self.options, self._listoption, self)
[1230]714        box.set_profile_core(self._profilecore)
[1052]715        label = NotebookLabel(tab_name)
716        #eventbox = gtk.EventBox()
[1049]717
[1052]718        #eventbox.add(label)
[1139]719        label.set_flags( label.flags() |  gtk.CAN_FOCUS) 
[1230]720        label.connect('key-press-event', self.on_key_press)
[1058]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)
[1052]727        #eventbox.show_all()
728        label.show_all()
729        self.sections_widgets[label] = number
[1241]730        self.sections_widgets_list.append(label)
[1052]731        self.append_page(box, label)
[1264]732        #self.set_tab_reorderable(label, True)
[1207]733   
[1230]734    def select(self, value):
735        if self._old_select!=None:
736            self._old_select.set_select(value)
[1241]737            self._old_select=None
[1230]738   
[1050]739    def on_button_press(self, widget, event):
[1230]740        log.debug('Button press on Notebook')
[1052]741        if self._old_select != None:
742            self._old_select.set_select(False)
743        widget.set_select(True)
744        self._old_select = widget
[1241]745       
[1050]746        self.set_current_page(self.sections_widgets[widget])
[1139]747        #XXX - this focus owns drag-n-drop received :(
[1207]748        #widget.grab_focus()
[1357]749        self._page_in = self.get_current_page()
750        log.debug('<<< Setting page %s'%self._page_in)
[1050]751        return True
[1357]752    def put_on_page(self):
753        log.debug('<<< Put on page %s'%self._page_in)
754        self.set_current_page(self._page_in)
[1207]755    def on_switch_page(self, widget, event, page):
[1264]756        self.grab_focus()
[1207]757        self.emit('changed','Sections', page)
[1050]758    def on_key_press(self, widget, event):
759        _keyval = gtk.gdk.keyval_name(event.keyval)
[1181]760        log.debug('Key press event on NotebookEditable')
761        if self._old_select==None:
762            return
763
764        if _keyval == "Delete" :
[1058]765            if self._old_select.is_voidplace():
[1089]766                self._old_select.unload_voidplace()
[1241]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)
[1058]777                self.remove_page(self.get_current_page())
[1241]778               
779
780               
[1058]781            else: 
[1092]782                cmd = CommandAddRemoveLabel(self._old_select, 
783                                            self._old_select.get_text(), False)
784                command_manager.add_command(cmd)
[1333]785        #else:
786            #self._old_select.unload_voidplace()
[1058]787    def label_drag_data_received(self, w, context, x, y, data, info, time):
788        print "received"
789
[1075]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)
[1088]794            command_manager.add_command(cmd)
[1075]795           
796        #else:
797        #    context.finish(False, False, time)
[1264]798       
799    def can_move_right(self):
800        n = self.get_n_pages()
801        current = self.get_current_page()
802        return (n-1) != (current)
[1266]803    def can_move_left(self):   
[1264]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)
[1333]809        self.emit('changed','Sections', None)
[1264]810    def move_left(self):
811        cmd = CommandMovePage(self, 1, self._profilecore, True)
812        command_manager.add_command(cmd)
[1333]813        self.emit('changed','Sections', None)
[1264]814           
815   
816   
[1207]817class ProfileEdit(gtk.HBox):
818   
[1166]819    def __init__(self, listoption):
[1207]820        gtk.HBox.__init__(self)
821        self._toolbar = ToolBarInterface()
[1271]822        self._proprieties = None 
823        self._notebook_tools = None 
[1049]824        #MAIN SCROLLED
[1050]825        self._scroolledmain = HIGScrolledWindow()
[1049]826        #NOTEBOOKEDITABLE :
[1230]827        self._profilecore = ProfileCore(profile_editor)
828        self.notebook = NotebookEditable(listoption, self._profilecore)
[1264]829        self._toolbar.set_notebook(self.notebook)
[1333]830        self.notebook.connect_after('changed', self.update_toolbar)
[1050]831        self.notebook.load_data()
[1353]832        self.pack_start(self._toolbar.get_toolbar(), False, True,0)
[1050]833        self.pack_start(self._scroolledmain, True, True)
834        self._scroolledmain.add_with_viewport(self.notebook)
835        self.show_all()
[1301]836    def get_profilecore(self):
837        return self._profilecore
[1271]838    def set_notebook(self, notebook):
839        self._notebook_tools = notebook
840    def set_proprieties(self, proprieties):
841        self._proprieties = proprieties
[1333]842        proprieties.disable_all()
[1207]843    def update_toolbar(self, action, others, page):
[1210]844        #print action
845        #print others
846        #print page
847        boxeditable = self.get_box_editable()
848        self._toolbar.set_box_editable(boxeditable)
[1213]849        self._toolbar.update_toolbar()
[1267]850       
851        #Update Proprieties box
[1271]852        if self._notebook_tools != None: 
853            self._notebook_tools.set_current_page(2)
[1267]854       
[1271]855        if boxeditable._old_selected!= None :
856            #SpecialHBox - Item
[1330]857            self._proprieties.set_boxeditable(boxeditable)
[1271]858            self._proprieties.set_item(boxeditable._old_selected)
[1330]859           
[1301]860            log.debug('<<< SpecialHBox Item update')
[1271]861        elif self.notebook._old_select!= None:
862            #Notebook_Label
863            self._proprieties.set_notebooklabel(self.notebook._old_select)
[1301]864            log.debug('<<< NotebookLabel update')
[1207]865   
[1210]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   
[1166]871    def save(self):
[1271]872        self._profilecore.write_file(profile_editor)
873        log.debug('<<< Saving to file %s ' % profile_editor)
[1166]874   
[1048]875    def create_events(self):
876        #....
[1049]877        pass
878
[1047]879       
Note: See TracBrowser for help on using the browser.