def __init__(self): self.tree_view_open = app_theme.get_pixbuf("treeview/open.png") self.tree_view_close = app_theme.get_pixbuf("treeview/close.png") self.tree_view_right = app_theme.get_pixbuf("treeview/right.png") self.tree_view_bottom = app_theme.get_pixbuf("treeview/bottom.png") # self.listview_color = ui_theme.get_color("scrolledbar") self.play_list_vbox = gtk.VBox() # self.list_scroll_win = ScrolledWindow(0, 0) self.list_scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.list_view = ListView() # self.tree_scroll_win = ScrolledWindow(0, 0) self.tree_scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.tree_view = TreeViewBase() self.note_book = NoteBook() # self.list_view.on_draw_sub_item = self.__listview_on_draw_sub_item self.list_view.columns.add_range(["filename", "time"]) self.list_view.columns[0].width = 120 self.list_view.columns[1].width = 95 # self.note_book.hide_title() self.tree_view.paint_nodes_event = self.__treeview_paint_nodes_event # self.list_scroll_win.add_with_viewport(self.list_view) self.tree_scroll_win.add_with_viewport(self.tree_view) self.note_book.add_layout1(self.list_scroll_win) self.note_book.add_layout2(self.tree_scroll_win) #self.play_list_vbox.pack_start(self.scroll_win, True, True) self.play_list_vbox.pack_start(self.note_book, True, True)
def __init__(self): DialogBox.__init__(self, _("Search"), 460, 300, DIALOG_MASK_SINGLE_PAGE, modal=False, window_hint=None, close_callback=self.hide_all) title_label = Label(_("Title:")) self.title_entry = TextEntry("") self.title_entry.set_size(300, 25) self.search_button = Button(_("Search")) self.search_button.connect("clicked", self.search_song) control_box = gtk.HBox(spacing=5) control_box.pack_start(title_label, False, False) control_box.pack_start(self.title_entry, False, False) control_box.pack_start(self.search_button, False, False) scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.result_view = ListView() self.result_view.connect("double-click-item", self.double_click_cb) self.result_view.draw_mask = self.get_mask_func(self.result_view) self.result_view.add_titles([_("Title"), _("Artist"), _("Album"), _("Type"), _("Size")]) scrolled_window.add_child(self.result_view) self.prompt_label = Label("") download_button = Button(_("Download")) download_button.connect("clicked", self.download_song) cancel_button = Button(_("Close")) cancel_button.connect("clicked", lambda w: self.hide_all()) self.body_box.set_spacing(5) self.body_box.pack_start(control_box, False, False) self.body_box.pack_start(scrolled_window, True, True) self.left_button_box.set_buttons([self.prompt_label]) self.right_button_box.set_buttons([download_button, cancel_button])
def __init__(self): DialogBox.__init__(self, _("Task Manager"), 350, 450, DIALOG_MASK_SINGLE_PAGE, modal=False, close_callback=self.hide_all) self.is_changed = False scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scrolled_align = gtk.Alignment() scrolled_align.set(1, 1, 1, 1) scrolled_align.set_padding(10, 0, 0, 0) scrolled_align.add(scrolled_window) self.jobs_view = JobsView() self.jobs_view.draw_mask = self.get_mask_func(self.jobs_view) scrolled_window.add_child(self.jobs_view) pause_button = Button(_("Pause")) pause_button.connect("clicked", self.pause_job) stop_button = Button(_("Close")) stop_button.connect("clicked", lambda w: self.hide_all()) self.body_box.add(scrolled_align) self.right_button_box.set_buttons([pause_button, stop_button]) Dispatcher.connect("transfor-job", self.add_new_job)
class DeviceIconView(ScrolledWindow): def __init__(self, items=None): ScrolledWindow.__init__(self, 0, 0) self.device_iconview = IconView() self.device_iconview.connect("right-click-item", self.__on_right_click_item) self.device_iconview.draw_mask = self.draw_mask if items: self.device_iconview.add_items(items) self.device_scrolledwindow = ScrolledWindow() self.device_scrolledwindow.add_child(self.device_iconview) self.add_child(self.device_scrolledwindow) event_manager.add_callback("text", self.__on_text) event_manager.add_callback("hide-text", self.__on_hide_text) def __on_text(self, name, obj, argv): disable(self, False) text(self, argv) def __on_hide_text(self, name, obj, argv): disable(self, True) def __do_remove_item(self, item): item.do_remove() self.device_iconview.delete_items([item]) def __on_right_click_item(self, widget, item, x, y): menu_items = [(None, _("Pair"), lambda: item.do_pair())] if item.is_paired: menu_items = [] menu_items.extend(item.menu_items) menu_items.append(None) menu_items.append((None, _("Remove Device"), lambda: self.__do_remove_item(item))) Menu(menu_items, True).show((int(x), int(y))) def clear(self): self.device_iconview.clear() def draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(*color_hex_to_cairo("#FFFFFF")) cr.rectangle(x, y, w, h) cr.fill() cr.set_source_rgb(*color_hex_to_cairo("#AEAEAE")) cr.rectangle(x, y, w, h) cr.stroke() def add_items(self, items, clear=False): if clear: self.device_iconview.clear() self.device_iconview.add_items(items)
def __init__(self, data_manager): # Init. gtk.VBox.__init__(self) self.data_manager = data_manager self.tab_box = gtk.HBox() self.tab_box.set_size_request(-1, RANK_TAB_HEIGHT) self.tab_box.set_spacing(1) self.tab_box_align = gtk.Alignment() self.tab_box_align.set(1, 0, 0, 0) self.tab_box_align.set_padding(3, 9, 25, 48) for (tab_index, tab_name) in enumerate([_("Top 25 weekly"), _("Top 25 monthly"), _("Top 25 totally")]): self.tab_box.pack_start(RankTab(tab_index, tab_name, tab_index == 0), False, False) self.page_box = gtk.VBox() self.page_align = gtk.Alignment() self.page_align.set(0.5, 0.5, 1, 1) self.page_align.set_padding(0, 0, 15, 15) self.week_rank_icon_view = IconView() self.week_rank_icon_view_scrlledwindow = ScrolledWindow() self.week_rank_icon_view.draw_mask = self.draw_mask self.month_rank_icon_view = IconView() self.month_rank_icon_view_scrlledwindow = ScrolledWindow() self.month_rank_icon_view.draw_mask = self.draw_mask self.all_rank_icon_view = IconView() self.all_rank_icon_view_scrlledwindow = ScrolledWindow() self.all_rank_icon_view.draw_mask = self.draw_mask self.week_rank_icon_view_scrlledwindow.add_child(self.week_rank_icon_view) self.month_rank_icon_view_scrlledwindow.add_child(self.month_rank_icon_view) self.all_rank_icon_view_scrlledwindow.add_child(self.all_rank_icon_view) self.tab_box_align.add(self.tab_box) self.page_box.pack_start(self.page_align) self.pack_start(self.tab_box_align, False, False) self.pack_start(self.page_box, True, True) self.loading = LoadingBox() self.view_list = [ ('week', self.week_rank_icon_view, self.week_rank_icon_view_scrlledwindow), ('month', self.month_rank_icon_view, self.month_rank_icon_view_scrlledwindow), ('all', self.all_rank_icon_view, self.all_rank_icon_view_scrlledwindow)] self.pkg_names = [] self.show_flag = None self.all_show_flag = ['week', 'month', 'all'] global_event.register_event("update-rank-page", self.update_rank_page) gtk.timeout_add(300, self.get_pkgs_status) global_event.emit("update-rank-page", 0)
class DeviceIconView(ScrolledWindow): def __init__(self, items=None): ScrolledWindow.__init__(self, 0, 0) self.device_iconview = IconView() self.device_iconview.connect("right-click-item", self.__on_right_click_item) self.device_iconview.draw_mask = self.draw_mask if items: self.device_iconview.add_items(items) self.device_scrolledwindow = ScrolledWindow() self.device_scrolledwindow.add_child(self.device_iconview) self.add_child(self.device_scrolledwindow) event_manager.add_callback("text", self.__on_text) event_manager.add_callback("hide-text", self.__on_hide_text) def __on_text(self, name, obj, argv): disable(self, False) text(self, argv) def __on_hide_text(self, name, obj, argv): disable(self, True) def __do_remove_item(self, item): item.do_remove() self.device_iconview.delete_items([item]) def __on_right_click_item(self, widget, item, x, y): menu_items = [(None, _("Pair"), lambda : item.do_pair())] if item.is_paired: menu_items = [] menu_items.extend(item.menu_items) menu_items.append(None) menu_items.append((None, _("Remove Device"), lambda : self.__do_remove_item(item))) Menu(menu_items, True).show((int(x), int(y))) def clear(self): self.device_iconview.clear() def draw_mask(self, cr, x, y, w, h): cr.set_source_rgb(*color_hex_to_cairo("#FFFFFF")) cr.rectangle(x, y, w, h) cr.fill() cr.set_source_rgb(*color_hex_to_cairo("#AEAEAE")) cr.rectangle(x, y, w, h) cr.stroke() def add_items(self, items, clear=False): if clear: self.device_iconview.clear() self.device_iconview.add_items(items)
def __init__(self): self.one_close = app_theme.get_pixbuf("treeview/1-close.png") self.one_open = app_theme.get_pixbuf("treeview/1-open.png") self.two_close = app_theme.get_pixbuf("treeview/2-close.png") self.two_open = app_theme.get_pixbuf("treeview/2-open.png") self.three_close = app_theme.get_pixbuf("treeview/3-close.png") self.three_open = app_theme.get_pixbuf("treeview/3-open.png") # self.tree_view_open = app_theme.get_pixbuf("treeview/open.png") self.tree_view_close = app_theme.get_pixbuf("treeview/close.png") self.tree_view_right = app_theme.get_pixbuf("treeview/right.png") self.tree_view_bottom = app_theme.get_pixbuf("treeview/bottom.png") # self.listview_color = ui_theme.get_color("scrolledbar") self.play_list_vbox = gtk.VBox() # self.list_view_vbox = gtk.VBox() self.list_scroll_win = ScrolledWindow(0, 0) self.list_scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.list_view = ListView() # self.play_list_con = PlayListControl() # self.list_view_vbox.pack_start(self.list_scroll_win, True, True) self.list_view_vbox.pack_start(self.play_list_con, False, False) # 网络列表,搜索框. self.tree_scroll_win = ScrolledWindow(0, 0) self.tree_scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.tree_view_vbox = gtk.VBox() self.tree_view = TreeViewBase() self.search_ali = gtk.Alignment(0, 0, 1, 1) self.search = Search() self.search_ali.add(self.search) # self.search_ali.set_padding(7, 5, 12, 12) self.tree_view_vbox.pack_start(self.search_ali, False, False) self.tree_view_vbox.pack_start(self.tree_scroll_win, True, True) self.search_ali.connect("expose-event", self.search_ali_expose_event) # self.note_book = NoteBook() # self.list_view.on_draw_sub_item = self.__listview_on_draw_sub_item self.list_view.columns.add_range(["filename", "time"]) self.list_view.columns[0].width = 120 self.list_view.columns[1].width = 95 # self.note_book.hide_title() self.tree_view.paint_nodes_event = self.__treeview_paint_nodes_event # self.list_scroll_win.add_with_viewport(self.list_view) self.tree_scroll_win.add_with_viewport(self.tree_view) #self.note_book.add_layout1(self.list_scroll_win) self.note_book.add_layout1(self.list_view_vbox) self.note_book.add_layout2(self.tree_view_vbox) #self.play_list_vbox.pack_start(self.scroll_win, True, True) self.play_list_vbox.pack_start(self.note_book, True, True)
def __init__(self): DialogBox.__init__( self, _("Lyrics search"), 460, 300, DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all, modal=False, window_hint=None, skip_taskbar_hint=False) self.artist_entry = InputEntry() self.artist_entry.set_size(130, 23) self.title_entry = InputEntry() self.title_entry.set_size(130, 23) artist_label = Label(_("Artist:")) title_label = Label(_("Title:")) right_align = gtk.Alignment() right_align.set(0, 0, 0, 1) search_button = Button(_("Search")) search_button.connect("clicked", self.search_lyric_cb) info_box = gtk.HBox(spacing=25) control_box = gtk.HBox(spacing=5) title_box = gtk.HBox(spacing=5) title_box.pack_start(title_label, False, False) title_box.pack_start(self.title_entry) artist_box = gtk.HBox(spacing=5) artist_box.pack_start(artist_label, False, False) artist_box.pack_start(self.artist_entry) control_box.pack_start(title_box, False, False) control_box.pack_start(artist_box, False, False) info_box.pack_start(control_box, False, False) info_box.pack_start(search_button, False, False) scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sort_items = [(lambda item: item.title, cmp), (lambda item: item.artist, cmp)] self.result_view = ListView(sort_items) self.result_view.connect("double-click-item", self.double_click_cb) self.result_view.add_titles([_("Title"), _("Artist")]) self.result_view.draw_mask = self.get_mask_func(self.result_view) scrolled_window.add_child(self.result_view) self.prompt_label = Label("") download_button = Button(_("Download")) download_button.connect("clicked", self.download_lyric_cb) cancel_button = Button(_("Close")) cancel_button.connect("clicked", lambda w: self.hide_all()) info_box_align = gtk.Alignment() info_box_align.set_padding(5, 0, 5, 0) info_box_align.add(info_box) self.body_box.set_spacing(5) self.body_box.pack_start(info_box_align, False, False) self.body_box.pack_start(scrolled_window, True, True) self.left_button_box.set_buttons([self.prompt_label]) self.right_button_box.set_buttons([download_button, cancel_button]) self.lrc_manager = LrcManager()
class SearchPage(gtk.VBox): ''' class docs ''' def __init__(self, module_infos): ''' init docs ''' gtk.VBox.__init__(self) self.scrolled_window = ScrolledWindow() self.scrolled_window.set_size_request(800, 425) self.result_align = self.__setup_align( padding_top=TEXT_WINDOW_TOP_PADDING, padding_left=TEXT_WINDOW_LEFT_PADDING) self.result_box = gtk.VBox() self.result_box.connect("expose-event", self.__expose) self.result_align.add(self.result_box) ''' struct keywords { module_id, module_name, module_keywords { uid, keyword } } ''' self.__keywords = [] self.__module_infos = module_infos ''' TODO: from EACH MODULE import keywords ''' for module_info_list in self.__module_infos: for module_info in module_info_list: if module_info.search_keyword != "None": try: module = __import__( "%s.%s" % (module_info.id, module_info.search_keyword), fromlist=["keywords"]) self.__keywords.append( (module_info.id, module_info.name, module.keywords, module_info.menu_icon_pixbuf)) except Exception, e: print "Error %s %s" % (module_info.id, e) continue self.__keyword_search = KeywordSearch(self.__keywords) self.scrolled_window.add_child(self.result_align) self.pack_start(self.scrolled_window)
def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.status_box = StatusBox() self.scroll = ScrolledWindow() self.scroll.set_size_request(800, 432) self.scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.label_padding_x = 10 self.label_padding_y = 10 self.theme_box = gtk.VBox() self.user_theme_label = Label( _("My Themes"), text_size=TITLE_FONT_SIZE, text_color=app_theme.get_color("globalTitleForeground")) self.user_theme_view = UserThemeView(status_box=self.status_box) self.user_theme_scrolledwindow = self.user_theme_view.get_scrolled_window( ) self.system_theme_label = Label( _("System Themes"), text_size=TITLE_FONT_SIZE, text_color=app_theme.get_color("globalTitleForeground")) self.system_theme_view = SystemThemeView(status_box=self.status_box) self.system_theme_scrolledwindow = self.system_theme_view.get_scrolled_window( ) self.theme_box.pack_start(self.user_theme_label, False, False) self.theme_box.pack_start(get_separator(), False, False) self.theme_box.pack_start(self.user_theme_scrolledwindow, False, False) self.theme_box.pack_start(self.system_theme_label, False, False) self.theme_box.pack_start(get_separator(), False, False) self.theme_box.pack_start(self.system_theme_scrolledwindow, True, True) main_align = gtk.Alignment() main_align.set_padding(15, 0, 20, 20) main_align.set(1, 1, 1, 1) main_align.add(self.theme_box) self.scroll.add_child(main_align) main_align.connect("expose-event", self.expose_label_align) self.pack_start(self.scroll, False, False) self.pack_start(self.status_box)
class AlbumSummaryView(gtk.VBox): ''' class docs ''' def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.scrolled_window = ScrolledWindow() self.iconview = IconView() self.iconview.draw_mask = self.draw_mask self.scrolled_window.add_child(self.iconview) self.pack_start(self.scrolled_window, True, True) global_event.register_event('download-album-infos-finish', self.update_item) def try_fetch_data(self): FetchAlbumData(LANGUAGE).start() @post_gui def update_item(self, data): items = [] if data: for album_info in data: items.append(AlbumSummaryItem(album_info)) items.sort(key=attrgetter('album_order'), reverse=True) self.iconview.add_items(items) global_event.emit('switch-to-album-summary-view') else: global_event.emit('switch-to-network-problem-view') def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [(0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)),] )
def get_scrolled_window(self): scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scrolled_window.connect("vscrollbar-state-changed", self.__on_vscrollbar_state_changed) scrolled_window.add_child(self) return scrolled_window
class AlbumSummaryView(gtk.VBox): ''' class docs ''' def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.scrolled_window = ScrolledWindow() self.iconview = IconView() self.iconview.draw_mask = self.draw_mask self.scrolled_window.add_child(self.iconview) self.pack_start(self.scrolled_window, True, True) global_event.register_event('download-album-infos-finish', self.update_item) def try_fetch_data(self): FetchAlbumData(LANGUAGE).start() @post_gui def update_item(self, data): items = [] if data: for album_info in data: items.append(AlbumSummaryItem(album_info)) items.sort(key=attrgetter('album_order'), reverse=True) self.iconview.add_items(items) global_event.emit('switch-to-album-summary-view') else: global_event.emit('switch-to-network-problem-view') def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [ (0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)), ])
def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.scrolled_window = ScrolledWindow() self.iconview = IconView() self.iconview.draw_mask = self.draw_mask self.scrolled_window.add_child(self.iconview) self.pack_start(self.scrolled_window, True, True) global_event.register_event('download-album-infos-finish', self.update_item)
def get_icon_view(self, padding_x=0, padding_y=10): ''' Draggable IconView ''' icon_view = IconView(padding_x, padding_y) targets = [("text/deepin-songs", gtk.TARGET_SAME_APP, 1), ("text/uri-list", 0, 2)] icon_view.drag_source_set(gtk.gdk.BUTTON1_MASK, targets, gtk.gdk.ACTION_COPY) icon_view.connect("drag-data-get", self.__on_drag_data_get) icon_view.connect("double-click-item", self.__on_double_click_item) icon_view.connect("single-click-item", self.__on_single_click_item) icon_view.connect("right-click-item", self.__on_right_click_item) icon_view.draw_mask = self.on_iconview_draw_mask scrolled_window = ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scrolled_window.add_child(icon_view) return icon_view, scrolled_window
def init_recommend_page(self): self.recommend_scrolled_window = ScrolledWindow() self.background_box = BackgroundBox() self.background_box.draw_mask = self.draw_mask self.box = gtk.VBox() self.loading_box = LoadingBox() self.network_failed_box = NetworkConnectFailed( self.check_network_connection) self.network_timeout_box = NetworkConnectTimeout( self.check_network_connection) self.timeout_times = 0 self.recommend_scrolled_window_initial = False
def __init__(self): super(GuideBox, self).__init__() self.scrolled_window = ScrolledWindow() self.backgroundbox = BackgroundBox() self.backgroundbox.draw_mask = self.draw_mask self.guide_pixbuf = utils.get_common_image_pixbuf('guide.png') self.top_title = gtk.HBox() self.top_left_icon = gtk.VBox() self.top_left_icon.set_size_request(self.guide_pixbuf.get_width(), self.guide_pixbuf.get_height()) self.top_left_icon.connect('expose-event', self.expose_top_left_icon) top_left_icon_align = gtk.Alignment(0.5, 0.5, 0, 0) top_left_icon_align.set_padding(15, 3, 13, 3) top_left_icon_align.add(self.top_left_icon) self.top_right_text = Label( _("Introduction"), ui_theme.get_color('label_select_background'), 14) top_right_text_align = gtk.Alignment(0.5, 0.5, 0, 0) top_right_text_align.set_padding(18, 3, 3, 3) top_right_text_align.add(self.top_right_text) self.top_title.pack_start(top_left_icon_align, False, False) self.top_title.pack_start(top_right_text_align, False, False) self.content_box = gtk.VBox() self.guide_label = Label('', enable_select=False, wrap_width=200, text_size=9, text_color=DynamicColor('#808080')) guide_label_align = gtk.Alignment(0.5, 0.5, 1, 1) guide_label_align.set_padding(5, 5, 10, 10) guide_label_align.add(self.guide_label) self.content_box.pack_start(guide_label_align, False, False) self.backgroundbox.pack_start(self.top_title, False, False) self.backgroundbox.pack_start(self.content_box) self.scrolled_window.add_child(self.backgroundbox) self.add(self.scrolled_window) global_event.register_event('download-app-info-finish', self.update_content)
class SearchPage(gtk.VBox): ''' class docs ''' def __init__(self, module_infos): ''' init docs ''' gtk.VBox.__init__(self) self.scrolled_window = ScrolledWindow() self.scrolled_window.set_size_request(800, 425) self.result_align = self.__setup_align(padding_top = TEXT_WINDOW_TOP_PADDING, padding_left = TEXT_WINDOW_LEFT_PADDING) self.result_box = gtk.VBox() self.result_box.connect("expose-event", self.__expose) self.result_align.add(self.result_box) ''' struct keywords { module_id, module_name, module_keywords { uid, keyword } } ''' self.__keywords = [] self.__module_infos = module_infos ''' TODO: from EACH MODULE import keywords ''' for module_info_list in self.__module_infos: for module_info in module_info_list: if module_info.search_keyword != "None": try: module = __import__("%s.%s" % (module_info.id, module_info.search_keyword), fromlist=["keywords"]) self.__keywords.append((module_info.id, module_info.name, module.keywords, module_info.menu_icon_pixbuf)) except Exception, e: print "Error %s %s" % (module_info.id, e) continue self.__keyword_search = KeywordSearch(self.__keywords) self.scrolled_window.add_child(self.result_align) self.pack_start(self.scrolled_window)
def get_pkg_icon_view_page(self): items = [] for info in self.recommend_infos: items.append(RecommendIconItem(info)) self.pkg_icon_view = IconView() self.pkg_icon_view.add_items(items) self.pkg_icon_scrolled_window = ScrolledWindow() self.pkg_icon_scrolled_window.add_child(self.pkg_icon_view) self.pkg_icon_view.draw_mask = self.draw_mask self.pkg_icon_view_align = gtk.Alignment() self.pkg_icon_view_align.set(0.5, 0.5, 1, 1) self.pkg_icon_view_align.set_padding(6, 0, 1, 11) self.pkg_icon_view_align.add(self.pkg_icon_scrolled_window) return self.pkg_icon_view_align
def button_press(self, column, offset_x, offset_y): # init Loading widget loading_box = LoadingBox() global_event.emit("show-pkg-view", loading_box) self.page_box = gtk.VBox() self.all_pkg_names = self.data_manager.get_second_category_packages(self.second_category_name) self.message_bar = MessageBar(18) self.message_bar.set_message(_("%s > %s : %s applications") % ( get_category_name(self.first_category_name), get_category_name(self.second_category_name), len(self.all_pkg_names), )) self.pkg_icon_view = IconView() self.pkg_icon_view.connect("motion-notify-item", tooltip_aciton) if len(self.all_pkg_names) > LOAD_ITEMS_NUMBER: self.load_new_items(self.all_pkg_names[:LOAD_ITEMS_NUMBER]) else: self.load_new_items(self.all_pkg_names) self.pkg_icon_scrolled_window = ScrolledWindow() self.pkg_icon_scrolled_window.connect("vscrollbar-state-changed", self.scrolled_window_vscrollbar_handler) self.pkg_icon_scrolled_window.add_child(self.pkg_icon_view) self.pkg_icon_view.draw_mask = self.draw_mask self.pkg_icon_view.draw_row_mask = self.draw_row_mask self.page_box.pack_start(self.message_bar, False, False) self.page_box.pack_start(self.pkg_icon_scrolled_window, True, True) global_event.emit("update-current-status-pkg-page", self.pkg_icon_view)
def __init__(self, items=None): ScrolledWindow.__init__(self, 0, 0) self.device_iconview = IconView() self.device_iconview.connect("right-click-item", self.__on_right_click_item) self.device_iconview.draw_mask = self.draw_mask if items: self.device_iconview.add_items(items) self.device_scrolledwindow = ScrolledWindow() self.device_scrolledwindow.add_child(self.device_iconview) self.add_child(self.device_scrolledwindow) event_manager.add_callback("text", self.__on_text) event_manager.add_callback("hide-text", self.__on_hide_text)
def __init__(self, module_infos, start_callback): ''' init docs ''' # Init. gtk.Alignment.__init__(self) (self.first_module_infos, self.second_module_infos, self.third_module_infos, self.extend_module_infos) = module_infos self.start_callback = start_callback self.module_dir = os.path.join(os.path.dirname(__file__), "modules") # Init widgets. self.set(0.5, 0.5, 1, 1) self.set_padding(50, 0, 0, 0) self.layout = gtk.VBox() self.first_iconview = IconView(18) self.second_iconview = IconView(18) self.third_iconview = IconView(18) self.extend_iconview = IconView(18) self.first_iconview_scrolledwindow = ScrolledWindow() self.second_iconview_scrolledwindow = ScrolledWindow() self.third_iconview_scrolledwindow = ScrolledWindow() self.extend_iconview_scrolledwindow = ScrolledWindow() # Connect widgets. self.add(self.layout) # Add icons. self.add_modules(self.first_module_infos, self.first_iconview, self.first_iconview_scrolledwindow) self.add_modules(self.second_module_infos, self.second_iconview, self.second_iconview_scrolledwindow) self.add_modules(self.third_module_infos, self.third_iconview, self.third_iconview_scrolledwindow) self.add_modules(self.extend_module_infos, self.extend_iconview, self.extend_iconview_scrolledwindow) self.first_iconview.draw_mask = self.draw_mask self.second_iconview.draw_mask = self.draw_mask self.third_iconview.draw_mask = self.draw_mask self.extend_iconview.draw_mask = self.draw_mask self.connect("expose-event", self.expose_navigate_page)
def update(self, playlist): '''update''' self.playlist = playlist songs = self.playlist.get_songs() self.song_view = SongView() self.song_view.add_songs(songs) self.song_view.connect("begin-add-items", lambda w: self.switch_it()) self.song_view.connect("empty-items", lambda w: self.switch_it(False)) self.scrolled_window = ScrolledWindow(0, 0) self.scrolled_window.add_child(self.song_view) self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.scrolled_window.set_size_request(220, -1) self.title = playlist.get_name()
def init_recommend_page(self): self.recommend_scrolled_window = ScrolledWindow() self.background_box = BackgroundBox() self.background_box.draw_mask = self.draw_mask self.box = gtk.VBox() self.loading_box = LoadingBox() self.network_failed_box = NetworkConnectFailed(self.check_network_connection) self.network_timeout_box = NetworkConnectTimeout(self.check_network_connection) self.timeout_times = 0 self.recommend_scrolled_window_initial = False
class ConvTAskGui(DialogBox): def __init__(self): DialogBox.__init__(self, _("Task Manager for format conversion"), FORM_WIDTH, FORM_HEIGHT, mask_type=DIALOG_MASK_SINGLE_PAGE, #DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all, modal=True, window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG, window_pos=gtk.WIN_POS_CENTER, resizable=False, ) self.init_widgets() # add widgets. self.body_box.pack_start(self.scrolled_window, False, False) def init_widgets(self): self.scrolled_window = ScrolledWindow() self.list_view = ListView() self.list_view.draw_mask = self.get_mask_func(self.list_view) self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.scrolled_window.add_child(self.list_view) # self.start_btn = Button(_("Start")) self.show_time_label = Label("") self.pause_btn = Button(_("Pause")) self.close_btn = Button(_("Close")) self.show_time_label_align = gtk.Alignment() self.show_time_label_align.set(0.0, 0.5, 1.0, 1.0) self.show_time_label_align.add(self.show_time_label) self.left_button_box.set_buttons([self.show_time_label_align]) self.right_button_box.set_buttons([self.pause_btn, self.close_btn]) self.close_btn.connect("clicked", lambda w : self.hide_all())
def __init__(self): ''' init docs ''' Window.__init__(self) self.window_width = 0 self.window_height = 0 self.max_columns = 4 self.max_rows = 3 self.iconview = IconView(mask_bound_height=0) self.iconview.draw_mask = self.draw_iconview_mask self.iconview.draw_background = self.draw_iconvew_background self.iconview_scrolledwindow = ScrolledWindow(0, 0) self.iconview_scrolledwindow.add_child(self.iconview) self.window_frame.add(self.iconview_scrolledwindow) self.connect("show", self.show_start_desktop_window) wrap_grab_window(start_desktop_grab_window, self)
def button_press(self, column, offset_x, offset_y): # init Loading widget loading_box = LoadingBox() global_event.emit("show-pkg-view", loading_box) self.page_box = gtk.VBox() self.all_pkg_names = self.data_manager.get_second_category_packages( self.second_category_name) self.message_bar = MessageBar(18) self.message_bar.set_message( _("%s > %s : %s applications") % ( get_category_name(self.first_category_name), get_category_name(self.second_category_name), len(self.all_pkg_names), )) self.pkg_icon_view = IconView() self.pkg_icon_view.connect("motion-notify-item", tooltip_aciton) if len(self.all_pkg_names) > LOAD_ITEMS_NUMBER: self.load_new_items(self.all_pkg_names[:LOAD_ITEMS_NUMBER]) else: self.load_new_items(self.all_pkg_names) self.pkg_icon_scrolled_window = ScrolledWindow() self.pkg_icon_scrolled_window.connect( "vscrollbar-state-changed", self.scrolled_window_vscrollbar_handler) self.pkg_icon_scrolled_window.add_child(self.pkg_icon_view) self.pkg_icon_view.draw_mask = self.draw_mask self.pkg_icon_view.draw_row_mask = self.draw_row_mask self.page_box.pack_start(self.message_bar, False, False) self.page_box.pack_start(self.pkg_icon_scrolled_window, True, True) global_event.emit("update-current-status-pkg-page", self.pkg_icon_view)
def __init_ui(self): self.vbox = gtk.VBox(False, BETWEEN_SPACING) self.__init_sections( -1) self.vbox.set_size_request(WINDOW_WIDTH - 2 * TEXT_WINDOW_LEFT_PADDING, -1) scroll_win = ScrolledWindow(right_space=0, top_bottom_space=0) #scroll_win.connect("event", self.test) scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) # FIXME UI a align to adjust ui ui_align = gtk.Alignment(0, 0, 0, 0) ui_align.set_padding(TEXT_WINDOW_TOP_PADDING, TEXT_WINDOW_TOP_PADDING, TEXT_WINDOW_LEFT_PADDING, TEXT_WINDOW_LEFT_PADDING) ui_align.add(self.vbox) scroll_win.add_with_viewport(ui_align) self.eventbox = gtk.EventBox() self.eventbox.set_above_child(False) self.eventbox.add(scroll_win) self.vbox.connect("expose-event", self.expose_callback) ui_align.connect("expose-event", self.expose_callback)
def __init__(self, slide_back_cb, change_crumb_cb): gtk.Alignment.__init__(self, 0, 0, 0, 0) self.slide_back = slide_back_cb self.change_crumb = change_crumb_cb self.scroll_win = ScrolledWindow() self.scroll_win.set_can_focus(False) self.scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) main_vbox = gtk.VBox() self.foot_box = FootBox() self.hbox = gtk.HBox() self.scroll_win.add_with_viewport(self.hbox) self.scroll_align = gtk.Alignment() self.scroll_win.set_size_request(800, 435) self.scroll_align.set(0, 0, 0, 0) self.scroll_align.set_padding(0, 0, 30, 0) self.scroll_align.add(self.scroll_win) padding_align = gtk.Alignment(0, 0, 0, 0) padding_align.set_padding(15, 0, 0, 0) self.sidebar = SideBar(None) padding_align.add(self.sidebar) self.hpaned = MyPaned() self.hpaned.set_size_request(800, -1) self.hpaned.connect("expose-event", self.expose_line) #self.hpaned.do_enter_notify_event = self.enter_notify_event self.hpaned.add1(padding_align) self.hpaned.add2(self.scroll_align) self.connect_after("show", self.__init_paned) main_vbox.pack_start(self.hpaned, True, True) main_vbox.pack_start(self.foot_box, False, False) self.add(main_vbox) self.__init_signals()
def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.status_box = StatusBox() self.scroll = ScrolledWindow() self.scroll.set_size_request(800, 432) self.scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.label_padding_x = 10 self.label_padding_y = 10 self.theme_box = gtk.VBox() self.user_theme_label = Label(_("My Themes"), text_size=TITLE_FONT_SIZE, text_color=app_theme.get_color("globalTitleForeground")) self.user_theme_view = UserThemeView(status_box = self.status_box) self.user_theme_scrolledwindow = self.user_theme_view.get_scrolled_window() self.system_theme_label = Label(_("System Themes"), text_size=TITLE_FONT_SIZE, text_color=app_theme.get_color("globalTitleForeground")) self.system_theme_view = SystemThemeView(status_box = self.status_box) self.system_theme_scrolledwindow = self.system_theme_view.get_scrolled_window() self.theme_box.pack_start(self.user_theme_label, False, False) self.theme_box.pack_start(get_separator(), False, False) self.theme_box.pack_start(self.user_theme_scrolledwindow, False, False) self.theme_box.pack_start(self.system_theme_label, False, False) self.theme_box.pack_start(get_separator(), False, False) self.theme_box.pack_start(self.system_theme_scrolledwindow, True, True) main_align = gtk.Alignment() main_align.set_padding(15, 0, 20, 20) main_align.set(1, 1, 1, 1) main_align.add(self.theme_box) self.scroll.add_child(main_align) main_align.connect("expose-event", self.expose_label_align) self.pack_start(self.scroll, False, False) self.pack_start(self.status_box)
def init_widgets(self): self.scrolled_window = ScrolledWindow() self.list_view = ListView() self.list_view.draw_mask = self.get_mask_func(self.list_view) self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.scrolled_window.add_child(self.list_view) # self.start_btn = Button(_("Start")) self.show_time_label = Label("") self.pause_btn = Button(_("Pause")) self.close_btn = Button(_("Close")) self.show_time_label_align = gtk.Alignment() self.show_time_label_align.set(0.0, 0.5, 1.0, 1.0) self.show_time_label_align.add(self.show_time_label) self.left_button_box.set_buttons([self.show_time_label_align]) self.right_button_box.set_buttons([self.pause_btn, self.close_btn]) self.close_btn.connect("clicked", lambda w : self.hide_all())
def __init__(self): super(GuideBox, self).__init__() self.scrolled_window = ScrolledWindow() self.backgroundbox = BackgroundBox() self.backgroundbox.draw_mask = self.draw_mask self.guide_pixbuf = utils.get_common_image_pixbuf('guide.png') self.top_title = gtk.HBox() self.top_left_icon = gtk.VBox() self.top_left_icon.set_size_request(self.guide_pixbuf.get_width(), self.guide_pixbuf.get_height()) self.top_left_icon.connect('expose-event', self.expose_top_left_icon) top_left_icon_align = gtk.Alignment(0.5, 0.5, 0, 0) top_left_icon_align.set_padding(15, 3, 13, 3) top_left_icon_align.add(self.top_left_icon) self.top_right_text = Label(_("Introduction"), ui_theme.get_color('label_select_background'), 14) top_right_text_align = gtk.Alignment(0.5, 0.5, 0, 0) top_right_text_align.set_padding(18, 3, 3, 3) top_right_text_align.add(self.top_right_text) self.top_title.pack_start(top_left_icon_align, False, False) self.top_title.pack_start(top_right_text_align, False, False) self.content_box = gtk.VBox() self.guide_label = Label('', enable_select=False, wrap_width=200, text_size=9, text_color=DynamicColor('#808080')) guide_label_align = gtk.Alignment(0.5, 0.5, 1, 1) guide_label_align.set_padding(5, 5, 10, 10) guide_label_align.add(self.guide_label) self.content_box.pack_start(guide_label_align, False, False) self.backgroundbox.pack_start(self.top_title, False, False) self.backgroundbox.pack_start(self.content_box) self.scrolled_window.add_child(self.backgroundbox) self.add(self.scrolled_window) global_event.register_event('download-app-info-finish', self.update_content)
def single_click(self, column, offset_x, offset_y): # init Loading widget loading_box = LoadingBox() global_event.emit("show-pkg-view", loading_box) self.page_box = gtk.VBox() self.all_pkg_names = [] self.all_desktop_infos = {} for (second_category, pkg_dict) in self.second_category_items.items(): for (pkg_name, desktop_info) in pkg_dict.items(): self.all_pkg_names.append(pkg_name) self.all_desktop_infos[pkg_name] = desktop_info self.message_bar = MessageBar(18) self.message_bar.set_message(_("%s: %s applications") % ( get_category_name(self.first_category_name), len(self.all_pkg_names), )) self.pkg_icon_view = IconView() self.pkg_icon_view.connect("motion-notify-item", tooltip_aciton) if len(self.all_pkg_names) > LOAD_ITEMS_NUMBER: self.load_new_items(self.all_pkg_names[:LOAD_ITEMS_NUMBER]) else: self.load_new_items(self.all_pkg_names) self.pkg_icon_view.draw_mask = self.draw_mask self.pkg_icon_view.draw_row_mask = self.draw_row_mask self.pkg_icon_scrolled_window = ScrolledWindow() self.pkg_icon_scrolled_window.connect("vscrollbar-state-changed", self.scrolled_window_vscrollbar_handler) self.pkg_icon_scrolled_window.add_child(self.pkg_icon_view) self.page_box.pack_start(self.message_bar, False, False) self.page_box.pack_start(self.pkg_icon_scrolled_window, True, True) global_event.emit("update-current-status-pkg-page", self.pkg_icon_view)
def __init__(self): PreferenceDialog.__init__(self, 566, 488) self.current_mirror_item = None self.normal_settings = gtk.VBox() self.normal_settings.set_spacing(TABLE_ROW_SPACING) self.normal_settings.pack_start(self.create_uninstall_box(), False, True) self.normal_settings.pack_start(self.create_download_dir_table(), False, True) self.normal_settings_align = gtk.Alignment(0, 0, 1, 1) self.normal_settings_align.set_padding(padding_left=5, padding_right=5, padding_top=25, padding_bottom=10) self.normal_settings_align.add(self.normal_settings) self.mirror_settings = gtk.VBox() self.mirror_settings.set_app_paintable(True) self.mirror_settings.connect("expose-event", self.mirror_settings_align_expose) self.mirror_settings.set_spacing(TABLE_ROW_SPACING) self.mirror_settings.pack_start(self.create_mirror_select_table(), False, True) self.mirror_settings.pack_start(self.create_source_update_frequency_table(), False, True) self.mirror_settings_inner_align = gtk.Alignment(0.5, 0.5, 1, 1) self.mirror_settings_inner_align.set_padding(padding_top=25, padding_bottom=10, padding_left=0, padding_right=0) self.mirror_settings_inner_align.add(self.mirror_settings) self.mirror_settings_scrolled_win = ScrolledWindow() self.mirror_settings_scrolled_win.add_child(self.mirror_settings_inner_align) self.mirror_settings_align = gtk.Alignment(0, 0, 1, 1) self.mirror_settings_align.set_padding(padding_left=0, padding_right=0, padding_top=0, padding_bottom=3) self.mirror_settings_align.add(self.mirror_settings_scrolled_win) self.set_preference_items([ (_("General"), self.normal_settings_align), (_("Mirrors"), self.mirror_settings_align), (_("About"), AboutBox()), ])
def __init__(self, slide_back_cb, change_crumb_cb): gtk.Alignment.__init__(self, 0, 0, 0, 0) self.slide_back = slide_back_cb self.change_crumb = change_crumb_cb self.scroll_win = ScrolledWindow() self.scroll_win.set_can_focus(False) self.scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) main_vbox = gtk.VBox() self.foot_box = FootBox() self.hbox = gtk.HBox() self.scroll_win.add_with_viewport(self.hbox) self.scroll_align = gtk.Alignment() self.scroll_win.set_size_request(800, 435) self.scroll_align.set(0, 0, 0, 0) self.scroll_align.set_padding(0, 0, 30, 0) self.scroll_align.add(self.scroll_win) padding_align = gtk.Alignment(0, 0, 0, 0) padding_align.set_padding(15, 0, 0, 0) self.sidebar = SideBar( None) padding_align.add(self.sidebar) self.hpaned = MyPaned() self.hpaned.set_size_request(800, -1) self.hpaned.connect("expose-event",self.expose_line) #self.hpaned.do_enter_notify_event = self.enter_notify_event self.hpaned.add1(padding_align) self.hpaned.add2(self.scroll_align) self.connect_after("show", self.__init_paned) main_vbox.pack_start(self.hpaned, True, True) main_vbox.pack_start(self.foot_box, False, False) self.add(main_vbox) self.__init_signals()
def __init_ui(self): self.vbox = gtk.VBox(False, BETWEEN_SPACING) self.__init_sections(-1) self.vbox.set_size_request(WINDOW_WIDTH - 2 * TEXT_WINDOW_LEFT_PADDING, -1) scroll_win = ScrolledWindow(right_space=0, top_bottom_space=0) #scroll_win.connect("event", self.test) scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) # FIXME UI a align to adjust ui ui_align = gtk.Alignment(0, 0, 0, 0) ui_align.set_padding(TEXT_WINDOW_TOP_PADDING, TEXT_WINDOW_TOP_PADDING, TEXT_WINDOW_LEFT_PADDING, TEXT_WINDOW_LEFT_PADDING) ui_align.add(self.vbox) scroll_win.add_with_viewport(ui_align) self.eventbox = gtk.EventBox() self.eventbox.set_above_child(False) self.eventbox.add(scroll_win) self.vbox.connect("expose-event", self.expose_callback) ui_align.connect("expose-event", self.expose_callback)
class GuideBox(gtk.VBox): def __init__(self): super(GuideBox, self).__init__() self.scrolled_window = ScrolledWindow() self.backgroundbox = BackgroundBox() self.backgroundbox.draw_mask = self.draw_mask self.guide_pixbuf = utils.get_common_image_pixbuf('guide.png') self.top_title = gtk.HBox() self.top_left_icon = gtk.VBox() self.top_left_icon.set_size_request(self.guide_pixbuf.get_width(), self.guide_pixbuf.get_height()) self.top_left_icon.connect('expose-event', self.expose_top_left_icon) top_left_icon_align = gtk.Alignment(0.5, 0.5, 0, 0) top_left_icon_align.set_padding(15, 3, 13, 3) top_left_icon_align.add(self.top_left_icon) self.top_right_text = Label( _("Introduction"), ui_theme.get_color('label_select_background'), 14) top_right_text_align = gtk.Alignment(0.5, 0.5, 0, 0) top_right_text_align.set_padding(18, 3, 3, 3) top_right_text_align.add(self.top_right_text) self.top_title.pack_start(top_left_icon_align, False, False) self.top_title.pack_start(top_right_text_align, False, False) self.content_box = gtk.VBox() self.guide_label = Label('', enable_select=False, wrap_width=200, text_size=9, text_color=DynamicColor('#808080')) guide_label_align = gtk.Alignment(0.5, 0.5, 1, 1) guide_label_align.set_padding(5, 5, 10, 10) guide_label_align.add(self.guide_label) self.content_box.pack_start(guide_label_align, False, False) self.backgroundbox.pack_start(self.top_title, False, False) self.backgroundbox.pack_start(self.content_box) self.scrolled_window.add_child(self.backgroundbox) self.add(self.scrolled_window) global_event.register_event('download-app-info-finish', self.update_content) @post_gui def update_content(self, js): js = json.loads(js) self.guide_label.set_text(js['summary']) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' sidebar_color = "#ffffff" draw_vlinear(cr, x, y, w, h, [ (0, (sidebar_color, 0.9)), (1, (sidebar_color, 0.9)), ]) def expose_top_left_icon(self, widget, event): # Init. cr = widget.window.cairo_create() rect = widget.allocation # Draw pkg icon. draw_pixbuf(cr, self.guide_pixbuf, rect.x, rect.y)
def get_scrolled_window(self): scrolled_window = ScrolledWindow() scrolled_window.add_child(self) return scrolled_window
notebook_c.pack_start(notebook_frame, False, False) notebook_c.pack_start(notebook_box, True, True) #application.main_box.pack_start(notebook_frame, False, False) slider.to_page_now(notebook_c) application.main_box.pack_start(slider, True, True) notebook_box.add(tab_1_box) # Add body box. body_box = gtk.HBox() horizontal_frame = HorizontalFrame() horizontal_frame.add(body_box) tab_1_box.pack_start(horizontal_frame, True, True) scrolled_window = ScrolledWindow() items_length = 1000 items = map( lambda index: ListItem( "豆浆油条 测试标题 %04d" % index, "林俊杰 %04d" % index, "10:%02d" % index, ), range(0, items_length)) list_view = ListView([(lambda item: item.title, cmp), (lambda item: item.artist, cmp), (lambda item: item.length, cmp)], drag_data=([ ("text/deepin-webcasts", gtk.TARGET_SAME_APP, 1),
class RecommendItem(TreeItem): ''' class docs ''' def __init__(self, data_manager, recommend_status): ''' init docs ''' TreeItem.__init__(self) self.name = _("Home") self.data_manager = data_manager self.recommend_status = recommend_status self.page_cache = {} self.page_name = ['recommend', 'album', 'download_rank'] self.init_recommend_page() global_event.register_event('download-home-infos-finish', self.update_home_page) def init_recommend_page(self): self.recommend_scrolled_window = ScrolledWindow() self.background_box = BackgroundBox() self.background_box.draw_mask = self.draw_mask self.box = gtk.VBox() self.loading_box = LoadingBox() self.network_failed_box = NetworkConnectFailed( self.check_network_connection) self.network_timeout_box = NetworkConnectTimeout( self.check_network_connection) self.timeout_times = 0 self.recommend_scrolled_window_initial = False @post_gui def update_home_page(self, data): if not data: self.check_network_connection() return slide_infos = sort_for_home_page_data(data['slide']) self.slider_switcher = IndexSlideSwitcher(slide_infos) self.slider_switcher.connect( "motion-notify-index", lambda w, i: global_event.emit("set-cursor", gtk.gdk.HAND2)) self.slider_switcher.connect( "button-press-index", lambda w, i: global_event.emit( "switch-to-detail-page", slide_infos[i][0])) self.slider_switcher.connect( "leave-notify-index", lambda w, i: global_event.emit("set-cursor", None)) self.recommend_infos = sort_for_home_page_data(data['recommend']) self.tab_switcher = TabSwitcher( [_("Recommendations"), _("HotApps"), _("Download rank")], CATEGORY_ITEM_NAME_SIZE) self.tab_switcher_align = gtk.Alignment() self.tab_switcher_align.set(0.5, 0.5, 1, 1) self.tab_switcher_align.set_padding(10, 0, 0, 9) self.tab_switcher_align.add(self.tab_switcher) self.tab_switcher_pages_callback = [ "get_pkg_icon_view_page", "get_album_page", "get_download_rank_page", ] self.page_box = gtk.VBox() self.box.pack_start(self.slider_switcher, False, False) self.box.pack_start(self.tab_switcher_align, False, False) self.box_align = gtk.Alignment() self.box_align.set(0.5, 0.5, 1, 1) self.box_align.set_padding(5, 0, 10, 11) self.box_align.add(self.box) self.page_box_align = gtk.Alignment() self.page_box_align.set(0.5, 0, 1, 1) self.page_box_align.add(self.page_box) self.background_box.pack_start(self.box_align, False, False) self.background_box.pack_start(self.page_box_align) self.recommend_scrolled_window.add_child(self.background_box) self.switch_page(0) self.tab_switcher.connect( "tab-switch-start", lambda switcher, page_index: self.switch_page(page_index)) self.tab_switcher.connect( "click-current-tab", lambda switcher, page_index: self.click_page()) self.switch_page_view(self.recommend_scrolled_window) self.recommend_scrolled_window_initial = True def try_fetch_data(self): FetchHomeData(LANGUAGE, self.recommend_status).start() self.timeout_times += 1 def check_network_connection(self): if is_network_connected(): if self.timeout_times < NETWORK_TRY_TIMES: self.network_connected_flag = True self.switch_page_view(self.loading_box) self.try_fetch_data() else: self.network_connected_flag = False self.switch_page_view(self.network_timeout_box) self.timeout_times = 0 else: self.network_connected_flag = False self.switch_page_view(self.network_failed_box) def switch_page_view(self, view): global_event.emit('show-pkg-view', view) def render_name(self, cr, rect): text_color = "#333333" font_image_color = app_theme.get_color("sidebar_select").get_color() if self.is_select: cr.set_source_rgba(*color_hex_to_cairo( app_theme.get_color("sidebar_select").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() text_color = "#FFFFFF" font_image_color = "#FFFFFF" elif self.is_hover: cr.set_source_rgba(*color_hex_to_cairo( app_theme.get_color("sidebar_hover").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() pixbuf = app_theme.get_pixbuf("category/12.png").get_pixbuf() #draw_pixbuf( #cr, #pixbuf, #rect.x + 12, #rect.y + (rect.height - pixbuf.get_height()) / 2) category_img_path = os.path.join(get_parent_dir(__file__, 2), "image", "category", "1.png") surface = cairo.ImageSurface.create_from_png(category_img_path) cr.set_source_rgb(*color_hex_to_cairo(font_image_color)) cr.mask_surface(surface, rect.x + 14, rect.y + (rect.height - 24) / 2) draw_text( cr, self.name, rect.x + pixbuf.get_width() + 22, rect.y, rect.width, rect.height, text_size=CATEGORY_ITEM_NAME_SIZE, text_color=text_color, ) def get_height(self): return CATEGORY_ITEM_HEIGHT def get_column_widths(self): return [CATEGORY_ITEM_NAME_WIDTH] def get_column_renders(self): return [self.render_name] def hover(self, column, offset_x, offset_y): self.is_hover = True if self.redraw_request_callback: self.redraw_request_callback(self) def unhover(self, column, offset_x, offset_y): self.is_hover = False if self.redraw_request_callback: self.redraw_request_callback(self) def select(self): self.is_select = True if self.redraw_request_callback: self.redraw_request_callback(self) def unselect(self): self.is_select = False if self.redraw_request_callback: self.redraw_request_callback(self) def button_press(self, column, offset_x, offset_y): self.show_page() def get_pkg_icon_view_page(self): items = [] for info in self.recommend_infos: items.append(RecommendIconItem(info)) self.pkg_icon_view = IconView() self.pkg_icon_view.add_items(items) self.pkg_icon_scrolled_window = ScrolledWindow() self.pkg_icon_scrolled_window.add_child(self.pkg_icon_view) self.pkg_icon_view.draw_mask = self.draw_mask self.pkg_icon_view_align = gtk.Alignment() self.pkg_icon_view_align.set(0.5, 0.5, 1, 1) self.pkg_icon_view_align.set_padding(6, 0, 1, 11) self.pkg_icon_view_align.add(self.pkg_icon_scrolled_window) return self.pkg_icon_view_align def get_download_rank_page(self): self.download_rank_page = DownloadRankPage(self.data_manager) return self.download_rank_page def get_album_page(self): self.album_page = AlbumPage(self.data_manager) return self.album_page # from deepin_utils.date_time import print_exec_time # @print_exec_time def show_page(self): if self.recommend_scrolled_window_initial: global_event.emit("show-pkg-view", self.recommend_scrolled_window) else: self.check_network_connection() def draw_blank_mask(self, cr, x, y, w, h): pass def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [ (0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)), ]) def click_page(self): pass #if isinstance(self.active_page, AlbumPage) and self.active_page.in_detail_view: #self.active_page.switch_to_album_summary_view() def switch_page(self, page_index): container_remove_all(self.page_box) page_name = self.page_name[page_index] if not self.page_cache.has_key(self.page_name[page_index]): self.page_cache[page_name] = getattr( self, self.tab_switcher_pages_callback[page_index])() self.active_page = self.page_cache[page_name] self.page_box.pack_start(self.active_page, True, True) #if isinstance(self.active_page, AlbumPage): #if self.active_page.in_detail_view: #self.active_page.switch_to_album_summary_view() self.recommend_scrolled_window.show_all()
class ShareToWeibo(object): '''share picture to weibo''' def __init__(self, filename=""): ''' init share @param filename: the file to share ''' self.upload_image = filename self.thumb_width = 188 self.thumb_height = 168 self.MAX_CHAR = 140 #self.__text_frame_color = (0.76, 0.76, 0.76) self.__win_width = 602 open(COOKIE_FILE,'wb').close() self.window = DialogBox(_("Share to social networks"), close_callback=gtk.main_quit) self.window.set_keep_above(True) self.window.set_size_request(self.__win_width+20, 288) self.window.set_resizable(False) self.window.titlebar.connect("expose-event", self.__expose_top_and_bottome) self.window.button_box.connect("expose-event", self.__expose_top_and_bottome) # create slider self.slider = HSlider() self.slider_list = [] self.share_box = gtk.VBox(False, 2) # first page, input context self.web_box = gtk.VBox(False, 10) # second page, login self.result_box = gtk.VBox(False, 10) # third page, share result share_align = gtk.Alignment() share_align.set(0.5, 0.5, 0, 0) share_align.add(self.share_box) share_align.connect("expose-event", self.__slider_expose) # go back button web_left_button = ImageButton( app_theme.get_pixbuf("share/back_normal.png"), app_theme.get_pixbuf("share/back_hover.png"), app_theme.get_pixbuf("share/back_press.png")) web_left_button.connect("clicked", lambda w: self.set_slide_index(0)) web_left_button.set_can_focus(False) utils.set_clickable_cursor(web_left_button) # show url entry self.web_url_entry = InputEntry() self.web_url_entry.set_editable(False) self.web_url_entry.set_size(555, 20) self.web_url_entry.entry.right_menu_visible_flag = False # alig url entry web_navigate_vbox = gtk.VBox(False) web_navigate_vbox.pack_start(self.web_url_entry) web_navigate_t_align = gtk.Alignment() web_navigate_t_align.set(0.0, 0.5, 0, 0) web_navigate_t_align.add(web_navigate_vbox) # pack back button and url entry web_navigate_box = gtk.HBox(False, 7) web_navigate_box.pack_start(web_left_button, False, False) web_navigate_box.pack_start(web_navigate_t_align) web_navigate_align = gtk.Alignment() web_navigate_align.set(0.5, 0.5, 0, 0) web_navigate_align.set_padding(4, 0, 11, 13) web_navigate_align.add(web_navigate_box) # create a webkit self.web_view = WebView(COOKIE_FILE) self.web_view.connect("notify::load-status", self.web_view_load_status) self.web_view.connect("load-error", self.web_view_load_error) self.web_scrolled_window = ScrolledWindow() self.web_scrolled_window.add(self.web_view) self.web_scrolled_window.set_size_request(590, 228) self.web_box.pack_start(web_navigate_align, False, False) self.web_box.pack_start(self.web_scrolled_window) #self.web_box.set_size_request(-1, 258) web_align = gtk.Alignment() web_align.set(0.5, 0.0, 0, 1) web_align.add(self.web_box) web_align.connect("expose-event", self.__slider_expose) res_align = gtk.Alignment() res_align.set(0.5, 0.5, 0, 0) res_align.add(self.result_box) res_align.connect("expose-event", self.__slider_expose) self.slider.set_to_page(share_align) self.slider_list.append(share_align) self.slider_list.append(web_align) self.slider_list.append(res_align) self.__weibo_list = [] self.sina = weibo.Sina(self.web_view) self.qq = weibo.Tencent(self.web_view) self.twitter = weibo.Twitter(self.web_view) self.__weibo_list.append(self.sina) self.__weibo_list.append(self.qq) self.__weibo_list.append(self.twitter) self.__current_weibo = None self.window.body_box.pack_start(self.slider, True, True) self.init_share_box() # webkit load-status, login success, go back def web_view_load_status(self, web, status): '''web_view notify load-status callback''' state = web.get_property("load-status") url = web.get_property('uri') if url: self.web_url_entry.set_editable(True) self.web_url_entry.set_text(url) self.web_url_entry.entry.move_to_start() self.web_url_entry.set_editable(False) if state == webkit.LOAD_FAILED: # load failed print "load failed", print web.get_property('uri') elif state == webkit.LOAD_COMMITTED: if self.__current_weibo and self.__current_weibo.is_callback_url(url): web.stop_loading() # if go to callback url, stop loading # access token #print "load committed", url t = threading.Thread(target=self.weibo_login_thread) t.setDaemon(True) t.start() def web_view_load_error(self, web, fram, url, error, data=None): web.load_string( "<html><body><p><h1>%s</h1></p>%s</body></html>" % ( _("Unable to load page"), _("Problem occurred while loading the URL '%s'") % (url)), "text/html", "UTF-8", "") print url return True # login or switch user def weibo_login(self, widget, weibo): '''weibo button clicked callback''' self.web_view.load_uri("about:blank") utils.set_cursor(widget) self.set_slide_index(1) self.__current_weibo = weibo t = threading.Thread(target=self.__current_weibo.request_oauth) t.setDaemon(True) t.start() def weibo_login_thread(self): '''in webkit login finish, get user info again''' self.__current_weibo.access_token() self.get_user_info_again() gtk.gdk.threads_enter() self.set_slide_index(0) gtk.gdk.threads_leave() def get_user_info_again(self): ''' login or switch user, and get user info again''' box = self.__current_weibo.get_box() #print "cuurent weibo:", self.__current_weibo.t_type gtk.gdk.threads_enter() children = box.get_children() for child in children: if child in self.__weibo_check_button_list: self.__weibo_check_button_list.remove(child) if child in self.__weibo_image_button_list: self.__weibo_image_button_list.remove(child) child.destroy() gtk.gdk.threads_leave() self.get_user_info(self.__current_weibo) gtk.gdk.threads_enter() box.show_all() gtk.gdk.threads_leave() def set_slide_index(self, index): ''' set slide to index @param index: the index of widget in slider, an int num ''' if index >= len(self.slider_list): return direct = "right" if index == 1 and self.window.button_box in self.window.window_frame.get_children(): #self.slider.set_size_request(-1, 260) win = self.window if win.left_button_box in win.button_box.get_children(): win.button_box.remove(win.left_button_box) if win.right_button_box in win.button_box.get_children(): win.button_box.remove(win.right_button_box) tmp = gtk.HSeparator() tmp.set_size_request(-1, 1) tmp.show() win.button_box.pack_start(tmp) direct = "right" #if self.window.button_box in self.window.window_frame.get_children(): #self.window.window_frame.remove(self.window.button_box) elif index == 0: #self.slider.set_size_request(-1, 223) win = self.window for each in win.button_box.get_children(): each.destroy() if win.left_button_box not in win.button_box.get_children(): win.button_box.pack_start(win.left_button_box) if win.right_button_box not in win.button_box.get_children(): win.button_box.pack_start(win.right_button_box) direct = "left" #if self.window.button_box not in self.window.window_frame.get_children(): #self.window.window_frame.pack_start(self.window.button_box, False, False) elif index == 2: self.window.left_button_box.set_buttons([]) l = Label(" ") l.show() self.window.right_button_box.set_buttons([l]) direct = "right" #self.slider.set_size_request(-1, 223) self.slider.slide_to_page(self.slider_list[index], direct) def weibo_check_toggle(self, button, weibo): '''weibo check button toggled callback. check the weibo to share''' if button.get_active(): self.to_share_weibo[weibo] = 1 else: self.to_share_weibo[weibo] = 0 def create_ico_image(self, name): ''' create image from file''' pix1 = app_theme_get_dynamic_pixbuf('image/share/%s.png' % name).get_pixbuf() pix2 = app_theme_get_dynamic_pixbuf('image/share/%s_no.png' % name).get_pixbuf() return (pix1, pix2) def get_user_info(self, weibo): '''get weibo user info''' info = weibo.get_user_name() gtk.gdk.threads_enter() #self.get_user_error_text = "" weibo_hbox = weibo.get_box() hbox = gtk.HBox(False) vbox = gtk.VBox(False) weibo_hbox.pack_start(vbox, False, False) vbox.pack_start(hbox) #print weibo.t_type, info if info: self.is_get_user_info[weibo] = 1 label = Label(text=info, label_width=70, enable_select=False) check = CheckButton() #check = gtk.CheckButton() check.connect("toggled", self.weibo_check_toggle, weibo) check.set_active(True) check_vbox = gtk.VBox(False) check_align = gtk.Alignment(0.5, 0.5, 0, 0) check_align.add(check_vbox) check_vbox.pack_start(check, False, False) button = ImageButton( app_theme.get_pixbuf("share/" + weibo.t_type + ".png"), app_theme.get_pixbuf("share/" + weibo.t_type + ".png"), app_theme.get_pixbuf("share/" + weibo.t_type + ".png")) utils.set_clickable_cursor(button) button.connect("enter-notify-event", self.show_tooltip, _("Click to switch user")) hbox.pack_start(check_align, False, False) hbox.pack_start(button, False, False, 5) hbox.pack_start(label, False, False) else: self.is_get_user_info[weibo] = 0 check = CheckButton() #check = gtk.CheckButton() check.set_sensitive(False) check_vbox = gtk.VBox(False) check_align = gtk.Alignment(0.5, 0.5, 0, 0) check_align.add(check_vbox) check_vbox.pack_start(check, False, False) button = ImageButton( app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"), app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"), app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png")) utils.set_clickable_cursor(button) button.connect("enter-notify-event", self.show_tooltip, _("Click to login")) hbox.pack_start(check_align, False, False) hbox.pack_start(button, False, False, 5) # curl time out info_error = weibo.get_curl_error() if info_error: #self.get_user_error_text += "%s:%s." % (weibo.t_type, _(info_error)) hbox.pack_start( Label(text="(%s)" % _(info_error), label_width=70,enable_select=False, text_color = app_theme.get_color("left_char_num1")), False, False) button.connect("clicked", self.weibo_login, weibo) self.__weibo_check_button_list.append(check) self.__weibo_image_button_list.append(button) gtk.gdk.threads_leave() return weibo_hbox def show_tooltip(self, widget, event, text): '''Create help tooltip.''' Tooltip.text(widget, text) def init_user_info_thread(self, button, text_view): '''get user name thread''' time.sleep(0.1) for weibo in self.__weibo_list: self.get_user_info(weibo) gtk.gdk.threads_enter() #self.share_box.set_sensitive(True) button.set_sensitive(True) text_view.set_editable(True) for weibo in self.__weibo_list: weibo.get_box().show_all() weibo.get_box().queue_draw() self.loading_label.destroy() gtk.gdk.threads_leave() # init share box, create share button, input def init_share_box(self): '''get weibo info, and create button''' self.to_share_weibo = {} self.to_share_weibo_res = {} self.deepin_info = {} self.is_get_user_info = {} self.__weibo_check_button_list = [] self.__weibo_image_button_list = [] # create Thumbnail if exists(self.upload_image): pixbuf = gtk.gdk.pixbuf_new_from_file(self.upload_image) pix_w = pixbuf.get_width() pix_h = pixbuf.get_height() if pix_w > pix_h: pix_s_w = self.thumb_width pix_s_h = int(pix_h / (float(pix_w) / self.thumb_width)) else: pix_s_h = self.thumb_height pix_s_w = int(pix_w / (float(pix_h) / self.thumb_height)) pixbuf = pixbuf.scale_simple(pix_s_w, pix_s_h, gtk.gdk.INTERP_TILES) thumb = gtk.image_new_from_pixbuf(pixbuf) else: thumb = gtk.Image() thumb.set_size_request(self.thumb_width, self.thumb_height) # weibo context input text_box = gtk.HBox(False, 2) text_vbox = gtk.VBox(False, 2) text_bg_vbox = gtk.VBox(False) text_bg_align = gtk.Alignment() text_bg_align.set(0.5, 0.5, 0, 0) text_bg_align.set_padding(5, 5, 16, 5) text_bg_align.connect("expose-event", self.text_view_bg_expose) text_scrolled_win = ScrolledWindow() text_scrolled_win.set_size_request(340, 157) text_view = gtk.TextView() text_view.set_left_margin(10) text_view.set_right_margin(10) text_view.set_pixels_above_lines(5) text_view.set_pixels_below_lines(5) text_view.set_wrap_mode(gtk.WRAP_WORD| gtk.WRAP_CHAR) text_view.connect("expose-event", self.text_view_expose) buf = text_view.get_buffer() text_scrolled_win.add(text_view) text_bg_vbox.pack_start(text_scrolled_win) text_bg_align.add(text_bg_vbox) text_align = gtk.Alignment() text_align.set(0.5, 0.5, 0, 0) text_align.set_padding(25, 30, 10, 10) text_box.pack_start(thumb, False, False, 10) text_box.pack_start(text_bg_align) text_vbox.pack_start(text_box, False, False, 10) text_align.add(text_vbox) #tmp_align = gtk.Alignment() #tmp_align.set(0.5, 0, 0, 1) #self.share_box.pack_start(tmp_align, False, False) self.share_box.pack_start(text_align, False, False) # dialog button box left_box = self.window.left_button_box right_box = self.window.right_button_box # input tip label self.input_num_label = Label("%d" % self.MAX_CHAR, text_size=16, text_x_align=pango.ALIGN_CENTER, label_width=50, enable_select=False) self.input_num_label.text_color = app_theme.get_color("left_char_num") # login box #weibo_box = gtk.HBox(False, 1) #weibo_box.set_size_request(-1, 50) weibo_box_list = [] self.loading_label = Label("%s..." % _("Loading"), text_size=12, label_width=70, enable_select=False) weibo_box_list.append(self.loading_label) for weibo in self.__weibo_list: box = gtk.HBox(False, 2) weibo.set_box(box) weibo_box_list.append(box) left_box.set_buttons(weibo_box_list) # share button button = Button(_("Share")) #button.set_size_request(75, 25) button.connect("clicked", self.share_button_clicked, text_view) buf.connect("changed", self.text_view_changed, button) # check char num tmp_vbox = gtk.VBox(False) tmp_align = gtk.Alignment() tmp_align.set(0.5, 0.5, 0, 0) tmp_vbox.pack_start(button, False, False) #tmp_vbox.pack_start(tmp_align) tmp_align.add(tmp_vbox) right_box.set_buttons([self.input_num_label, tmp_align]) # at first, set widget insensitive button.set_sensitive(False) text_view.set_editable(False) t = threading.Thread(target=self.init_user_info_thread, args=(button, text_view)) t.setDaemon(True) t.start() # draw text view background def text_view_bg_expose(self, widget, event): '''draw text view bg''' cr = widget.window.cairo_create() rect = widget.allocation text_pixbuf = app_theme_get_dynamic_pixbuf('image/share/text_view.png').get_pixbuf() draw.draw_pixbuf(cr, text_pixbuf, rect.x, rect.y) # if text is empty, show tip info def text_view_expose(self, text_view, event): '''text_view expose''' buf = text_view.get_buffer() text = buf.get_text(*buf.get_bounds()) if text == "" and text_view.get_editable() and not text_view.is_focus(): win = text_view.get_window(gtk.TEXT_WINDOW_TEXT) cr = win.cairo_create() cr.move_to(10, 5) context = pangocairo.CairoContext(cr) layout = context.create_layout() layout.set_font_description(pango.FontDescription("Snas 10")) layout.set_alignment(pango.ALIGN_LEFT) layout.set_text(_("Please input text here")) cr.set_source_rgb(0.66, 0.66, 0.66) context.update_layout(layout) context.show_layout(layout) # show input char num def text_view_changed(self, buf, button): '''text_view changed callback''' count = buf.get_char_count() if count <= self.MAX_CHAR: #self.input_tip_label.set_text(_("left")) self.input_num_label.set_text("%d" % (self.MAX_CHAR - count)) self.input_num_label.text_color = app_theme.get_color("left_char_num") if not button.is_sensitive(): button.set_sensitive(True) else: #self.input_tip_label.set_text(_("exceeds")) self.input_num_label.set_text("-%d" % (count - self.MAX_CHAR)) self.input_num_label.text_color = app_theme.get_color("left_char_num1") if button.is_sensitive(): button.set_sensitive(False) def share_button_clicked(self, button, text_view): '''share_button_clicked callback''' # file is not exist. if not exists(self.upload_image): d = ConfirmDialog(_("Error"), "%s." % ( _("Picture does not exist."))) d.show_all() d.set_transient_for(self.window) return False has_share_web = False for weibo in self.to_share_weibo: if self.to_share_weibo[weibo]: has_share_web = True break # have no web selected if not has_share_web: d = ConfirmDialog(_("Error"), _("Please choose at least one platform to share on")) d.show_all() d.set_transient_for(self.window) return False # at first, set widget insensitive button.set_sensitive(False) text_view.set_editable(False) #self.window.left_button_box.set_sensitive(False) # set weibo checkbutton sensitive for check in self.__weibo_check_button_list: check.set_sensitive(False) # disconnect weibo ico button clicked function for img in self.__weibo_image_button_list: try: img.disconnect_by_func(self.weibo_login) except: pass button.set_label(_("Uploading")) t = threading.Thread(target=self.share_to_weibo_thread, args=(text_view, )) t.setDaemon(True) t.start() # upload image thread def share_to_weibo_thread(self, text_view): '''share in thread''' buf = text_view.get_buffer() text = buf.get_text(*buf.get_bounds()) if text.strip() == "": text = _("from Deepin Screenshot") # get deepin official info self.deepin_info[self.sina] = self.sina.get_deepin_info() self.deepin_info[self.qq] = self.qq.get_deepin_info() if default_locale != 'zh_CN': self.deepin_info[self.twitter] = self.twitter.get_deepin_info() # upload for weibo in self.to_share_weibo: if self.to_share_weibo[weibo]: self.to_share_weibo_res[weibo] = weibo.upload_image(self.upload_image, text) self.share_to_weibo_result() # show upload result @post_gui def share_to_weibo_result(self): '''result of share to weibo''' font_color = app_theme.get_color("share_result_text") res_hbox = gtk.HBox(False) res_hbox.set_size_request(-1, 240) res_left_box = DialogLeftButtonBox() res_right_box = DialogRightButtonBox() res_left_box.button_align.set(0.5, 0.0, 0, 1) res_right_box.button_align.set(0.5, 0.0, 0, 1) res_left_box.button_align.set_padding(5, 9, 19, 0) res_right_box.button_align.set_padding(30, 0, 0, 0) res_left_box.set_size_request(405, -1) res_right_box.set_size_request(195, -1) res_hbox.pack_start(res_left_box) res_hbox.pack_start( VSeparator(app_theme.get_shadow_color("VSeparator").get_color_info(), 0, 0)) res_hbox.pack_start(res_right_box) res_vbox = gtk.VBox(False) follow_vbox = gtk.VBox(False) tmp_img = gtk.Image() # only use as a placeholder tmp_img.set_size_request(-1, 50) res_vbox.pack_start(tmp_img, False, False) follow_tip_hbox = gtk.HBox(False) img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/deepin_logo.png")) follow_tip_hbox.pack_start(img, False, False, 5) follow_tip_hbox.pack_start( Label("%s %s" % (_("Follow"), "Linux Deepin"), text_color=app_theme_get_dynamic_color("#5f5f5f"), text_size=12, enable_select=False), False, False) follow_vbox.pack_start(follow_tip_hbox, False, False, 13) for weibo in self.to_share_weibo_res: vbox = gtk.VBox(False, 1) tip_box = gtk.HBox() error_box = gtk.HBox() vbox.pack_start(tip_box, False, False) vbox.pack_start(error_box, False, False) if self.to_share_weibo_res[weibo][0]: # upload succeed img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/share_succeed.png")) #link = LinkButton(_(weibo.t_type), text_size=13, self.to_share_weibo_res[weibo][1]) link = Label(_(weibo.t_type), text_size=12, text_color=app_theme.get_color("link_text")) #, enable_gaussian=True, gaussian_radious=1, border_radious=0) link.add_events(gtk.gdk.BUTTON_PRESS_MASK) link.connect("enter-notify-event", lambda w, e: self.__draw_under_line(w)) link.connect("leave-notify-event", lambda w, e: w.queue_draw()) link.connect("button-press-event", self.goto_weibo_button_clicked, weibo) link_box = gtk.HBox(False) link_box.pack_start(link, False, False) utils.set_clickable_cursor(link) text = _("Share to") label = Label(text, text_size=12, text_color=font_color, enable_select=False) text = _("Successful") label1 = Label(text, text_size=12, text_color=font_color, enable_select=False) tip_box.pack_start(img, False, False, 15) tip_box.pack_start(label, False, False, 3) tip_box.pack_start(link_box, False, False, 3) tip_box.pack_start(label1, False, False) # only use as a placeholder img = gtk.Image() img.set_size_request(20, 1) error_box.pack_start(img, False, False, 16) tmp = Label(" ", text_size=9, label_width=200) tmp.set_size_request(200, 1) error_box.pack_start(tmp, False, False) #print text else: # upload failed img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/share_failed.png")) #text = "% %s %s." % (_(weibo.t_type), _("upload failed")) text = _("Share to") label1 = Label(text, text_size=12, text_color=font_color, enable_select=False) label2 = Label(_(weibo.t_type), text_size=12, text_color=font_color, enable_select=False) text = _("Failed") label3 = Label(text, text_size=12, text_color=font_color, enable_select=False) if weibo.curl.error: error = "(%s)" % _(weibo.curl.error) elif weibo.get_error_msg(): error = "(%s)" % _(weibo.get_error_msg()) else: error = "(%s)" % _("Unknown reason") #print "%s: %s" % (weibo.t_type, error) #print "%s: %s" % (weibo.t_type, weibo.get_error_msg()) label = Label(text, text_size=12, text_color=font_color, enable_select=False) tip_box.pack_start(img, False, False, 15) tip_box.pack_start(label1, False, False, 3) tip_box.pack_start(label2, False, False, 3) tip_box.pack_start(label3, False, False) img = gtk.Image() # only use as a placeholder img.set_size_request(20, 20) error_box.pack_start(img, False, False, 16) error_box.pack_start(Label(error, text_size=9, label_width=200, text_color=font_color, enable_select=False), False, False) #print text res_vbox.pack_start(vbox, False, False, 10) for weibo in self.deepin_info: box = gtk.HBox(False, 15) # followed img = gtk.image_new_from_pixbuf(app_theme.get_pixbuf("share/"+weibo.t_type+".png").get_pixbuf()) box.pack_start(img, False, False) if self.deepin_info[weibo] is not None and self.deepin_info[weibo][3]: if not default_locale.startswith("zh_"): button = gtk.image_new_from_pixbuf( app_theme.get_pixbuf("share/followed_en.png").get_pixbuf()) else: button = gtk.image_new_from_pixbuf( app_theme.get_pixbuf("share/followed.png").get_pixbuf()) else: # to follow if not default_locale.startswith("zh_"): button = ImageButton( app_theme.get_pixbuf("share/follow_normal_en.png"), app_theme.get_pixbuf("share/follow_hover_en.png"), app_theme.get_pixbuf("share/follow_press_en.png")) else: button = ImageButton( app_theme.get_pixbuf("share/follow_normal.png"), app_theme.get_pixbuf("share/follow_hover.png"), app_theme.get_pixbuf("share/follow_press.png")) button.connect("clicked", self.friendships_add_button_clicked, weibo, box) box.pack_start(button, False, False) align = gtk.Alignment() align.set(0.0, 0.5, 0, 0) align.set_padding(0, 0, 30, 0) align.add(box) follow_vbox.pack_start(align, False, False, 8) res_left_box.set_buttons([res_vbox]) res_right_box.set_buttons([follow_vbox]) self.result_box.pack_start(res_hbox, False, False) self.result_box.show_all() self.set_slide_index(2) def goto_weibo_button_clicked(self, widget, event, weibo): '''goto my weibo''' #print "goto weibo button clicked", weibo.t_type, "xdg-open %s" % self.to_share_weibo_res[weibo][1] if weibo in self.to_share_weibo_res: if self.to_share_weibo_res[weibo][1]: utils.run_command("xdg-open %s" % self.to_share_weibo_res[weibo][1]) def friendships_add_button_clicked(self, widget, weibo, box): '''add friendships''' #self.result_box.set_sensitive(False) if not self.is_get_user_info[weibo]: utils.run_command("xdg-open %s" % weibo.index_url) return True widget.set_sensitive(False) t = threading.Thread(target=self.friendships_add_thread, args=(widget, weibo, box)) t.setDaemon(True) t.start() def friendships_add_thread(self, button, weibo, box): '''add friendships''' if weibo.friendships_create() is not None: gtk.gdk.threads_enter() button.destroy() if not default_locale.startswith("zh_"): button = gtk.image_new_from_pixbuf( app_theme.get_pixbuf("share/followed_en.png").get_pixbuf()) else: button = gtk.image_new_from_pixbuf( app_theme.get_pixbuf("share/followed.png").get_pixbuf()) button.show() box.pack_start(button, False, False) #button.set_label("已关注") gtk.gdk.threads_leave() # show window def show(self): '''show''' self.window.show_window() # close widnow def quit(self, widget): ''' close ''' gtk.main_quit() def __slider_expose(self, widget, event): ''' slider expose redraw''' cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgba(1.0, 1.0, 1.0, 0.8) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() def __expose_top_and_bottome(self, widget, event): '''titlebar or button_box expose''' cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(0.89, 0.89, 0.89) cr.rectangle(rect.x+2, rect.y+2, rect.width-4, rect.height-4) cr.fill() def __draw_under_line(self, widget): '''draw under line''' cr = widget.window.cairo_create() with utils.cairo_disable_antialias(cr): x, y, w, h = widget.allocation # #1A70b1 cr.set_source_rgba(0.1, 0.43, 0.69, 1.0) cr.set_line_width(1) cr.move_to(x, y+h-3) cr.line_to(x+w, y+h-3) cr.stroke()
class SecondCategoryItem(TreeItem): ''' class docs ''' def __init__(self, first_category_name, second_category_name, data_manager): ''' init docs ''' TreeItem.__init__(self) self.first_category_name = first_category_name self.second_category_name = second_category_name self.data_manager = data_manager def render_name(self, cr, rect): text_color = "#333333" if self.is_select: cr.set_source_rgba(*color_hex_to_cairo( app_theme.get_color("sidebar_select").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() text_color = "#FFFFFF" elif self.is_hover: cr.set_source_rgba(*color_hex_to_cairo( app_theme.get_color("sidebar_hover").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() draw_text( cr, get_category_name(self.second_category_name), rect.x + SECOND_CATEGORY_PADDING_X, rect.y, rect.width, rect.height, text_size=SECOND_CATEGORY_ITEM_NAME_SIZE, text_color=text_color, ) def get_height(self): return SECOND_CATEGORY_ITEM_HEIGHT def get_column_widths(self): return [CATEGORY_ITEM_NAME_WIDTH] def get_column_renders(self): return [self.render_name] def hover(self, column, offset_x, offset_y): self.is_hover = True if self.redraw_request_callback: self.redraw_request_callback(self) def unhover(self, column, offset_x, offset_y): self.is_hover = False if self.redraw_request_callback: self.redraw_request_callback(self) def select(self): self.is_select = True if self.redraw_request_callback: self.redraw_request_callback(self) def unselect(self): self.is_select = False if self.redraw_request_callback: self.redraw_request_callback(self) def scrolled_window_vscrollbar_handler(self, widget, state): if state == "bottom": current_item_number = len(self.pkg_icon_view.items) all_pkgs_number = len(self.all_pkg_names) start = current_item_number if current_item_number < all_pkgs_number and ( current_item_number + LOAD_ITEMS_NUMBER) < all_pkgs_number: end = current_item_number + LOAD_ITEMS_NUMBER elif current_item_number < all_pkgs_number and ( current_item_number + LOAD_ITEMS_NUMBER) >= all_pkgs_number: end = all_pkgs_number else: return self.load_new_items(self.all_pkg_names[start:end]) def load_new_items(self, pkg_names): items = [] for pkg_name in pkg_names: info = self.data_manager.get_item_pkg_info(pkg_name) items.append( PkgIconItem(info[0], info[1], info[2], self.data_manager)) self.pkg_icon_view.add_items(items) global_event.emit("show-pkg-view", self.page_box) def handle_pkg_install_status_request(self, status, items): for (index, state) in enumerate(status): items[index].is_installed = state items[index].emit_redraw_request() def button_press(self, column, offset_x, offset_y): # init Loading widget loading_box = LoadingBox() global_event.emit("show-pkg-view", loading_box) self.page_box = gtk.VBox() self.all_pkg_names = self.data_manager.get_second_category_packages( self.second_category_name) self.message_bar = MessageBar(18) self.message_bar.set_message( _("%s > %s : %s applications") % ( get_category_name(self.first_category_name), get_category_name(self.second_category_name), len(self.all_pkg_names), )) self.pkg_icon_view = IconView() self.pkg_icon_view.connect("motion-notify-item", tooltip_aciton) if len(self.all_pkg_names) > LOAD_ITEMS_NUMBER: self.load_new_items(self.all_pkg_names[:LOAD_ITEMS_NUMBER]) else: self.load_new_items(self.all_pkg_names) self.pkg_icon_scrolled_window = ScrolledWindow() self.pkg_icon_scrolled_window.connect( "vscrollbar-state-changed", self.scrolled_window_vscrollbar_handler) self.pkg_icon_scrolled_window.add_child(self.pkg_icon_view) self.pkg_icon_view.draw_mask = self.draw_mask self.pkg_icon_view.draw_row_mask = self.draw_row_mask self.page_box.pack_start(self.message_bar, False, False) self.page_box.pack_start(self.pkg_icon_scrolled_window, True, True) global_event.emit("update-current-status-pkg-page", self.pkg_icon_view) def draw_row_mask(self, cr, rect, row): if row % 2 == 1: cr.set_source_rgba(1, 1, 1, 0.5) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [ (0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)), ])
class CategoryItem(TreeItem): ''' class docs ''' def __init__(self, index, first_category_name, data_manager): ''' init docs ''' TreeItem.__init__(self) self.index = index self.first_category_name = first_category_name self.data_manager = data_manager def render_name(self, cr, rect): text_color = "#333333" font_image_color = app_theme.get_color("sidebar_select").get_color() if self.is_select: cr.set_source_rgba(*color_hex_to_cairo( app_theme.get_color("sidebar_select").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() text_color = "#FFFFFF" font_image_color = "#FFFFFF" elif self.is_hover: cr.set_source_rgba(*color_hex_to_cairo( app_theme.get_color("sidebar_hover").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() pixbuf = app_theme.get_pixbuf("category/%s.png" % (self.index)).get_pixbuf() category_img_path = os.path.join(get_parent_dir(__file__, 2), "image", "category", "%s.png" % (self.index + 1, )) surface = cairo.ImageSurface.create_from_png(category_img_path) cr.set_source_rgb(*color_hex_to_cairo(font_image_color)) cr.mask_surface(surface, rect.x + 14, rect.y + (rect.height - 24) / 2) draw_text( cr, get_category_name(self.first_category_name), rect.x + pixbuf.get_width() + 22, rect.y, rect.width, rect.height, text_size=CATEGORY_ITEM_NAME_SIZE, text_color=text_color, ) if self.is_hover: if self.is_expand: pixbuf = app_theme.get_pixbuf("sidebar/close.png").get_pixbuf() else: pixbuf = app_theme.get_pixbuf("sidebar/open.png").get_pixbuf() draw_pixbuf(cr, pixbuf, rect.x + rect.width - CATEGORY_ITEM_EXPAND_PADDING_X, rect.y + (rect.height - pixbuf.get_height()) / 2) def get_height(self): return CATEGORY_ITEM_HEIGHT def get_column_widths(self): return [CATEGORY_ITEM_NAME_WIDTH] def get_column_renders(self): return [self.render_name] def hover(self, column, offset_x, offset_y): self.is_hover = True if self.redraw_request_callback: self.redraw_request_callback(self) def unhover(self, column, offset_x, offset_y): self.is_hover = False if self.redraw_request_callback: self.redraw_request_callback(self) def select(self): self.is_select = True if self.redraw_request_callback: self.redraw_request_callback(self) def unselect(self): self.is_select = False if self.redraw_request_callback: self.redraw_request_callback(self) def is_in_expand_button_area(self, column, offset_x, offset_y): pixbuf = app_theme.get_pixbuf("sidebar/close.png").get_pixbuf() return is_in_rect( (offset_x, offset_y), (CATEGORY_VIEW_WIDTH - CATEGORY_ITEM_EXPAND_PADDING_X, (self.get_height() - pixbuf.get_height()) / 2, pixbuf.get_width(), pixbuf.get_height())) def motion_notify(self, column, offset_x, offset_y): if self.is_in_expand_button_area(column, offset_x, offset_y): global_event.emit("set-cursor", gtk.gdk.HAND2) else: global_event.emit("set-cursor", None) def button_press(self, column, offset_x, offset_y): if self.is_in_expand_button_area(column, offset_x, offset_y): if self.is_expand: self.unexpand() else: self.expand() def scrolled_window_vscrollbar_handler(self, widget, state): if state == "bottom": current_item_number = len(self.pkg_icon_view.items) all_pkgs_number = len(self.all_pkg_names) start = current_item_number if current_item_number < all_pkgs_number and ( current_item_number + LOAD_ITEMS_NUMBER) < all_pkgs_number: end = current_item_number + LOAD_ITEMS_NUMBER elif current_item_number < all_pkgs_number and ( current_item_number + LOAD_ITEMS_NUMBER) >= all_pkgs_number: end = all_pkgs_number else: return self.load_new_items(self.all_pkg_names[start:end]) def load_new_items(self, pkg_names): items = [] for pkg_name in pkg_names: info = self.data_manager.get_item_pkg_info(pkg_name) items.append( PkgIconItem(info[0], info[1], info[2], self.data_manager)) self.pkg_icon_view.add_items(items) global_event.emit("show-pkg-view", self.page_box) def handle_pkg_install_status_request(self, status, items): for (index, state) in enumerate(status): items[index].is_installed = state items[index].emit_redraw_request() def single_click(self, column, offset_x, offset_y): # init Loading widget loading_box = LoadingBox() global_event.emit("show-pkg-view", loading_box) self.page_box = gtk.VBox() self.all_pkg_names = [] self.all_desktop_infos = {} self.all_pkg_names = self.data_manager.get_first_category_packages( self.first_category_name) self.message_bar = MessageBar(18) self.message_bar.set_message( _("%s: %s applications") % ( get_category_name(self.first_category_name), len(self.all_pkg_names), )) self.pkg_icon_view = IconView() self.pkg_icon_view.connect("motion-notify-item", tooltip_aciton) if len(self.all_pkg_names) > LOAD_ITEMS_NUMBER: self.load_new_items(self.all_pkg_names[:LOAD_ITEMS_NUMBER]) else: self.load_new_items(self.all_pkg_names) self.pkg_icon_view.draw_mask = self.draw_mask self.pkg_icon_view.draw_row_mask = self.draw_row_mask self.pkg_icon_scrolled_window = ScrolledWindow() self.pkg_icon_scrolled_window.connect( "vscrollbar-state-changed", self.scrolled_window_vscrollbar_handler) self.pkg_icon_scrolled_window.add_child(self.pkg_icon_view) self.page_box.pack_start(self.message_bar, False, False) self.page_box.pack_start(self.pkg_icon_scrolled_window, True, True) global_event.emit("update-current-status-pkg-page", self.pkg_icon_view) def draw_row_mask(self, cr, rect, row): if row % 2 == 1: cr.set_source_rgba(1, 1, 1, 0.5) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' draw_vlinear(cr, x, y, w, h, [ (0, ("#FFFFFF", 0.9)), (1, ("#FFFFFF", 0.9)), ]) def double_click(self, column, offset_x, offset_y): if self.is_expand: self.unexpand() else: self.expand() def add_child_item(self): items = [] second_category_names = self.data_manager.get_second_category( self.first_category_name) for second_category_name in second_category_names: items.append( SecondCategoryItem(self.first_category_name, second_category_name, self.data_manager)) self.child_items = items self.add_items_callback(self.child_items, self.row_index + 1) def delete_chlid_item(self): self.delete_items_callback(self.child_items) def expand(self): self.is_expand = True self.add_child_item() if self.redraw_request_callback: self.redraw_request_callback(self) global_event.emit("category-expand", self) def unexpand(self): self.is_expand = False self.delete_chlid_item() if self.redraw_request_callback: self.redraw_request_callback(self)
def __create_widget(self): '''create gtk widget''' title_item_font_size = TITLE_FONT_SIZE option_item_font_szie = CONTENT_FONT_SIZE self.label_widgets["speaker"] = Label(_("Speaker"), app_theme.get_color("globalTitleForeground"), text_size=title_item_font_size, enable_select=False, enable_double_click=False) self.label_widgets["microphone"] = Label(_("Microphone"), app_theme.get_color("globalTitleForeground"), text_size=title_item_font_size, enable_select=False, enable_double_click=False) self.label_widgets["left"] = Label(_("Left"), enable_select=False, enable_double_click=False) self.label_widgets["right"] = Label(_("Right"), enable_select=False, enable_double_click=False) self.label_widgets["speaker_port"] = Label(_("Output Port"), text_size=option_item_font_szie, text_x_align=ALIGN_END, enable_select=False, enable_double_click=False, fixed_width=STANDARD_LINE) self.label_widgets["speaker_volume"] = Label(_("Output Volume"), text_size=option_item_font_szie, text_x_align=ALIGN_END, enable_select=False, enable_double_click=False, fixed_width=STANDARD_LINE) self.label_widgets["speaker_mute"] = Label(_("Sound Enabled"), text_size=option_item_font_szie, text_x_align=ALIGN_END, enable_select=False, enable_double_click=False, fixed_width=STANDARD_LINE) self.label_widgets["speaker_balance"] = Label(_("Balance"), text_size=option_item_font_szie, text_x_align=ALIGN_END, enable_select=False, enable_double_click=False, fixed_width=STANDARD_LINE) self.label_widgets["microphone_port"] = Label(_("Input Port"), text_size=option_item_font_szie, text_x_align=ALIGN_END, enable_select=False, enable_double_click=False, fixed_width=STANDARD_LINE) self.label_widgets["microphone_volume"] = Label(_("Input Volume"), text_size=option_item_font_szie, text_x_align=ALIGN_END, enable_select=False, enable_double_click=False, fixed_width=STANDARD_LINE) self.label_widgets["microphone_mute"] = Label(_("Sound Enabled"), text_size=option_item_font_szie, text_x_align=ALIGN_END, enable_select=False, enable_double_click=False, fixed_width=STANDARD_LINE) ##################################### # image init self.image_widgets["balance"] = ImageBox(app_theme.get_pixbuf("%s/balance.png" % MODULE_NAME)) self.image_widgets["speaker"] = ImageBox(app_theme.get_pixbuf("%s/speaker-3.png" % MODULE_NAME)) self.image_widgets["microphone"] = ImageBox(app_theme.get_pixbuf("%s/microphone.png" % MODULE_NAME)) self.image_widgets["device"] = app_theme.get_pixbuf("%s/device.png" % MODULE_NAME) # button init self.button_widgets["balance"] = SwitchButton( inactive_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"), active_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png")) self.button_widgets["speaker"] = SwitchButton( inactive_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"), active_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png")) self.button_widgets["microphone"] = SwitchButton( inactive_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"), active_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png")) self.button_widgets["advanced"] = Button(_("Advanced")) self.button_widgets["speaker_combo"] = ComboBox(fixed_width=HSCALEBAR_WIDTH) self.button_widgets["microphone_combo"] = ComboBox(fixed_width=HSCALEBAR_WIDTH) # container init self.container_widgets["main_vbox"] = gtk.VBox(False) self.container_widgets["statusbar"] = StatusBar() self.container_widgets["slider"] = HSlider() self.container_widgets["swin"] = ScrolledWindow() self.container_widgets["advance_set_tab_box"] = TabBox() self.container_widgets["advance_set_tab_box"].draw_title_background = self.draw_tab_title_background self.container_widgets["main_hbox"] = gtk.HBox(False) self.container_widgets["left_vbox"] = gtk.VBox(False) self.container_widgets["right_vbox"] = gtk.VBox(False) self.container_widgets["balance_hbox"] = gtk.HBox(False) self.container_widgets["speaker_main_vbox"] = gtk.VBox(False) # speaker self.container_widgets["speaker_label_hbox"] = gtk.HBox(False) self.container_widgets["speaker_table"] = gtk.Table(4, 2) self.container_widgets["microphone_main_vbox"] = gtk.VBox(False) # microphone self.container_widgets["microphone_label_hbox"] = gtk.HBox(False) self.container_widgets["microphone_table"] = gtk.Table(4, 2) # alignment init self.alignment_widgets["slider"] = gtk.Alignment() self.alignment_widgets["main_hbox"] = gtk.Alignment() self.alignment_widgets["advance_set_tab_box"] = gtk.Alignment() self.alignment_widgets["left"] = gtk.Alignment() self.alignment_widgets["right"] = gtk.Alignment() self.alignment_widgets["speaker_label"] = gtk.Alignment() # speaker self.alignment_widgets["speaker_set"] = gtk.Alignment() self.alignment_widgets["microphone_label"] = gtk.Alignment() # microphone self.alignment_widgets["microphone_set"] = gtk.Alignment() # adjust init volume_max_percent = pypulse.MAX_VOLUME_VALUE * 100 / pypulse.NORMAL_VOLUME_VALUE self.adjust_widgets["balance"] = gtk.Adjustment(0, -1.0, 1.0, 0.1, 0.2) self.adjust_widgets["speaker"] = gtk.Adjustment(0, 0, volume_max_percent, 1, 5) self.adjust_widgets["microphone"] = gtk.Adjustment(0, 0, volume_max_percent, 1, 5) # scale init self.scale_widgets["balance"] = HScalebar(value_min=-1, value_max=1, gray_progress=True) self.scale_widgets["balance"].set_magnetic_values([(0, 0.1), (1, 0.1), (2, 0.1)]) self.scale_widgets["speaker"] = HScalebar(show_value=True, format_value="%", value_min=0, value_max=volume_max_percent) self.scale_widgets["speaker"].set_magnetic_values([(0, 5), (100, 5), (volume_max_percent, 5)]) self.scale_widgets["microphone"] = HScalebar(show_value=True, format_value="%", value_min=0, value_max=volume_max_percent) self.scale_widgets["microphone"].set_magnetic_values([(0, 5), (100, 5), (volume_max_percent, 5)]) ################################### # advance set self.container_widgets["advance_input_box"] = gtk.VBox(False) self.container_widgets["advance_output_box"] = gtk.VBox(False) self.container_widgets["advance_hardware_box"] = gtk.VBox(False) self.alignment_widgets["advance_input_box"] = gtk.Alignment() self.alignment_widgets["advance_output_box"] = gtk.Alignment() self.alignment_widgets["advance_hardware_box"] = gtk.Alignment() # self.label_widgets["ad_output"] = Label(_("Choose a device for sound output:"), enable_select=False, enable_double_click=False) self.label_widgets["ad_input"] = Label(_("Choose a device for sound input:"), enable_select=False, enable_double_click=False) self.label_widgets["ad_hardware"] = Label(_("Choose a device to configure:"), enable_select=False, enable_double_click=False) # self.container_widgets["ad_output"] = gtk.VBox(False) self.container_widgets["ad_input"] = gtk.VBox(False) self.container_widgets["ad_hardware"] = gtk.VBox(False) # self.view_widgets["ad_output"] = TreeView() self.view_widgets["ad_input"] = TreeView() self.view_widgets["ad_hardware"] = TreeView()
def get_scrolled_window(self): scrolled_window = ScrolledWindow() scrolled_window.connect("vscrollbar-state-changed", self.__on_vscrollbar_state_changed) scrolled_window.add_child(self) return scrolled_window
class SettingUI(gtk.Alignment): def __init__(self, slide_back_cb, change_crumb_cb): gtk.Alignment.__init__(self, 0, 0, 0, 0) self.slide_back = slide_back_cb self.change_crumb = change_crumb_cb self.scroll_win = ScrolledWindow() self.scroll_win.set_can_focus(False) self.scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) main_vbox = gtk.VBox() self.foot_box = FootBox() self.hbox = gtk.HBox() self.scroll_win.add_with_viewport(self.hbox) self.scroll_align = gtk.Alignment() self.scroll_win.set_size_request(800, 435) self.scroll_align.set(0, 0, 0, 0) self.scroll_align.set_padding(0, 0, 30, 0) self.scroll_align.add(self.scroll_win) padding_align = gtk.Alignment(0, 0, 0, 0) padding_align.set_padding(15, 0, 0, 0) self.sidebar = SideBar( None) padding_align.add(self.sidebar) self.hpaned = MyPaned() self.hpaned.set_size_request(800, -1) self.hpaned.connect("expose-event",self.expose_line) #self.hpaned.do_enter_notify_event = self.enter_notify_event self.hpaned.add1(padding_align) self.hpaned.add2(self.scroll_align) self.connect_after("show", self.__init_paned) main_vbox.pack_start(self.hpaned, True, True) main_vbox.pack_start(self.foot_box, False, False) self.add(main_vbox) self.__init_signals() def enter_notify_event(self, e): pass def __init_paned(self, widget): log.debug("") self.hpaned.saved_position = 160 self.hpaned.set_position(1) self.hpaned.animation_position_frames = [0] self.hpaned.update_position() def __init_signals(self): Dispatcher.connect("connection-change", self.switch_content) Dispatcher.connect("setting-saved", self.save_connection_setting) Dispatcher.connect("setting-appled", self.apply_connection_setting) Dispatcher.connect("request_redraw", lambda w: self.scroll_win.show_all()) def load_module(self, module_obj, hide_left): # create a reference self.setting_group = module_obj # init paned self.__init_paned(None) log.info("dss start load module", module_obj) self.hpaned.set_button_show(hide_left) # init foot_box self.foot_box.set_setting(module_obj) # init sidebar self.sidebar.load_list(module_obj) self.apply_method = module_obj.apply_changes self.save_method = module_obj.save_changes def switch_content(self, widget, connection): container_remove_all(self.hbox) self.set_tab_content(connection) self.set_foot_bar_button(connection) self.focus_connection = connection def set_foot_bar_button(self, connection): if type(connection) == NMRemoteConnection: self.foot_box.show_delete(connection) else: self.foot_box.hide_delete() states = self.setting_group.get_button_state(connection) if states: Dispatcher.set_button(*states) def set_tab_content(self, connection): log.debug("set tab content", connection) setting = self.setting_group.init_items(connection) self.hbox.add(setting) self.hbox.show_all() self.foot_box.set_lock(False) def expose_line(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation style.draw_out_line(cr, rect, exclude=["left", "right", "top"]) def draw_tab_title_background(self, cr, widget): rect = widget.allocation cr.set_source_rgb(1, 1, 1) cr.rectangle(0, 0, rect.width, rect.height - 1) cr.fill() def save_connection_setting(self, widget): self.save_method(self.focus_connection) def apply_connection_setting(self, widget): #print type(self.focus_connection) self.apply_method(self.focus_connection) def create_new_connection(self): self.sidebar.add_new_connection()
def __init__(self, filename=""): ''' init share @param filename: the file to share ''' self.upload_image = filename self.thumb_width = 188 self.thumb_height = 168 self.MAX_CHAR = 140 #self.__text_frame_color = (0.76, 0.76, 0.76) self.__win_width = 602 open(COOKIE_FILE,'wb').close() self.window = DialogBox(_("Share to social networks"), close_callback=gtk.main_quit) self.window.set_keep_above(True) self.window.set_size_request(self.__win_width+20, 288) self.window.set_resizable(False) #self.window.titlebar.connect("expose-event", self.__expose_top_and_bottome) #self.window.button_box.connect("expose-event", self.__expose_top_and_bottome) # create slider self.slider = HSlider() self.slider_list = [] self.share_box = gtk.VBox(False) # first page, input context self.web_box = gtk.VBox(False, 10) # second page, login self.result_box = gtk.VBox(False, 10) # third page, share result share_align = gtk.Alignment() share_align.set(0.5, 0.5, 0, 0) share_align.add(self.share_box) share_align.connect("expose-event", self.__slider_expose) # go back button web_left_button = ImageButton( app_theme.get_pixbuf("share/back_normal.png"), app_theme.get_pixbuf("share/back_hover.png"), app_theme.get_pixbuf("share/back_press.png")) web_left_button.connect("clicked", lambda w: self.set_slide_index(0)) web_left_button.set_can_focus(False) utils.set_clickable_cursor(web_left_button) # show url entry self.web_url_entry = InputEntry() self.web_url_entry.set_editable(False) self.web_url_entry.set_size(555, 20) self.web_url_entry.entry.right_menu_visible_flag = False # alig url entry web_navigate_vbox = gtk.VBox(False) web_navigate_vbox.pack_start(self.web_url_entry) web_navigate_t_align = gtk.Alignment() web_navigate_t_align.set(0.0, 0.5, 0, 0) web_navigate_t_align.add(web_navigate_vbox) # pack back button and url entry web_navigate_box = gtk.HBox(False, 7) web_navigate_box.pack_start(web_left_button, False, False) web_navigate_box.pack_start(web_navigate_t_align) web_navigate_align = gtk.Alignment() web_navigate_align.set(0.5, 0.5, 0, 0) web_navigate_align.set_padding(4, 0, 11, 13) web_navigate_align.add(web_navigate_box) # create a webkit self.web_view = WebView(COOKIE_FILE) self.web_view.connect("notify::load-status", self.web_view_load_status) self.web_view.connect("load-error", self.web_view_load_error) self.web_scrolled_window = ScrolledWindow() self.web_scrolled_window.add(self.web_view) self.web_scrolled_window.set_size_request(590, 228) self.web_box.pack_start(web_navigate_align, False, False) self.web_box.pack_start(self.web_scrolled_window) #self.web_box.set_size_request(-1, 258) web_align = gtk.Alignment() web_align.set(0.5, 0.0, 0, 1) web_align.add(self.web_box) web_align.connect("expose-event", self.__slider_expose) res_align = gtk.Alignment() res_align.set(0.5, 0.5, 0, 0) res_align.add(self.result_box) res_align.connect("expose-event", self.__slider_expose) self.slider.set_to_page(share_align) self.slider_list.append(share_align) self.slider_list.append(web_align) self.slider_list.append(res_align) self.__weibo_list = [] self.sina = weibo.Sina(self.web_view) self.qq = weibo.Tencent(self.web_view) self.__weibo_list.append(self.sina) self.__weibo_list.append(self.qq) if default_locale != 'zh_CN': self.twitter = weibo.Twitter(self.web_view) #self.__weibo_list.append(self.twitter) self.__current_weibo = None self.weibo_name_l18n = { 'Sina': _("Sina"), 'Tencent': _("Tencent"), 'Twitter': _("Twitter"), } self.window.body_box.pack_start(self.slider, True, True) self.init_share_box()
class ShareToWeibo(object): '''share picture to weibo''' def __init__(self, filename=""): ''' init share @param filename: the file to share ''' self.upload_image = filename self.thumb_width = 188 self.thumb_height = 168 self.MAX_CHAR = 140 #self.__text_frame_color = (0.76, 0.76, 0.76) self.__win_width = 602 open(COOKIE_FILE,'wb').close() self.window = DialogBox(_("Share to social networks"), close_callback=gtk.main_quit) self.window.set_keep_above(True) self.window.set_size_request(self.__win_width+20, 288) self.window.set_resizable(False) #self.window.titlebar.connect("expose-event", self.__expose_top_and_bottome) #self.window.button_box.connect("expose-event", self.__expose_top_and_bottome) # create slider self.slider = HSlider() self.slider_list = [] self.share_box = gtk.VBox(False) # first page, input context self.web_box = gtk.VBox(False, 10) # second page, login self.result_box = gtk.VBox(False, 10) # third page, share result share_align = gtk.Alignment() share_align.set(0.5, 0.5, 0, 0) share_align.add(self.share_box) share_align.connect("expose-event", self.__slider_expose) # go back button web_left_button = ImageButton( app_theme.get_pixbuf("share/back_normal.png"), app_theme.get_pixbuf("share/back_hover.png"), app_theme.get_pixbuf("share/back_press.png")) web_left_button.connect("clicked", lambda w: self.set_slide_index(0)) web_left_button.set_can_focus(False) utils.set_clickable_cursor(web_left_button) # show url entry self.web_url_entry = InputEntry() self.web_url_entry.set_editable(False) self.web_url_entry.set_size(555, 20) self.web_url_entry.entry.right_menu_visible_flag = False # alig url entry web_navigate_vbox = gtk.VBox(False) web_navigate_vbox.pack_start(self.web_url_entry) web_navigate_t_align = gtk.Alignment() web_navigate_t_align.set(0.0, 0.5, 0, 0) web_navigate_t_align.add(web_navigate_vbox) # pack back button and url entry web_navigate_box = gtk.HBox(False, 7) web_navigate_box.pack_start(web_left_button, False, False) web_navigate_box.pack_start(web_navigate_t_align) web_navigate_align = gtk.Alignment() web_navigate_align.set(0.5, 0.5, 0, 0) web_navigate_align.set_padding(4, 0, 11, 13) web_navigate_align.add(web_navigate_box) # create a webkit self.web_view = WebView(COOKIE_FILE) self.web_view.connect("notify::load-status", self.web_view_load_status) self.web_view.connect("load-error", self.web_view_load_error) self.web_scrolled_window = ScrolledWindow() self.web_scrolled_window.add(self.web_view) self.web_scrolled_window.set_size_request(590, 228) self.web_box.pack_start(web_navigate_align, False, False) self.web_box.pack_start(self.web_scrolled_window) #self.web_box.set_size_request(-1, 258) web_align = gtk.Alignment() web_align.set(0.5, 0.0, 0, 1) web_align.add(self.web_box) web_align.connect("expose-event", self.__slider_expose) res_align = gtk.Alignment() res_align.set(0.5, 0.5, 0, 0) res_align.add(self.result_box) res_align.connect("expose-event", self.__slider_expose) self.slider.set_to_page(share_align) self.slider_list.append(share_align) self.slider_list.append(web_align) self.slider_list.append(res_align) self.__weibo_list = [] self.sina = weibo.Sina(self.web_view) self.qq = weibo.Tencent(self.web_view) self.__weibo_list.append(self.sina) self.__weibo_list.append(self.qq) if default_locale != 'zh_CN': self.twitter = weibo.Twitter(self.web_view) #self.__weibo_list.append(self.twitter) self.__current_weibo = None self.weibo_name_l18n = { 'Sina': _("Sina"), 'Tencent': _("Tencent"), 'Twitter': _("Twitter"), } self.window.body_box.pack_start(self.slider, True, True) self.init_share_box() # webkit load-status, login success, go back def web_view_load_status(self, web, status): '''web_view notify load-status callback''' state = web.get_property("load-status") url = web.get_property('uri') if url: self.web_url_entry.set_editable(True) self.web_url_entry.set_text(url) self.web_url_entry.entry.move_to_start() self.web_url_entry.set_editable(False) if state == webkit.LOAD_FAILED: # load failed print "load failed", print web.get_property('uri') elif state == webkit.LOAD_COMMITTED: if self.__current_weibo and self.__current_weibo.is_callback_url(url): web.stop_loading() # if go to callback url, stop loading # access token #print "load committed", url t = threading.Thread(target=self.weibo_login_thread) t.setDaemon(True) t.start() def web_view_load_error(self, web, fram, url, error, data=None): web.load_string( "<html><body><p><h1>%s</h1></p>%s</body></html>" % ( _("Unable to load page"), _("Problem occurred while loading the URL '%s'") % (url)), "text/html", "UTF-8", "") print url return True # login or switch user def weibo_login(self, widget, weibo): '''weibo button clicked callback''' self.web_view.load_uri("about:blank") utils.set_cursor(widget) self.set_slide_index(1) self.__current_weibo = weibo t = threading.Thread(target=self.__current_weibo.request_oauth) t.setDaemon(True) t.start() def weibo_login_thread(self): '''in webkit login finish, get user info again''' self.__current_weibo.access_token() self.get_user_info_again() gtk.gdk.threads_enter() self.set_slide_index(0) gtk.gdk.threads_leave() def get_user_info_again(self): ''' login or switch user, and get user info again''' box = self.__current_weibo.get_box() #print "cuurent weibo:", self.__current_weibo.t_type gtk.gdk.threads_enter() children = box.get_children() for child in children: if child in self.__weibo_check_button_list: self.__weibo_check_button_list.remove(child) if child in self.__weibo_image_button_list: self.__weibo_image_button_list.remove(child) child.destroy() gtk.gdk.threads_leave() self.get_user_info(self.__current_weibo) gtk.gdk.threads_enter() box.show_all() gtk.gdk.threads_leave() def set_slide_index(self, index): ''' set slide to index @param index: the index of widget in slider, an int num ''' if index >= len(self.slider_list): return direct = "right" if index == 1 and self.window.button_box in self.window.window_frame.get_children(): #self.slider.set_size_request(-1, 260) win = self.window if win.left_button_box in win.button_box.get_children(): win.button_box.remove(win.left_button_box) if win.right_button_box in win.button_box.get_children(): win.button_box.remove(win.right_button_box) tmp = gtk.HSeparator() tmp.set_size_request(-1, 1) tmp.show() win.button_box.pack_start(tmp) direct = "right" #if self.window.button_box in self.window.window_frame.get_children(): #self.window.window_frame.remove(self.window.button_box) elif index == 0: #self.slider.set_size_request(-1, 223) win = self.window for each in win.button_box.get_children(): each.destroy() if win.left_button_box not in win.button_box.get_children(): win.button_box.pack_start(win.left_button_box) if win.right_button_box not in win.button_box.get_children(): win.button_box.pack_start(win.right_button_box) direct = "left" #if self.window.button_box not in self.window.window_frame.get_children(): #self.window.window_frame.pack_start(self.window.button_box, False, False) elif index == 2: self.window.left_button_box.set_buttons([]) l = Label(" ") l.show() self.window.right_button_box.set_buttons([l]) direct = "right" #self.slider.set_size_request(-1, 223) self.slider.slide_to_page(self.slider_list[index], direct) def weibo_check_toggle(self, button, weibo): '''weibo check button toggled callback. check the weibo to share''' if button.get_active(): self.to_share_weibo[weibo] = 1 else: self.to_share_weibo[weibo] = 0 def create_ico_image(self, name): ''' create image from file''' pix1 = app_theme_get_dynamic_pixbuf('image/share/%s.png' % name).get_pixbuf() pix2 = app_theme_get_dynamic_pixbuf('image/share/%s_no.png' % name).get_pixbuf() return (pix1, pix2) def get_user_info(self, weibo): '''get weibo user info''' info = weibo.get_user_name() gtk.gdk.threads_enter() #self.get_user_error_text = "" weibo_hbox = weibo.get_box() hbox = gtk.HBox(False) vbox = gtk.VBox(False) weibo_hbox.pack_start(vbox, False, False) vbox.pack_start(hbox) #print weibo.t_type, info if info: self.is_get_user_info[weibo] = 1 label = Label(text=info, label_width=70, enable_select=False) check = CheckButton() #check = gtk.CheckButton() check.connect("toggled", self.weibo_check_toggle, weibo) check.set_active(True) check_vbox = gtk.VBox(False) check_align = gtk.Alignment(0.5, 0.5, 0, 0) check_align.add(check_vbox) check_vbox.pack_start(check, False, False) button = ImageButton( app_theme.get_pixbuf("share/" + weibo.t_type + ".png"), app_theme.get_pixbuf("share/" + weibo.t_type + ".png"), app_theme.get_pixbuf("share/" + weibo.t_type + ".png")) utils.set_clickable_cursor(button) button.connect("enter-notify-event", self.show_tooltip, _("Click to switch user")) hbox.pack_start(check_align, False, False) hbox.pack_start(button, False, False, 5) hbox.pack_start(label, False, False) else: self.is_get_user_info[weibo] = 0 check = CheckButton() #check = gtk.CheckButton() check.set_sensitive(False) check_vbox = gtk.VBox(False) check_align = gtk.Alignment(0.5, 0.5, 0, 0) check_align.add(check_vbox) check_vbox.pack_start(check, False, False) button = ImageButton( app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"), app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png"), app_theme.get_pixbuf("share/" + weibo.t_type + "_no.png")) utils.set_clickable_cursor(button) button.connect("enter-notify-event", self.show_tooltip, _("Click to login")) hbox.pack_start(check_align, False, False) hbox.pack_start(button, False, False, 5) # curl time out info_error = weibo.get_curl_error() if info_error: #self.get_user_error_text += "%s:%s." % (weibo.t_type, _(info_error)) hbox.pack_start( Label(text="(%s)" % _(info_error), label_width=70,enable_select=False, text_color = ui_theme.get_color("category_item")), False, False) button.connect("clicked", self.weibo_login, weibo) self.__weibo_check_button_list.append(check) self.__weibo_image_button_list.append(button) gtk.gdk.threads_leave() return weibo_hbox def show_tooltip(self, widget, event, text): '''Create help tooltip.''' Tooltip.text(widget, text) def init_user_info_thread(self, button, text_view): '''get user name thread''' time.sleep(0.1) for weibo in self.__weibo_list: self.get_user_info(weibo) gtk.gdk.threads_enter() #self.share_box.set_sensitive(True) button.set_sensitive(True) text_view.set_editable(True) for weibo in self.__weibo_list: weibo.get_box().show_all() weibo.get_box().queue_draw() self.loading_label.destroy() gtk.gdk.threads_leave() # init share box, create share button, input def init_share_box(self): '''get weibo info, and create button''' self.to_share_weibo = {} self.to_share_weibo_res = {} self.deepin_info = {} self.is_get_user_info = {} self.__weibo_check_button_list = [] self.__weibo_image_button_list = [] # create Thumbnail if exists(self.upload_image): pixbuf = gtk.gdk.pixbuf_new_from_file(self.upload_image) pix_w = pixbuf.get_width() pix_h = pixbuf.get_height() if pix_w > pix_h: pix_s_w = self.thumb_width pix_s_h = int(pix_h / (float(pix_w) / self.thumb_width)) else: pix_s_h = self.thumb_height pix_s_w = int(pix_w / (float(pix_h) / self.thumb_height)) pixbuf = pixbuf.scale_simple(pix_s_w, pix_s_h, gtk.gdk.INTERP_TILES) thumb = gtk.image_new_from_pixbuf(pixbuf) else: thumb = gtk.Image() thumb.set_size_request(self.thumb_width, self.thumb_height) # weibo context input text_box = gtk.HBox(False, 2) text_vbox = gtk.VBox(False, 2) text_bg_vbox = gtk.VBox(False) text_bg_align = gtk.Alignment() text_bg_align.set(0.5, 0.5, 0, 0) text_bg_align.set_padding(5, 5, 16, 5) text_bg_align.connect("expose-event", self.text_view_bg_expose) text_scrolled_win = gtk.ScrolledWindow() text_scrolled_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER) text_scrolled_win.set_size_request(340, 157) text_view = gtk.TextView() text_view.set_left_margin(10) text_view.set_right_margin(10) text_view.set_pixels_above_lines(5) text_view.set_pixels_below_lines(5) text_view.set_wrap_mode(gtk.WRAP_WORD| gtk.WRAP_CHAR) text_view.connect("expose-event", self.text_view_expose) buf = text_view.get_buffer() text_scrolled_win.add(text_view) text_bg_vbox.pack_start(text_scrolled_win) text_bg_align.add(text_bg_vbox) text_align = gtk.Alignment() text_align.set(0.5, 0.5, 0, 0) text_align.set_padding(25, 30, 10, 10) text_box.pack_start(thumb, False, False, 10) text_box.pack_start(text_bg_align) text_vbox.pack_start(text_box, False, False, 10) text_align.add(text_vbox) #tmp_align = gtk.Alignment() #tmp_align.set(0.5, 0, 0, 1) #self.share_box.pack_start(tmp_align, False, False) self.share_box.pack_start(text_align, False, False) # dialog button box left_box = self.window.left_button_box right_box = self.window.right_button_box # input tip label self.input_num_label = Label("%d" % self.MAX_CHAR, text_size=16, text_x_align=pango.ALIGN_CENTER, label_width=50, enable_select=False) self.input_num_label.text_color = ui_theme.get_color("label_select_text") # login box #weibo_box = gtk.HBox(False, 1) #weibo_box.set_size_request(-1, 50) weibo_box_list = [] self.loading_label = Label("%s..." % _("Loading"), text_size=12, label_width=70, enable_select=False) weibo_box_list.append(self.loading_label) for weibo in self.__weibo_list: box = gtk.HBox(False, 2) weibo.set_box(box) weibo_box_list.append(box) left_box.set_buttons(weibo_box_list) # share button button = Button(_("Share")) #button.set_size_request(75, 25) button.connect("clicked", self.share_button_clicked, text_view) buf.connect("changed", self.text_view_changed, button) # check char num tmp_vbox = gtk.VBox(False) tmp_align = gtk.Alignment() tmp_align.set(0.5, 0.5, 0, 0) tmp_vbox.pack_start(button, False, False) #tmp_vbox.pack_start(tmp_align) tmp_align.add(tmp_vbox) right_box.set_buttons([self.input_num_label, tmp_align]) # at first, set widget insensitive button.set_sensitive(False) text_view.set_editable(False) t = threading.Thread(target=self.init_user_info_thread, args=(button, text_view)) t.setDaemon(True) t.start() # draw text view background def text_view_bg_expose(self, widget, event): '''draw text view bg''' cr = widget.window.cairo_create() rect = widget.allocation text_pixbuf = app_theme_get_dynamic_pixbuf('image/share/text_view.png').get_pixbuf() draw.draw_pixbuf(cr, text_pixbuf, rect.x, rect.y) # if text is empty, show tip info def text_view_expose(self, text_view, event): '''text_view expose''' buf = text_view.get_buffer() text = buf.get_text(*buf.get_bounds()) if text == "" and text_view.get_editable() and not text_view.is_focus(): win = text_view.get_window(gtk.TEXT_WINDOW_TEXT) cr = win.cairo_create() cr.move_to(10, 5) context = pangocairo.CairoContext(cr) layout = context.create_layout() layout.set_font_description(pango.FontDescription("Snas 10")) layout.set_alignment(pango.ALIGN_LEFT) layout.set_text(_("Please input text here")) cr.set_source_rgb(0.66, 0.66, 0.66) context.update_layout(layout) context.show_layout(layout) # show input char num def text_view_changed(self, buf, button): '''text_view changed callback''' count = buf.get_char_count() if count <= self.MAX_CHAR: #self.input_tip_label.set_text(_("left")) self.input_num_label.set_text("%d" % (self.MAX_CHAR - count)) self.input_num_label.text_color = ui_theme.get_color("category_item") if not button.is_sensitive(): button.set_sensitive(True) else: #self.input_tip_label.set_text(_("exceeds")) self.input_num_label.set_text("-%d" % (count - self.MAX_CHAR)) self.input_num_label.text_color = ui_theme.get_color("category_item") if button.is_sensitive(): button.set_sensitive(False) def show_confirm_dialog(self, title, content): d = ConfirmDialog( title, content, text_wrap_width=300, ) d.show_all() d.set_transient_for(self.window) def share_button_clicked(self, button, text_view): '''share_button_clicked callback''' # file is not exist. if not exists(self.upload_image): self.show_confirm_dialog( _("Error"), _("Nonexistent picture"), ) return False has_share_web = False for weibo in self.to_share_weibo: if self.to_share_weibo[weibo]: has_share_web = True break # have no web selected if not has_share_web: self.show_confirm_dialog( _("Error"), _("Please choose at least one platform to share on"), ) return False # at first, set widget insensitive button.set_sensitive(False) text_view.set_editable(False) #self.window.left_button_box.set_sensitive(False) # set weibo checkbutton sensitive for check in self.__weibo_check_button_list: check.set_sensitive(False) # disconnect weibo ico button clicked function for img in self.__weibo_image_button_list: try: img.disconnect_by_func(self.weibo_login) except: pass button.set_label(_("Sharing")) t = threading.Thread(target=self.share_to_weibo_thread, args=(text_view, )) t.setDaemon(True) t.start() # upload image thread def share_to_weibo_thread(self, text_view): '''share in thread''' buf = text_view.get_buffer() text = buf.get_text(*buf.get_bounds()) if text.strip() == "": text = _("from Deepin Game") # get deepin official info self.deepin_info[self.sina] = self.sina.get_deepin_info() self.deepin_info[self.qq] = self.qq.get_deepin_info() if default_locale != 'zh_CN': self.deepin_info[self.twitter] = self.twitter.get_deepin_info() # upload for weibo in self.to_share_weibo: if self.to_share_weibo[weibo]: self.to_share_weibo_res[weibo] = weibo.upload_image(self.upload_image, text) self.share_to_weibo_result() # show upload result @post_gui def share_to_weibo_result(self): '''result of share to weibo''' font_color = ui_theme.get_color("category_item") res_hbox = gtk.HBox(False) res_hbox.set_size_request(-1, 240) res_left_box = DialogLeftButtonBox() res_right_box = DialogRightButtonBox() res_left_box.button_align.set(0.5, 0.0, 0, 1) res_right_box.button_align.set(0.5, 0.0, 0, 1) res_left_box.button_align.set_padding(5, 9, 19, 0) res_right_box.button_align.set_padding(30, 0, 0, 0) res_left_box.set_size_request(405, -1) res_right_box.set_size_request(195, -1) res_hbox.pack_start(res_left_box) res_hbox.pack_start( VSeparator(app_theme.get_shadow_color("VSeparator").get_color_info(), 0, 0)) res_hbox.pack_start(res_right_box) res_vbox = gtk.VBox(False) follow_vbox = gtk.VBox(False) tmp_img = gtk.Image() # only use as a placeholder tmp_img.set_size_request(-1, 50) res_vbox.pack_start(tmp_img, False, False) follow_tip_hbox = gtk.HBox(False) img = gtk.image_new_from_icon_name("deepin-logo", 16) if img.get_pixel_size() == -1: img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/deepin_logo.png")) follow_tip_hbox.pack_start(img, False, False, 5) follow_tip_hbox.pack_start( Label("%s %s" % (_("Follow"), "Linux Deepin"), text_color=app_theme_get_dynamic_color("#5f5f5f"), text_size=12, enable_select=False), False, False) follow_vbox.pack_start(follow_tip_hbox, False, False, 13) for weibo in self.to_share_weibo_res: vbox = gtk.VBox(False, 1) tip_box = gtk.HBox() error_box = gtk.HBox() vbox.pack_start(tip_box, False, False) vbox.pack_start(error_box, False, False) if self.to_share_weibo_res[weibo][0]: # upload succeed img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/share_succeed.png")) #link = LinkButton(_(weibo.t_type), text_size=13, self.to_share_weibo_res[weibo][1]) link = Label(self.weibo_name_l18n[weibo.t_type], text_size=12, text_color=ui_theme.get_color("link_text")) #, enable_gaussian=True, gaussian_radious=1, border_radious=0) link.add_events(gtk.gdk.BUTTON_PRESS_MASK) link.connect("enter-notify-event", lambda w, e: self.__draw_under_line(w)) link.connect("leave-notify-event", lambda w, e: w.queue_draw()) link.connect("button-press-event", self.goto_weibo_button_clicked, weibo) link_box = gtk.HBox(False) link_box.pack_start(link, False, False) utils.set_clickable_cursor(link) text = _("Share to") label = Label(text, text_size=12, text_color=font_color, enable_select=False) text = _("Successful") label1 = Label(text, text_size=12, text_color=font_color, enable_select=False) tip_box.pack_start(img, False, False, 15) tip_box.pack_start(label, False, False, 3) tip_box.pack_start(link_box, False, False, 3) tip_box.pack_start(label1, False, False) # only use as a placeholder img = gtk.Image() img.set_size_request(20, 1) error_box.pack_start(img, False, False, 16) tmp = Label(" ", text_size=9, label_width=200) tmp.set_size_request(200, 1) error_box.pack_start(tmp, False, False) #print text else: # upload failed img = gtk.image_new_from_file(app_theme.get_theme_file_path("image/share/share_failed.png")) #text = "% %s %s." % (_(weibo.t_type), _("upload failed")) text = _("Share to") label1 = Label(text, text_size=12, text_color=font_color, enable_select=False) label2 = Label(_(weibo.t_type), text_size=12, text_color=font_color, enable_select=False) text = _("Failed") label3 = Label(text, text_size=12, text_color=font_color, enable_select=False) if weibo.curl.error: error = "(%s)" % _(weibo.curl.error) elif weibo.get_error_msg(): error = "(%s)" % _(weibo.get_error_msg()) else: error = "(%s)" % _("Unknown reason") #print "%s: %s" % (weibo.t_type, error) #print "%s: %s" % (weibo.t_type, weibo.get_error_msg()) label = Label(text, text_size=12, text_color=font_color, enable_select=False) tip_box.pack_start(img, False, False, 15) tip_box.pack_start(label1, False, False, 3) tip_box.pack_start(label2, False, False, 3) tip_box.pack_start(label3, False, False) img = gtk.Image() # only use as a placeholder img.set_size_request(20, 20) error_box.pack_start(img, False, False, 16) error_box.pack_start(Label(error, text_size=9, label_width=200, text_color=font_color, enable_select=False), False, False) #print text res_vbox.pack_start(vbox, False, False, 10) for weibo in self.deepin_info: box = gtk.HBox(False, 15) # followed img = gtk.image_new_from_pixbuf(app_theme.get_pixbuf("share/"+weibo.t_type+".png").get_pixbuf()) box.pack_start(img, False, False) if self.deepin_info[weibo] is not None and self.deepin_info[weibo][3]: if not default_locale.startswith("zh_"): button = gtk.image_new_from_pixbuf( app_theme.get_pixbuf("share/followed_en.png").get_pixbuf()) else: button = gtk.image_new_from_pixbuf( app_theme.get_pixbuf("share/followed.png").get_pixbuf()) else: # to follow if not default_locale.startswith("zh_"): button = ImageButton( app_theme.get_pixbuf("share/follow_normal_en.png"), app_theme.get_pixbuf("share/follow_hover_en.png"), app_theme.get_pixbuf("share/follow_press_en.png")) else: button = ImageButton( app_theme.get_pixbuf("share/follow_normal.png"), app_theme.get_pixbuf("share/follow_hover.png"), app_theme.get_pixbuf("share/follow_press.png")) button.connect("clicked", self.friendships_add_button_clicked, weibo, box) box.pack_start(button, False, False) align = gtk.Alignment() align.set(0.0, 0.5, 0, 0) align.set_padding(0, 0, 30, 0) align.add(box) follow_vbox.pack_start(align, False, False, 8) res_left_box.set_buttons([res_vbox]) res_right_box.set_buttons([follow_vbox]) self.result_box.pack_start(res_hbox, False, False) self.result_box.show_all() self.set_slide_index(2) def goto_weibo_button_clicked(self, widget, event, weibo): '''goto my weibo''' #print "goto weibo button clicked", weibo.t_type, "xdg-open %s" % self.to_share_weibo_res[weibo][1] if weibo in self.to_share_weibo_res: if self.to_share_weibo_res[weibo][1]: webbrowser.open(self.to_share_weibo_res[weibo][1]) def friendships_add_button_clicked(self, widget, weibo, box): '''add friendships''' #self.result_box.set_sensitive(False) if not self.is_get_user_info[weibo]: utils.run_command("xdg-open %s" % weibo.index_url) return True widget.set_sensitive(False) t = threading.Thread(target=self.friendships_add_thread, args=(widget, weibo, box)) t.setDaemon(True) t.start() def friendships_add_thread(self, button, weibo, box): '''add friendships''' if weibo.friendships_create() is not None: gtk.gdk.threads_enter() button.destroy() if not default_locale.startswith("zh_"): button = gtk.image_new_from_pixbuf( app_theme.get_pixbuf("share/followed_en.png").get_pixbuf()) else: button = gtk.image_new_from_pixbuf( app_theme.get_pixbuf("share/followed.png").get_pixbuf()) button.show() box.pack_start(button, False, False) #button.set_label("已关注") gtk.gdk.threads_leave() # show window def show(self): '''show''' self.window.show_window() # close widnow def quit(self, widget): ''' close ''' gtk.main_quit() def __slider_expose(self, widget, event): ''' slider expose redraw''' cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgba(1.0, 1.0, 1.0, 0.8) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() def __expose_top_and_bottome(self, widget, event): '''titlebar or button_box expose''' cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(0.89, 0.89, 0.89) cr.rectangle(rect.x+2, rect.y+2, rect.width-4, rect.height-4) cr.fill() def __draw_under_line(self, widget): '''draw under line''' cr = widget.window.cairo_create() with utils.cairo_disable_antialias(cr): x, y, w, h = widget.allocation # #1A70b1 cr.set_source_rgba(0.1, 0.43, 0.69, 1.0) cr.set_line_width(1) cr.move_to(x, y+h-3) cr.line_to(x+w, y+h-3) cr.stroke()
def init_share_box(self): '''get weibo info, and create button''' self.to_share_weibo = {} self.to_share_weibo_res = {} self.deepin_info = {} self.is_get_user_info = {} self.__weibo_check_button_list = [] self.__weibo_image_button_list = [] # create Thumbnail if exists(self.upload_image): pixbuf = gtk.gdk.pixbuf_new_from_file(self.upload_image) pix_w = pixbuf.get_width() pix_h = pixbuf.get_height() if pix_w > pix_h: pix_s_w = self.thumb_width pix_s_h = int(pix_h / (float(pix_w) / self.thumb_width)) else: pix_s_h = self.thumb_height pix_s_w = int(pix_w / (float(pix_h) / self.thumb_height)) pixbuf = pixbuf.scale_simple(pix_s_w, pix_s_h, gtk.gdk.INTERP_TILES) thumb = gtk.image_new_from_pixbuf(pixbuf) else: thumb = gtk.Image() thumb.set_size_request(self.thumb_width, self.thumb_height) # weibo context input text_box = gtk.HBox(False, 2) text_vbox = gtk.VBox(False, 2) text_bg_vbox = gtk.VBox(False) text_bg_align = gtk.Alignment() text_bg_align.set(0.5, 0.5, 0, 0) text_bg_align.set_padding(5, 5, 16, 5) text_bg_align.connect("expose-event", self.text_view_bg_expose) text_scrolled_win = ScrolledWindow() text_scrolled_win.set_size_request(340, 157) text_view = gtk.TextView() text_view.set_left_margin(10) text_view.set_right_margin(10) text_view.set_pixels_above_lines(5) text_view.set_pixels_below_lines(5) text_view.set_wrap_mode(gtk.WRAP_WORD| gtk.WRAP_CHAR) text_view.connect("expose-event", self.text_view_expose) buf = text_view.get_buffer() text_scrolled_win.add(text_view) text_bg_vbox.pack_start(text_scrolled_win) text_bg_align.add(text_bg_vbox) text_align = gtk.Alignment() text_align.set(0.5, 0.5, 0, 0) text_align.set_padding(25, 30, 10, 10) text_box.pack_start(thumb, False, False, 10) text_box.pack_start(text_bg_align) text_vbox.pack_start(text_box, False, False, 10) text_align.add(text_vbox) #tmp_align = gtk.Alignment() #tmp_align.set(0.5, 0, 0, 1) #self.share_box.pack_start(tmp_align, False, False) self.share_box.pack_start(text_align, False, False) # dialog button box left_box = self.window.left_button_box right_box = self.window.right_button_box # input tip label self.input_num_label = Label("%d" % self.MAX_CHAR, text_size=16, text_x_align=pango.ALIGN_CENTER, label_width=50, enable_select=False) self.input_num_label.text_color = app_theme.get_color("left_char_num") # login box #weibo_box = gtk.HBox(False, 1) #weibo_box.set_size_request(-1, 50) weibo_box_list = [] self.loading_label = Label("%s..." % _("Loading"), text_size=12, label_width=70, enable_select=False) weibo_box_list.append(self.loading_label) for weibo in self.__weibo_list: box = gtk.HBox(False, 2) weibo.set_box(box) weibo_box_list.append(box) left_box.set_buttons(weibo_box_list) # share button button = Button(_("Share")) #button.set_size_request(75, 25) button.connect("clicked", self.share_button_clicked, text_view) buf.connect("changed", self.text_view_changed, button) # check char num tmp_vbox = gtk.VBox(False) tmp_align = gtk.Alignment() tmp_align.set(0.5, 0.5, 0, 0) tmp_vbox.pack_start(button, False, False) #tmp_vbox.pack_start(tmp_align) tmp_align.add(tmp_vbox) right_box.set_buttons([self.input_num_label, tmp_align]) # at first, set widget insensitive button.set_sensitive(False) text_view.set_editable(False) t = threading.Thread(target=self.init_user_info_thread, args=(button, text_view)) t.setDaemon(True) t.start()
pass def icon_item_release_resource(self): # Return True to tell IconView call gc.collect() to release memory resource. if self.pixbuf: del self.pixbuf self.pixbuf = None return True if __name__ == '__main__': gtk.gdk.threads_init() module_frame = ModuleFrame( os.path.join(get_parent_dir(__file__, 2), "config.ini")) scrolled_window = ScrolledWindow() scrolled_window.set_size_request(788, 467) wallpaper_view = WallpaperView() scrolled_window.add_child(wallpaper_view) module_frame.add(scrolled_window) scrolled_window.connect("vscrollbar-state-changed", wallpaper_view.load_more_background) download_pool = MissionThreadPool(5) download_pool.start() def message_handler(*message): (message_type, message_content) = message if message_type == "show_again": module_frame.send_module_info()
def __init__(self, filename=""): ''' init share @param filename: the file to share ''' self.upload_image = filename self.thumb_width = 188 self.thumb_height = 168 self.MAX_CHAR = 140 #self.__text_frame_color = (0.76, 0.76, 0.76) self.__win_width = 602 open(COOKIE_FILE,'wb').close() self.window = DialogBox(_("Share to social networks"), close_callback=gtk.main_quit) self.window.set_keep_above(True) self.window.set_size_request(self.__win_width+20, 288) self.window.set_resizable(False) self.window.titlebar.connect("expose-event", self.__expose_top_and_bottome) self.window.button_box.connect("expose-event", self.__expose_top_and_bottome) # create slider self.slider = HSlider() self.slider_list = [] self.share_box = gtk.VBox(False, 2) # first page, input context self.web_box = gtk.VBox(False, 10) # second page, login self.result_box = gtk.VBox(False, 10) # third page, share result share_align = gtk.Alignment() share_align.set(0.5, 0.5, 0, 0) share_align.add(self.share_box) share_align.connect("expose-event", self.__slider_expose) # go back button web_left_button = ImageButton( app_theme.get_pixbuf("share/back_normal.png"), app_theme.get_pixbuf("share/back_hover.png"), app_theme.get_pixbuf("share/back_press.png")) web_left_button.connect("clicked", lambda w: self.set_slide_index(0)) web_left_button.set_can_focus(False) utils.set_clickable_cursor(web_left_button) # show url entry self.web_url_entry = InputEntry() self.web_url_entry.set_editable(False) self.web_url_entry.set_size(555, 20) self.web_url_entry.entry.right_menu_visible_flag = False # alig url entry web_navigate_vbox = gtk.VBox(False) web_navigate_vbox.pack_start(self.web_url_entry) web_navigate_t_align = gtk.Alignment() web_navigate_t_align.set(0.0, 0.5, 0, 0) web_navigate_t_align.add(web_navigate_vbox) # pack back button and url entry web_navigate_box = gtk.HBox(False, 7) web_navigate_box.pack_start(web_left_button, False, False) web_navigate_box.pack_start(web_navigate_t_align) web_navigate_align = gtk.Alignment() web_navigate_align.set(0.5, 0.5, 0, 0) web_navigate_align.set_padding(4, 0, 11, 13) web_navigate_align.add(web_navigate_box) # create a webkit self.web_view = WebView(COOKIE_FILE) self.web_view.connect("notify::load-status", self.web_view_load_status) self.web_view.connect("load-error", self.web_view_load_error) self.web_scrolled_window = ScrolledWindow() self.web_scrolled_window.add(self.web_view) self.web_scrolled_window.set_size_request(590, 228) self.web_box.pack_start(web_navigate_align, False, False) self.web_box.pack_start(self.web_scrolled_window) #self.web_box.set_size_request(-1, 258) web_align = gtk.Alignment() web_align.set(0.5, 0.0, 0, 1) web_align.add(self.web_box) web_align.connect("expose-event", self.__slider_expose) res_align = gtk.Alignment() res_align.set(0.5, 0.5, 0, 0) res_align.add(self.result_box) res_align.connect("expose-event", self.__slider_expose) self.slider.set_to_page(share_align) self.slider_list.append(share_align) self.slider_list.append(web_align) self.slider_list.append(res_align) self.__weibo_list = [] self.sina = weibo.Sina(self.web_view) self.qq = weibo.Tencent(self.web_view) self.twitter = weibo.Twitter(self.web_view) self.__weibo_list.append(self.sina) self.__weibo_list.append(self.qq) self.__weibo_list.append(self.twitter) self.__current_weibo = None self.window.body_box.pack_start(self.slider, True, True) self.init_share_box()
def get_scrolled_window(self): scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scrolled_window.add_child(self) return scrolled_window