| 1 | #!/usr/bin/env python |
|---|
| 2 | # Copyright (C) 2005 Insecure.Com LLC. |
|---|
| 3 | # |
|---|
| 4 | # Author: Luis A. Bastiao Silva <luis.kop@gmail.com> |
|---|
| 5 | # |
|---|
| 6 | # This program is free software; you can redistribute it and/or modify |
|---|
| 7 | # it under the terms of the GNU General Public License as published by |
|---|
| 8 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | # (at your option) any later version. |
|---|
| 10 | # |
|---|
| 11 | # This program is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with this program; if not, write to the Free Software |
|---|
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | from gettext import gettext as _ |
|---|
| 22 | |
|---|
| 23 | import gtk |
|---|
| 24 | |
|---|
| 25 | #HIG |
|---|
| 26 | |
|---|
| 27 | from higwidgets.higwindows import HIGWindow, HIGMainWindow |
|---|
| 28 | from higwidgets.higboxes import HIGVBox, HIGHBox, HIGSpacer,hig_box_space_holder |
|---|
| 29 | from higwidgets.higexpanders import HIGExpander |
|---|
| 30 | from higwidgets.higlabels import HIGSectionLabel, HIGEntryLabel |
|---|
| 31 | from higwidgets.higscrollers import HIGScrolledWindow |
|---|
| 32 | from higwidgets.higtextviewers import HIGTextView |
|---|
| 33 | from higwidgets.higbuttons import HIGButton |
|---|
| 34 | from higwidgets.higtables import HIGTable |
|---|
| 35 | from higwidgets.higdialogs import HIGAlertDialog, HIGDialog |
|---|
| 36 | from higwidgets.hignotebooks import HIGNotebook |
|---|
| 37 | from higwidgets.higframe import HIGFrame |
|---|
| 38 | import gobject |
|---|
| 39 | from os.path import split, join |
|---|
| 40 | |
|---|
| 41 | from umitInterfaceEditor.Profile import ProfileEdit |
|---|
| 42 | from umitInterfaceEditor.WizardEditor import WizardEdit |
|---|
| 43 | from umitCore.Logging import log |
|---|
| 44 | from umitCore.I18N import _ |
|---|
| 45 | #PWE project |
|---|
| 46 | #from umitInterfaceEditor.PWOptions import PWOptions |
|---|
| 47 | #from umitInterfaceEditor.Editor import Editor |
|---|
| 48 | from umitInterfaceEditor.OptionManager import OptionList, OptionDisplay, OptionDisplayMainFrame |
|---|
| 49 | #END |
|---|
| 50 | from umitCore.Paths import Path |
|---|
| 51 | #Path.set_umit_conf(join(split(__file__)[0], 'config', 'umit.conf')) |
|---|
| 52 | |
|---|
| 53 | profile_editor = Path.profile_editor |
|---|
| 54 | wizard = Path.wizard |
|---|
| 55 | |
|---|
| 56 | from umitInterfaceEditor.Tools import ToolDesign, Proprieties |
|---|
| 57 | |
|---|
| 58 | from umitInterfaceEditor.Command import command_manager |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | class umitInterfaceEditor(HIGMainWindow): |
|---|
| 62 | def __init__(self): |
|---|
| 63 | HIGMainWindow.__init__(self) |
|---|
| 64 | self._proprieties = None |
|---|
| 65 | self.profile_box = None |
|---|
| 66 | self.wizard_box = None |
|---|
| 67 | self._current_edit_mode = None |
|---|
| 68 | self._tooldesign = None |
|---|
| 69 | self.profile_box_b = None |
|---|
| 70 | self.wizard_box_b = None |
|---|
| 71 | self.set_title(_('Umit Interface Editor - v0.1')) |
|---|
| 72 | self.set_size_request(800, 400) |
|---|
| 73 | self.set_position(gtk.WIN_POS_CENTER) |
|---|
| 74 | #self.maximize() |
|---|
| 75 | self.list_options_box = OptionList() |
|---|
| 76 | self.notebook = HIGNotebook() |
|---|
| 77 | self._proprieties = Proprieties() |
|---|
| 78 | self.create_profile_edit() |
|---|
| 79 | self.create_wizard_edit() |
|---|
| 80 | self.obj = self.profile_box |
|---|
| 81 | #Create Widgets |
|---|
| 82 | self.__create_widgets() |
|---|
| 83 | #Packing - Group of widgets |
|---|
| 84 | self.__pack_widgets() |
|---|
| 85 | self.__option_display() |
|---|
| 86 | self.edit_mode_opt = "Options" |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | self.connect("delete_event", self._destroy) |
|---|
| 90 | |
|---|
| 91 | self.opt_display.set_profile(self.profile_box) |
|---|
| 92 | self.opt_display.set_wizard(self.wizard_box) |
|---|
| 93 | self.profile_box.notebook.connect_after('need-save', self._update_menu_s) |
|---|
| 94 | self.wizard_box.notebook.connect_after('need-save', self._update_menu_s) |
|---|
| 95 | self.profile_box.notebook.connect_after('changed', self._update_menu) |
|---|
| 96 | self.wizard_box.notebook.connect_after('changed', self._update_menu) |
|---|
| 97 | self.opt_display.connect_after('need-save', self._update_menu_s) |
|---|
| 98 | |
|---|
| 99 | def _update_menu(self, actions, others, page): |
|---|
| 100 | obj = None |
|---|
| 101 | if self.edit_mode_opt == "Profile": |
|---|
| 102 | obj = self.profile_box |
|---|
| 103 | elif self.edit_mode_opt == "Wizard": |
|---|
| 104 | obj = self.wizard_box |
|---|
| 105 | if obj == None: |
|---|
| 106 | return |
|---|
| 107 | #Check if there is something selected: |
|---|
| 108 | current_page = obj.notebook.get_nth_page(obj.notebook.get_current_page()) |
|---|
| 109 | if obj.notebook._old_select != None: |
|---|
| 110 | #Section is Selected |
|---|
| 111 | log.debug('Section is selected << updating toolbar') |
|---|
| 112 | |
|---|
| 113 | pass |
|---|
| 114 | elif current_page._old_selected != None: |
|---|
| 115 | #Item Selected |
|---|
| 116 | log.debug('Item is selected << updating toolbar') |
|---|
| 117 | pass |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | def _update_menu_s(self, action, others, page): |
|---|
| 122 | log.debug('<<< Update Main menubar ') |
|---|
| 123 | save = self.main_action_group.get_action('Save') |
|---|
| 124 | if self.edit_mode_opt == "Profile": |
|---|
| 125 | log.debug('profile updating menubar save') |
|---|
| 126 | save.set_sensitive(self.profile_box.is_changed()) |
|---|
| 127 | elif self.edit_mode_opt == "Wizard": |
|---|
| 128 | log.debug('wizard updating menubar save') |
|---|
| 129 | save.set_sensitive(self.wizard_box.is_changed()) |
|---|
| 130 | elif self.edit_mode_opt == 'Options': |
|---|
| 131 | log.debug('options updating menubar save') |
|---|
| 132 | save.set_sensitive(self.opt_display.is_changed()) |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | # |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | def _destroy(self, widget, event): |
|---|
| 140 | self.destroy() |
|---|
| 141 | def create_wizard_edit(self): |
|---|
| 142 | ''' |
|---|
| 143 | create a profile area editing |
|---|
| 144 | and connect to Undo Redo Manager to update the buttons |
|---|
| 145 | ''' |
|---|
| 146 | if self.wizard_box != None: |
|---|
| 147 | self.wizard_box.set_proprieties(self._proprieties) |
|---|
| 148 | #return |
|---|
| 149 | if self.wizard_box ==None : |
|---|
| 150 | self.wizard_box = WizardEdit(self.list_options_box.get_list_option()) |
|---|
| 151 | #else: |
|---|
| 152 | # self.profile_box.show_all() |
|---|
| 153 | #command_manager.connect_after('changed', self._update_undo_redo_cb) |
|---|
| 154 | self.wizard_box.set_notebook(self.notebook) |
|---|
| 155 | |
|---|
| 156 | def create_profile_edit(self): |
|---|
| 157 | ''' |
|---|
| 158 | create a profile area editing |
|---|
| 159 | and connect to Undo Redo Manager to update the buttons |
|---|
| 160 | ''' |
|---|
| 161 | if self.profile_box != None: |
|---|
| 162 | self.profile_box.set_proprieties(self._proprieties) |
|---|
| 163 | #return |
|---|
| 164 | if self.profile_box ==None : |
|---|
| 165 | self.profile_box = ProfileEdit(self.list_options_box.get_list_option()) |
|---|
| 166 | #else: |
|---|
| 167 | # self.profile_box.show_all() |
|---|
| 168 | command_manager.connect_after('changed', self._update_undo_redo_cb) |
|---|
| 169 | self.profile_box.set_notebook(self.notebook) |
|---|
| 170 | def _update_undo_redo_cb(self, action, other): |
|---|
| 171 | ''' |
|---|
| 172 | Verify if exists undo and redo |
|---|
| 173 | and update the buttons on the toolbar/menubar |
|---|
| 174 | #DO: |
|---|
| 175 | - sensitive -> True/False |
|---|
| 176 | - Ajust tips |
|---|
| 177 | #### |
|---|
| 178 | ''' |
|---|
| 179 | |
|---|
| 180 | can_undo = command_manager.can_undo() |
|---|
| 181 | can_redo = command_manager.can_redo() |
|---|
| 182 | self.main_action_group.get_action('Undo').set_sensitive(can_undo) |
|---|
| 183 | self.main_action_group.get_action('Redo').set_sensitive(can_redo) |
|---|
| 184 | if can_undo: |
|---|
| 185 | self.main_action_group.get_action('Undo').tooltip = 'sss' |
|---|
| 186 | self.main_action_group.get_action('Undo').create_menu_item() |
|---|
| 187 | def __create_widgets(self): |
|---|
| 188 | """ |
|---|
| 189 | Create widgets |
|---|
| 190 | """ |
|---|
| 191 | self.main_vbox = gtk.VBox() |
|---|
| 192 | self.widgets = {} |
|---|
| 193 | |
|---|
| 194 | #UI Manager |
|---|
| 195 | self.__create_ui_manager() |
|---|
| 196 | #Table - contains menubar and toolbar |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | #Menubar |
|---|
| 200 | self.__create_menubar() |
|---|
| 201 | #Toolbar |
|---|
| 202 | self.__create_toolbar() |
|---|
| 203 | |
|---|
| 204 | self.display_frame = HIGFrame() |
|---|
| 205 | self.display_frame.set_shadow_type(gtk.SHADOW_ETCHED_IN) |
|---|
| 206 | self.display_frame.set_border_width(6) |
|---|
| 207 | |
|---|
| 208 | self.hbox_edit = gtk.HBox() |
|---|
| 209 | self.hspacer = gtk.HPaned() |
|---|
| 210 | self.hspacer.set_border_width(0) |
|---|
| 211 | self.vbox_right = HIGVBox() |
|---|
| 212 | self.vbox_left = HIGVBox() |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | self.edit_mode_exp = gtk.Expander(_('Edit Modes')) |
|---|
| 217 | self.edit_mode_box = self.create_edit_mode() |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | self.notebook.set_scrollable(True) |
|---|
| 223 | self.notebook.append_page(self.list_options_box, |
|---|
| 224 | HIGEntryLabel(_('Option List'))) |
|---|
| 225 | |
|---|
| 226 | self.list_options_box.reload() |
|---|
| 227 | |
|---|
| 228 | self.__create_status_bar() |
|---|
| 229 | def __option_display(self): |
|---|
| 230 | |
|---|
| 231 | self.display_frame.set_label('Options') |
|---|
| 232 | self.opt_display = OptionDisplayMainFrame() |
|---|
| 233 | self.opt_display.set_options_list(self.list_options_box) |
|---|
| 234 | self.list_options_box.set_option_display(self.opt_display) |
|---|
| 235 | self.display_frame.add_with_properties(self.opt_display) |
|---|
| 236 | self.vbox_left.pack_start(self.display_frame, False, False) |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | def __pack_widgets(self): |
|---|
| 240 | """ |
|---|
| 241 | Packing widgets of mainly windows |
|---|
| 242 | """ |
|---|
| 243 | |
|---|
| 244 | self.add(self.main_vbox) |
|---|
| 245 | |
|---|
| 246 | #Pack widgets to main_box |
|---|
| 247 | |
|---|
| 248 | self.main_vbox.pack_start(self.hbox_edit, True, True) |
|---|
| 249 | |
|---|
| 250 | #Paned |
|---|
| 251 | self.hbox_edit.pack_start(self.hspacer) |
|---|
| 252 | separator = gtk.VSeparator() |
|---|
| 253 | self.hspacer.pack1(self.vbox_left, False, False) |
|---|
| 254 | self.hspacer.set_position(580) |
|---|
| 255 | self.hspacer.pack2(self.vbox_right, False, True) |
|---|
| 256 | |
|---|
| 257 | #Edit Mode |
|---|
| 258 | self.edit_mode_exp.add(self.edit_mode_box) |
|---|
| 259 | self.edit_mode_exp.set_expanded(True) |
|---|
| 260 | |
|---|
| 261 | #Frame right |
|---|
| 262 | self.vbox_right.pack_start(self.edit_mode_exp, False, False) |
|---|
| 263 | self.vbox_right.pack_end(self.notebook, True, True) |
|---|
| 264 | |
|---|
| 265 | #Status bar |
|---|
| 266 | self.main_vbox.pack_start(self.statusbar,False, False) |
|---|
| 267 | |
|---|
| 268 | def create_edit_mode(self): |
|---|
| 269 | """ |
|---|
| 270 | Create a treeview that contains a three edit modes |
|---|
| 271 | returns vbox contains a treeview |
|---|
| 272 | |
|---|
| 273 | @return: returns the treeview with list of edit modes |
|---|
| 274 | @rtype: vbox |
|---|
| 275 | """ |
|---|
| 276 | |
|---|
| 277 | model = gtk.TreeStore(gtk.gdk.Pixbuf,gobject.TYPE_STRING) |
|---|
| 278 | self.edit_mode_tv = gtk.TreeView(model) |
|---|
| 279 | self.edit_mode_tv.set_headers_visible(False) |
|---|
| 280 | renderer = gtk.CellRendererText() |
|---|
| 281 | cell_renderer_pix = gtk.CellRendererPixbuf() |
|---|
| 282 | column = gtk.TreeViewColumn() |
|---|
| 283 | column.set_title(_('Name')) |
|---|
| 284 | column.pack_start(cell_renderer_pix, False) |
|---|
| 285 | column.add_attribute(cell_renderer_pix, 'pixbuf', 0) |
|---|
| 286 | column.pack_start(renderer, True) |
|---|
| 287 | column.add_attribute(renderer, 'text', 1) |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | self.edit_mode_tv.append_column(column) |
|---|
| 291 | myiter = model.insert_before(None, None) |
|---|
| 292 | icon = gtk.Image() |
|---|
| 293 | icon = icon.render_icon('gtk-edit',gtk.ICON_SIZE_MENU) |
|---|
| 294 | model.set_value(myiter, 0, icon) |
|---|
| 295 | model.set_value(myiter, 1, "Profile") |
|---|
| 296 | myiter = model.insert_before(None, None) |
|---|
| 297 | icon = gtk.Image() |
|---|
| 298 | icon = icon.render_icon('gtk-convert',gtk.ICON_SIZE_MENU) |
|---|
| 299 | model.set_value(myiter, 0, icon) |
|---|
| 300 | model.set_value(myiter, 1, "Wizard") |
|---|
| 301 | myiter = model.insert_before(None, None) |
|---|
| 302 | icon = gtk.Image() |
|---|
| 303 | |
|---|
| 304 | icon = icon.render_icon(gtk.STOCK_DND_MULTIPLE, gtk.ICON_SIZE_MENU) |
|---|
| 305 | model.set_value(myiter, 0, icon) |
|---|
| 306 | model.set_value(myiter, 1, "Options") |
|---|
| 307 | selection = self.edit_mode_tv.get_selection() |
|---|
| 308 | selection.select_iter(myiter) |
|---|
| 309 | self.edit_mode_tv.connect("cursor-changed", self.change_edit_mode) |
|---|
| 310 | vbox = HIGVBox() |
|---|
| 311 | vbox.pack_start(self.edit_mode_tv, False, False) |
|---|
| 312 | return vbox |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | def change_edit_mode(self, widget): |
|---|
| 316 | """ |
|---|
| 317 | Change box of main screen and others changes at toolbar |
|---|
| 318 | """ |
|---|
| 319 | selection = self.edit_mode_tv.get_selection() |
|---|
| 320 | (model,iter) = selection.get_selected() |
|---|
| 321 | edit = model.get_value(iter, 1) |
|---|
| 322 | if edit == "Options" and not self.edit_mode_opt == "Options": |
|---|
| 323 | # |
|---|
| 324 | self._remove_previews() |
|---|
| 325 | self.edit_mode_opt = "Options" |
|---|
| 326 | #self.vbox_left.pack_start(self.display_frame, False, False ) |
|---|
| 327 | self.display_frame.show_all() |
|---|
| 328 | if self.notebook.get_n_pages > 1 : |
|---|
| 329 | self.notebook.remove_page(-1) |
|---|
| 330 | self.notebook.remove_page(-1) |
|---|
| 331 | |
|---|
| 332 | elif edit == "Profile" and not self.edit_mode_opt == "Profile": |
|---|
| 333 | # |
|---|
| 334 | self._remove_previews() |
|---|
| 335 | self.edit_mode_opt="Profile" |
|---|
| 336 | bool = self.profile_box_b==None |
|---|
| 337 | self.create_profile_edit() |
|---|
| 338 | if bool: |
|---|
| 339 | self.vbox_left.pack_start(self.profile_box, True, True) |
|---|
| 340 | self.profile_box_b= True |
|---|
| 341 | log.debug('<<< show :: Profile Edit Mode :: ') |
|---|
| 342 | self.profile_box.show_all() |
|---|
| 343 | self.profile_box.notebook.put_on_page() |
|---|
| 344 | self._create_tooldesign() |
|---|
| 345 | |
|---|
| 346 | self.profile_box.show() |
|---|
| 347 | self.obj = self.profile_box |
|---|
| 348 | elif edit == "Wizard" and not self.edit_mode_opt == "Wizard": |
|---|
| 349 | log.debug('<<< show :: Wizard Edit Mode - basic mode ') |
|---|
| 350 | self._remove_previews() |
|---|
| 351 | self.edit_mode_opt="Wizard" |
|---|
| 352 | |
|---|
| 353 | bool = self.wizard_box_b==None |
|---|
| 354 | self.create_wizard_edit() |
|---|
| 355 | if bool: |
|---|
| 356 | self.vbox_left.pack_start(self.wizard_box, True, True) |
|---|
| 357 | self.wizard_box_b = True |
|---|
| 358 | |
|---|
| 359 | self.wizard_box.show_all() |
|---|
| 360 | self.wizard_box.notebook.put_on_page() |
|---|
| 361 | self._create_tooldesign() |
|---|
| 362 | self.wizard_box.show() |
|---|
| 363 | self.obj = self.wizard_box |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | def _remove_previews(self): |
|---|
| 367 | ''' |
|---|
| 368 | Remove the previews Edit mode |
|---|
| 369 | |
|---|
| 370 | ''' |
|---|
| 371 | #XXX Lack the toolbars and some ajusts |
|---|
| 372 | if self.edit_mode_opt == "Profile": |
|---|
| 373 | #self.vbox_left.remove(self.profile_box) |
|---|
| 374 | self.profile_box.hide_all() |
|---|
| 375 | elif self.edit_mode_opt == "Options": |
|---|
| 376 | #self.vbox_left.remove(self.display_frame) |
|---|
| 377 | self.display_frame.hide_all() |
|---|
| 378 | elif self.edit_mode_opt == "Wizard": |
|---|
| 379 | self.wizard_box.hide_all() |
|---|
| 380 | |
|---|
| 381 | def _create_tooldesign(self): |
|---|
| 382 | ''' |
|---|
| 383 | create tooldesign that contains widgets to put |
|---|
| 384 | in work area of edit profile |
|---|
| 385 | ''' |
|---|
| 386 | if self._tooldesign == None : |
|---|
| 387 | self._tooldesign = ToolDesign() |
|---|
| 388 | |
|---|
| 389 | if self._proprieties == None : |
|---|
| 390 | self._proprieties = Proprieties() |
|---|
| 391 | if self.notebook.get_n_pages() < 2: |
|---|
| 392 | self.notebook.append_page(self._tooldesign, |
|---|
| 393 | HIGEntryLabel(_('Design'))) |
|---|
| 394 | self.notebook.append_page(self._proprieties, |
|---|
| 395 | HIGEntryLabel(_('Proprieties'))) |
|---|
| 396 | self.notebook.show_all() |
|---|
| 397 | if self.edit_mode_opt == "Profile": |
|---|
| 398 | obj = self.profile_box |
|---|
| 399 | elif self.edit_mode_opt == "Wizard": |
|---|
| 400 | obj = self.wizard_box |
|---|
| 401 | obj.set_proprieties(self._proprieties) |
|---|
| 402 | profilecore = obj.get_profilecore() |
|---|
| 403 | self._proprieties.set_profilecore(profilecore) |
|---|
| 404 | |
|---|
| 405 | def __optinlist_from_group(self): |
|---|
| 406 | """ |
|---|
| 407 | After Select a Option from a group this treeview refresh options lists |
|---|
| 408 | that each group contains |
|---|
| 409 | """ |
|---|
| 410 | model = gtk.TreeStore(gobject.TYPE_STRING) |
|---|
| 411 | self.profile_optionlist_tvw = gtk.TreeView(model) |
|---|
| 412 | renderer = gtk.CellRendererText() |
|---|
| 413 | column = gtk.TreeViewColumn("Name", renderer, text=0) |
|---|
| 414 | self.profile_optionlist_tvw.append_column(column) |
|---|
| 415 | |
|---|
| 416 | self.wizard_file = PWOptions(profile_editor) |
|---|
| 417 | group_list = self.wizard_file.read("group", "name", "group") |
|---|
| 418 | for i,v in group_list: |
|---|
| 419 | myiter = model.insert_after(None, None) |
|---|
| 420 | model.set_value(myiter, 0, i) |
|---|
| 421 | def __proprieties(self): |
|---|
| 422 | """ |
|---|
| 423 | Create a editable options - Proprieties of Options |
|---|
| 424 | """ |
|---|
| 425 | #Create a listview with options |
|---|
| 426 | self.prop_frame_option = gtk.Frame() |
|---|
| 427 | self.prop_frame_option.set_label("List Options") |
|---|
| 428 | self.prop_frame_option.set_shadow_type(gtk.SHADOW_ETCHED_OUT) |
|---|
| 429 | prop_sw = HIGScrolledWindow() |
|---|
| 430 | prop_sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) |
|---|
| 431 | prop_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 432 | model = gtk.TreeStore(gobject.TYPE_STRING) |
|---|
| 433 | treeview = gtk.TreeView(model) |
|---|
| 434 | renderer = gtk.CellRendererText() |
|---|
| 435 | column = gtk.TreeViewColumn("Name", renderer, text=0) |
|---|
| 436 | treeview.append_column(column) |
|---|
| 437 | self.prop_frame_option.add(treeview) |
|---|
| 438 | self.prop_frame_option.add(prop_sw) |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | """ |
|---|
| 443 | Box Edit |
|---|
| 444 | """ |
|---|
| 445 | |
|---|
| 446 | #Frame |
|---|
| 447 | self.prop_frame = gtk.Frame() |
|---|
| 448 | self.prop_frame.set_label("Edit Option") |
|---|
| 449 | self.prop_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT) |
|---|
| 450 | |
|---|
| 451 | self.prop_exp = HIGExpander("Proprieties") |
|---|
| 452 | |
|---|
| 453 | label = gtk.Label('s') |
|---|
| 454 | self.prop_exp.add(label) |
|---|
| 455 | self.prop_frame.add(self.prop_exp) |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | def __grouplist(self): |
|---|
| 460 | """ |
|---|
| 461 | Group List, Tree view |
|---|
| 462 | """ |
|---|
| 463 | |
|---|
| 464 | model = gtk.TreeStore(gobject.TYPE_STRING) |
|---|
| 465 | self.treeview = gtk.TreeView(model) |
|---|
| 466 | renderer = gtk.CellRendererText() |
|---|
| 467 | column = gtk.TreeViewColumn("Name", renderer, text=0) |
|---|
| 468 | self.treeview.append_column(column) |
|---|
| 469 | |
|---|
| 470 | self.wizard_file = PWOptions(profile_editor) |
|---|
| 471 | group_list = self.wizard_file.read("group", "name", "group") |
|---|
| 472 | for i,v in group_list: |
|---|
| 473 | myiter = model.insert_after(None, None) |
|---|
| 474 | model.set_value(myiter, 0, i) |
|---|
| 475 | |
|---|
| 476 | def __create_toolbar(self): |
|---|
| 477 | """ |
|---|
| 478 | Create a Main Toolbar of Profile Wizard Editor |
|---|
| 479 | """ |
|---|
| 480 | |
|---|
| 481 | self.toolbar = self.ui_manager.get_widget('/toolbar') |
|---|
| 482 | self.toolbar.set_style(gtk.TOOLBAR_BOTH) |
|---|
| 483 | |
|---|
| 484 | self.main_vbox.pack_start(self.toolbar, False, True,0) |
|---|
| 485 | self.toolbar.show_all() |
|---|
| 486 | def save_all(self, widget): |
|---|
| 487 | pass |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | def save(self, widget): |
|---|
| 491 | if self.edit_mode_opt == 'Options': |
|---|
| 492 | obj = self.list_options_box |
|---|
| 493 | elif self.edit_mode_opt == 'Profile': |
|---|
| 494 | obj = self.profile_box |
|---|
| 495 | elif self.edit_mode_opt == 'Wizard': |
|---|
| 496 | obj = self.wizard_box |
|---|
| 497 | |
|---|
| 498 | obj.save() |
|---|
| 499 | def quit(self, widget): |
|---|
| 500 | self.destroy() |
|---|
| 501 | def np(self, widget): |
|---|
| 502 | print "Don't work yet" |
|---|
| 503 | def __create_ui_manager(self): |
|---|
| 504 | """ |
|---|
| 505 | Create a UI Manager |
|---|
| 506 | """ |
|---|
| 507 | self.ui_manager = gtk.UIManager() |
|---|
| 508 | self.main_action_group = gtk.ActionGroup('MainActionGroup') |
|---|
| 509 | self.main_actions = [ \ |
|---|
| 510 | ('File', None, _('_File'), None), |
|---|
| 511 | ('Save', gtk.STOCK_SAVE, _('_Save'), None, _('Save'), self.save), |
|---|
| 512 | ('Save all', gtk.STOCK_SAVE, _('_Save all'), None, _('Save all'), |
|---|
| 513 | self.np), |
|---|
| 514 | ('Quit', gtk.STOCK_QUIT, _('_Quit'), None, _('Quit'), self.quit), |
|---|
| 515 | ('Edit', None, _('Edit'), None), |
|---|
| 516 | ('Undo', gtk.STOCK_UNDO, _('_Undo'), None, _('Undo'), self._undo_cb), |
|---|
| 517 | ('Redo', gtk.STOCK_REDO, _('_Redo'), None, _('Redo'), self._redo_cb), |
|---|
| 518 | ('View', None, _('View'), None), |
|---|
| 519 | ('Right Bar', None, _('_Right Bar'), None, |
|---|
| 520 | _('Right Bar'), self.np), |
|---|
| 521 | ('Tools', None, _('Tools'), None), |
|---|
| 522 | ('Section', None, _('Section'), None), |
|---|
| 523 | ('Items', None, _('Items'), None), |
|---|
| 524 | ('Label', None, _('_Label'), None, |
|---|
| 525 | _('Label'), self.np), |
|---|
| 526 | ('New Section', None, _('_New Section'), None, |
|---|
| 527 | _('New Section'), self._add_section), |
|---|
| 528 | ('Remove Section Label', None, _('_Remove Section Label'), None, |
|---|
| 529 | _('Remove Section Label'), self._remove_section), |
|---|
| 530 | ('Remove Section', None, _('_Remove Section'), None, |
|---|
| 531 | _('Remove Section'), self._remove_section), |
|---|
| 532 | ('Add new voidplace', None, _('_Add new voidplace'), None, |
|---|
| 533 | _('Add new voidplace'), self._add_place), |
|---|
| 534 | ('Remove option', None, _('_Remove Option'), None, |
|---|
| 535 | _('Remove option'), self._remove_option), |
|---|
| 536 | ('Remove voidplace', None, _('_Remove voidplace'), None, |
|---|
| 537 | _('Remove voidplace'), self._remove_option), |
|---|
| 538 | ('Add option selected', None, _('_Add option selected'), None, |
|---|
| 539 | _('Add option selected'), self.np), |
|---|
| 540 | ('Move Section Left', None, _('_Move Section Left'), None, |
|---|
| 541 | _('Move Section Left'), self._move_section_left), |
|---|
| 542 | ('Move Section Right', None, _('_Move Section Right'), None, |
|---|
| 543 | _('Move Section Right'), self._move_section_right), |
|---|
| 544 | ('Move Item Down', None, _('_Move Item Down'), None, |
|---|
| 545 | _('Move Item Down'), self._move_item_down), |
|---|
| 546 | ('Move Item Up', None, _('_Move Item Up'), None, |
|---|
| 547 | _('Move Item Up'), self._move_item_up), |
|---|
| 548 | ('Help', None, _('Help'), None), |
|---|
| 549 | ('About', gtk.STOCK_PASTE, _('_About'), None, _('About'), self.np), |
|---|
| 550 | |
|---|
| 551 | ] |
|---|
| 552 | |
|---|
| 553 | self.ui_info = """ |
|---|
| 554 | <menubar> |
|---|
| 555 | <menu action='File'> |
|---|
| 556 | <menuitem action='Save'/> |
|---|
| 557 | <menuitem action='Save all'/> |
|---|
| 558 | <separator/> |
|---|
| 559 | <menuitem action='Quit'/> |
|---|
| 560 | </menu> |
|---|
| 561 | <menu action='Edit'> |
|---|
| 562 | <menuitem action='Undo'/> |
|---|
| 563 | <menuitem action='Redo'/> |
|---|
| 564 | </menu> |
|---|
| 565 | <menu action='View'> |
|---|
| 566 | <menuitem action='Right Bar'/> |
|---|
| 567 | </menu> |
|---|
| 568 | <menu action='Section'> |
|---|
| 569 | <menuitem action='Insert Label'/> |
|---|
| 570 | <menuitem action='New Section'/> |
|---|
| 571 | <menuitem action='Remove Section Label'/> |
|---|
| 572 | <menuitem action='Remove Section'/> |
|---|
| 573 | <menuitem action='Move Section Left'/> |
|---|
| 574 | <menuitem action='Move Section Right'/> |
|---|
| 575 | </menu> |
|---|
| 576 | <menu action='Items'> |
|---|
| 577 | <menuitem action='Add new voidplace'/> |
|---|
| 578 | <menuitem action='Remove option'/> |
|---|
| 579 | <menuitem action='Remove voidplace'/> |
|---|
| 580 | <menuitem action='Move Item Up'/> |
|---|
| 581 | <menuitem action='Move Item Down'/> |
|---|
| 582 | </menu> |
|---|
| 583 | </menu> |
|---|
| 584 | <menu action='Help'> |
|---|
| 585 | <menuitem action='About'/> |
|---|
| 586 | </menu> |
|---|
| 587 | </menubar> |
|---|
| 588 | <toolbar> |
|---|
| 589 | <toolitem action='Save'/> |
|---|
| 590 | <toolitem action='Save all'/> |
|---|
| 591 | <separator/> |
|---|
| 592 | <toolitem action='Undo'/> |
|---|
| 593 | <toolitem action='Redo'/> |
|---|
| 594 | |
|---|
| 595 | <separator/> |
|---|
| 596 | <toolitem action='Quit'/> |
|---|
| 597 | </toolbar> |
|---|
| 598 | """ |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | self.main_action_group.add_actions(self.main_actions) |
|---|
| 602 | self.main_accel_group = gtk.AccelGroup() |
|---|
| 603 | for action in self.main_action_group.list_actions(): |
|---|
| 604 | |
|---|
| 605 | action.set_accel_group(self.main_accel_group) |
|---|
| 606 | action.connect_accelerator() |
|---|
| 607 | |
|---|
| 608 | #ENABLE = FALSE |
|---|
| 609 | self.main_action_group.get_action('Save all').set_sensitive(False) |
|---|
| 610 | self.main_action_group.get_action('Save').set_sensitive(False) |
|---|
| 611 | self.main_action_group.get_action('Undo').set_sensitive(False) |
|---|
| 612 | self.main_action_group.get_action('Redo').set_sensitive(False) |
|---|
| 613 | |
|---|
| 614 | #END ENABLE |
|---|
| 615 | |
|---|
| 616 | self.ui_manager.insert_action_group(self.main_action_group, 0) |
|---|
| 617 | #try: |
|---|
| 618 | self.ui_manager.add_ui_from_string(self.ui_info) |
|---|
| 619 | #except gobject.GError, msg: |
|---|
| 620 | # print "Fails %s" % msg |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | # ACTIONS |
|---|
| 624 | def _add_section(self, widget): |
|---|
| 625 | self.obj._toolbar._add_section(widget) |
|---|
| 626 | def _remove_section(self, widget): |
|---|
| 627 | self.obj._toolbar._remove_section(widget) |
|---|
| 628 | def _add_place(self,widget): |
|---|
| 629 | self.obj._toolbar._add_place(widget) |
|---|
| 630 | def _move_item_up(self, widget): |
|---|
| 631 | self.obj._toolbar._move_item_down(widget) |
|---|
| 632 | def _move_item_down(self, widget): |
|---|
| 633 | self.obj._toolbar._move_item_down(widget) |
|---|
| 634 | def _move_section_left(self, widget): |
|---|
| 635 | self.obj._toolbar._move_section_left(widget) |
|---|
| 636 | def _move_section_right(self, widget): |
|---|
| 637 | self.obj._toolbar._move_section_right(widget) |
|---|
| 638 | def _remove_option(self, widget): |
|---|
| 639 | self.obj._toolbar._remove_option(widget) |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | def _undo_cb(self, widget): |
|---|
| 643 | command_manager.do_undo() |
|---|
| 644 | def _redo_cb(self, widget): |
|---|
| 645 | command_manager.do_redo() |
|---|
| 646 | |
|---|
| 647 | def __create_menubar(self): |
|---|
| 648 | """ |
|---|
| 649 | Create a menubar |
|---|
| 650 | """ |
|---|
| 651 | |
|---|
| 652 | self.menubar = self.ui_manager.get_widget('/menubar') |
|---|
| 653 | |
|---|
| 654 | self.main_vbox.pack_start(self.menubar,False,True, 0) |
|---|
| 655 | |
|---|
| 656 | self.menubar.show_all() |
|---|
| 657 | |
|---|
| 658 | def __create_status_bar(self): |
|---|
| 659 | ''' |
|---|
| 660 | create status bar |
|---|
| 661 | ''' |
|---|
| 662 | self.statusbar = gtk.Statusbar() |
|---|
| 663 | |
|---|
| 664 | context_id = self.statusbar.push(1," ") |
|---|
| 665 | self.statusbar.show() |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | if __name__ == '__main__': |
|---|
| 669 | p = umitInterfaceEditor() |
|---|
| 670 | p.show_all() |
|---|
| 671 | gtk.main() |
|---|