本文整理汇总了Python中dtk.ui.treeview.TreeView.add_items方法的典型用法代码示例。如果您正苦于以下问题:Python TreeView.add_items方法的具体用法?Python TreeView.add_items怎么用?Python TreeView.add_items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dtk.ui.treeview.TreeView
的用法示例。
在下文中一共展示了TreeView.add_items方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AlbumDetailPage
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
class AlbumDetailPage(gtk.VBox):
'''
class docs
'''
def __init__(self, data_manager, album_info):
'''
init docs
'''
gtk.VBox.__init__(self)
self.treeview = TreeView(enable_drag_drop=False, expand_column=1)
items = []
for software_info in album_info['softwares']:
items.append(AlbumDetailItem(software_info, data_manager))
self.treeview.add_items(items)
self.treeview.draw_mask = self.draw_mask
self.pack_start(self.treeview, True, True)
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)),]
)
示例2: plugin_widget
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
def plugin_widget(self):
self.__get_devices()
plugin_box = gtk.VBox()
adapter_box = gtk.HBox(spacing = 5)
adapter_image = ImageBox(app_theme.get_pixbuf("bluetooth/enable_open.png"))
adapter_label = self.__setup_label(_("Adapter"))
adapter_toggle = self.__setup_toggle()
if self.my_bluetooth.adapter:
adapter_toggle.set_active(self.my_bluetooth.adapter.get_powered())
if self.my_bluetooth.adapter.get_powered():
self.tray_icon.set_icon_theme("enable")
else:
self.tray_icon.set_icon_theme("enable_disconnect")
adapter_toggle.connect("toggled", self.__adapter_toggled)
separator_align = self.__setup_align(padding_bottom = 0)
separator = self.__setup_separator()
separator_align.add(separator)
'''
devices treeview
'''
device_treeview = TreeView()
device_separator_align = self.__setup_align()
device_separator = self.__setup_separator()
device_separator_align.add(device_separator)
device_count = len(self.device_items)
if device_count:
device_treeview.delete_all_items()
device_treeview.add_items(self.device_items)
device_treeview.set_size_request(self.width, device_count * DeviceItem.ITEM_HEIGHT)
else:
device_treeview.set_child_visible(False)
device_separator_align.set_size_request(-1, 0)
device_separator_align.set_child_visible(False)
'''
select button
'''
select_button_align = self.__setup_align()
select_button = SelectButton(_("Advanced options..."),
font_size = 10,
ali_padding = 5)
select_button.set_size_request(self.width, 25)
select_button.connect("clicked", self.__bluetooth_selected) # I don't know why, but replacing "button-press-event" with
select_button_align.add(select_button) # clicked really works...
adapter_box.pack_start(adapter_image, False, False)
adapter_box.pack_start(adapter_label, False, False)
adapter_box.pack_start(adapter_toggle, False, False)
plugin_box.pack_start(adapter_box, False, False)
plugin_box.pack_start(separator_align, False, False)
plugin_box.pack_start(device_treeview, False, False)
plugin_box.pack_start(device_separator_align, False, False)
plugin_box.pack_start(select_button_align, False, False)
return plugin_box
示例3: CompletionWindow
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
class CompletionWindow(Window):
'''
class docs
'''
def __init__(self, window_width, window_height):
'''
init docs
'''
# Init.
Window.__init__(
self,
shadow_visible=False,
shadow_radius = 0,
shape_frame_function=self.shape_completion_window_frame,
expose_frame_function=self.expose_completion_window_frame,
# window_type=gtk.WINDOW_POPUP,
)
self.window_width = window_width
self.window_height = window_height
self.window_offset_x = 0
self.window_offset_y = 0
self.align_size = 2
self.treeview = TreeView(
enable_highlight=False,
enable_multiple_select=False,
enable_drag_drop=False,)
self.treeview.draw_mask = self.treeview_draw_mask
self.treeview.scrolled_window.tag_by_popup_grab_window = True
self.treeview_align = gtk.Alignment()
self.treeview_align.set(0.5, 0.5, 1, 1)
self.treeview_align.set_padding(self.align_size, self.align_size, self.align_size, self.align_size)
self.treeview_align.add(self.treeview)
self.window_frame.pack_start(self.treeview_align, True, True)
self.connect("realize", self.realize_completion_window)
self.get_scrolledwindow = self.get_scrolledwindow
wrap_grab_window(completion_grab_window, self)
def get_scrolledwindow(self):
return self.treeview.scrolled_window
def shape_completion_window_frame(self, widget, event):
pass
def treeview_draw_mask(self, cr, x, y, w, h):
cr.set_source_rgba(1, 1, 1, 0.95)
cr.rectangle(x, y, w, h)
cr.fill()
def expose_completion_window_frame(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
cr = widget.window.cairo_create()
rect = widget.allocation
cr.set_source_rgb(1,1,1)
cr.rectangle(rect.x, rect.y, rect.width, rect.height)
cr.fill()
cr.set_line_width(1)
cr.set_source_rgb(*color_hex_to_cairo("#c7c7c7"))
cr.rectangle(*rect)
cr.stroke()
def show(self, keyword):
self.treeview.delete_all_items()
self.treeview.add_items([TextItem(key) for key in ["linux", "deepin", "word", keyword]])
self.treeview.select_first_item()
# self.treeview.grab_focus()
(x, y) = get_widget_root_coordinate(search_entry, WIDGET_POS_BOTTOM_LEFT, True)
self.move(x + self.window_offset_x, y + self.window_offset_y)
self.show_all()
def realize_completion_window(self, widget):
self.set_default_size(self.window_width, self.window_height)
self.set_geometry_hints(
None,
self.window_width, # minimum width
self.window_height, # minimum height
self.window_width,
self.window_height,
-1, -1, -1, -1, -1, -1
)
示例4: TreeView
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
# Set application icon.
application.set_icon(os.path.join(get_current_dir(__file__), "icon.ico"))
# Set application preview pixbuf.
application.set_skin_preview(os.path.join(get_current_dir(__file__), "frame.png"))
# Add titlebar.
application.add_titlebar(
["theme", "max", "min", "close"],
os.path.join(get_current_dir(__file__), "logo.png"),
"TreeView demo",
"TreeView demo",
)
# Add TreeView.
treeview = TreeView()
treeview.add_items(map(TextItem, ["Node1", "Node2", "Node3"]))
treeview.visible_items[0].add_items(map(TextItem, ["Node1 - SubNode1", "Node1 - SubNode2", "Node1 - SubNode3"]))
treeview.visible_items[1].add_items(map(TextItem, ["Node2 - SubNode1", "Node2 - SubNode2", "Node2 - SubNode3"]))
treeview.visible_items[2].add_items(map(TextItem, ["Node3 - SubNode1", "Node3 - SubNode2", "Node3 - SubNode3"]))
treeview_align = gtk.Alignment()
treeview_align.set(0.5, 0.5, 1, 1)
treeview_align.set_padding(0, 2, 2, 2)
treeview_align.add(treeview)
application.main_box.pack_start(treeview_align)
application.window.connect("show", lambda w: treeview.visible_highlight())
application.run()
示例5: add_items
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
def add_items(self, items, insert_pos=None, clear_first=False):
for item in items:
song_view = getattr(item, "song_view", None)
if song_view:
setattr(song_view, "category_view", self)
TreeView.add_items(self, items, insert_pos, clear_first)
示例6: WebcastsBrowser
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
#.........这里部分代码省略.........
self.__db_query = WebcastQuery()
if WebcastDB.isloaded():
self.__on_db_loaded()
else:
WebcastDB.connect("loaded", lambda obj: self.__on_db_loaded())
def __on_db_loaded(self):
self.autoconnect(self.__db_query, "added", self.__on_added_songs)
self.autoconnect(self.__db_query, "removed", self.__on_removed_songs)
self.autoconnect(self.__db_query, "update-songs", self.__on_update_songs)
self.autoconnect(self.__db_query, "full-update", self.__on_full_update)
self.__db_query.set_query()
def __on_added_songs(self, db_query, songs):
self.reload_flag = True
def __on_removed_songs(self, db_query, songs):
self.reload_flag = True
def __on_update_songs(self, db_query, songs):
self.reload_flag = True
def __on_full_update(self, db_query):
self.load_view_data()
self.load_collect_data()
def __init_webcastbar(self):
self.webcastbar = TreeView(enable_drag_drop=False, enable_multiple_select=False)
self.webcastbar.connect("single-click-item", self.on_webcastbar_single_click_item)
items = []
for category in self.__categorys:
items.append(CategoryTreeItem(self.__category_gettexts[category], category=category))
items.append(CollectTreeItem(_("Favorites")))
self.webcastbar.add_items(items)
self.webcastbar.select_items([self.webcastbar.visible_items[0]])
self.webcastbar.set_size_request(121, -1)
self.webcastbar.draw_mask = self.on_webcastbar_draw_mask
def on_webcastbar_draw_mask(self, cr, x, y, w, h):
draw_alpha_mask(cr, x, y, w, h ,"layoutRight")
def on_webcastbar_single_click_item(self, widget, item, column, x, y):
if hasattr(item, "collect_flag"):
switch_tab(self.page_box, self.collected_view_sw)
else:
widget = self.page_box.get_children()[0]
if widget != self.metro_view_sw:
switch_tab(self.page_box, self.metro_view_sw)
if self.current_category != item.category:
self.current_category = item.category
self.load_view_data()
def init_listview_page(self):
self.listview_page = gtk.VBox()
self.text_prompt = TextPrompt("Default")
prompt_align = set_widget_gravity(self.text_prompt,
paddings=(10, 10, 0, 0))
prompt_box = gtk.HBox()
back_button = BackButton()
back_button.connect("clicked", self.on_backbutton_clicked)
back_button_align = set_widget_gravity(back_button, gravity=(0.5, 0.5, 0, 0),
paddings=(0, 0, 10, 5))
prompt_box.pack_start(back_button_align, False, True)
prompt_box.pack_start(prompt_align, False, False)
示例7: PreferenceDialog
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
class PreferenceDialog(DialogBox):
def __init__(self):
super(PreferenceDialog, self).__init__(_("Preferences"), 575, 495,
mask_type=DIALOG_MASK_MULTIPLE_PAGE,
close_callback=self.hide_all)
self.set_position(gtk.WIN_POS_CENTER)
self.main_box = gtk.VBox()
close_button = Button(_("Close"))
close_button.connect("clicked", lambda w: self.hide_all())
# Init widget.
self.general_setting = GeneralSetting()
self.hotkey_setting = HotKeySetting()
self.desktop_lyrics_setting = DesktopLyricsSetting()
self.scroll_lyrics_setting = ScrollLyricsSetting()
self.plugins_manager = PluginsManager()
# Category bar
self.category_bar = TreeView(enable_drag_drop=False, enable_multiple_select=False)
self.category_bar.set_expand_column(0)
self.category_bar.draw_mask = self.draw_treeview_mask
self.category_bar.set_size_request(132, 516)
self.category_bar.connect("single-click-item", self.on_categorybar_single_click)
# Init catagory bar.
self.__init_category_bar()
category_box = gtk.VBox()
background_box = BackgroundBox()
background_box.set_size_request(132, 11)
background_box.draw_mask = self.draw_treeview_mask
category_box.pack_start(background_box, False, False)
category_bar_align = gtk.Alignment()
category_bar_align.set(0, 0, 1, 1,)
category_bar_align.set_padding(0, 1, 0, 0)
category_bar_align.add(self.category_bar)
category_box.pack_start(category_bar_align, True, True)
# Pack widget.
left_box = gtk.VBox()
self.right_box = gtk.VBox()
left_box.add(category_box)
self.right_box.add(self.general_setting)
right_align = gtk.Alignment()
right_align.set_padding(0, 0, 10, 0)
right_align.add(self.right_box)
body_box = gtk.HBox()
body_box.pack_start(left_box, False, False)
body_box.pack_start(right_align, False, False)
self.main_box.add(body_box)
# DialogBox code.
self.body_box.pack_start(self.main_box, True, True)
self.right_button_box.set_buttons([close_button])
def __init_category_bar(self):
general_normal_item = NormalItem(_("General"), self.general_setting)
hotkey_normal_item = NormalItem(_("Hotkeys"), self.hotkey_setting)
self.lyrics_expand_item = ExpandItem(_("Lyrics"), None)
self.lyrics_expand_item.add_childs([(_("Desktop"), self.desktop_lyrics_setting),
(_("Window"), self.scroll_lyrics_setting)])
self.plugins_expand_item = NormalItem(_("Plugins"), self.plugins_manager)
about_normal_item = NormalItem(_("About"), AboutBox())
items = [general_normal_item,
hotkey_normal_item,
self.lyrics_expand_item,
self.plugins_expand_item,
about_normal_item]
self.category_bar.add_items(items)
self.category_bar.select_items([general_normal_item])
def switch_lyrics_page(self, index=3):
self.lyrics_expand_item.try_to_expand()
show_item = self.category_bar.visible_items[index]
self.category_bar.select_items([show_item])
self.on_categorybar_single_click(self.category_bar, show_item, None, None, None)
def show_scroll_lyrics_page(self):
self.switch_lyrics_page(4)
self.show_all()
def show_desktop_lyrics_page(self):
self.switch_lyrics_page(3)
self.show_all()
def draw_treeview_mask(self, cr, x, y, width, height):
draw_alpha_mask(cr, x, y, width, height, ("#FFFFFF", 0.9))
def on_categorybar_single_click(self, widget, item, column, x, y):
if item.allocate_widget:
switch_tab(self.right_box, item.allocate_widget)
def load_plugins(self):
self.plugins_manager.flush_plugins()
示例8: plugins_view_add_items
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
def plugins_view_add_items(self, items, insert_pos=None, clear_first=False):
for item in items:
item.plugins_view = self
TreeView.add_items(self.plugins_view, items, insert_pos, clear_first)
示例9: AddPage
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
class AddPage(gtk.HBox):
def __init__(self):
gtk.HBox.__init__(self)
self.aibizhi_cache_page = CachePage(Aibizhi())
self.bizhi360_cache_page = CachePage(Bizhi360())
self.aibizhi_cache_page.cache_view.try_to_fetch()
self.bizhi360_cache_page.cache_view.try_to_fetch()
self.system_wallpapers_page = SystemPage(get_system_wallpaper_dirs()[0])
self.picture_wallpapers_page = PicturePage(get_images_dir())
self.download_wallpapaers_page = UserPage(get_download_wallpaper_dir())
self.task_page = TaskPage()
self.__init_navigatebar()
self.switch_page = gtk.VBox()
self.pack_start(self.navigatebar, False, True)
self.pack_start(self.switch_page, True, True)
self.switch_page.add(self.system_wallpapers_page)
event_manager.add_callback("downloading-tasks-number", self.on_download_item_changed)
self.connect("expose-event", self.on_addpage_expose_event)
def set_theme(self, theme):
self.system_wallpapers_page.set_theme(theme)
self.picture_wallpapers_page.set_theme(theme)
self.download_wallpapaers_page.set_theme(theme)
self.aibizhi_cache_page.set_theme(theme)
self.bizhi360_cache_page.set_theme(theme)
def on_download_item_changed(self, name, obj, data):
pass
def __init_navigatebar(self):
self.navigatebar = TreeView(enable_drag_drop=False, enable_multiple_select=False)
self.navigatebar.connect("single-click-item", self.on_navigatebar_single_click)
self.navigatebar.set_size_request(132, -1)
self.navigatebar.draw_mask = self.on_navigatebar_draw_mask
local_expand_item = ExpandItem(_("Library"))
network_expand_item = ExpandItem(_("Internet"))
self.navigatebar.add_items([local_expand_item,
network_expand_item,
])
local_expand_item.add_childs([(_("System"), self.system_wallpapers_page),
(_("Pictures"), self.picture_wallpapers_page),
(_("Favorites"), self.download_wallpapaers_page)], expand=True)
network_expand_item.add_childs([(_("360 Wallpaper"), self.bizhi360_cache_page),
(_("LoveWallpaper"), self.aibizhi_cache_page),
], expand=True)
self.navigatebar.set_highlight_item(self.navigatebar.get_items()[1])
def on_addpage_expose_event(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
self.draw_mask(cr, *rect)
def on_navigatebar_draw_mask(self, cr, x, y, w, h):
self.draw_mask(cr, x, y, w, h)
draw_line(cr, (x + w, y), (0, h), "#d6d6d6")
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.
'''
cr.set_source_rgb(1, 1, 1)
cr.rectangle(x, y, w, h)
cr.fill()
def on_navigatebar_single_click(self, widget, item, column, x, y):
if item.widget:
widget.set_highlight_item(item)
switch_box(self.switch_page, item.widget)
示例10: TreeViewItem
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
wuhan_node = tree_view.add_item(None, TreeViewItem("Linux Deepin"))
wuhan_dev_node = tree_view.add_item(wuhan_node, TreeViewItem("test1"))
wuhan_des_node = tree_view.add_item(wuhan_node, TreeViewItem("test2"))
wuhan_sys_node = tree_view.add_item(wuhan_node, TreeViewItem("test3"))
tree_view.add_item(wuhan_dev_node, TreeViewItem("Deepin Music Player"))
tree_view.add_item(wuhan_dev_node, TreeViewItem("Deepin Media Player"))
tree_view.add_item(wuhan_dev_node, TreeViewItem("Deepin Software Center"))
tree_view.add_item(wuhan_sys_node, TreeViewItem("Deepin Talk"))
tree_view.add_item(wuhan_sys_node, TreeViewItem("Deepin IM"))
tree_view.add_item(wuhan_sys_node, TreeViewItem("Deepin Reader"))
tree_view.add_item(wuhan_des_node, TreeViewItem("ZHL"))
tree_view.add_item(wuhan_des_node, TreeViewItem("ZHL"))
tree_view.add_item(wuhan_des_node, TreeViewItem("zhm"))
beijing_node = tree_view.add_item(None, TreeViewItem("深度 Linux"))
tree_view.add_items(beijing_node, [TreeViewItem(name) for name in ("开发部", "设计部", "系统部")])
tree_view.set_index_text(1, "深度测试改名")
# text_view = TextView("this is line one\nline break is awesome\nblahblahlooooooooooooooooooooooooooooooooooooooooooooooooooooooooog")
# sw = ScrolledWindow()
# text_viewport = gtk.Viewport()
# text_viewport.add(text_view)
# sw.add(text_viewport)
# tab_5_box.pack_start(sw, True, True)
# Run.
application.run()
示例11: UninstallPage
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
class UninstallPage(gtk.VBox):
'''
class docs
'''
def __init__(self, bus_interface, data_manager):
'''
init docs
'''
# Init.
gtk.VBox.__init__(self)
self.bus_interface = bus_interface
self.data_manager = data_manager
self.search_flag = False
self.uninstall_change_items = {"add": [], "delete": []}
self.message_bar = MessageBar(32)
self.message_bar.search_entry.entry.connect("changed", self.search_cb)
self.message_bar.search_button.connect("clicked", self.search_cb)
self.treeview = TreeView(enable_drag_drop=False)
self.treeview.set_expand_column(0)
top_hbox = gtk.HBox()
top_hbox.pack_start(self.message_bar)
self.pack_start(top_hbox, False, False)
self.pack_start(self.treeview, True, True)
self.treeview.connect("items-change", self.update_message_bar)
self.fetch_uninstall_info()
self.treeview.draw_mask = self.draw_mask
def search_cb(self, widget, event=None):
if not self.search_flag:
self.cache_items = [item for item in self.treeview.visible_items]
results = []
keywords = self.message_bar.search_entry.get_text().strip()
if keywords != "":
self.search_flag = True
# TODO: comment this search_query api, there are many problems for this api
'''
pkg_names = self.data_manager.search_query(map(lambda word: word.encode("utf8"), keywords.split(" ")))
for item in self.cache_items:
if item.pkg_name in pkg_names:
results.append(item)
'''
for item in self.cache_items:
if keywords in item.pkg_name:
results.append(item)
self.treeview.clear()
self.treeview.add_items(results)
else:
self.treeview.clear()
self.search_flag = False
# for add items
if self.uninstall_change_items["add"] != []:
for item in self.uninstall_change_items["add"]:
self.cache_items.append(item)
self.uninstall_change_items["add"] = []
# for delete items
if self.uninstall_change_items["delete"] != []:
for item in self.uninstall_change_items["delete"]:
if item in self.cache_items:
self.cache_items.remove(item)
self.uninstall_change_items["delete"] = []
self.treeview.add_items(self.cache_items)
def normal_search_cb(self, keywords):
pass
def update_message_bar(self, treeview):
self.message_bar.set_message(_("%s applications can be uninstalled") % len(treeview.visible_items))
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 update_action_status(self, pkg_infos):
pkg_items = []
for (pkg_name, action_status) in pkg_infos:
pkg_item = None
for item in self.treeview.visible_items:
#.........这里部分代码省略.........
示例12: MainBox
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
class MainBox(gtk.HBox):
def __init__(self):
gtk.HBox.__init__(self)
self.connect("expose-event", self.on_page_expose_event)
self.aibizhi_cache_page = CachePage(Aibizhi())
self.bizhi360_cache_page = CachePage(Bizhi360())
self.aibizhi_cache_page.cache_view.try_to_fetch()
self.bizhi360_cache_page.cache_view.try_to_fetch()
self.favorites_page = FavoritePage(get_favorite_dir())
self.pictures_page = LocalPicturePage(get_download_wallpaper_dir())
self.add_item = AddItem()
self.pictures_page.select_view.add_items([self.add_item])
self.task_page = TaskPage()
self.switch_page = gtk.VBox()
self.__init_navigatebar()
self.pack_start(self.navigatebar, False, True)
self.pack_start(self.switch_page, True, True)
event_manager.add_callback("switch-to-local-pictures", self.switch_to_local_pictures)
def switch_to_local_pictures(self, name, obj, data=None):
item = self.navigatebar.get_items()[2]
self.on_navigatebar_single_click(self.navigatebar, item, 0, 0, 0)
def __init_navigatebar(self):
self.navigatebar = TreeView(enable_drag_drop=False, enable_multiple_select=False)
self.navigatebar.connect("single-click-item", self.on_navigatebar_single_click)
self.navigatebar.set_size_request(132, -1)
self.navigatebar.draw_mask = self.on_navigatebar_draw_mask
local_expand_item = ExpandItem(_("Library"))
network_expand_item = ExpandItem(_("Internet"))
self.navigatebar.add_items([local_expand_item,
network_expand_item,
])
local_expand_item.add_childs([
(FavoritesTitle, self.favorites_page),
(LocalWallpapersTitle, self.pictures_page),
],
expand=True)
network_expand_item.add_childs([(_("360 Wallpaper"), self.bizhi360_cache_page),
(_("LoveWallpaper"), self.aibizhi_cache_page),
], expand=True)
if get_favorite_number() == 0:
self.navigatebar.set_highlight_item(self.navigatebar.get_items()[2])
self.switch_page.add(self.pictures_page)
else:
self.navigatebar.set_highlight_item(self.navigatebar.get_items()[1])
self.switch_page.add(self.favorites_page)
def draw_mask(self, cr, x, y, w, h):
cr.set_source_rgb(1, 1, 1)
cr.rectangle(x, y, w, h)
cr.fill()
def on_page_expose_event(self, widget, event):
cr = widget.window.cairo_create()
width, height= widget.size_request()
self.draw_mask(cr, 0, 0, width, height)
def on_navigatebar_draw_mask(self, cr, x, y, w, h):
self.draw_mask(cr, x, y, w, h)
draw_line(cr, (x + w, y), (0, h), "#d6d6d6")
def on_navigatebar_single_click(self, widget, item, column, x, y):
if item.widget:
widget.set_highlight_item(item)
switch_box(self.switch_page, item.widget)
示例13: ListviewFactory
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
class ListviewFactory(object):
'''
class docs
'''
def __init__(self, items, owner):
'''
init docs
'''
self.items = [ListViewItem(x, owner) for x in items]
self.owner = owner
self.count_per_page = 10 if self.owner == "brief" else 20
self.listview = None
self.page_count = 0
self.page_index = 0
self.paged_items = self.get_paged_items()
self.init_listview()
def prepend_item(self, item):
if self.listview:
self.listview.add_items([ListViewItem(item, self.owner)], insert_pos=0)
def append_item(self, item):
if self.listview:
self.listview.add_items([ListViewItem(item, self.owner)])
def on_listview_button_pressed(self, widget, event, listview):
x = event.x
y = event.y
if event.button == 1:
for item in listview.get_items():
for index, rect in enumerate(item.pointer_hand_rectangles):
if is_in_rect((x, y), rect):
action = item.message["hints"]["x-deepin-hyperlinks"][index]
if action.has_key("href"):
webbrowser.open_new_tab(action.get("href"))
return
def on_listview_motion_notify(self, widget, event, listview):
x = event.x
y = event.y
flag = False
for item in listview.get_items():
if flag:
break
for rect in item.pointer_hand_rectangles:
if is_in_rect((x, y), rect):
flag = True
break
if flag:
widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1))
else:
widget.window.set_cursor(None)
def init_listview(self):
'''
docs
'''
items = self.paged_items[self.page_index]
self.listview = TreeView(items)
self.listview.draw_mask = self.on_listview_draw_mask
self.listview.set_expand_column(0)
if self.owner == "detail":
self.listview.set_column_titles([_("Content of messages"), _("Time")],
[self.sort_by_content, self.sort_by_time])
self.listview.draw_area.connect_after("button-press-event", self.on_listview_button_pressed, self.listview)
self.listview.draw_area.connect_after("motion-notify-event", self.on_listview_motion_notify, self.listview)
self.listview.connect("right-press-items", self.on_listview_right_press_items)
self.listview.scrolled_window.connect("vscrollbar-state-changed", self.update_listview)
event_manager.emit("listview-items-added", items)
def update_listview(self, widget, state):
if state == "bottom":
if self.page_index < self.page_count - 1:
self.page_index = self.page_index + 1
items = self.paged_items[self.page_index]
self.listview.add_items(items)
event_manager.emit("listview-items-added", items)
def on_listview_draw_mask(self, cr, x, y, w, h):
cr.set_source_rgb(1, 1, 1)
cr.rectangle(x, y, w, h)
cr.fill()
def on_listview_right_press_items(self, widget, root_x, root_y, current_item, select_items):
if self.owner == "detail":
#.........这里部分代码省略.........
示例14: SearchUI
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
#.........这里部分代码省略.........
self.result_view.set_column_titles([_("Title"), _("Artist")], sort_items)
self.result_view.draw_mask = self.draw_view_mask
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(self.result_view, 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()
def show_window(self):
DialogBox.show_window(self)
self.present()
def draw_view_mask(self, cr, x, y, width, height):
draw_alpha_mask(cr, x, y, width, height, "layoutMiddle")
def sort_by_key(self, items, sort_reverse, sort_key):
return sorted(items, reverse=sort_reverse, key=lambda item: getattr(item, sort_key))
def double_click_cb(self, widget, item, colume, x, y):
self.download_lyric_cb(widget)
def search_engine(self, artist, title, pid):
ting_result = poster.query_lrc_info(artist, title)
self.render_lyrics(ting_result, pid=pid)
ttplayer_result = TTPlayer().request(artist, title)
self.render_lyrics(ttplayer_result, pid=pid)
ttpod_result = TTPod().request(artist, title)
self.render_lyrics(ttpod_result, pid=pid)
duomi_result = DUOMI().request(artist, title)
self.render_lyrics(duomi_result, pid=pid, last=True)
def search_lyric_cb(self, widget):
self.result_view.clear()
artist = self.artist_entry.entry.get_text()
title = self.title_entry.entry.get_text()
# widget.set_sensitive(False)
self.prompt_label.set_text(_("Now searching..."))
if artist == "" and title == "":
self.prompt_label.set_text(_("Not found!"))
return
self.process_id += 1
utils.ThreadLoad(self.search_engine, artist, title, self.process_id).start()
@post_gui
def render_lyrics(self, result, last=False, pid=1):
'''docs'''
if pid != self.process_id:
return
if result != None:
try:
items = [SearchItem(each_info) for each_info in result]
except:
pass
else:
self.result_view.add_items(items)
self.prompt_label.set_text(_("%d lyrics found") % len(self.result_view.get_items()))
else:
if last:
if len(self.result_view.get_items()) > 0:
self.prompt_label.set_text(_("%d lyrics found") % len(self.result_view.get_items()))
else:
self.prompt_label.set_text(_("Not found!"))
def download_lyric_cb(self, widget):
select_items = self.result_view.select_rows
save_filepath = self.lrc_manager.get_lrc_filepath(Player.song)
if len(select_items) > 0:
self.prompt_label.set_text(_("Downloading lyrics..."))
item = self.result_view.get_items()[select_items[0]]
url = item.get_url()
net_encode = item.get_netcode()
utils.ThreadRun(utils.download, self.render_download, [url, save_filepath, net_encode]).start()
@post_gui
def render_download(self, result):
if result:
Dispatcher.reload_lrc(Player.song)
self.prompt_label.set_text("%s %s" % (_("File save to"), config.get("lyrics", "save_lrc_path")))
else:
self.prompt_label.set_text(_("Download failed."))
示例15: Region
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import add_items [as 别名]
#.........这里部分代码省略.........
print "provider has not selected"
return
try:
self.plan_select
except:
self.plan_select = None
def add_keys(settings):
self.prop_dict = settings
username = self.__sp.get_provider_username(self.code, self.provider_select)
password = self.__sp.get_provider_password(self.code, self.provider_select)
add_keys({"cdma": {
"number": "#777",
"username": username,
"password": password}})
provider_type = "cdma"
if self.plan_select:
self.prop_dict.pop("cdma")
apn = self.plan_select
index = self.__sp.get_provider_apns_name(self.code, self.provider_select).index(apn)
(network_id, network_type) = self.__sp.get_provider_networks(self.code, self.provider_select)[index]
add_keys({"gsm":{
"number": "*99#",
"username": username,
"password": password,
"apn": apn,
#"network_id": network_id,
"network_type": network_type}})
provider_type = "gsm"
#setting_page = nm_module.slider.get_page_by_name("setting")
#broadband = setting_page.setting_group.get_broadband()
if self.connection_type == None:
new_connection = getattr(nm_module.nm_remote_settings, "new_%s_connection"%provider_type)()
Dispatcher.emit("region-back", new_connection, self.prop_dict, provider_type)
#setting_page.sidebar.new_connection_list[provider_type].append(new_connection)
#setting_page.init(setting_page.sidebar.new_connection_list)
#setting_page.sidebar.set_active(new_connection)
#broadband.set_new_values(self.prop_dict, provider_type)
else:
Dispatcher.emit("region-back", self.connection, self.prop_dict, provider_type)
#broadband.set_new_values(self.prop_dict, provider_type)
nm_module.slider._slide_to_page("setting", "none")
def init(self, connection):
if connection == None:
self.connection_type = None
else:
self.connection = connection
mobile_type = connection.get_setting("connection").type
self.connection_type = mobile_type
Dispatcher.send_submodule_crumb(_("Region"), 2)
from mm.provider import ServiceProviders
self.__sp = ServiceProviders()
self.country_list = self.__sp.get_country_name_list()
self.country_tree.delete_all_items()
self.country_tree.add_items([CountryItem(_(country)) for country in self.country_list])
# add a bottom line for last item
code = self.__sp.get_country_from_timezone()
self.country_codes = self.__sp.get_country_list()
try:
selected_country = self.country_tree.visible_items[self.country_codes.index(code)]
self.country_tree.select_items([selected_country])
self.auto_scroll_to()
self.country_tree.emit("button-press-item", selected_country, 0, 1, 1)
except:
pass
def country_selected(self, widget, w, a, b, c):
self.provider_tree.delete_all_items()
self.code = self.country_codes[widget.select_rows[0]]
if self.connection_type:
self.provider_names = getattr(self.__sp, "get_country_%s_providers_name"%self.connection_type)(self.code)
else:
self.provider_names = self.__sp.get_country_providers_name(self.code)
self.provider_select = None
self.provider_tree.add_items([Item(p, self.__sp, self.code) for p in self.provider_names])
self.provider_tree.show_all()
def provider_selected(self, widget, item, column, offset_x, offset_y):
if type(item) is Item:
self.provider_select = item.content
self.plan_select = None
else:
self.plan_select = item.content
def auto_scroll_to(self):
vadjust = self.country_tree.scrolled_window.get_vadjustment()
upper = vadjust.upper
page_size = vadjust.page_size
vadjust.set_value(min(upper - page_size, (self.country_tree.select_rows[0]- 4)*30))