예제 #1
0
class PreferenceDialog(DialogBox):
    
    def __init__(self):
        super(PreferenceDialog, self).__init__(_("Preference"), 575, 495, 
                                               mask_type=DIALOG_MASK_MULTIPLE_PAGE,
                                               close_callback=self.hide_all)
        
        self.set_position(gtk.WIN_POS_CENTER)
        
        self.main_box = gtk.VBox()
        close_button = Button(_("Close"))
        close_button.connect("clicked", lambda w: self.hide_all())
        
        # Init widget.
        self.general_setting = GeneralSetting()
        self.hotkey_setting = HotKeySetting()
        self.desktop_lyrics_setting = DesktopLyricsSetting()
        self.scroll_lyrics_setting = ScrollLyricsSetting()
        
        # Category bar
        self.category_bar = TreeView(font_x_padding=20)
        self.category_bar.draw_mask = self.draw_treeview_mask
        self.general_category_item = CategoryItem(_("General"), self.general_setting)
        self.category_bar.add_item(None, self.general_category_item)
        self.category_bar.add_item(None, CategoryItem(_("Hotkeys"), self.hotkey_setting))
        lyrics_node = self.category_bar.add_item(None, CategoryItem(_("Lyrics")))
        self.category_bar.add_item(lyrics_node, CategoryItem(_("Desktop"), self.desktop_lyrics_setting))
        self.category_bar.add_item(lyrics_node, CategoryItem(_("Window"), self.scroll_lyrics_setting))
        self.category_bar.add_item(None, CategoryItem(_("About us"), AboutBox()))
        self.category_bar.connect("single-click-item", self.category_single_click_cb)
        self.category_bar.set_highlight_index(0)
        
        category_box = gtk.VBox()
        background_box = BackgroundBox()
        background_box.set_size_request(132, 11)
        background_box.draw_mask = self.draw_treeview_mask
        category_box.pack_start(background_box, False, False)
        
        category_scrolled_window = ScrolledWindow()
        category_scrolled_window.add_child(self.category_bar)
        category_scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
        category_scrolled_window.set_size_request(132, 516)
        
        category_scrolled_window_align = gtk.Alignment()
        category_scrolled_window_align.set(0, 0, 1, 1,)
        category_scrolled_window_align.set_padding(0, 1, 0, 0)
        category_scrolled_window_align.add(category_scrolled_window)
        
        category_box.pack_start(category_scrolled_window_align, True, True)
        
        # Pack widget.
        left_box = gtk.VBox()
        self.right_box = gtk.VBox()
        left_box.add(category_box)
        self.right_box.add(self.general_category_item.get_allocated_widget())
        right_align = gtk.Alignment()
        right_align.set_padding(0, 0, 10, 0)
        right_align.add(self.right_box)

        body_box = gtk.HBox()
        body_box.pack_start(left_box, False, False)
        body_box.pack_start(right_align, False, False)
        self.main_box.add(body_box)
        
        # DialogBox code.
        self.body_box.pack_start(self.main_box, True, True)
        self.right_button_box.set_buttons([close_button])        
        
    def switch_lyrics_page(self, index=3):
        self.category_bar.tree_list[2].show_child_items_bool = True
        self.category_bar.sort()
        self.category_bar.queue_draw()
        self.category_bar.set_highlight_index(index)
        highlight_item  = self.category_bar.get_highlight_item()
        self.category_single_click_cb(None, highlight_item)
        
    def show_scroll_lyrics_page(self):
        self.switch_lyrics_page(4)
        self.show_all()
        
    def show_desktop_lyrics_page(self):    
        self.switch_lyrics_page(3)
        self.show_all()
    
    def draw_treeview_mask(self, cr, x, y, width, height):
        draw_alpha_mask(cr, x, y, width, height, ("#FFFFFF", 0.9))
    
    def category_single_click_cb(self, widget, item):
        if item.get_allocated_widget():
            switch_tab(self.right_box, item.get_allocated_widget())