| 434 | | self.frame_vbox.add(self.treeview) |
|---|
| | 437 | self.frame_vbox.pack_start(self.treeview, expand=False) |
|---|
| | 438 | |
|---|
| | 439 | customs_frame = gtk.ScrolledWindow() |
|---|
| | 440 | customs_frame.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| | 441 | customs_vbox = gtk.VBox(False, 0) |
|---|
| | 442 | customs_frame.add_with_viewport(customs_vbox) |
|---|
| | 443 | button = gtk.Button('Add a custom code snippet') |
|---|
| | 444 | button.connect('clicked', self.add_custom, customs_vbox) |
|---|
| | 445 | self.frame_vbox.pack_start(button, expand=False) |
|---|
| | 446 | self.frame_vbox.add(customs_frame) |
|---|
| | 447 | |
|---|
| | 448 | def add_custom(self, _, vbox): |
|---|
| | 449 | custom_frame = gtk.Frame('code snippet') |
|---|
| | 450 | custom_vbox = gtk.VBox(False, 0) |
|---|
| | 451 | custom_vbox.set_size_request(-1, 150) |
|---|
| | 452 | textview = gtk.TextView() |
|---|
| | 453 | scrolled = gtk.ScrolledWindow() |
|---|
| | 454 | scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| | 455 | scrolled.add(textview) |
|---|
| | 456 | custom_vbox.add(scrolled) |
|---|
| | 457 | hbox = gtk.HBox(False, 0) |
|---|
| | 458 | where_box = gtk.combo_box_new_text() |
|---|
| | 459 | where_box.append_text('beginning') |
|---|
| | 460 | where_box.append_text('end') |
|---|
| | 461 | where_box.set_active(0) |
|---|
| | 462 | location_box = gtk.combo_box_new_text() |
|---|
| | 463 | for loc in Locations.locations: |
|---|
| | 464 | location_box.append_text(loc) |
|---|
| | 465 | location_box.set_active(0) |
|---|
| | 466 | hbox.add(gtk.Label(str='Add this at the ')) |
|---|
| | 467 | hbox.add(where_box) |
|---|
| | 468 | hbox.add(gtk.Label(str=' of the ')) |
|---|
| | 469 | hbox.add(location_box) |
|---|
| | 470 | hbox.add(gtk.Label(str=' section')) |
|---|
| | 471 | custom_vbox.pack_start(hbox, expand=False) |
|---|
| | 472 | textbuffer = textview.get_buffer() |
|---|
| | 473 | custom_vars = (where_box.get_active_text, location_box.get_active_text, |
|---|
| | 474 | lambda: textbuffer.get_text(textbuffer.get_start_iter(), |
|---|
| | 475 | textbuffer.get_end_iter())) |
|---|
| | 476 | self.customs_vars.append(custom_vars) |
|---|
| | 477 | button = gtk.Button('remove code snippet') |
|---|
| | 478 | button.connect('clicked', self.remove_custom, vbox, custom_frame, |
|---|
| | 479 | custom_vars) |
|---|
| | 480 | custom_vbox.pack_start(button, expand=False) |
|---|
| | 481 | custom_frame.add(custom_vbox) |
|---|
| | 482 | vbox.add(custom_frame) |
|---|
| | 483 | self.frame.show_all() |
|---|
| | 484 | |
|---|
| | 485 | def remove_custom(self, _, vbox, custom_frame, custom_vars): |
|---|
| | 486 | vbox.remove(custom_frame) |
|---|
| | 487 | self.customs_vars.remove(custom_vars) |
|---|