Esempio n. 1
0
 def __init__(self,  content=""):
     '''
     Initialize InputEntry class.
     '''
     # Init.
     gtk.VBox.__init__(self)
     clean_button = CleanButton()
     clean_button.connect("clicked", self.on_clean_clicked)
     self.entry = Entry(content, place_holder=_("Need some music? Find it here..."))
     entry_align = gtk.Alignment()
     entry_align.set(0.5, 0.5, 1, 1)
     entry_align.add(self.entry)
     
     clean_box = gtk.HBox(spacing=5)
     clean_box.pack_start(entry_align, True, True)
     self.clean_button_align = set_widget_gravity(clean_button, gravity=(0.5, 0.5, 0, 0),
                                             paddings=(0, 0, 0, 5))
     self.clean_button_align.set_no_show_all(True)
     
     clean_box.pack_start(self.clean_button_align, False, False)
     self.add(clean_box)
     
     self.entry.connect("press-return", self.__emit_enter_signal)
     self.entry.connect("changed", self.__on_entry_changed)
     self.connect("expose-event", self.expose_input_entry)
Esempio n. 2
0
 def __init__(self):
     gtk.HBox.__init__(self)
     self.__init_values()
     #
     self.align = gtk.Alignment(0, 0, 1, 1)
     self.ok_btn  = gtk.Button("查询")
     self.text = Entry(
                 content="搜视频...",
                 text_color=self.search_none_color,
                 #enable_clear_button=True
                 )
     #
     w, h = self.search_bg_pixbuf.get_width(), self.search_bg_pixbuf.get_height()
     self.align.set_size_request(w, h)
     ok_w, ok_h = self.search_hover_pixbuf.get_width(), self.search_normal_pixbuf.get_height()
     self.ok_btn.set_size_request(ok_w, ok_h)
     #
     self.text.add_events(gtk.gdk.ALL_EVENTS_MASK)
     self.text.connect("button-press-event", self.__text_button_press_event)
     self.text.connect("motion-notify-event", self.__text_motion_notify_event)
     self.text.connect("enter-notify-event", self.__text_entry_notify_event)
     self.text.connect("leave-notify-event", self.__text_leave_notify_event)
     self.text.clear_button.render = self.paint_clear_button
     #
     self.ok_btn.connect("expose-event", self.__ok_btn_expose_event)
     #
     self.align.add(self.text)
     self.align.connect("expose-event", self.__expose_text_entry)
     #
     self.pack_start(self.align, True, True)
     self.pack_start(self.ok_btn, False, False)
Esempio n. 3
0
class CustomEntry(gtk.VBox):
    __gsignals__ = {
        
        "clear" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
        "enter-press" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
    }
    
    def __init__(self,  content=""):
        '''
        Initialize InputEntry class.
        '''
        # Init.
        gtk.VBox.__init__(self)
        clean_button = CleanButton()
        clean_button.connect("clicked", self.on_clean_clicked)
        self.entry = Entry(content, place_holder=_("Need some music? Find it here..."))
        entry_align = gtk.Alignment()
        entry_align.set(0.5, 0.5, 1, 1)
        entry_align.add(self.entry)
        
        clean_box = gtk.HBox(spacing=5)
        clean_box.pack_start(entry_align, True, True)
        self.clean_button_align = set_widget_gravity(clean_button, gravity=(0.5, 0.5, 0, 0),
                                                paddings=(0, 0, 0, 5))
        self.clean_button_align.set_no_show_all(True)
        
        clean_box.pack_start(self.clean_button_align, False, False)
        self.add(clean_box)
        
        self.entry.connect("press-return", self.__emit_enter_signal)
        self.entry.connect("changed", self.__on_entry_changed)
        self.connect("expose-event", self.expose_input_entry)
        
    def on_clean_clicked(self, widget):    
        # self.emit("clear")
        self.set_text("")
        
    def get_clean_visible(self):    
        return self.clean_button_align.get_visible()
    
    def hide_clean_button(self):
        self.clean_button_align.hide_all()
        self.clean_button_align.set_no_show_all(True)
        
        
    def __emit_enter_signal(self, widget):    
        self.hide_clean_button()
        self.emit("enter-press", self.get_text())
        
    def __on_entry_changed(self, widget, string):    
        if string:
            self.clean_button_align.set_no_show_all(False)
            self.clean_button_align.show_all()
        else:    
            self.clean_button_align.hide_all()
            self.clean_button_align.set_no_show_all(True)

        
    def set_sensitive(self, sensitive):
        '''
        Internal function to wrap function `set_sensitive`.
        '''
        super(InputEntry, self).set_sensitive(sensitive)
        self.entry.set_sensitive(sensitive)
            
    def emit_action_active_signal(self):
        '''
        Internal callback for `action-active` signal.
        '''
        self.emit("action-active", self.get_text())                
        
    def expose_input_entry(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FFFFFF", 0.9)))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
        
        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgba(*color_hex_to_cairo("#C3C4C5"))
            cr.move_to(rect.x + rect.width, rect.y)
            cr.rel_line_to(0, rect.height)
            cr.stroke()
        
        propagate_expose(widget, event)
        
        # return True
    
    def set_size(self, width, height):
        '''
        Set input entry size with given value.
        
        @param width: New width of input entry.
        @param height: New height of input entry.
        '''
        # self.set_size_request(width, height)    
        self.entry.set_size_request(width - 2, height - 2)
        
    def set_editable(self, editable):
        '''
        Set editable status of input entry.
        
        @param editable: input entry can editable if option is True, else can't edit.
        '''
        self.entry.set_editable(editable)
        
    def set_text(self, text):
        '''
        Set text of input entry.
        
        @param text: input entry string.
        '''
        self.entry.set_text(text)
        
    def get_text(self):
        '''
        Get text of input entry.
        
        @return: Return text of input entry.
        '''
        return self.entry.get_text()
    
    def focus_input(self):
        '''
        Focus input cursor.
        '''
        self.entry.grab_focus()
    def double_click(self, widget, item, column):
        if not item.is_select:
            return
        #if not item.clicked:
            #return

        if not column in item.ENTRY_COLUMN:
            return
        if item.entry:
            item.entry.grab_focus()
            return
        item.get_buffer(column)
        item.entry_buffer.set_property('cursor-visible', True)
        hbox = gtk.HBox(False)
        align = gtk.Alignment(0, 0, 1, 1)
        entry = Entry()
        entry.set_data("item", item)
        entry.set_data("button_press", False)
        entry.set_buffer(item.entry_buffer)
        width = item.get_column_widths()[column]
        if width >= 0:
            entry.set_size_request(item.get_column_widths()[column]-4, 0)

        entry.connect("press-return", lambda w: hbox.destroy())
        entry.connect("destroy", self.edit_done, hbox, item)
        entry.connect_after("focus-in-event", self.entry_focus_changed, item)
        entry.connect_after("focus-out-event", self.entry_focus_changed, item)
        self.pack_start(hbox, False, False)
        self.set_data("entry_widget", entry)
        hbox.pack_start(entry, False, False)
        hbox.pack_start(align)
        hbox.show_all()
        entry.set_can_focus(True)
        entry.grab_focus()
        entry.select_all()
        item.entry = entry
Esempio n. 5
0
class Search(gtk.HBox):
    def __init__(self):
        gtk.HBox.__init__(self)
        self.__init_values()
        #
        self.align = gtk.Alignment(0, 0, 1, 1)
        self.ok_btn  = gtk.Button("查询")
        self.text = Entry(
                    content="搜视频...",
                    text_color=self.search_none_color,
                    #enable_clear_button=True
                    )
        #
        w, h = self.search_bg_pixbuf.get_width(), self.search_bg_pixbuf.get_height()
        self.align.set_size_request(w, h)
        ok_w, ok_h = self.search_hover_pixbuf.get_width(), self.search_normal_pixbuf.get_height()
        self.ok_btn.set_size_request(ok_w, ok_h)
        #
        self.text.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.text.connect("button-press-event", self.__text_button_press_event)
        self.text.connect("motion-notify-event", self.__text_motion_notify_event)
        self.text.connect("enter-notify-event", self.__text_entry_notify_event)
        self.text.connect("leave-notify-event", self.__text_leave_notify_event)
        self.text.clear_button.render = self.paint_clear_button
        #
        self.ok_btn.connect("expose-event", self.__ok_btn_expose_event)
        #
        self.align.add(self.text)
        self.align.connect("expose-event", self.__expose_text_entry)
        #
        self.pack_start(self.align, True, True)
        self.pack_start(self.ok_btn, False, False)

    def paint_clear_button(self, cr, rect, offset_y=0):
        if self.clear_check:
            pixbuf = self.clear_hover_pixbuf
        else:
            pixbuf = self.clear_normal_pixbuf
        #
        draw_pixbuf(cr, pixbuf, 
                    rect.x + rect.width + pixbuf.get_width()/2 + 4, 
                    rect.y + rect.height/2 - pixbuf.get_height()/2)

    def __text_button_press_event(self, widget, event):
        if self.text.enable_clear_button and not (event.x < self.text.clear_button_x):
            self.text.set_text("搜视频...")
            self.text.enable_clear_button = False
            self.text.set_editable(False)
            self.text.entry_buffer.text_color = self.search_none_color
        else:
            # 清空掉上面的搜索视频的文本.
            self.text.set_editable(True)
            if self.text.get_text() == "搜视频...":
                self.text.set_text("")
            self.text.entry_buffer.text_color = self.search_input_color
            self.text.enable_clear_button = True
        self.text.queue_draw()

    def __text_entry_notify_event(self, widget, event):
        self.clear_check = True
        self.text.queue_draw()

    def __text_leave_notify_event(self, widget, event):
        self.clear_check = False
        self.text.queue_draw()

    def __text_motion_notify_event(self, widget, event):
        if self.text.enable_clear_button:
            if not (event.x < self.text.clear_button_x):
                self.clear_check = True
                self.text.queue_draw()
            else:
                self.clear_check = False
                self.text.queue_draw()

    def __init_values(self):
        self.clear_check = False
        self.search_none_color = app_theme.get_color("searchNone").get_color()
        self.search_input_color = app_theme.get_color("searchInput").get_color()
        #
        self.search_bg_pixbuf = app_theme.get_pixbuf("net_search/search_bg.png").get_pixbuf()
        self.clear_normal_pixbuf = app_theme.get_pixbuf("net_search/clean_normal.png").get_pixbuf()
        self.clear_hover_pixbuf  = app_theme.get_pixbuf("net_search/clean_hover.png").get_pixbuf()
        self.search_hover_pixbuf = app_theme.get_pixbuf("net_search/search_hover.png").get_pixbuf()
        self.search_normal_pixbuf = app_theme.get_pixbuf("net_search/search_normal.png").get_pixbuf()

    def __expose_text_entry(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        draw_pixbuf(cr, self.search_bg_pixbuf, rect.x, rect.y)
        
        propagate_expose(widget, event)
        
        return True
    
    def __ok_btn_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        #
        if widget.state:
            pixbuf = self.search_normal_pixbuf
        else:
        #elif widget.state:
            pixbuf = self.search_hover_pixbuf
        draw_pixbuf(cr, pixbuf, rect.x, rect.y)
        return True