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

Revision 1116, 8.1 kB (checked in by kop-labs, 6 years ago)

Select each item - only one

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                t.connect('button-press-event', self._button_press_event)
123            elif type == 'option_list': 
124                eventbox = gtk.EventBox()
125                label = HIGEntryLabel(i.get_label())
126                eventbox.add(label)
127                tmp_widget = OptionList()
128                for j in i.get_option_list():
129                    d = {}
130                    d['name'] = j
131                    tmp_widget.append(d)
132                t.pack_start(eventbox)         
133                t.pack_start(tmp_widget)
134                #t.drag_source_set(gtk.gdk.BUTTON1_MASK |
135                                                  #gtk.gdk.BUTTON3_MASK,
136                                                  #target,
137                                                  #gtk.gdk.ACTION_COPY |
138                                                  #gtk.gdk.ACTION_MOVE)
139                #t.connect('drag_data_get', self.source_drag_data_get)
140                t.connect('button-press-event', self._button_press_event)
141               
142               
143            self._table.attach(t, 0,2, k,k+1)
144            k =k +1
145    def source_drag_data_get(self, btn, context, selection_data, info, time):
146        selection_data.set(selection_data.target, 8, "I'm Data!")
147
148
149    def _button_press_event(self,widget, event):
150        widget.set_select(True)
151        if widget == self._old_selected :
152            return 
153        widget.do_draw()
154        if self._old_selected != None:
155            self._old_selected.set_select(False)
156        log.debug('drawing')
157        self._old_selected = widget
158       
159   
160
161class NotebookEditable(HIGNotebook):
162    '''
163    Editable Notebook to Edit Profile Editor
164    '''
165    def __init__(self):
166        HIGNotebook.__init__(self)
167        self.sections_widgets = {}
168        #self.connect('key-press-event', self.on_key_press)
169        self._old_select = None 
170
171   
172    def reset(self):
173        pass
174   
175    def load_data(self):
176        self.profile = CommandProfile()
177        options_used = {}
178       
179        self.constructor = CommandConstructor(options_used)
180        self.options = ProfileCore(profile_editor) 
181        i = 0
182        for tab in self.options.groups:
183            self.create_tab(tab, self.options.section_names[tab], 
184                            self.options.tabs[tab], i)
185            i = i+1 
186    def create_tab(self, tab_name, section_name, tab, number):
187       
188        box = BoxEditable(tab_name, self.options)
189        label = NotebookLabel(tab_name)
190        #eventbox = gtk.EventBox()
191
192        #eventbox.add(label)
193        label.set_flags( label.flags() |  gtk.CAN_FOCUS)
194        label.connect('key-press-event', self.on_key_press)
195        label.connect('button-press-event', self.on_button_press) 
196
197       
198        label.connect('drag_data_received', self.label_drag_data_received)
199        label.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
200                            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
201        #eventbox.show_all()
202        label.show_all()
203        self.sections_widgets[label] = number
204        self.append_page(box, label)
205    def on_button_press(self, widget, event):
206        if self._old_select != None:
207            self._old_select.set_select(False)
208        widget.set_select(True)
209        self._old_select = widget
210        self.set_current_page(self.sections_widgets[widget])
211        widget.grab_focus()
212        return True
213    def on_key_press(self, widget, event):
214        _keyval = gtk.gdk.keyval_name(event.keyval)
215        print _keyval
216        if _keyval == "Delete":
217            if self._old_select.is_voidplace():
218                self._old_select.unload_voidplace()
219                self.remove_page(self.get_current_page())
220            else: 
221                cmd = CommandAddRemoveLabel(self._old_select, 
222                                            self._old_select.get_text(), False)
223                command_manager.add_command(cmd)
224
225        else: 
226            self._old_select.unload_voidplace()
227    def label_drag_data_received(self, w, context, x, y, data, info, time):
228        print "received"
229
230        if data and data.format == 8:
231            print 'Received "%s" in label' % data.data
232            context.finish(True, False, time)
233            cmd = CommandAddRemoveLabel(self._old_select, 'New Label', True)
234            command_manager.add_command(cmd)
235           
236           
237        #else:
238        #    context.finish(False, False, time)
239
240
241class ProfileEdit(gtk.VBox):
242    def __init__(self):
243        gtk.VBox.__init__(self)
244
245       
246        #MAIN SCROLLED
247        self._scroolledmain = HIGScrolledWindow()
248        #NOTEBOOKEDITABLE :
249        self.notebook = NotebookEditable()
250        self.notebook.load_data()
251        self.pack_start(self._scroolledmain, True, True)
252        self._scroolledmain.add_with_viewport(self.notebook)
253        self.show_all()
254        self._edit_area = EditArea()
255       
256       
257    def create_events(self):
258        #....
259        pass
260
261       
Note: See TracBrowser for help on using the browser.