本文整理汇总了Python中dtk.ui.treeview.TreeView.connect方法的典型用法代码示例。如果您正苦于以下问题:Python TreeView.connect方法的具体用法?Python TreeView.connect怎么用?Python TreeView.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dtk.ui.treeview.TreeView
的用法示例。
在下文中一共展示了TreeView.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DetailWindow
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
#.........这里部分代码省略.........
Menu(menu_items, True).show((int(root_x), int(root_y)))
def add_treeview(self):
categories = self.classified_items.keys()
# root eles
self.root_ele_software = TreeViewItem(_("Software Messages"), True)
self.root_ele_system = TreeViewItem(_("System Messages"), True)
self.treeview = TreeView([self.root_ele_software, self.root_ele_system], expand_column=0)
# add child items , CAN'T add_child_items before treeview constructed
software_children = []
system_children = []
for category in categories:
treeview_item = TreeViewItem(category)
if category in blacklist.bl:
treeview_item.is_in_blacklist = True
if category in SYSTEM_SOFTWARE_LIST:
system_children.append(treeview_item)
else:
software_children.append(treeview_item)
self.root_ele_software.add_child_items(software_children)
self.root_ele_system.add_child_items(system_children)
self.treeview.draw_mask = self.on_treeview_draw_mask
if len(software_children):
self.treeview.set_highlight_item(software_children[0])
elif len(system_children):
self.treeview.set_highlight_item(system_children[0])
self.treeview.set_size_request(220, -1)
self.treeview.connect("single-click-item", self.on_treeview_click_item)
self.treeview.connect("right-press-items", self.on_treeview_right_press_items)
self.treeview.connect("double-click-item", self.on_treeview_double_click_item)
container_remove_all(self.treeview_box)
self.treeview_box.pack_start(self.treeview, True, True)
self.treeview_box.show_all()
def treeview_add_item(self, item):
if item in SYSTEM_SOFTWARE_LIST:
self.root_ele_system.add_child_items([TreeViewItem(item)])
else:
self.root_ele_software.add_child_items([TreeViewItem(item)])
self.treeview_box.show_all()
def add_listview(self, items):
container_remove_all(self.listview_box)
if len(items) != 0:
self.factory = ListviewFactory(items, "detail")
self.listview = self.factory.listview
self.listview_box.pack_start(self.listview)
else:
empty_box_align = gtk.Alignment(0.5, 0.5, 0, 0)
empty_box_align.add(Label("(Empty)"))
self.listview_box.pack_start(empty_box_align)
self.listview_box.show_all()
def get_items_from_treeview_highlight(self):
'''
docs
示例2: WebcastsBrowser
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
class WebcastsBrowser(gtk.VBox, SignalContainer):
def __init__(self):
gtk.VBox.__init__(self)
SignalContainer.__init__(self)
# Init categorys.
self.get_categorys()
# load data.
self.__load_webcast_query()
# Init webcastbar.
self.__init_webcastbar()
# Init iconview.
self.metro_view = self.get_icon_view()
self.metro_view_sw = self.metro_view.get_scrolled_window()
self.page_box = gtk.VBox()
self.page_box.add(self.metro_view_sw)
# webcasts view
self.webcast_view = self.get_webcast_view()
self.webcast_view_sw = self.webcast_view.get_scrolled_window()
# collect view
self.collected_db_file = get_config_file("favorite_webcasts.db")
self.collected_view = self.get_webcast_view()
self.collected_view_sw = self.collected_view.get_scrolled_window()
# Init collect view.
# init listview page.
self.init_listview_page()
Dispatcher.connect("change-webcast", self.on_dispatcher_change_webcast)
WebcastDB.connect("changed", self.on_db_update_songs)
body_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True)
body_paned.add1(self.webcastbar)
body_paned.add2(self.page_box)
self.add(body_paned)
def get_categorys(self):
lang = utils.get_system_lang()
if lang.startswith("zh"):
self.__categorys = ["region", "genre", "composite"]
self.current_category = "region"
else:
self.__categorys = ["region_en", "genre_en"]
self.current_category = "region_en"
self.__category_gettexts = {
"region" : "地域分类",
"genre" : "流派分类",
"region_en" : _("Region"),
"genre_en" : _("Genre"),
"composite" : "综合分类",
"finance" : "财经",
"sports" : "体育",
"music" : "音乐",
"news" : "新闻",
"network" : "网络",
}
def __load_webcast_query(self):
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")))
#.........这里部分代码省略.........
示例3: PluginsManager
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
class PluginsManager(gtk.VBox):
def __init__(self):
gtk.VBox.__init__(self)
self.set_spacing(5)
self.plugins = utils.get_main_window().plugins
self.plugins_view = TreeView()
self.plugins_view.set_expand_column(0)
self.plugins_view.draw_mask = self.plugins_view_draw_mask
self.plugins_view.set_size_request(420, 330)
self.plugins_view.connect("single-click-item", self.on_plugins_view_single_click)
self.plugins_view.set_column_titles([_("Add-on"), _("Version"), _("Enable"), ""],
(self.sort_by_title, self.sort_by_title,
self.sort_by_title, self.sort_by_title))
plugins_view_align = set_widget_gravity(self.plugins_view, gravity=(1, 1, 1, 1),
paddings=(10, 0, 0, 0))
self.plugin_infos = PluginInfos()
self.plugin_infos.set_size_request(420, 90)
# plugin info
self.pack_start(plugins_view_align, False, True)
self.pack_start(self.plugin_infos, False, True)
def sort_by_title(self, items, reverse):
return sorted(items, key=lambda item: item.plugin, reverse=reverse)
def plugins_view_draw_mask(self, cr, x, y, width, height):
draw_alpha_mask(cr, x, y, width, height, "layoutLeft")
def flush_plugins(self):
self.__load_plugin_list()
def __load_plugin_list(self):
# clear plugins_view items.
self.plugins_view.clear()
plugins = self.plugins.list_installed_plugins()
plugins_list = []
failed_list = []
for plugin in plugins:
try:
info = self.plugins.get_plugin_info(plugin)
except Exception:
failed_list.append(plugin)
continue
enabled = plugin in self.plugins.enabled_plugins
plugins_list.append((plugin, info, enabled))
plugins_list.sort(key=lambda x: locale.strxfrm(x[1]["Name"]))
plugins_items = [PluginItem(*args) for args in plugins_list]
self.plugins_view.add_items(plugins_items)
def on_plugins_view_single_click(self, widget, item, column, x, y):
if column == 2:
plugin = item.plugin
will_enable = not item.enabled
if will_enable:
try:
self.plugins.enable_plugin(plugin)
except Exception, e:
print e
return
else:
try:
self.plugins.disable_plugin(plugin)
except Exception, e:
print e
return
item.toggle_enabled()
示例4: UninstallPage
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [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.white_kernel_pkg_names = self.get_white_kernel_pkg_names()
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
#.........这里部分代码省略.........
示例5: AddPage
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [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)
示例6: PreferenceDialog
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
class PreferenceDialog(DialogBox):
def __init__(self):
super(PreferenceDialog, self).__init__(_("Preference"), 575, 495,
mask_type=DIALOG_MASK_MULTIPLE_PAGE,
close_callback=self.hide_all)
self.set_position(gtk.WIN_POS_CENTER)
self.main_box = gtk.VBox()
close_button = Button(_("Close"))
close_button.connect("clicked", lambda w: self.hide_all())
# Init widget.
self.general_setting = GeneralSetting()
self.hotkey_setting = HotKeySetting()
self.desktop_lyrics_setting = DesktopLyricsSetting()
self.scroll_lyrics_setting = ScrollLyricsSetting()
# Category bar
self.category_bar = TreeView(font_x_padding=20)
self.category_bar.draw_mask = self.draw_treeview_mask
self.general_category_item = CategoryItem(_("General"), self.general_setting)
self.category_bar.add_item(None, self.general_category_item)
self.category_bar.add_item(None, CategoryItem(_("Hotkeys"), self.hotkey_setting))
lyrics_node = self.category_bar.add_item(None, CategoryItem(_("Lyrics")))
self.category_bar.add_item(lyrics_node, CategoryItem(_("Desktop"), self.desktop_lyrics_setting))
self.category_bar.add_item(lyrics_node, CategoryItem(_("Window"), self.scroll_lyrics_setting))
self.category_bar.add_item(None, CategoryItem(_("About us"), AboutBox()))
self.category_bar.connect("single-click-item", self.category_single_click_cb)
self.category_bar.set_highlight_index(0)
category_box = gtk.VBox()
background_box = BackgroundBox()
background_box.set_size_request(132, 11)
background_box.draw_mask = self.draw_treeview_mask
category_box.pack_start(background_box, False, False)
category_scrolled_window = ScrolledWindow()
category_scrolled_window.add_child(self.category_bar)
category_scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
category_scrolled_window.set_size_request(132, 516)
category_scrolled_window_align = gtk.Alignment()
category_scrolled_window_align.set(0, 0, 1, 1,)
category_scrolled_window_align.set_padding(0, 1, 0, 0)
category_scrolled_window_align.add(category_scrolled_window)
category_box.pack_start(category_scrolled_window_align, True, True)
# Pack widget.
left_box = gtk.VBox()
self.right_box = gtk.VBox()
left_box.add(category_box)
self.right_box.add(self.general_category_item.get_allocated_widget())
right_align = gtk.Alignment()
right_align.set_padding(0, 0, 10, 0)
right_align.add(self.right_box)
body_box = gtk.HBox()
body_box.pack_start(left_box, False, False)
body_box.pack_start(right_align, False, False)
self.main_box.add(body_box)
# DialogBox code.
self.body_box.pack_start(self.main_box, True, True)
self.right_button_box.set_buttons([close_button])
def switch_lyrics_page(self, index=3):
self.category_bar.tree_list[2].show_child_items_bool = True
self.category_bar.sort()
self.category_bar.queue_draw()
self.category_bar.set_highlight_index(index)
highlight_item = self.category_bar.get_highlight_item()
self.category_single_click_cb(None, highlight_item)
def show_scroll_lyrics_page(self):
self.switch_lyrics_page(4)
self.show_all()
def show_desktop_lyrics_page(self):
self.switch_lyrics_page(3)
self.show_all()
def draw_treeview_mask(self, cr, x, y, width, height):
draw_alpha_mask(cr, x, y, width, height, ("#FFFFFF", 0.9))
def category_single_click_cb(self, widget, item):
if item.get_allocated_widget():
switch_tab(self.right_box, item.get_allocated_widget())
示例7: MainBox
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [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)
示例8: UninstallPage
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [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:
#.........这里部分代码省略.........
示例9: Region
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
class Region(gtk.Alignment):
def __init__(self, connection=None):
gtk.Alignment.__init__(self, 0, 0, 0, 0)
#################
self.provider_select = None
self.connect('expose-event', self.expose_event)
self.prop_dict = {}
main_table = gtk.Table(2, 2, False)
main_table.set_row_spacing(1, 10)
main_table.set_col_spacings(4)
self.add(main_table)
self.country_tree = TreeView(enable_multiple_select=False,
enable_drag_drop=False,
)
self.country_tree.set_expand_column(1)
self.country_tree.set_size_request(365, 380)
self.country_tree.draw_mask = self.draw_mask
self.country_tree.connect("button-press-item", self.country_selected)
left_box_align = gtk.Alignment(0, 0, 0, 0)
left_box_align.set_padding(1,1,1,1)
left_box_align.add(self.country_tree)
left_box_align.show_all()
left_box = gtk.VBox()
# wrap title
country_title = TitleBar(app_theme.get_pixbuf("network/globe-green.png"),
_("Country or Region:"),
has_separator=False)
left_box.pack_start(country_title, False, False)
left_box.pack_start(left_box_align, False, False)
self.provider_tree = TreeView(enable_multiple_select=False,
enable_drag_drop=False,
)
self.provider_tree.set_expand_column(0)
self.provider_tree.set_size_request(365, 380)
self.provider_tree.draw_mask = self.draw_mask
self.provider_tree.connect("button-press-item", self.provider_selected)
right_box_align = gtk.Alignment(0, 0, 0, 0)
right_box_align.set_padding(1,1,1,1)
right_box_align.add(self.provider_tree)
right_box = gtk.VBox()
# wrap title
provider_title = TitleBar(app_theme.get_pixbuf("network/building.png"),
_("Provider:"),
has_separator=False)
right_box.pack_start(provider_title, False, False)
right_box.pack_start(right_box_align, False, False)
main_left_align = gtk.Alignment(0, 0, 0, 0)
main_left_align.set_padding(15, 0, 20, 0)
main_left_align.add(left_box)
main_table.attach(main_left_align, 0, 1, 0, 1)
main_right_align = gtk.Alignment(0, 0, 0, 0)
main_right_align.set_padding(15, 0, 0, 20)
main_right_align.add(right_box)
main_table.attach(main_right_align, 1, 2, 0, 1)
hints = _("Tips:This assistant helps you easily set up a mobile broadband connection to a cellular network.")
left_box_align.connect("expose-event", self.expose_outline)
right_box_align.connect("expose-event", self.expose_outline)
next_button = Button("Next")
next_button.connect("clicked", self.next_button_clicked)
self.foot_box = FootBox()
self.foot_box.set_buttons([next_button])
self.foot_box.set_tip(hints)
main_table.attach(self.foot_box, 0, 2, 1, 2)
self.show_all()
#self.init()
def expose_outline(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
with cairo_disable_antialias(cr):
cr.set_line_width(1)
cr.set_source_rgb(*BORDER_COLOR)
cr.rectangle(rect.x, rect.y, rect.width , rect.height )
cr.stroke()
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 expose_event(self, widget, event):
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()
#.........这里部分代码省略.........
示例10: SearchUI
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
class SearchUI(DialogBox):
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, window_pos=gtk.WIN_POS_CENTER)
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)
self.search_button = Button(_("Search"))
self.search_button.connect("clicked", self.search_lyric_cb)
self.process_id = 0
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(self.search_button, False, False)
sort_items = [ lambda items, reverse : self.sort_by_key(items, reverse, "title"),
lambda items, reverse : self.sort_by_key(items, reverse, "artist")]
self.result_view = TreeView()
self.result_view.set_expand_column(0)
self.result_view.connect("double-click-item", self.double_click_cb)
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
#.........这里部分代码省略.........
示例11: CompletionWindow
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
class CompletionWindow(Window):
'''
class docs
'''
def __init__(self, window_width, window_height):
'''
init docs
'''
# Init.
Window.__init__(
self,
# shadow_visible=False,
shape_frame_function=self.shape_completion_window_frame,
expose_frame_function=self.expose_completion_window_frame)
self.window_width = window_width
self.window_height = window_height
self.window_offset_x = 8
self.window_offset_y = 34
self.align_size = 2
self.treeview = TreeView(
[],
enable_highlight=False,
enable_multiple_select=False,
enable_drag_drop=False,
expand_column=0,
)
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.treeview.connect("press-return", self.treeview_press_return)
self.treeview.draw_mask = self.draw_mask
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)
completion_grab_window.connect("input-method-focus-in", self.input_method_focus_in)
completion_grab_window.connect("input-method-commit", self.input_method_commit)
self.keymap = {
"Home" : self.treeview.select_first_item,
"End" : self.treeview.select_last_item,
"Page_Up" : self.treeview.scroll_page_up,
"Page_Down" : self.treeview.scroll_page_down,
"Up" : self.treeview.select_prev_item,
"Down" : self.treeview.select_next_item,
}
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 treeview_press_return(self, treeview, select_items):
if len(select_items) > 0:
completion_grab_window.popup_grab_window_focus_out()
global_event.emit("switch-to-detail-page", select_items[0].text)
def set_input_method_cursor(self):
entry_buffer = search_entry.entry.entry_buffer
cursor_pos = entry_buffer.get_cursor_pos(entry_buffer.get_insert_index())[0]
(entry_x, entry_y) = search_entry.translate_coordinates(search_entry.get_toplevel(), 0, 0)
(window_x, window_y) = search_entry.get_toplevel().window.get_origin()
completion_grab_window.im.set_cursor_location(
gtk.gdk.Rectangle(
window_x + entry_x + cursor_pos[0],
window_y + entry_y + cursor_pos[1],
1,
cursor_pos[3]))
def input_method_focus_in(self, grab_window, im):
self.set_input_method_cursor()
def input_method_commit(self, grab_window, im, input_text):
self.set_input_method_cursor()
search_entry.set_text("%s%s" % (search_entry.get_text(), input_text))
def get_scrolledwindow(self):
return self.treeview.scrolled_window
def shape_completion_window_frame(self, widget, event):
#.........这里部分代码省略.........
示例12: TreeView
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
"TreeView demo",
"TreeView demo",
)
# Add TreeView.
print os.path.expanduser("~")
treeview = TreeView(get_dir_items(os.path.expanduser("~")))
# expand column.
treeview.set_expand_column(3)
# hide column
treeview.set_hide_columns([1, 2])
#treeview.set_highlight_item(treeview.get_items()[35])
treeview.connect("delete-select-items", m_delete_select_items)
treeview.connect("button-press-item", m_button_press_item)
treeview.connect("double-click-item", m_double_click_item)
treeview.connect("right-press-items", m_right_press_items)
treeview.connect("single-click-item", m_single_click_item)
# treeview = TreeView(get_dir_items("/"))
treeview_align = gtk.Alignment()
treeview_align.set(0.5, 0.5, 1, 1)
treeview_align.set_padding(0, 2, 2, 2)
treeview.set_column_titles(["文件名", "大小", "类型", "修改时间"],
[sort_by_name, sort_by_size, sort_by_type, sort_by_mtime])
treeview_align.add(treeview)
application.main_box.pack_start(treeview_align)
application.window.connect("show", lambda w: treeview.visible_highlight())
示例13: SessionView
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [as 别名]
class SessionView(gtk.VBox):
def __init__(self):
gtk.VBox.__init__(self)
self.open_dialog = False
self.tmp_editing_session = None
# UI style
style.draw_background_color(self)
self.tree = TreeView([],enable_drag_drop=False,
enable_hover=True,
enable_multiple_select=False,
)
self.tree.set_expand_column(3)
self.tree.set_column_titles((_("Active"), _("Application"), _("Description"), _("Exec")),)
self.tree.set_size_request(800, -1)
self.tree.connect("right-press-items", self.right_press_item)
self.tree.draw_mask = self.draw_mask
self.tree.add_items(self.get_list())
align = gtk.Alignment(0, 0, 0, 1)
align.set_padding(15, 0, 20, 20)
align.add(self.tree)
align.connect("expose-event", self.expose_line)
add_button = Button(_("New"))
self.delete_button = Button(_("Delete"))
add_button.connect("clicked", self.add_autostart)
self.delete_button.connect("clicked", self.delete_autostart)
self.delete_button.set_sensitive(False)
foot_box = FootBox(adjustment=15)
foot_box.set_buttons([add_button, self.delete_button])
self.pack_start(align, True, True)
self.pack_end(foot_box, False, False)
#self.pack_end(self.new_box, False, False)
self.show_all()
self._init_monitor()
def disable_delete_button(self, value):
self.delete_button.set_sensitive(not value)
def _init_monitor(self):
self.library_monitor = LibraryMonitor(get_user_config_dir())
self.library_monitor.set_property("monitored", True)
self.library_monitor.connect("file-added", self.refresh_list)
self.library_monitor.connect("location-removed", self.refresh_list)
def right_press_item(self, widget, x_root, y_root, current_item, select_items):
self.tmp_editing_session = current_item.item
for item in select_items:
item.unselect()
if current_item != None:
current_item.select()
if self.open_dialog == False:
dialog = NewSessionDialog(confirm_callback = self.edit_done, cancel_callback = self.cancel_callback)
dialog.name_entry.set_text(current_item.item.name)
dialog.exec_entry.set_text(current_item.item.exec_)
dialog.desc_entry.set_text(current_item.item.comment)
dialog.place_center()
dialog.show_all()
self.open_dialog = True
def create_session_item(self, dialog):
name = dialog.name_entry.get_text()
exec_ = dialog.exec_entry.get_text()
comment = dialog.desc_entry.get_text()
session_manager.add(name, exec_, comment)
self.open_dialog = 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 sort_method(self):
pass
def add_autostart(self, widget):
if self.open_dialog == False:
dialog = NewSessionDialog(confirm_callback= self.create_session_item, cancel_callback = self.cancel_callback)
dialog.show_all()
self.open_dialog = True
def delete_autostart(self, widget):
items = map(lambda row: self.tree.visible_items[row], self.tree.select_rows)
item = items[0].item
item.delete()
self.tree.delete_select_items()
if self.tree.visible_items == []:
self.tree.add_items([NothingItem()])
def edit_done(self, dialog):
self.tmp_editing_session.set_name(dialog.name_entry.get_text())
self.tmp_editing_session.set_exec(dialog.exec_entry.get_text())
self.tmp_editing_session.set_comment(dialog.desc_entry.get_text())
#.........这里部分代码省略.........
示例14: PreferenceDialog
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [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()
示例15: ListviewFactory
# 需要导入模块: from dtk.ui.treeview import TreeView [as 别名]
# 或者: from dtk.ui.treeview.TreeView import connect [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":
#.........这里部分代码省略.........