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

Revision 1118, 8.2 kB (checked in by kop-labs, 6 years ago)

Delete event at options added (lack do a subclass of Command

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
27Path.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
32sys.path.append("selectborder")
33from WidgetsPlace import EditArea
34from WrapperWidgets import NotebookLabel, SpecialHBox
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
46
47
48TARGET_STRING = 0
49TARGET_ROOTWIN = 1
50
51target = [
52    ('STRING', 0, TARGET_STRING),
53    ('text/plain', 0, TARGET_STRING),
54    ('application/x-rootwin-drop', 0, TARGET_ROOTWIN)
55]
56
57
58from ProfileCore import ProfileCore, ProfileOption
59from Command import Command, TwiceCommand, command_manager
60
61class CommandAddRemoveLabel(TwiceCommand, Command):
62    '''
63    Add or Remove Label from Title pages of NotebookEditable
64    ###
65    trik : state is a inicial value if it is remove or add.
66    '''
67    def __init__(self, widget, text, state):
68        TwiceCommand.__init__(self, state)
69        Command.__init__(self, _('Add Label'))
70        self._widget = widget
71        self._text = text
72       
73   
74    def _add_label(self):
75        self._widget.unload_voidplace()
76        self._widget.set_text(self._text) 
77        log.debug('Adding label')
78    _execute_1 = _add_label
79    def _remove_label(self):
80        self._widget.voidplace()
81        log.debug('Removing label, Adding Void Place')
82    _execute_2 = _remove_label
83
84
85
86class BoxEditable(HIGVBox):
87    def __init__(self, section_name, profile):
88        '''
89        A Box Editable contains a options of each tab
90        @param section_name: section name <tab>
91        @type section_name: str
92        @param profile: A class that view and modify xml file
93        @type profile: ProfileCore
94        '''
95        HIGVBox.__init__(self)
96
97        self._profile = profile
98        self._table = HIGTable()
99        self._options = self._profile.get_section(section_name)
100        self._fill_table()
101       
102        box_tmp = HIGVBox()
103        box_tmp.pack_start(self._table, False, False)
104        self._sw = HIGScrolledWindow()
105        #self._sw.set_size_request(400,200)
106        vp = gtk.Viewport()
107        vp.add(box_tmp)
108        vp.set_shadow_type(gtk.SHADOW_NONE)
109        self._sw.add(vp)
110        self.pack_start(self._sw, True, True)
111        self._old_selected = None 
112    #Private API
113    def _fill_table(self):
114
115        k = 0
116        for i in self._options:
117            t = SpecialHBox()
118            type = i.get_type()
119            if type== 'option_check':
120                tmp_widget = OptionCheckIcon(i.get_label(),i.get_option(),'asddas')
121                t.pack_start(tmp_widget)
122            elif type == 'option_list': 
123                eventbox = gtk.EventBox()
124                label = HIGEntryLabel(i.get_label())
125                eventbox.add(label)
126                tmp_widget = OptionList()
127                for j in i.get_option_list():
128                    d = {}
129                    d['name'] = j
130                    tmp_widget.append(d)
131                t.pack_start(eventbox)         
132                t.pack_start(tmp_widget)
133                #t.drag_source_set(gtk.gdk.BUTTON1_MASK |
134                                                  #gtk.gdk.BUTTON3_MASK,
135                                                  #target,
136                                                  #gtk.gdk.ACTION_COPY |
137                                                  #gtk.gdk.ACTION_MOVE)
138                #t.connect('drag_data_get', self.source_drag_data_get)
139            t.set_flags( t.flags() |  gtk.CAN_FOCUS)
140            t.connect('button-press-event', self._button_press_event)
141            t.connect('key-press-event', self._key_press_event)
142               
143               
144            self._table.attach(t, 0,2, k,k+1)
145            k =k +1
146    def source_drag_data_get(self, btn, context, selection_data, info, time):
147        selection_data.set(selection_data.target, 8, "I'm Data!")
148       
149    def _key_press_event(self, widget, event):
150        print "key pressed"
151        widget.do_voidplace()
152
153    def _button_press_event(self,widget, event):
154        widget.set_select(True)
155        if widget == self._old_selected :
156            return 
157        widget.do_draw()
158        if self._old_selected != None:
159            self._old_selected.set_select(False)
160        log.debug('drawing')
161        self._old_selected = widget
162        widget.grab_focus()
163       
164   
165
166class NotebookEditable(HIGNotebook):
167    '''
168    Editable Notebook to Edit Profile Editor
169    '''
170    def __init__(self):
171        HIGNotebook.__init__(self)
172        self.sections_widgets = {}
173        #self.connect('key-press-event', self.on_key_press)
174        self._old_select = None 
175
176   
177    def reset(self):
178        pass
179   
180    def load_data(self):
181        self.profile = CommandProfile()
182        options_used = {}
183       
184        self.constructor = CommandConstructor(options_used)
185        self.options = ProfileCore(profile_editor) 
186        i = 0
187        for tab in self.options.groups:
188            self.create_tab(tab, self.options.section_names[tab], 
189                            self.options.tabs[tab], i)
190            i = i+1 
191    def create_tab(self, tab_name, section_name, tab, number):
192       
193        box = BoxEditable(tab_name, self.options)
194        label = NotebookLabel(tab_name)
195        #eventbox = gtk.EventBox()
196
197        #eventbox.add(label)
198        label.set_flags( label.flags() |  gtk.CAN_FOCUS)
199        label.connect('key-press-event', self.on_key_press)
200        label.connect('button-press-event', self.on_button_press) 
201
202       
203        label.connect('drag_data_received', self.label_drag_data_received)
204        label.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
205                            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
206        #eventbox.show_all()
207        label.show_all()
208        self.sections_widgets[label] = number
209        self.append_page(box, label)
210    def on_button_press(self, widget, event):
211        if self._old_select != None:
212            self._old_select.set_select(False)
213        widget.set_select(True)
214        self._old_select = widget
215        self.set_current_page(self.sections_widgets[widget])
216        widget.grab_focus()
217        return True
218    def on_key_press(self, widget, event):
219        _keyval = gtk.gdk.keyval_name(event.keyval)
220        print _keyval
221        if _keyval == "Delete":
222            if self._old_select.is_voidplace():
223                self._old_select.unload_voidplace()
224                self.remove_page(self.get_current_page())
225            else: 
226                cmd = CommandAddRemoveLabel(self._old_select, 
227                                            self._old_select.get_text(), False)
228                command_manager.add_command(cmd)
229
230        else: 
231            self._old_select.unload_voidplace()
232    def label_drag_data_received(self, w, context, x, y, data, info, time):
233        print "received"
234
235        if data and data.format == 8:
236            print 'Received "%s" in label' % data.data
237            context.finish(True, False, time)
238            cmd = CommandAddRemoveLabel(self._old_select, 'New Label', True)
239            command_manager.add_command(cmd)
240           
241           
242        #else:
243        #    context.finish(False, False, time)
244
245
246class ProfileEdit(gtk.VBox):
247    def __init__(self):
248        gtk.VBox.__init__(self)
249
250       
251        #MAIN SCROLLED
252        self._scroolledmain = HIGScrolledWindow()
253        #NOTEBOOKEDITABLE :
254        self.notebook = NotebookEditable()
255        self.notebook.load_data()
256        self.pack_start(self._scroolledmain, True, True)
257        self._scroolledmain.add_with_viewport(self.notebook)
258        self.show_all()
259        self._edit_area = EditArea()
260       
261       
262    def create_events(self):
263        #....
264        pass
265
266       
Note: See TracBrowser for help on using the browser.