def draw_cursor(self, cr, rect): x, y, w, h = rect.x, rect.y, rect.width, rect.height cursor_ir = self.__buffer.get_iter_at_cursor() left_str = cursor_ir.get_line_text()[0:cursor_ir.get_line_offset()] left_str_width = self.get_content_width(left_str) current_line = cursor_ir.get_line() line_offset = 0 utf_8_height = get_content_size("好Height", self.font_size)[-1] no_utf_8_height = get_content_size("Height", self.font_size)[-1] for x in range(0, current_line): if self.__is_utf_8_text_in_line(x): line_offset += utf_8_height else: line_offset += no_utf_8_height temp_line_offset = 1 # solve the offset problem while adding lines cr.set_source_rgb(0,0,0) cr.rectangle(x + self.padding_x + left_str_width - temp_line_offset * current_line, y + line_offset + utf_8_height - no_utf_8_height , 1, no_utf_8_height) cr.fill()
def update_size(self): '''Update size.''' if self.label_width == None: (label_width, label_height) = get_content_size(self.text, self.text_size, wrap_width=self.wrap_width) else: (label_width, label_height) = get_content_size(self.text, self.text_size, wrap_width=self.wrap_width) label_width = self.label_width if self.enable_gaussian: label_width += self.gaussian_radious * 2 label_height += self.gaussian_radious * 2 self.set_size_request(label_width, label_height)
def __time_label_press(self, widget, event): (self.time_width, text_height) = get_content_size("12") (self.time_comma_width, text_comma_height) = get_content_size(" : ") if event.x < self.padding_x + self.time_width: self.set_time = self.SET_HOUR return if event.x > self.padding_x + self.time_width and event.x < self.padding_x + (self.time_width + self.time_comma_width) * 2: self.set_time = self.SET_MIN return if event.x > self.padding_x + self.time_width + self.time_comma_width * 2: self.set_time = self.SET_SEC return
def __init__(self, item, index, font_size, icon_width, padding_left, padding_middle, padding_right, set_index, get_index): '''Init category item.''' # Init. gtk.Button.__init__(self) self.font_size = font_size self.index = index self.set_index = set_index self.get_index = get_index self.padding_left = padding_left self.padding_right = padding_right (self.icon_dpixbuf, self.content, self.clicked_callback) = item (content_width, font_height) = get_content_size(self.content, self.font_size) # Init item button. self.font_offset = 0 if icon_width == 0: self.font_offset = 0 else: self.font_offset = padding_middle + icon_width self.set_size_request( padding_left + self.font_offset + content_width + padding_right, -1 ) self.connect("expose-event", self.expose_category_item) self.connect("clicked", lambda w: self.wrap_category_item_clicked_action())
def get_valid_image_obj(self, img_objs): """ Find the valid BeautifulSoup image object from the various different image objects present in the current page or URL based on string matching of the image link and base_url, and the size of the image in the image obj. :param img_objs: List of all BeautifulSoup image objects present in the current page """ maxval = 0 match_obj = None for img_obj in img_objs: img_size = get_content_size(img_obj['src'].strip(), self.proxy_dict) if 'alt' in img_obj.attrs: sequence_match_ratio = sm(None, str(img_obj['alt']), self.base_url.replace("http", "")).ratio() if sequence_match_ratio > maxval and img_size > 99999: maxval = sm(None, str(img_obj['alt']), self.base_url).ratio() match_obj = img_obj return match_obj
def draw_ip(self, cr, rect): x, y, w, h = rect.x, rect.y, rect.width, rect.height ip_segment_distance = self.width / self.segment_number for (ip_segment_index, ip_segment) in enumerate(self.ip.split(self.segment_split_char)): text_color = "#000000" if ip_segment_index == self.highlight_segment_index: (ip_segment_width, ip_segment_height) = get_content_size(ip_segment) if self.grab_focus_flag: background_color = self.select_active_color.get_color_info() else: background_color = self.select_inactive_color.get_color_info() draw_hlinear( cr, x + ip_segment_index * ip_segment_distance + (ip_segment_distance - ip_segment_width) / 2, y + self.cursor_padding_y, ip_segment_width + 1, h - self.cursor_padding_y * 2, background_color, ) text_color = "#FFFFFF" draw_text(cr, ip_segment, x + ip_segment_index * ip_segment_distance, y, ip_segment_distance, h, alignment=pango.ALIGN_CENTER, text_color=text_color, )
def realize_item_box(self, widget, item_content): ''' Internal function, realize item box. @param widget: DropItem widget. @param item_content: Item content. ''' # Set button size. (width, height) = get_content_size(item_content, self.font_size) self.item_box_height = self.item_padding_y * 2 + int(height) self.item_box_width = self.item_padding_left + self.item_padding_right + int( width) if self.fixed_width != None: self.item_box_width = self.fixed_width elif self.max_width != None: ''' when max_width > item_box_width, it might choosing the max one ''' self.item_box_width = max(self.item_box_width, self.max_width) else: self.item_box_width = self.item_box_width self.item_box.set_size_request(self.item_box_width, self.item_box_height)
def __init__(self, title, item_value, item_width=None, font_size=DEFAULT_FONT_SIZE, ): ''' Initialize ComboTextItem class. @param title: Title of item, we use this for display name (include internationalization). @param item_value: The value of item, use for index item in program. @param item_width: The width of item, default is None to calculate width with item content. @param font_size: Font size of item, default is DEFAULT_FONT_SIZE. ''' AbstractItem.__init__(self) self.column_index = 0 self.item_height = 22 self.spacing_x = 15 self.padding_x = 5 self.font_size = font_size if item_width == None: self.item_width, _ = get_content_size(title, font_size) self.item_width += self.spacing_x * 2 else: self.item_width = item_width self.title = title self.item_value = item_value
def calculate_tab_width(self): ''' Internal function to calculate tab width. ''' self.icon_width = 0 max_tab_content_width = 0 for (item_icon, item_content, item_callback) in self.items: if self.icon_width == 0 and item_icon != None: self.icon_width = item_icon.get_pixbuf().get_width() (content_width, content_height) = get_content_size(item_content, DEFAULT_FONT_SIZE) if content_width > max_tab_content_width: max_tab_content_width = content_width tab_image_height = self.foreground_left_pixbuf.get_pixbuf().get_height( ) if self.icon_width == 0: tab_width = self.padding_side * 2 + max_tab_content_width else: tab_width = self.padding_side * 2 + self.padding_middle + self.icon_width + max_tab_content_width return (tab_width, tab_image_height)
def __init__(self, element, index, font_size, padding_x, padding_y, vertical, set_index, get_index, item_hover_pixbuf, item_press_pixbuf, ): ''' Initialize NavItem class. @param element: Item format: (item_icon_dpixbuf, item_content, clicked_callback) @param index: Item index. @param font_size: Font size. @param padding_x: Padding value horizontal. @param padding_y: Padding value vertical. @param vertical: Draw direction. @param set_index: Set index callback. @param get_index: Get index callback. @param item_hover_pixbuf: Item hover pixbuf. @param item_press_pixbuf: Item press pixbuf. ''' # Init. self.index = index self.font_size = font_size self.vertical = vertical self.set_index = set_index self.get_index = get_index self.item_hover_pixbuf = item_hover_pixbuf self.item_press_pixbuf = item_press_pixbuf self.notify_num = 0 (self.icon_dpixbuf, self.content, self.clicked_callback) = element self.nav_item_pixbuf = self.icon_dpixbuf.get_pixbuf() pixbuf = self.item_hover_pixbuf.get_pixbuf() (self.text_width, self.text_height) = get_content_size(self.content, self.font_size) # Init item button. self.pixbuf_width_scale = False self.item_button = gtk.Button() if self.text_width + self.nav_item_pixbuf.get_width() > pixbuf.get_width(): self.item_button.set_size_request( self.text_width + self.nav_item_pixbuf.get_width()+ 10, pixbuf.get_height()) self.pixbuf_width_scale = True else: self.item_button.set_size_request(pixbuf.get_width(), pixbuf.get_height()) widget_fix_cycle_destroy_bug(self.item_button) self.item_button.connect("expose-event", self.expose_nav_item) self.item_button.connect("clicked", lambda w: self.wrap_nav_item_clicked_action()) # Init item box. self.item_box = gtk.Alignment() self.item_box.set(0.5, 0.5, 1.0, 1.0) self.item_box.set_padding(padding_y, padding_y, padding_x, padding_x) self.item_box.add(self.item_button)
def __time_label_press(self, widget, event): (self.time_width, text_height) = get_content_size("12") (self.time_comma_width, text_comma_height) = get_content_size(" : ") if event.x < self.padding_x + self.time_width: self.set_time = self.SET_HOUR return if event.x > self.padding_x + self.time_width and event.x < self.padding_x + ( self.time_width + self.time_comma_width) * 2: self.set_time = self.SET_MIN return if event.x > self.padding_x + self.time_width + self.time_comma_width * 2: self.set_time = self.SET_SEC return
def calculate_cursor_positions(self): self.cursor_positions = [] ip_segment_distance = self.width / self.segment_number ip_segments = self.ip.split(self.segment_split_char) for (ip_segment_index, ip_segment) in enumerate(ip_segments): if len(ip_segment) == 0: self.cursor_positions.append(ip_segment_distance * ip_segment_index + ip_segment_distance / 2) else: (ip_segment_width, ip_segment_height) = get_content_size(ip_segment) ip_segment_x = ip_segment_distance * ip_segment_index ip_segment_offset_x = (ip_segment_distance - ip_segment_width) / 2 ip_char_width = ip_segment_width / len(ip_segment) # Append ip char position. for (ip_char_index, ip_char) in enumerate(ip_segment): self.cursor_positions.append(ip_segment_x + ip_segment_offset_x + ip_char_width * ip_char_index) # Append the position of last char in ip segment. self.cursor_positions.append(ip_segment_x + ip_segment_offset_x + ip_char_width * (ip_char_index + 1))
def calculate_cursor_positions(self): self.cursor_positions = [] mac_segment_distance = self.width / self.segment_number mac_segments = self.mac.split(self.segment_split_char) for (mac_segment_index, mac_segment) in enumerate(mac_segments): if len(mac_segment) == 0: self.cursor_positions.append(mac_segment_distance * mac_segment_index + mac_segment_distance / 2) else: (mac_segment_width, mac_segment_height) = get_content_size(mac_segment) mac_segment_x = mac_segment_distance * mac_segment_index mac_segment_offset_x = (mac_segment_distance - mac_segment_width) / 2 mac_char_width = mac_segment_width / len(mac_segment) # Append mac char position. for (mac_char_index, mac_char) in enumerate(mac_segment): self.cursor_positions.append(mac_segment_x + mac_segment_offset_x + mac_char_width * mac_char_index) # Append the position of last char in mac segment. self.cursor_positions.append(mac_segment_x + mac_segment_offset_x + mac_char_width * (mac_char_index + 1))
def __init__( self, title, item_value, item_width=None, font_size=DEFAULT_FONT_SIZE, ): ''' Initialize ComboTextItem class. @param title: Title of item, we use this for display name (include internationalization). @param item_value: The value of item, use for index item in program. @param item_width: The width of item, default is None to calculate width with item content. @param font_size: Font size of item, default is DEFAULT_FONT_SIZE. ''' AbstractItem.__init__(self) self.column_index = 0 self.item_height = 22 self.spacing_x = 15 self.padding_x = 5 self.font_size = font_size if item_width == None: self.item_width, _ = get_content_size(title, font_size) self.item_width += self.spacing_x * 2 else: self.item_width = item_width self.title = title self.item_value = item_value
def __init__(self, tab_names, font_size=11, padding_x=0, padding_y=0): """ Initialize TabSwitcher class. @param tab_names: The name of tabs. @param padding_x: The padding x around tab name, default is 0 pixel. @param padding_y: The padding y around tab name, default is 0 pixel. """ EventBox.__init__(self) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.tab_names = tab_names self.tab_name_size = font_size self.tab_number = len(self.tab_names) tab_sizes = map(lambda tab_name: get_content_size(tab_name, self.tab_name_size), self.tab_names) self.tab_name_padding_x = 10 self.tab_name_padding_y = 2 self.tab_width = max(map(lambda (width, height): width, tab_sizes)) + self.tab_name_padding_x * 2 self.tab_height = tab_sizes[0][1] + self.tab_name_padding_y * 2 self.tab_line_height = 3 self.tab_index = 0 self.tab_animation_x = 0 self.tab_animation_time = 200 # milliseconds self.padding_x = padding_x self.padding_y = padding_y self.in_animiation = False self.line_dcolor = ui_theme.get_color("globalItemHighlight") self.set_size_request(-1, self.tab_height + self.tab_line_height) self.connect("realize", self.realize_tab_switcher) self.connect("expose-event", self.expose_tab_switcher) self.connect("button-press-event", self.button_press_tab_switcher)
def set_label(self, label, font_size=DEFAULT_FONT_SIZE): '''Set label.''' self.label = label (self.label_width, self.label_height) = get_content_size(label, self.font_size) self.set_size_request(max(self.label_width + self.padding_x * 2, self.min_width), max(self.label_height + self.padding_y * 2, self.min_height)) self.queue_draw()
def add_items(self, items, default_index=0): '''Add items.''' self.tab_items += items for item in items: self.tab_title_widths.append(get_content_size(item[0], DEFAULT_FONT_SIZE)[0] + self.tab_padding_x * 2) self.switch_content(default_index)
def get_droplist_width(self): '''Get droplist width.''' item_content_width = max(map(lambda item: get_content_size(item.item[0], self.font_size)[0], filter(lambda item: isinstance(item.item_box, gtk.Button), self.droplist_items))) if self.max_width != None: return self.padding_x * 2 + min(self.max_width, self.item_padding_left + self.item_padding_right + int(item_content_width)) else: return self.padding_x * 2 + self.item_padding_left + self.item_padding_right + int(item_content_width)
def get_content_width(self, content): ''' Internal fucntion to get content width. ''' (content_width, content_height) = get_content_size(content, self.text_size, wrap_width=self.wrap_width) return content_width
def get_tab_width(self, tab_name): ''' docs ''' (text_width, text_height) = get_content_size(tab_name) tab_height = self.height triangle_width = int(tab_height / math.tan(math.radians(self.tab_angle))) middle_width = text_width + self.tab_name_padding_x * 2 return middle_width + self.tab_radious * 4 + triangle_width * 2
def show(self, text): ''' Show. @param text: OSD tooltip text. ''' # Remove callback.j remove_signal_id(self.configure_event_callback_id) remove_signal_id(self.destroy_callback_id) remove_signal_id(self.focus_out_callback_id) remove_timeout_id(self.start_hide_callback_id) # Update text. self.text = text # Get tooltip size. (tooltip_width, tooltip_height) = get_content_size( self.text, self.text_size + self.border_radious * 2, self.text_font) self.tooltip_width = tooltip_width * 2 self.tooltip_height = tooltip_height # Move tooltip to given position. (monitor_x, monitor_y) = self.monitor_widget.window.get_origin() self.tooltip_x = monitor_x + self.offset_x self.tooltip_y = monitor_y + self.offset_y # Monitor configure-event signal. self.monitor_window = self.monitor_widget.get_toplevel() configure_event_handler_id = self.monitor_window.connect("configure-event", self.handle_configure_event) self.configure_event_callback_id = (self.monitor_window, configure_event_handler_id) destroy_handler_id = self.monitor_window.connect("destroy", lambda w: self.hide_immediately()) self.destroy_callback_id = (self.monitor_window, destroy_handler_id) focus_out_handler_id = self.monitor_window.connect("focus-out-event", lambda w, e: self.hide_immediately()) self.focus_out_callback_id = (self.monitor_window, focus_out_handler_id) # Save monitor window position. rect = self.monitor_window.allocation (monitor_window_x, monitor_window_y) = self.monitor_window.window.get_origin() monitor_window_width, monitor_window_height = rect.width, rect.height self.monitor_window_x = monitor_window_x self.monitor_window_y = monitor_window_y self.monitor_window_width = monitor_window_width self.monitor_window_height = monitor_window_height # Show. self.set_opacity(1) self.show_all() self.start_hide_callback_id = gobject.timeout_add( self.start_hide_delay, lambda : Animation(self, "opacity", self.hide_time, [1, 0], stop_callback=self.hide_immediately).start()) self.queue_draw() # make sure redraw
def __init__(self, label_content, label_wrap_width, label_init_height, label_init_line, label_font_size, label_font_color, animation_time=200, # milliseconds ): ''' Initialize ResizableLabelBuffer class. @param label_content: The content of label. @param label_wrap_width: The wrap width of label. @param label_init_height: The initialize height of label. @param label_init_line: The initialize line number of label. @param label_font_size: The font size. @param label_font_color: The font color. @param animation_time: The time of animation, default is 200 milliseconds. ''' gobject.GObject.__init__(self) self.label_content = label_content self.label_init_height = label_init_height self.label_init_line = label_init_line self.label_font_size = label_font_size self.label_font_color = label_font_color self.label_wrap_width = label_wrap_width self.animation_time = animation_time self.in_animation = False self.label_line_height = int(float(self.label_init_height / self.label_init_line)) self.label_expand_height = self.label_line_height * 2 (self.max_width, self.max_height) = self.get_max_size() self.is_expandable = not (self.max_height <= self.label_init_height) (self.init_width, self.init_height) = self.get_init_size() self.has_expand = False (self.expand_width, self.expand_height) = self.get_expand_size() self.expand_button_content = _("Expand") self.shrink_button_content = _("Shrink") (self.expand_button_width, self.expand_button_height) = get_content_size(self.expand_button_content, self.label_font_size) (self.shrink_button_width, self.shrink_button_height) = get_content_size(self.shrink_button_content, self.label_font_size)
def realize_item_box(self, widget, item_content): '''Realize item box.''' # Set button size. (width, height) = get_content_size(item_content, self.font_size) self.item_box_height = self.item_padding_y * 2 + int(height) self.item_box_width = self.item_padding_left + self.item_padding_right + int(width) if self.max_width != None: self.item_box_width = min(self.item_box_width, self.max_width) else: self.item_box_width = self.item_box_width self.item_box.set_size_request(self.item_box_width, self.item_box_height)
def add_items(self, items, default_index=0): ''' Add items. @param items: A list of tab item, tab item format: (tab_name, tab_widget) @param default_index: Initialize index, default is 0. ''' self.tab_items += items for item in items: self.tab_title_widths.append(get_content_size(item[0], DEFAULT_FONT_SIZE)[0] + self.tab_padding_x * 2) self.switch_content(default_index)
def __init__(self, icon_dpixbufs, text, text_size=DEFAULT_FONT_SIZE, icon_width=16, padding_x=10, padding_y=6): """ Initialize IconTextItem class. """ # Init. TreeItem.__init__(self) (self.icon_normal_dpixbuf, self.icon_hover_dpixbuf, self.icon_disable_dpixbuf) = icon_dpixbufs self.item_width = 160 self.text = text self.text_size = text_size self.icon_width = 16 self.padding_x = padding_x self.padding_y = padding_y (self.text_width, self.text_height) = get_content_size(self.text)
def realize_item_box(self, widget, item_content): '''Realize item box.''' # Set button size. (width, height) = get_content_size(item_content, self.font_size) self.item_box_height = self.item_padding_y * 2 + max(int(height), self.icon_height) if self.select_scale: self.item_box_width = widget.get_parent().get_parent().allocation.width else: self.item_box_width = self.item_padding_x * 3 + self.icon_width + int(width) if self.have_submenu: self.item_box_width += self.item_padding_x + self.submenu_width + self.arrow_padding_x * 2 self.item_box_width = max(self.item_box_width, self.min_width) self.item_box.set_size_request(self.item_box_width, self.item_box_height)
def __init__(self, item, index, font_size, icon_width, padding_left, padding_middle, padding_right, set_index, get_index): ''' Initialize CategoryItem class. @param item: Category item, format: (item_dpixbuf, content, click_callback) @param index: Category item index. @param font_size: Font size. @param icon_width: Icon width. @param padding_left: Padding at left of item. @param padding_middle: Padding between icon and font. @param padding_right: Padding at right of item. @param set_index: Set index callback. @param get_index: Get index callback. ''' # Init. gtk.Button.__init__(self) self.font_size = font_size self.index = index self.set_index = set_index self.get_index = get_index self.padding_left = padding_left self.padding_right = padding_right (self.icon_dpixbuf, self.content, self.clicked_callback) = item (content_width, font_height) = get_content_size(self.content, self.font_size) # Init item button. self.font_offset = 0 if icon_width == 0: self.font_offset = 0 else: self.font_offset = padding_middle + icon_width self.set_size_request( padding_left + self.font_offset + content_width + padding_right, -1 ) self.connect("expose-event", self.expose_category_item) self.connect("clicked", lambda w: self.wrap_category_item_clicked_action())
def draw_entry_cursor(self, cr, rect): '''Draw entry cursor.''' if self.grab_focus_flag and self.select_start_index == self.select_end_index: # Init. x, y, w, h = rect.x, rect.y, rect.width, rect.height left_str = self.content[0:self.cursor_index] left_str_width = self.get_content_width(left_str) padding_y = (h - (get_content_size("Height", self.font_size)[-1])) / 2 # Draw cursor. cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("entry_cursor").get_color())) cr.rectangle(x + self.padding_x + left_str_width - self.offset_x, y + padding_y, 1, h - padding_y * 2 ) cr.fill()
def update_size(self): ''' Internal function to update size. ''' (label_width, label_height) = get_content_size(self.text, self.text_size, wrap_width=self.wrap_width) if self.label_width != None: if self.update_size_hook != None: self.update_size_hook(self, label_width, self.label_width) label_width = self.label_width if self.enable_gaussian: label_width += self.gaussian_radious * 2 label_height += self.gaussian_radious * 2 if self.fixed_width: label_width = self.fixed_width self.set_size_request(label_width, label_height)
def add_items(self, items, default_index=0): ''' Add items. @param items: A list of tab item, tab item format: (tab_name, tab_widget) @param default_index: Initialize index, default is 0. ''' self.tab_items += items for item in items: self.tab_title_widths.append( get_content_size(item[0], DEFAULT_FONT_SIZE)[0] + self.tab_padding_x * 2) if self.current_tab_index < 0: self.switch_content(default_index) else: self.switch_content(self.current_tab_index)
def realize_item_box(self, widget, item_content): ''' Internal function, realize item box. @param widget: DropItem widget. @param item_content: Item content. ''' # Set button size. (width, height) = get_content_size(item_content, self.font_size) self.item_box_height = self.item_padding_y * 2 + int(height) self.item_box_width = self.item_padding_left + self.item_padding_right + int(width) if self.max_width != None: self.item_box_width = min(self.item_box_width, self.max_width) else: self.item_box_width = self.item_box_width self.item_box.set_size_request(self.item_box_width, self.item_box_height)
def draw_button(widget, cache_pixbuf, normal_dpixbuf, hover_dpixbuf, press_dpixbuf, scale_x=False, button_label=None, font_size=DEFAULT_FONT_SIZE, label_dcolor=ui_theme.get_color("button_default_font")): '''Create button.''' # Init request size. if scale_x: request_width = get_content_size(button_label, font_size)[0] else: request_width = normal_dpixbuf.get_pixbuf().get_width() request_height = normal_dpixbuf.get_pixbuf().get_height() widget.set_size_request(request_width, request_height) # Expose button. widget.connect("expose-event", lambda w, e: expose_button( w, e, cache_pixbuf, scale_x, False, normal_dpixbuf, hover_dpixbuf, press_dpixbuf, button_label, font_size, label_dcolor))
def calculate_tab_width(self): """Calculate tab width.""" self.icon_width = 0 max_tab_content_width = 0 for (item_icon, item_content, item_callback) in self.items: if self.icon_width == 0 and item_icon != None: self.icon_width = item_icon.get_pixbuf().get_width() (content_width, content_height) = get_content_size(item_content, DEFAULT_FONT_SIZE) if content_width > max_tab_content_width: max_tab_content_width = content_width tab_image_height = self.foreground_left_pixbuf.get_pixbuf().get_height() if self.icon_width == 0: tab_width = self.padding_side * 2 + max_tab_content_width else: tab_width = self.padding_side * 2 + self.padding_middle + self.icon_width + max_tab_content_width return (tab_width, tab_image_height)
def __init__(self, icon_dpixbufs, text, text_size=DEFAULT_FONT_SIZE, icon_width=16, padding_x=10, padding_y=6): ''' Initialize IconTextItem class. ''' # Init. TreeItem.__init__(self) (self.icon_normal_dpixbuf, self.icon_hover_dpixbuf, self.icon_disable_dpixbuf) = icon_dpixbufs self.item_width = 160 self.text = text self.text_size = text_size self.icon_width = 16 self.padding_x = padding_x self.padding_y = padding_y (self.text_width, self.text_height) = get_content_size(self.text)
def draw_value(self, cr, rect, text, value, type_=None, mark_check=False): text_width, text_height = get_content_size(text) text_y = rect.y if gtk.POS_TOP == type_: text_y = text_y if gtk.POS_BOTTOM == type_: text_y = rect.y + (rect.height-self.bottom_space)/2 + self.point_height + self.bottom_space - text_height/2 x = rect.x + int(float(value) / self.value_max * (rect.width - self.point_width)) max_value = max(x - (text_width/2 - self.point_width/2), rect.x) min_value = min(max_value, rect.x + rect.width - text_width) if self.enable_check: draw_text(cr, text, min_value, text_y, rect.width, 0) else: draw_text(cr, text, min_value, text_y, rect.width, 0, DEFAULT_FONT_SIZE, self.bg_side_color) mark_y = text_y-self.bottom_space/2-(self.point_height-self.line_height)/2 if mark_check: cr.set_source_rgb(*color_hex_to_cairo(self.bg_side_color)) cr.rectangle(x + self.point_width/2, mark_y, self.mark_width, self.mark_height) cr.fill()
def realize_item_box(self, widget, item_content): ''' Internal callback for `realize` signal. ''' # Set button size. (width, height) = get_content_size(item_content, self.font_size) self.item_box_height = self.item_padding_y * 2 + max( int(height), self.icon_height) if self.select_scale: self.item_box_width = widget.get_parent().get_parent( ).allocation.width else: self.item_box_width = self.item_padding_x * 3 + self.icon_width + int( width) if self.have_submenu: self.item_box_width += self.item_padding_x + self.submenu_width + self.arrow_padding_x * 2 self.item_box_width = max(self.item_box_width, self.min_width) self.item_box.set_size_request(self.item_box_width, self.item_box_height)
def expose_textview(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # draw text self.draw_text(cr, rect) # draw cursor if self.grab_focus_flag: self.draw_cursor(cr, rect) propagate_expose(widget, event) # resize widget for scrolledwindow-support max = 0 for x in range(0, self.__buffer.get_line_count()): if max < self.get_content_width(self.__buffer.get_iter_at_line(x).get_line_text()): max = self.get_content_width(self.__buffer.get_iter_at_line(x).get_line_text()) height = get_content_size("好Height", self.font_size)[-1] * (self.__buffer.get_iter_at_cursor().get_line()) self.set_size_request(max + 10, height) return True
def __init__(self, inactive_normal_dpixbuf, active_normal_dpixbuf, inactive_hover_dpixbuf=None, active_hover_dpixbuf=None, inactive_press_dpixbuf=None, active_press_dpixbuf=None, inactive_disable_dpixbuf=None, active_disable_dpixbuf=None, button_label=None, padding_x=0): '''Init font button.''' gtk.ToggleButton.__init__(self) font_size = DEFAULT_FONT_SIZE label_dcolor = ui_theme.get_color("button_default_font") self.button_press_flag = False self.inactive_pixbuf_group = (inactive_normal_dpixbuf, inactive_hover_dpixbuf, inactive_press_dpixbuf, inactive_disable_dpixbuf) self.active_pixbuf_group = (active_normal_dpixbuf, active_hover_dpixbuf, active_press_dpixbuf, active_disable_dpixbuf) # Init request size. label_width = 0 button_width = inactive_normal_dpixbuf.get_pixbuf().get_width() button_height = inactive_normal_dpixbuf.get_pixbuf().get_height() if button_label: label_width = get_content_size(button_label, font_size)[0] self.set_size_request(button_width + label_width + padding_x * 2, button_height) self.connect("button-press-event", self.button_press_cb) self.connect("button-release-event", self.button_release_cb) # Expose button. self.connect("expose-event", lambda w, e : self.expose_toggle_button( w, e, button_label, padding_x, font_size, label_dcolor))
def draw_ip(self, cr, rect): x, y, w, h = rect.x, rect.y, rect.width, rect.height ip_segment_distance = self.width / self.segment_number for (ip_segment_index, ip_segment) in enumerate(self.ip.split(self.segment_split_char)): text_color = "#000000" if ip_segment_index == self.highlight_segment_index: (ip_segment_width, ip_segment_height) = get_content_size(ip_segment) if self.grab_focus_flag: background_color = self.select_active_color.get_color_info( ) else: background_color = self.select_inactive_color.get_color_info( ) draw_hlinear( cr, x + ip_segment_index * ip_segment_distance + (ip_segment_distance - ip_segment_width) / 2, y + self.cursor_padding_y, ip_segment_width + 1, h - self.cursor_padding_y * 2, background_color, ) text_color = "#FFFFFF" draw_text( cr, ip_segment, x + ip_segment_index * ip_segment_distance, y, ip_segment_distance, h, alignment=pango.ALIGN_CENTER, text_color=text_color, )
def set_label(self, label, font_size = DEFAULT_FONT_SIZE): ''' Set label for left button. @param label: Label @param font_size: Label's Font size, default is DEFAULT_FONT_SIZE. ''' self.label = label (self.label_w, self.label_h) = get_content_size(self.label, font_size) if self.menu == None: self.set_size_request( max(self.label_w + 2 * self.padding_x, self.btn_min), self.height) self.button_width = self.get_size_request()[0] else: self.set_size_request( max(self.label_w + 2 * self.padding_x + self.menu_min, self.btn_min + self.menu_min), self.height) self.button_width = self.get_size_request()[0] - self.menu_min self.queue_draw()
def get_droplist_width(self): ''' Get droplist width. @return: Return width of droplist. ''' if self.fixed_width != None: return self.padding_x * 2 + self.fixed_width else: item_content_width = max( map( lambda item: get_content_size(item.item[0], self.font_size) [0], filter(lambda item: isinstance(item.item_box, gtk.Button), self.droplist_items))) if self.max_width != None: return self.padding_x * 2 + min( self.max_width, self.item_padding_left + self.item_padding_right + int(item_content_width)) else: return self.padding_x * 2 + self.item_padding_left + self.item_padding_right + int( item_content_width)
def set_label(self, label, font_size=DEFAULT_FONT_SIZE): ''' Set label for left button. @param label: Label @param font_size: Label's Font size, default is DEFAULT_FONT_SIZE. ''' self.label = label (self.label_w, self.label_h) = get_content_size(self.label, font_size) if self.menu == None: self.set_size_request( max(self.label_w + 2 * self.padding_x, self.btn_min), self.height) self.button_width = self.get_size_request()[0] else: self.set_size_request( max(self.label_w + 2 * self.padding_x + self.menu_min, self.btn_min + self.menu_min), self.height) self.button_width = self.get_size_request()[0] - self.menu_min self.queue_draw()
def __init__( self, element, index, font_size, padding_x, padding_y, vertical, set_index, get_index, item_hover_pixbuf, item_press_pixbuf, ): ''' Initialize NavItem class. @param element: Item format: (item_icon_dpixbuf, item_content, clicked_callback) @param index: Item index. @param font_size: Font size. @param padding_x: Padding value horizontal. @param padding_y: Padding value vertical. @param vertical: Draw direction. @param set_index: Set index callback. @param get_index: Get index callback. @param item_hover_pixbuf: Item hover pixbuf. @param item_press_pixbuf: Item press pixbuf. ''' # Init. self.index = index self.font_size = font_size self.vertical = vertical self.set_index = set_index self.get_index = get_index self.item_hover_pixbuf = item_hover_pixbuf self.item_press_pixbuf = item_press_pixbuf self.notify_num = 0 (self.icon_dpixbuf, self.content, self.clicked_callback) = element self.nav_item_pixbuf = self.icon_dpixbuf.get_pixbuf() pixbuf = self.item_hover_pixbuf.get_pixbuf() (self.text_width, self.text_height) = get_content_size(self.content, self.font_size) # Init item button. self.pixbuf_width_scale = False self.item_button = gtk.Button() if self.text_width + self.nav_item_pixbuf.get_width( ) > pixbuf.get_width(): self.item_button.set_size_request( self.text_width + self.nav_item_pixbuf.get_width() + 10, pixbuf.get_height()) self.pixbuf_width_scale = True else: self.item_button.set_size_request(pixbuf.get_width(), pixbuf.get_height()) widget_fix_cycle_destroy_bug(self.item_button) self.item_button.connect("expose-event", self.expose_nav_item) self.item_button.connect("clicked", lambda w: self.wrap_nav_item_clicked_action()) # Init item box. self.item_box = gtk.Alignment() self.item_box.set(0.5, 0.5, 1.0, 1.0) self.item_box.set_padding(padding_y, padding_y, padding_x, padding_x) self.item_box.add(self.item_button)
def get_modification_time_width(time): return get_content_size(time)[0] + MODIFICATION_TIME_PADDING_LEFT
def __init__(self): ''' Initialize MACEntry class. ''' gtk.VBox.__init__(self) self.width = 130 self.height = 22 self.set_size_request(self.width, self.height) self.normal_frame = ui_theme.get_color("entry_normal_frame") self.alert_frame = ui_theme.get_color("entry_alert_frame") self.frame_color = self.normal_frame self.default_address = ":::::" self.mac = self.default_address self.grab_focus_flag = False self.segment_split_char = ":" self.dot_size = get_content_size(self.segment_split_char)[0] self.chars_a_z = map(lambda a: str(chr(a)), range(97, 103)) self.chars_A_Z = map(lambda a: str(chr(a)), range(65, 71)) self.mac_chars = self.chars_a_z + self.chars_A_Z + map( str, range(0, 10)) + [self.segment_split_char] self.select_active_color = ui_theme.get_shadow_color( "select_active_background") self.select_inactive_color = ui_theme.get_shadow_color( "select_inactive_background") self.segment_number = 6 self.last_segment_index = self.segment_number - 1 self.segment_max_chars = 2 self.cursor_index = 0 self.cursor_padding_y = 2 self.cursor_positions = [] self.cursor_segment_index = 0 self.highlight_segment_index = None self.cursor_alpha = 1 self.cursor_blank_id = None self.edit_complete_flag = True self.edit_timeout_id = None self.draw_area = gtk.EventBox() self.draw_area.set_visible_window(False) self.draw_area.add_events(gtk.gdk.ALL_EVENTS_MASK) self.draw_area.set_can_focus( True) # can focus to response key-press signal self.pack_start(self.draw_area, True, True, 1) self.draw_area.connect("button-press-event", self.button_press_mac_entry) self.draw_area.connect("key-press-event", self.key_press_mac_entry) self.draw_area.connect("expose-event", self.expose_mac_entry) self.draw_area.connect("focus-in-event", self.focus_in_mac_entry) self.draw_area.connect("focus-out-event", self.focus_out_mac_entry) self.connect("editing", self.__edit_going) self.keymap = { "Left": self.move_to_left, "Right": self.move_to_right, "Home": self.move_to_start, "End": self.move_to_end, "Ctrl + a": self.select_current_segment, "Ctrl + c": self.copy_to_clipboard, "Ctrl + x": self.cut_to_clipboard, "Ctrl + v": self.paste_from_clipboard, "BackSpace": self.backspace, "Space": self.insert_mac_dot, ":": self.insert_mac_dot, } self.right_menu = Menu([ (None, _("Cut"), self.cut_to_clipboard), (None, _("Copy"), self.copy_to_clipboard), (None, _("Paste"), self.paste_from_clipboard), ], True) self.calculate_cursor_positions()
def get_type_width(file_type): return get_content_size(file_type)[0] + CONTENT_TYPE_PADDING_LEFT
def get_max_size(self): return get_content_size( self.label_content, self.label_font_size, wrap_width=self.label_wrap_width)
def __init__(self, point_dpixbuf=ui_theme.get_pixbuf("hscalebar/point.png"), show_value=False, show_value_type=gtk.POS_TOP, show_point_num=0, format_value="", value_min = 0, value_max = 100, line_height=6, gray_progress=False ): ''' @param point_dpixbuf: a DynamicPixbuf object. @param show_value: If True draw the current value next to the slider. @param show_value_type: The position where the current value is displayed. gtk.POS_TOP or gtk.POS_BOTTOM. @param show_point_num: The accuracy of the value. If 0 value is int type. @param format_value: A string that displayed after the value. @param value_min: The min value, default is 0. @param value_max: The max value, default is 100. @param line_height: The line height, default is 6 pixels. @param gray_progress: If True the HScalebar looks gray, default is False. ''' gtk.Button.__init__(self) self.position_list = [] self.mark_check = False self.enable_check = True self.new_mark_x = 0 self.next_mark_x = 0 self.value = 0 self.show_value_type = show_value_type self.show_point_num = show_point_num self.value_max = value_max - value_min self.value_min = value_min self.drag = False self.gray_progress = gray_progress self.magnetic_values = [] # Init color. self.fg_side_color = "#0071B3" self.bg_side_color = "#B3B3B3" self.fg_inner_color = "#30ABEE" self.bg_inner1_color = "#CCCCCC" self.bg_inner2_color = "#E6E6E6" self.fg_corner_color = "#2E84B7" self.bg_corner_color = "#C1C5C6" self.point_pixbuf = point_dpixbuf self.line_height = line_height self.line_width = 1.0 self.progress_border = 1 self.mark_height = 6 self.mark_width = 1 self.bottom_space = 2 # vertical space between bottom mark line and drag point self.format_value = format_value self.show_value = show_value self.point_width = self.point_pixbuf.get_pixbuf().get_width() self.point_height = self.point_pixbuf.get_pixbuf().get_height() self.text_height_factor = 2 self.set_size_request(-1, self.point_height + get_content_size("0")[1] * self.text_height_factor + self.bottom_space) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.connect("expose-event", self.__progressbar_expose_event) self.connect("button-press-event", self.__progressbar_press_event) self.connect("button-release-event", self.__progressbar_release_event) self.connect("motion-notify-event", self.__progressbar_motion_notify_event) self.connect("scroll-event", self.__progressbar_scroll_event)
def expose_icon_view(self, widget, event): ''' Internal callback for `expose-event` signal. ''' # Update vadjustment. self.update_vadjustment() # Init. cr = widget.window.cairo_create() rect = widget.allocation # Get offset. (offset_x, offset_y, viewport) = self.get_offset_coordinate(widget) # Draw background on widget cairo. self.draw_background(widget, cr) # Draw mask on widget cairo. scrolled_window = get_match_parent(self, ["ScrolledWindow"]) vadjust = scrolled_window.get_vadjustment() vadjust_value = int(vadjust.get_value()) hadjust = scrolled_window.get_hadjustment() hadjust_value = int(hadjust.get_value()) self.draw_mask(cr, hadjust_value, vadjust_value, viewport.allocation.width, viewport.allocation.height) # We need clear render surface every time. with cairo_state(self.render_surface_cr): self.render_surface_cr.set_operator(cairo.OPERATOR_CLEAR) self.render_surface_cr.paint() if self.is_loading: load_text = _("Loading...") load_width, load_height = get_content_size(load_text) draw_text(cr, load_text, rect.x + (rect.width - load_width) / 2, rect.y + rect.height - load_height, rect.width, load_height) # Draw items on surface cairo. self.draw_items(self.render_surface_cr, rect) # Draw bound mask. scrolled_window = get_match_parent(self, ["ScrolledWindow"]) width = scrolled_window.allocation.width height = scrolled_window.allocation.height vadjust_value = int(scrolled_window.get_vadjustment().get_value()) vadjust_upper = int(scrolled_window.get_vadjustment().get_upper()) vadjust_page_size = int( scrolled_window.get_vadjustment().get_page_size()) hadjust_value = int(scrolled_window.get_hadjustment().get_value()) if vadjust_value == 0: with cairo_state(cr): cr.rectangle(hadjust_value, vadjust_value, width, self.mask_bound_height) cr.clip() cr.set_source_surface(self.render_surface, hadjust_value, vadjust_value) cr.paint() elif self.mask_bound_height > 0: i = 0 while (i <= self.mask_bound_height): with cairo_state(cr): cr.rectangle(hadjust_value, vadjust_value + i, width, 1) cr.clip() cr.set_source_surface(self.render_surface, hadjust_value, vadjust_value) cr.paint_with_alpha( math.sin(i * math.pi / 2 / self.mask_bound_height)) i += 1 with cairo_state(cr): cr.rectangle(hadjust_value, vadjust_value + self.mask_bound_height, width, height - self.mask_bound_height * 2) cr.clip() cr.set_source_surface(self.render_surface, hadjust_value, vadjust_value) cr.paint() if vadjust_value + vadjust_page_size == vadjust_upper: with cairo_state(cr): cr.rectangle(hadjust_value, vadjust_value + height - self.mask_bound_height, width, self.mask_bound_height) cr.clip() cr.set_source_surface(self.render_surface, hadjust_value, vadjust_value) cr.paint() elif self.mask_bound_height > 0: i = 0 while (i < self.mask_bound_height): with cairo_state(cr): cr.rectangle( hadjust_value, vadjust_value + height - self.mask_bound_height + i, width, 1) cr.clip() cr.set_source_surface(self.render_surface, hadjust_value, vadjust_value) cr.paint_with_alpha(1.0 - (math.sin(i * math.pi / 2 / self.mask_bound_height))) i += 1 return False
def expose_notebook(self, widget, event): ''' Internal callback for `expose-event` signal. @param widget: Notebook wiget. @param event: Expose event. ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation foreground_left_pixbuf = self.foreground_left_pixbuf.get_pixbuf() self.cache_fg_pixbuf.scale( self.foreground_middle_pixbuf.get_pixbuf(), self.tab_width - foreground_left_pixbuf.get_width() * 2, self.tab_height) foreground_middle_pixbuf = self.cache_fg_pixbuf.get_cache() foreground_right_pixbuf = self.foreground_right_pixbuf.get_pixbuf() background_left_pixbuf = self.background_left_pixbuf.get_pixbuf() self.cache_bg_pixbuf.scale( self.background_middle_pixbuf.get_pixbuf(), self.tab_width - background_left_pixbuf.get_width() * 2, self.tab_height) background_middle_pixbuf = self.cache_bg_pixbuf.get_cache() background_right_pixbuf = self.background_right_pixbuf.get_pixbuf() # Draw tab. for (index, (item_icon, item_content, item_callback)) in enumerate(self.items): # Draw background. if self.current_item_index == index: draw_pixbuf(cr, foreground_left_pixbuf, rect.x + index * self.tab_width, rect.y) draw_pixbuf( cr, foreground_middle_pixbuf, rect.x + index * self.tab_width + foreground_left_pixbuf.get_width(), rect.y) draw_pixbuf( cr, foreground_right_pixbuf, rect.x + (index + 1) * self.tab_width - foreground_left_pixbuf.get_width(), rect.y) else: draw_pixbuf(cr, background_left_pixbuf, rect.x + index * self.tab_width, rect.y) draw_pixbuf( cr, background_middle_pixbuf, rect.x + index * self.tab_width + background_left_pixbuf.get_width(), rect.y) draw_pixbuf( cr, background_right_pixbuf, rect.x + (index + 1) * self.tab_width - background_left_pixbuf.get_width(), rect.y) # Draw content. (content_width, content_height) = get_content_size(item_content, DEFAULT_FONT_SIZE) if item_icon != None: tab_render_width = self.icon_width + self.padding_middle + content_width draw_pixbuf( cr, item_icon.get_pixbuf(), rect.x + index * self.tab_width + (self.tab_width - tab_render_width) / 2, rect.y + (self.tab_height - item_icon.get_pixbuf().get_height()) / 2) draw_text( cr, item_content, rect.x + index * self.tab_width + (self.tab_width - tab_render_width) / 2 + self.icon_width + self.padding_middle, rect.y + (self.tab_height - content_height) / 2, content_width, content_height, DEFAULT_FONT_SIZE, ui_theme.get_color("notebook_font").get_color(), ) else: tab_render_width = content_width draw_text( cr, item_content, rect.x + index * self.tab_width + (self.tab_width - tab_render_width) / 2 + self.icon_width + self.padding_middle, rect.y + (self.tab_height - content_height) / 2, content_width, content_height, DEFAULT_FONT_SIZE, ui_theme.get_color("notebook_font").get_color(), ) propagate_expose(widget, event) return True
def get_size_width(size): return get_content_size(size)[0] + SIZE_PADDING_LEFT
def expose_nav_item(self, widget, event): ''' Internal callback `expose-event` signal. ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation select_index = self.get_index() hover_pixbuf = self.item_hover_pixbuf.get_pixbuf() press_pixbuf = self.item_press_pixbuf.get_pixbuf() # Draw background. if widget.state == gtk.STATE_NORMAL: if select_index == self.index: select_pixbuf = press_pixbuf else: select_pixbuf = None elif widget.state == gtk.STATE_PRELIGHT: if select_index == self.index: select_pixbuf = press_pixbuf else: select_pixbuf = hover_pixbuf elif widget.state == gtk.STATE_ACTIVE: select_pixbuf = press_pixbuf if select_pixbuf: select_pixbuf = select_pixbuf.scale_simple(rect.width, rect.height, gtk.gdk.INTERP_BILINEAR) draw_pixbuf(cr, select_pixbuf, rect.x, rect.y) # Draw navigate item. if self.vertical: draw_pixbuf( cr, self.nav_item_pixbuf, rect.x + (rect.width - self.nav_item_pixbuf.get_width()) / 2, rect.y) draw_text( cr, self.content, rect.x, rect.y + self.nav_item_pixbuf.get_height() - 3, rect.width, rect.height - self.nav_item_pixbuf.get_height(), text_size=self.font_size, text_color="#FFFFFF", alignment=pango.ALIGN_CENTER, gaussian_radious=2, gaussian_color="#000000", border_radious=1, border_color="#000000", ) else: padding_x = (rect.width - self.nav_item_pixbuf.get_width() - self.text_width) / 2 draw_pixbuf( cr, self.nav_item_pixbuf, rect.x + padding_x, rect.y + (rect.height - self.nav_item_pixbuf.get_height()) / 2) draw_text( cr, self.content, rect.x + self.nav_item_pixbuf.get_width() + padding_x, rect.y, rect.width, rect.height, text_size=self.font_size, text_color="#FFFFFF", gaussian_radious=2, gaussian_color="#000000", border_radious=1, border_color="#000000", ) # Draw notify number. text_size = 8 (number_width, number_height) = get_content_size(str(self.notify_num), text_size) padding_x = 2 padding_y = 0 radious = 3 draw_offset_x = -5 draw_offset_y = 8 draw_x = rect.x + self.nav_item_pixbuf.get_width( ) + padding_x + draw_offset_x draw_y = rect.y + draw_offset_y if self.notify_num > 0: cr.set_source_rgb(*color_hex_to_cairo("#BF0000")) draw_round_rectangle(cr, draw_x, draw_y, number_width + padding_x * 2, number_height + padding_y * 2, radious) cr.fill() draw_text( cr, str(self.notify_num), draw_x + padding_x, draw_y + padding_y, number_width, number_height, text_color="#FFFFFF", text_size=text_size, ) # Propagate expose to children. propagate_expose(widget, event) return True
def get_name_width(column_index, name): expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_down.png").get_pixbuf() return COLUMN_OFFSET * column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT + ICON_SIZE + ICON_PADDING_RIGHT + get_content_size(name)[0]
def show(self, text): ''' Show. @param text: OSD tooltip text. ''' # Remove callback.j remove_signal_id(self.configure_event_callback_id) remove_signal_id(self.destroy_callback_id) remove_signal_id(self.focus_out_callback_id) remove_timeout_id(self.start_hide_callback_id) # Update text. self.text = text # Get tooltip size. (tooltip_width, tooltip_height) = get_content_size( self.text, self.text_size + self.border_radious * 2, self.text_font) self.tooltip_width = tooltip_width * 2 self.tooltip_height = tooltip_height # Move tooltip to given position. (monitor_x, monitor_y) = self.monitor_widget.window.get_origin() self.tooltip_x = monitor_x + self.offset_x self.tooltip_y = monitor_y + self.offset_y # Monitor configure-event signal. self.monitor_window = self.monitor_widget.get_toplevel() configure_event_handler_id = self.monitor_window.connect( "configure-event", self.handle_configure_event) self.configure_event_callback_id = (self.monitor_window, configure_event_handler_id) destroy_handler_id = self.monitor_window.connect( "destroy", lambda w: self.hide_immediately()) self.destroy_callback_id = (self.monitor_window, destroy_handler_id) focus_out_handler_id = self.monitor_window.connect( "focus-out-event", lambda w, e: self.hide_immediately()) self.focus_out_callback_id = (self.monitor_window, focus_out_handler_id) # Save monitor window position. rect = self.monitor_window.allocation (monitor_window_x, monitor_window_y) = self.monitor_window.window.get_origin() monitor_window_width, monitor_window_height = rect.width, rect.height self.monitor_window_x = monitor_window_x self.monitor_window_y = monitor_window_y self.monitor_window_width = monitor_window_width self.monitor_window_height = monitor_window_height # Show. self.set_opacity(1) self.show_all() self.start_hide_callback_id = gobject.timeout_add( self.start_hide_delay, lambda: Animation(self, "opacity", self.hide_time, [1, 0], stop_callback=self.hide_immediately).start()) self.queue_draw() # make sure redraw
0, rect.width, rect.height).save(filepath, "png") # Exit after generate png file. gtk.main_quit() if __name__ == "__main__": # Get input arguments. input_args = sys.argv[1::] (select_num, vlinear_color, text_color, filepath) = input_args # Init. num_padding_x = 8 num_padding_y = 1 (num_width, num_height) = get_content_size(select_num) pixbuf_width = num_width + num_padding_x * 2 pixbuf_height = num_height + num_padding_y * 2 # Create window. window = gtk.Window(gtk.WINDOW_POPUP) window.set_colormap(gtk.gdk.Screen().get_rgba_colormap()) window.move(-pixbuf_width, -pixbuf_height) # move out of screen window.set_default_size(pixbuf_width, pixbuf_height) window.connect("expose-event", lambda w, e: render_pixbuf(w, e, input_args)) window.show_all() gtk.main()