| 1 | #!/usr/bin/env python |
|---|
| 2 | # Copyright (C) 2007 Adriano Monteiro Marques <py.adriano@gmail.com> |
|---|
| 3 | # |
|---|
| 4 | # Author: Luis 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 |
|---|
| 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 | import gobject |
|---|
| 38 | from os.path import split, join |
|---|
| 39 | |
|---|
| 40 | from umit.core.PWOptions import PWOptions |
|---|
| 41 | |
|---|
| 42 | from umit.core.Paths import Path |
|---|
| 43 | Path.set_umit_conf(join(split(__file__)[0], 'config', 'umit.conf')) |
|---|
| 44 | |
|---|
| 45 | profile_editor = Path.profile_editor |
|---|
| 46 | |
|---|
| 47 | # This is my first tests with higwidgets |
|---|
| 48 | |
|---|
| 49 | class ProfileWizardEditor(HIGWindow): |
|---|
| 50 | def __init__(self): |
|---|
| 51 | HIGWindow.__init__(self) |
|---|
| 52 | self.set_title(_('Profile and Wizard Editor')) |
|---|
| 53 | #self.set_default_size(700, 500) |
|---|
| 54 | |
|---|
| 55 | self.set_position(gtk.WIN_POS_CENTER) |
|---|
| 56 | |
|---|
| 57 | #Create Widgets |
|---|
| 58 | self.__create_widgets() |
|---|
| 59 | #Packing - Group of widgets |
|---|
| 60 | self.__pack_widgets() |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | def __create_widgets(self): |
|---|
| 65 | """ |
|---|
| 66 | Create widgets |
|---|
| 67 | """ |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | self.main_vbox = HIGVBox() |
|---|
| 71 | self.widgets = {} |
|---|
| 72 | |
|---|
| 73 | #UI Manager |
|---|
| 74 | self.__create_ui_manager() |
|---|
| 75 | #Menubar |
|---|
| 76 | self.__create_menubar() |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | #Toolbar |
|---|
| 81 | self.__create_toolbar() |
|---|
| 82 | |
|---|
| 83 | #Mainly frame - contains a toolbar, and notebook |
|---|
| 84 | #(tabs with Wizard, Profile and Options) |
|---|
| 85 | self.hbox_edit = HIGHBox() |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | """ |
|---|
| 89 | Notebook |
|---|
| 90 | """ |
|---|
| 91 | |
|---|
| 92 | self.notebook = HIGNotebook() |
|---|
| 93 | |
|---|
| 94 | self.list_combo = gtk.combo_box_entry_new_text() |
|---|
| 95 | self.list_combo.append_text("New Style") |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | """ |
|---|
| 99 | Profile Tab |
|---|
| 100 | """ |
|---|
| 101 | # Contains the combo and a HBox |
|---|
| 102 | self.profile_vbox = HIGVBox() |
|---|
| 103 | # HBox - three columns |
|---|
| 104 | self.profile_hbox = HIGHBox() |
|---|
| 105 | self.profile_vbox_group = HIGVBox() |
|---|
| 106 | self.profile_vbox_option = HIGVBox() |
|---|
| 107 | self.profile_group_sw = HIGScrolledWindow() |
|---|
| 108 | self.profile_group_sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) |
|---|
| 109 | self.profile_group_sw.set_policy(gtk.POLICY_AUTOMATIC, |
|---|
| 110 | gtk.POLICY_AUTOMATIC) |
|---|
| 111 | |
|---|
| 112 | self.profile_group_sw.set_size_request(150,250) |
|---|
| 113 | self.profile_vbox_proprieties = HIGVBox() |
|---|
| 114 | |
|---|
| 115 | self.__grouplist() |
|---|
| 116 | self.profile_separator = gtk.VSeparator() |
|---|
| 117 | self.__optinlist_from_group() |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | self.profile_separator2 = gtk.VSeparator() |
|---|
| 121 | # Buttons << and >> |
|---|
| 122 | # BBOX buttons move right move left |
|---|
| 123 | self.profile_bbox_rl = gtk.VButtonBox() |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | self.profile_bbox_rl.set_layout(gtk.BUTTONBOX_SPREAD) |
|---|
| 127 | self.profile_bbox_rl.set_spacing(12) |
|---|
| 128 | #Buttons |
|---|
| 129 | self.profile_left_but = HIGButton() |
|---|
| 130 | self.profile_left_but.set_label('<<') |
|---|
| 131 | self.profile_right_but = HIGButton() |
|---|
| 132 | self.profile_right_but.set_label('>>') |
|---|
| 133 | #Add Buttons to ButtonBox |
|---|
| 134 | self.profile_bbox_rl.add(self.profile_right_but) |
|---|
| 135 | self.profile_bbox_rl.add(self.profile_left_but) |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | self.profile_separator3 = gtk.VSeparator() |
|---|
| 139 | |
|---|
| 140 | self.__proprieties() |
|---|
| 141 | |
|---|
| 142 | """ |
|---|
| 143 | Wizard Tab |
|---|
| 144 | """ |
|---|
| 145 | |
|---|
| 146 | self.wizard_vbox = HIGVBox() |
|---|
| 147 | self.wizard_group_label = HIGSectionLabel(_('Group List')) |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | """ |
|---|
| 151 | Down of notebook |
|---|
| 152 | """ |
|---|
| 153 | |
|---|
| 154 | self.main_buttons_down = gtk.HButtonBox() |
|---|
| 155 | self.main_buttons_down.set_layout(gtk.BUTTONBOX_END) |
|---|
| 156 | self.main_buttons_down.set_spacing(12) |
|---|
| 157 | #Buttons |
|---|
| 158 | self.main_down_ok_but = HIGButton(stock='gtk-ok') |
|---|
| 159 | self.main_down_cancel_but = HIGButton(stock='gtk-cancel') |
|---|
| 160 | self.main_down_help_but = HIGButton(stock='gtk-help') |
|---|
| 161 | #Add Buttons to ButtonBox |
|---|
| 162 | self.main_buttons_down.add(self.main_down_ok_but) |
|---|
| 163 | self.main_buttons_down.add(self.main_down_cancel_but) |
|---|
| 164 | self.main_buttons_down.add(self.main_down_help_but) |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | def __pack_widgets(self): |
|---|
| 169 | """ |
|---|
| 170 | Packing widgets of mainly windows |
|---|
| 171 | """ |
|---|
| 172 | |
|---|
| 173 | self.add(self.main_vbox) |
|---|
| 174 | |
|---|
| 175 | #Pack widgets to main_box |
|---|
| 176 | self.main_vbox.pack_start(self.hbox_edit) |
|---|
| 177 | |
|---|
| 178 | #HBox_Edit |
|---|
| 179 | self.hbox_edit._pack_expand_fill(self.notebook) |
|---|
| 180 | |
|---|
| 181 | #Profile: |
|---|
| 182 | |
|---|
| 183 | self.profile_vbox._pack_noexpand_nofill(self.list_combo) |
|---|
| 184 | self.profile_vbox._pack_expand_fill(self.profile_hbox) |
|---|
| 185 | |
|---|
| 186 | """ |
|---|
| 187 | Group |
|---|
| 188 | """ |
|---|
| 189 | |
|---|
| 190 | self.profile_hbox._pack_expand_fill(self.profile_vbox_group) |
|---|
| 191 | self.profile_vbox_group._pack_noexpand_nofill(self.profile_group_label) |
|---|
| 192 | |
|---|
| 193 | self.profile_vbox_group._pack_expand_fill(self.profile_group_sw) |
|---|
| 194 | box = HIGHBox() |
|---|
| 195 | box._pack_expand_fill(self.treeview) |
|---|
| 196 | self.profile_group_sw.add_with_viewport(box) |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | self.profile_hbox.pack_start(self.profile_separator) |
|---|
| 200 | |
|---|
| 201 | """ |
|---|
| 202 | Option |
|---|
| 203 | """ |
|---|
| 204 | |
|---|
| 205 | self.profile_hbox.pack_start(self.profile_vbox_option) |
|---|
| 206 | self.profile_vbox_option._pack_noexpand_nofill(self.profile_option_list_lbl) |
|---|
| 207 | self.profile_vbox_option._pack_noexpand_nofill(self.profile_optionlist_tvw) |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | self.profile_hbox._pack_noexpand_nofill( |
|---|
| 211 | self.profile_separator2) |
|---|
| 212 | |
|---|
| 213 | """ |
|---|
| 214 | Buttons move left and move right |
|---|
| 215 | """ |
|---|
| 216 | |
|---|
| 217 | self.profile_hbox.pack_start( |
|---|
| 218 | self.profile_bbox_rl) |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | #self.profile_hbox._pack_noexpand_nofill(self.profile_separator3) |
|---|
| 222 | """ |
|---|
| 223 | Proprieties |
|---|
| 224 | """ |
|---|
| 225 | |
|---|
| 226 | self.profile_hbox.pack_start(self.profile_vbox_proprieties) |
|---|
| 227 | self.profile_vbox_proprieties.pack_start(self.prop_frame_option) |
|---|
| 228 | self.profile_vbox_proprieties.pack_start(self.prop_frame) |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | #Wizard: |
|---|
| 232 | |
|---|
| 233 | self.wizard_vbox._pack_noexpand_nofill(self.wizard_group_label) |
|---|
| 234 | |
|---|
| 235 | self.notebook.append_page(self.profile_vbox, |
|---|
| 236 | gtk.Label(_('Profile'))) |
|---|
| 237 | self.notebook.append_page(self.wizard_vbox, |
|---|
| 238 | gtk.Label(_('Wizard'))) |
|---|
| 239 | |
|---|
| 240 | """ |
|---|
| 241 | Down --- |
|---|
| 242 | after notebook |
|---|
| 243 | Apply changes, quit or cancel |
|---|
| 244 | |
|---|
| 245 | """ |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | self.main_vbox._pack_noexpand_nofill(self.main_buttons_down) |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | def __optinlist_from_group(self): |
|---|
| 253 | """ |
|---|
| 254 | After Select a Option from a group this treeview refresh options lists that |
|---|
| 255 | each group contains |
|---|
| 256 | """ |
|---|
| 257 | self.profile_option_list_lbl = HIGSectionLabel(_('Option of List')) |
|---|
| 258 | |
|---|
| 259 | model = gtk.TreeStore(gobject.TYPE_STRING) |
|---|
| 260 | self.profile_optionlist_tvw = gtk.TreeView(model) |
|---|
| 261 | renderer = gtk.CellRendererText() |
|---|
| 262 | column = gtk.TreeViewColumn("Name", renderer, text=0) |
|---|
| 263 | self.profile_optionlist_tvw.append_column(column) |
|---|
| 264 | |
|---|
| 265 | self.wizard_file = PWOptions(profile_editor) |
|---|
| 266 | group_list = self.wizard_file.read("group", "name", "group") |
|---|
| 267 | for i,v in group_list: |
|---|
| 268 | myiter = model.insert_after(None, None) |
|---|
| 269 | model.set_value(myiter, 0, i) |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | def __proprieties(self): |
|---|
| 273 | """ |
|---|
| 274 | |
|---|
| 275 | Create a editable options - Proprieties of Options |
|---|
| 276 | """ |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | #Create a listview with options |
|---|
| 280 | self.prop_frame_option = gtk.Frame() |
|---|
| 281 | self.prop_frame_option.set_label("List Options") |
|---|
| 282 | self.prop_frame_option.set_shadow_type(gtk.SHADOW_ETCHED_OUT) |
|---|
| 283 | prop_sw = HIGScrolledWindow() |
|---|
| 284 | prop_sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) |
|---|
| 285 | prop_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 286 | prop_sw.set_size_request(150,250) |
|---|
| 287 | model = gtk.TreeStore(gobject.TYPE_STRING) |
|---|
| 288 | treeview = gtk.TreeView(model) |
|---|
| 289 | renderer = gtk.CellRendererText() |
|---|
| 290 | column = gtk.TreeViewColumn("Name", renderer, text=0) |
|---|
| 291 | treeview.append_column(column) |
|---|
| 292 | prop_sw.add(treeview) |
|---|
| 293 | self.prop_frame_option.add(prop_sw) |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | """ |
|---|
| 298 | Box Edit |
|---|
| 299 | """ |
|---|
| 300 | |
|---|
| 301 | #Frame |
|---|
| 302 | self.prop_frame = gtk.Frame() |
|---|
| 303 | self.prop_frame.set_label("Edit Option") |
|---|
| 304 | self.prop_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT) |
|---|
| 305 | |
|---|
| 306 | self.prop_exp = HIGExpander("Proprieties") |
|---|
| 307 | |
|---|
| 308 | self.prop_frame.add(self.prop_exp) |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | def __grouplist(self): |
|---|
| 313 | """ |
|---|
| 314 | Group List, Tree view |
|---|
| 315 | """ |
|---|
| 316 | self.profile_group_label = HIGSectionLabel(_('Group List')) |
|---|
| 317 | model = gtk.TreeStore(gobject.TYPE_STRING) |
|---|
| 318 | self.treeview = gtk.TreeView(model) |
|---|
| 319 | renderer = gtk.CellRendererText() |
|---|
| 320 | column = gtk.TreeViewColumn("Name", renderer, text=0) |
|---|
| 321 | self.treeview.append_column(column) |
|---|
| 322 | |
|---|
| 323 | self.wizard_file = PWOptions(profile_editor) |
|---|
| 324 | group_list = self.wizard_file.read("group", "name", "group") |
|---|
| 325 | for i,v in group_list: |
|---|
| 326 | myiter = model.insert_after(None, None) |
|---|
| 327 | model.set_value(myiter, 0, i) |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | def __create_toolbar(self): |
|---|
| 332 | """ |
|---|
| 333 | Create a Main Toolbar of Profile Wizard Editor |
|---|
| 334 | """ |
|---|
| 335 | |
|---|
| 336 | self.toolbar = gtk.Toolbar() |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | def np(self): |
|---|
| 340 | print "np" |
|---|
| 341 | def __create_ui_manager(self): |
|---|
| 342 | """ |
|---|
| 343 | Create a UI Manager |
|---|
| 344 | """ |
|---|
| 345 | |
|---|
| 346 | self.ui_manager = gtk.UIManager() |
|---|
| 347 | self.main_action_group = gtk.ActionGroup('MainActionGroup') |
|---|
| 348 | self.main_actions = [ \ |
|---|
| 349 | ('Manage', None, _('_Manage'), None), |
|---|
| 350 | ('Open', gtk.STOCK_OPEN, _('_Open'), None, _('Open'), self.np), |
|---|
| 351 | ('Quit', gtk.STOCK_OPEN, _('_Quit'), None, _('Quit'), self.np), |
|---|
| 352 | ('Edit', None, _('Edit'), None), |
|---|
| 353 | ('Undo', gtk.STOCK_OPEN, _('Undo'), None, _('Edit'), self.np), |
|---|
| 354 | ] |
|---|
| 355 | |
|---|
| 356 | self.ui_info = """<menubar> |
|---|
| 357 | <menu action='Manage'> |
|---|
| 358 | <menuitem action='Open'/> |
|---|
| 359 | <menuitem action='Quit'/> |
|---|
| 360 | </menu> |
|---|
| 361 | <menu action='Edit'> |
|---|
| 362 | <menuitem action='Edit'/> |
|---|
| 363 | </menu> |
|---|
| 364 | </menubar> |
|---|
| 365 | """ |
|---|
| 366 | |
|---|
| 367 | |
|---|
| 368 | self.main_action_group.add_actions(self.main_actions) |
|---|
| 369 | self.main_accel_group = gtk.AccelGroup() |
|---|
| 370 | for action in self.main_action_group.list_actions(): |
|---|
| 371 | action.set_accel_group(self.main_accel_group) |
|---|
| 372 | action.connect_accelerator() |
|---|
| 373 | |
|---|
| 374 | self.ui_manager.insert_action_group(self.main_action_group, 0) |
|---|
| 375 | #try: |
|---|
| 376 | self.ui_manager.add_ui_from_string(self.ui_info) |
|---|
| 377 | #except gobject.GError, msg: |
|---|
| 378 | # print "Fails %s" % msg |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | def __create_menubar(self): |
|---|
| 382 | """ |
|---|
| 383 | Create a menubar |
|---|
| 384 | """ |
|---|
| 385 | |
|---|
| 386 | self.menubar = self.ui_manager.get_widget('/menubar') |
|---|
| 387 | self.main_vbox._pack_noexpand_nofill(self.menubar) |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | if __name__ == '__main__': |
|---|
| 391 | p = ProfileWizardEditor() |
|---|
| 392 | p.show_all() |
|---|
| 393 | gtk.main() |
|---|