Changeset 202

Show
Ignore:
Timestamp:
07/11/08 23:26:14 (6 months ago)
Author:
poillubo
Message:

* pycagenconf:

+ custom code generation support
+ added a default size

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/utils/pycagenconf

    r201 r202  
    342342    def __init__(self): 
    343343        self.plugins_vars = list() 
     344 
    344345        hbox = gtk.HBox(False, 0) 
    345346        self.frame_vbox.pack_start(hbox, expand=False) 
     
    420421 
    421422    def __init__(self): 
     423        self.customs_vars = list() 
     424 
    422425        self.frame.connect('map', self.display_vars) 
    423426        self.frame_vbox.pack_start( 
     
    432435            column.add_attribute(cell, 'text', i) 
    433436            self.treeview.append_column(column) 
    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) 
    435488 
    436489    def display_vars(self, _): 
     
    442495            self.treestore.append(None, [var, val]) 
    443496 
     497    def generate_code(self, gen_code): 
     498        gen_vars = ((w(), l(), t()) for w, l, t in self.customs_vars) 
     499        for where, loc, text in gen_vars: 
     500            lcode = gen_code[Locations.locations.index(loc)] 
     501            if where == 'beginning': 
     502                lcode.insert(0, text) 
     503            elif where == 'end': 
     504                lcode.append(text) 
     505 
    444506class GuiGenerator(object): 
    445507    def __init__(self): 
     
    447509        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
    448510        self.window.set_title('PycaWM Config Generator') 
     511        self.window.set_default_size(500, 600) 
    449512        self.window.connect('destroy', gtk.main_quit) 
    450513        vbox = gtk.VBox(False, 10) 
     
    513576if __name__ == '__main__': 
    514577    gui = GuiGenerator() 
    515     gui.loop() 
     578    try: 
     579        gui.loop() 
     580    except KeyboardInterrupt: 
     581        pass