当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 5 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 【菜单图标已经漂亮的显示出来了】菜单显示不出图标,也显示不出快捷键,难道我选择恶 gtk3 选错了?
帖子发表于 : 2013-02-26 18:36 
头像

注册: 2008-06-23 15:19
帖子: 3051
地址: 北欧某国
系统: ���������
送出感谢: 21
接收感谢: 6
附件:
菜单显示不出漂亮的图标.jpg
菜单显示不出漂亮的图标.jpg [ 50.19 KiB | 被浏览 1705 次 ]



我把生成菜单的代码放在一的单独文件里了
menu.py:
[python]#!/usr/bin/python
#coding:utf8

from gi.repository import Gtk, Pango, GtkSource, Gdk, GObject
import string

def CreateFullMenu(parent = None, history = []):
"""建立一个菜单栏"""
mb = Gtk.MenuBar()

mb.append(create_file_menu(parent))

#编辑菜单
editmenu = Gtk.Menu()

undo = Gtk.ImageMenuItem(Gtk.STOCK_UNDO)
undo.set_label("撤销")
editmenu.append(undo)

editm = Gtk.MenuItem.new_with_label("编辑")
editm.set_submenu(editmenu)
mb.append(editm)

mb.append(create_view_menu(parent))

mb.append(create_search_menu(parent))

return mb

def create_file_menu(parent):

#文件菜单
filemenu = Gtk.Menu()

agr = Gtk.AccelGroup()

new = Gtk.ImageMenuItem(Gtk.STOCK_NEW)
key, mod = Gtk.accelerator_parse("<Ctrl>N")
new.add_accelerator("activate", agr, key, mod, Gtk.AccelFlags.VISIBLE)
new.set_label("新建")
filemenu.append(new)
new.connect("activate", parent.on_new)

openitem = Gtk.ImageMenuItem(Gtk.STOCK_OPEN)
key, mod = Gtk.accelerator_parse("<Ctrl>O")
openitem.add_accelerator("activate", agr, key, mod, Gtk.AccelFlags.VISIBLE)
openitem.set_label("打开")
filemenu.append(openitem)
openitem.connect("activate", parent.on_open_file)

filemenu.append(Gtk.SeparatorMenuItem.new()) #分隔符

save = Gtk.ImageMenuItem(Gtk.STOCK_SAVE)
save.set_label("保存")
filemenu.append(save)
save.connect("activate", parent.on_save)
saveAs = Gtk.ImageMenuItem(Gtk.STOCK_SAVE_AS)
saveAs.set_label("另存为")
filemenu.append(saveAs)
reOpen = Gtk.MenuItem.new_with_label("还原")
filemenu.append(reOpen)

filemenu.append(Gtk.SeparatorMenuItem.new()) #分隔符

print_preview = Gtk.ImageMenuItem(Gtk.STOCK_PRINT_PREVIEW)
print_preview.set_label("打印预览")
filemenu.append(print_preview)

printitem = Gtk.ImageMenuItem(Gtk.STOCK_PRINT)
printitem.set_label("打印")
filemenu.append(printitem)

filemenu.append(Gtk.SeparatorMenuItem.new()) #分隔符

for i in parent.history:
new = Gtk.MenuItem.new_with_label(i)
filemenu.append(new)
new.show()
new.connect("activate", parent.open_with_menu)

filemenu.append(Gtk.SeparatorMenuItem.new()) #分隔符

close = Gtk.ImageMenuItem(Gtk.STOCK_CLOSE)
close.set_label("关闭")
filemenu.append(close)

exit = Gtk.MenuItem.new_with_label("退出")
filemenu.append(exit)

filem = Gtk.MenuItem.new_with_label("文件")
filem.set_submenu(filemenu)

return filem

def create_view_menu(parent):

#查看菜单
viewmenu = Gtk.Menu()

wrap = Gtk.MenuItem.new_with_label("自动换行")
viewmenu.append(wrap)

viewm = Gtk.MenuItem.new_with_label("查看")
viewm.set_submenu(viewmenu)

#语法加亮菜单
languagemenu = Gtk.Menu()
languagem = Gtk.MenuItem.new_with_label("语法高亮模式")
languagem.set_submenu(languagemenu)

textm = Gtk.MenuItem.new_with_label("纯文本")
languagemenu.append(textm)

#标记
markmenu = Gtk.Menu()
markm = Gtk.MenuItem.new_with_label("标记")
markm.set_submenu(markmenu)
languagemenu.append(markm)

BibTeXm = Gtk.MenuItem.new_with_label("BibTeX")
markmenu.append(BibTeXm)

Docbookm = Gtk.MenuItem.new_with_label("Docbook")
markmenu.append(Docbookm)

DTDm = Gtk.MenuItem.new_with_label("DTD")
markmenu.append(DTDm)

gtkdocm = Gtk.MenuItem.new_with_label("gtk-doc")
markmenu.append(gtkdocm)

Haddockm = Gtk.MenuItem.new_with_label("Haddock")
markmenu.append(Haddockm)

HTMLm = Gtk.MenuItem.new_with_label("html")
HTMLm.connect("activate", parent.set_language)
markmenu.append(HTMLm)

XMLm = Gtk.MenuItem.new_with_label("xml")
XMLm.connect("activate", parent.set_language)
markmenu.append(XMLm)

#脚本
scriptmenu = Gtk.Menu()
scriptm = Gtk.MenuItem.new_with_label("脚本")
scriptm.set_submenu(scriptmenu)
languagemenu.append(scriptm)

Luam = Gtk.MenuItem.new_with_label("Lua")
scriptmenu.append(Luam)

Pythonm = Gtk.MenuItem.new_with_label("Python")
scriptmenu.append(Pythonm)

viewmenu.append(languagem)

return viewm


def create_search_menu(parent):

searchmenu = Gtk.Menu()

find = Gtk.ImageMenuItem(Gtk.STOCK_FIND)
find.set_label("查找")
searchmenu.append(find)

searchm = Gtk.MenuItem.new_with_label("搜索")
searchm.set_submenu(searchmenu)

return searchm[/python]
我想使用 ImageMenuItem 和 set_label 显示图标。可是只显示出了文字,是不是还需要什么设置呢?
快捷键也没有设置好。。。
main.py:
[python]#!/usr/bin/python
#coding:utf8

from gi.repository import Gtk, Pango, GtkSource, Gdk, GObject, GdkPixbuf
import string
import os
import re
import cairo

from menu import CreateFullMenu
from preferences_dialog import PreferencesDialog

class SearchDialog(Gtk.Dialog):
"""这里是一个在文本中搜索字符串的对话框。"""
def __init__(self, parent):
Gtk.Dialog.__init__(self, "Search", parent,
Gtk.DialogFlags.MODAL, buttons=(
Gtk.STOCK_FIND, Gtk.ResponseType.OK,
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL
)
)

box = self.get_content_area()

box.add(Gtk.Label("查找:"))

self.entry = Gtk.Entry()
box.add(self.entry)

self.show_all()

class TextViewWindow(Gtk.Window):
"""程序的主要部分"""

history = []

def __init__(self):
Gtk.Window.__init__(self, title="带背景的文本编辑器")

GObject.signal_new("changed", BEditDocument, GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ())


self.grid = Gtk.Grid()
self.add(self.grid)

#载入历史记录
self.load_config()
self.set_default_size(self.sizeWidth, self.sizeHeight)

self.create_notebook()
self.create_menubar()
self.create_toolbar()

self.on_new()
self.set_style()

def create_toolbar(self):
"""建立工具栏,这里的工具栏,实际上是选项卡上的一些标签页。"""

self.button = [Gtk.ToolButton.new_from_stock(Gtk.STOCK_NEW),
Gtk.MenuToolButton.new_from_stock(Gtk.STOCK_OPEN),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_SAVE),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_PRINT),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_UNDO),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_REDO),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_CUT),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_COPY),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_PASTE),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_FIND),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_FIND_AND_REPLACE),
Gtk.ToolButton.new_from_stock(Gtk.STOCK_PREFERENCES)]

for i in self.button:
self.notebook.append_page(Gtk.Box(spacing=6), i)

self.button[0].connect("clicked", self.on_new)
self.button[1].connect("clicked", self.on_open_file)
self.button[2].connect("clicked", self.on_save)
self.button[9].connect("clicked", self.on_find)
self.button[-1].connect("clicked", self.on_preferences)

#历史记录
historymenu = Gtk.Menu()
for i in self.history:
new = Gtk.MenuItem.new_with_label(i)
historymenu.append(new)
new.show()
new.connect("activate", self.open_with_menu)
self.button[1].set_menu(historymenu)

def create_menubar(self):
"""建立一个菜单栏"""
self.menubar = CreateFullMenu(self, self.history)
self.grid.attach(self.menubar, 0, 0, 1, 1)

def set_language(self, menu = None):

src_view = self.notebook.get_nth_page(self.notebook.get_current_page()).get_child()
src_buffer = src_view.get_buffer()

manager = GtkSource.LanguageManager()
language = manager.get_language(menu.get_label())
src_buffer.set_language(language)

def open_with_menu(self, menu = None):
"""通过历史菜单打开文件"""
# 判断最后一个标签里面是否是空文档
last_doc = self.notebook.get_nth_page(-1).get_child()
if last_doc.filename != "无标题文档" or last_doc.change_number > 0 or last_doc.stext != "":
self.on_new()
last_doc = self.notebook.get_nth_page(-1).get_child()
last_doc.open(menu.get_label())
self.append_history(menu.get_label())
self.save_config()

def create_notebook(self):
"""建立选项卡"""
self.notebook = Gtk.Notebook()
self.grid.attach(self.notebook, 0, 1, 1, 1)

def on_new(self, widget = None):
"""在这里新建一个文档"""
language = GtkSource.LanguageManager.get_default().get_language("python")
buffer = GtkSource.Buffer.new_with_language(language)
new_textview = BEditDocument()
new_textview.set_buffer(buffer)
new_textview.connect("changed", self.on_update_title)
new_scrolledwindow = Gtk.ScrolledWindow()
new_scrolledwindow.set_hexpand(True)
new_scrolledwindow.set_vexpand(True)
new_scrolledwindow.add(new_textview)

new_label = Gtk.Label("无标题文档")
self.notebook.append_page(new_scrolledwindow, new_label)
#切换到刚插入的一页
self.show_all()
self.notebook.set_current_page(self.notebook.get_n_pages()-1)

def on_open_file(self, widget):
dialog = Gtk.FileChooserDialog("打开文件", self,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

self.add_filters(dialog)

response = dialog.run()
if response == Gtk.ResponseType.OK:
# 判断最后一个标签里面是否是空文档
last_doc = self.notebook.get_nth_page(-1).get_child()
if last_doc.filename != "无标题文档" or last_doc.change_number > 0 or last_doc.stext != "":
self.on_new()
last_doc = self.notebook.get_nth_page(-1).get_child()
last_doc.open(dialog.get_filename())
self.append_history(dialog.get_filename())
self.save_config()

dialog.destroy()

def on_save(self, widget = None):
cur_wid = self.notebook.get_nth_page(self.notebook.get_current_page()).get_child()
# 判断文件是否有文件名
if cur_wid.filepath == "":
dialog = Gtk.FileChooserDialog("另存为", self,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

self.add_filters(dialog)

response = dialog.run()
if response == Gtk.ResponseType.OK:
cur_wid.save(dialog.get_filename())
self.append_history(dialog.get_filename())
self.save_config()
dialog.destroy()
else:
# 直接使用已经存在的文件名
filename = cur_wid.save()
self.append_history(filename)
self.save_config()


def on_find(self, widget = None):
dialog = SearchDialog(self)
response = dialog.run()
if response == Gtk.ResponseType.OK:
cursor_textbuffer = self.notebook.get_nth_page(self.notebook.get_current_page()).get_child().get_buffer()
cursor_mark = cursor_textbuffer.get_insert()
start = cursor_textbuffer.get_iter_at_mark(cursor_mark)
if start.get_offset() == self.textbuffer.get_char_count():
start = self.textbuffer.get_start_iter()

self.search_and_mark(dialog.entry.get_text(), start)

dialog.destroy()

def on_preferences(self, widget = None):
"""显示属性对话框"""

dialog = PreferencesDialog(self)

#还要从 css 中读取属性
file_object = open(os.environ['HOME']+"/.local/share/bedit/gtk-widgets3.css")
try:
text = file_object.read()
for i in text.split('}'):
css = i.split('{')
if 'GtkWindow' in css[0]:
Pattern = re.compile(r"background-image: url\('(.*?)'\);")
match = Pattern.search(css[1])
if match:
dialog.set_background_image(match.group(1))
if 'GtkNotebook' in css[0]:
Pattern = re.compile(r"background-color: RGBA\((\d+),(\d+),(\d+),(\d*\.?\d*)\);")
match = Pattern.search(css[1])
if match:
dialog.set_notebook_color(
string.atoi(match.group(1)),
string.atoi(match.group(2)),
string.atoi(match.group(3)),
string.atof(match.group(4))
)
finally:
file_object.close()

response = dialog.run()

file_object = open(os.environ['HOME']+"/.local/share/bedit/gtk-widgets3.css","w")
try:
file_object.write("""GtkWindow {
background-image: url('""")
file_object.write(dialog.get_background_image())
file_object.write("""');
}
GtkNotebook {
background-color: RGBA(""")
file_object.write(dialog.get_notebook_RGBA())
file_object.write(""");
}
GtkScrolledWindow , GtkSourceView {
background-color: RGBA(255,100,100,0);
}
GtkSourceView:selected { background-color: #C80; }""")
finally:
file_object.close()

dialog.destroy()

#更新样式
self.set_style()

def on_update_title(self, widget = None):
"""更新标题栏"""
cw = self.notebook.get_nth_page(self.notebook.get_current_page())
cwt = cw.get_child()
if cwt.change_number == 0:
self.set_title(cwt.filename+" ("+cwt.filepath+") - bedit")
new_label = Gtk.Label(cwt.filename)
self.notebook.set_tab_label(cw, new_label)
else:
self.set_title("*" + cwt.filename+" ("+cwt.filepath+") - bedit")
new_label = Gtk.Label("*" + cwt.filename)
self.notebook.set_tab_label(cw, new_label)
new_label.set_name("BEditTabLabel")

def add_filters(self, dialog):
filter_text = Gtk.FileFilter()
filter_text.set_name("文本文件")
filter_text.add_mime_type("text/plain")
dialog.add_filter(filter_text)

filter_py = Gtk.FileFilter()
filter_py.set_name("Python 文件")
filter_py.add_mime_type("text/x-python")
dialog.add_filter(filter_py)

filter_any = Gtk.FileFilter()
filter_any.set_name("所有文件")
filter_any.add_mime_type("*")
dialog.add_filter(filter_any)

def set_style(self):
"""用来设置外观"""

style_provider = Gtk.CssProvider()
style_provider.load_from_path(os.environ['HOME']+'/.local/share/bedit/gtk-widgets3.css')
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)

def load_config(self):
file_object = open(os.environ['HOME']+"/.local/share/bedit/config")
try:
for eachline in file_object:
els = eachline.split()
if els[0] == "wrap_mode":
#读取换行模式
if els[1] == "NONE":
self.wrap_mode = Gtk.WrapMode.NONE
if els[1] == "CHAR":
self.wrap_mode = Gtk.WrapMode.CHAR
if els[1] == "WORD":
self.wrap_mode = Gtk.WrapMode.WORD
if els[1] == "WORD_CHAR":
self.wrap_mode = Gtk.WrapMode.WORD_CHAR
elif els[0] == "width":
#读取窗口的长宽
self.sizeWidth = string.atoi(els[1])
elif els[0] == "height":
self.sizeHeight = string.atoi(els[1])
else:
#读取历史记录
self.history.append(eachline.strip('\n'))
finally:
file_object.close()

def save_config(self):
file_object = open(os.environ['HOME']+"/.local/share/bedit/config","w")
try:
if self.wrap_mode == Gtk.WrapMode.NONE:
file_object.write("wrap_mode NONE\n")
elif self.wrap_mode == Gtk.WrapMode.CHAR:
file_object.write("wrap_mode CHAR\n")
elif self.wrap_mode == Gtk.WrapMode.WORD:
file_object.write("wrap_mode WORD\n")
elif self.wrap_mode == Gtk.WrapMode.WORD_CHAR:
file_object.write("wrap_mode WORD_CHAR\n")

#保存大小
width, height = self.get_size()
file_object.write("width "+str(width)+"\n")
file_object.write("height "+str(height)+"\n")

for eachline in self.history:
file_object.write(eachline+'\n')
finally:
file_object.close()

def main_quit(self, widget, event, data=None):
self.save_config()
Gtk.main_quit()

def append_history(self, file):
filemenu = self.menubar.get_children()[0].get_submenu()
toolmenu = self.button[1].get_menu()
if file in self.history:
self.history.remove(file)
#还要从文件菜单中移除
for i in filemenu.get_children():
if i.get_label() == file:
filemenu.remove(i)
for i in toolmenu.get_children():
if i.get_label() == file:
toolmenu.remove(i)
#插入菜单
new1 = Gtk.MenuItem.new_with_label(file)
new2 = Gtk.MenuItem.new_with_label(file)
filemenu.insert(new1,10)
toolmenu.insert(new2,0)
new1.show()
new2.show()
new1.connect("activate", self.open_with_menu)
new2.connect("activate", self.open_with_menu)
self.history.insert(0,file)

class BEditDocument(GtkSource.View):
"""为 GtkSource.View 添加一些原来没有的东西。"""
def __init__(self):
GtkSource.View.__init__(self)
self.filename = "无标题文档"
self.filepath = ""
self.stext = ""
self.change_number = 0

#修改后的信号
self.get_buffer().connect("changed", self.text_change)
self.load_config()

self.buffer = GtkSource.Buffer()
self.sourceview = GtkSource.View.new_with_buffer(self.buffer)


def text_change(self, buffer):
text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), False)
if self.stext == text:
if self.change_number > 0:
self.change_number = 0
#发出改变标题栏的信号
self.emit('changed')
#如果被修改了
else:
self.change_number = self.change_number+1
if self.change_number == 1:
self.emit('changed')

def open(self, filename):
# 在这里读取文件
file_object = open(filename)
try:
self.stext = file_object.read()
self.get_buffer().set_text(self.stext)
# 将绝对路径分解成路径和文件名
self.filepath , self.filename = os.path.split(filename)
self.emit('changed')
finally:
file_object.close()

def save(self, filename = ""):
"""在这里保存文件"""
if filename == "":
file_object = open(self.filepath + "/" + self.filename, 'w')
else:
file_object = open(filename, 'w')
self.filepath , self.filename = os.path.split(filename)
try:
self.stext = self.get_buffer().get_text(self.get_buffer().get_start_iter(), self.get_buffer().get_end_iter(), False)
file_object.write(self.stext)
# 将绝对路径分解成路径和文件名
self.change_number = 0
self.emit('changed')
finally:
file_object.close()

return self.filepath + "/" + self.filename

def load_config(self):
"""读取配置文件"""
file_object = open(os.environ['HOME']+"/.local/share/bedit/config")
try:
for eachline in file_object:
els = eachline.split()
if els[0] == "wrap_mode":
if els[1] == "NONE":
self.set_wrap_mode(Gtk.WrapMode.NONE)
if els[1] == "CHAR":
self.set_wrap_mode(Gtk.WrapMode.CHAR)
if els[1] == "WORD":
self.set_wrap_mode(Gtk.WrapMode.WORD)
if els[1] == "WORD_CHAR":
self.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
finally:
file_object.close()


if __name__ == "__main__":
win = TextViewWindow()
win.connect("delete-event", win.main_quit)
#win.show_all()
Gtk.main()[/python]
对话框类,preferences_dialog.py:
[python]#!/usr/bin/python
#coding:utf8

from gi.repository import Gtk, Pango, GtkSource, Gdk, GObject, GdkPixbuf
import string

class PreferencesDialog(Gtk.Dialog):
"""属性对话框"""
def __init__(self, parent):
Gtk.Dialog.__init__(self, "bedit 首选项", parent,
Gtk.DialogFlags.MODAL, buttons=(
Gtk.STOCK_HELP, Gtk.ResponseType.HELP,
Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE
)
)

box = self.get_content_area()

self.notebook = Gtk.Notebook()

self.notebook.append_page(Gtk.Box(spacing=6), Gtk.Label("查看"))
self.notebook.append_page(Gtk.Box(spacing=6), Gtk.Label("编辑器"))

#字体和颜色
boxFontColor = Gtk.Box(spacing=6)
frameColorBackground = Gtk.Frame()
frameColorBackground.set_label("配色和背景")
boxFontColor.add(frameColorBackground)
self.notebook.append_page(boxFontColor, Gtk.Label("字体和颜色"))
self.fsBackground = Gtk.FileChooserButton()
self.gridColor = Gtk.Grid()
frameColorBackground.add(self.gridColor)
self.gridColor.attach(self.fsBackground,1,0,1,1)
#文件选择按钮也可以有消息映射的
self.fsBackground.connect("file-set", self.background_selected)
self.gridColor.attach(Gtk.Label("背景图片:"),0,0,1,1)

self.thumbnail = Gtk.Image()
self.gridColor.attach(self.thumbnail,0,1,2,1)

self.gridColor.attach(Gtk.Label("标签页颜色:"),0,3,1,1)
self.buttonNotebookColor = Gtk.ColorButton()
self.buttonNotebookColor.set_use_alpha(True)
self.gridColor.attach(self.buttonNotebookColor,1,3,1,1)

#插件
self.notebook.append_page(Gtk.Box(spacing=6), Gtk.Label("插件"))

#历史记录
self.history = parent.history
modelHistory = Gtk.ListStore(str)
self.treeViewHistory = Gtk.TreeView(modelHistory)
cell = Gtk.CellRendererText()
treeviewcolumn = Gtk.TreeViewColumn("路径", cell, text=0)
self.treeViewHistory.append_column(treeviewcolumn)
for i in parent.history:
modelHistory.append([i])
gridHistory = Gtk.Grid()
gridHistory.attach(self.treeViewHistory,0,0,2,1)
clearOne = Gtk.Button("移除历史记录")
clearAll = Gtk.Button("移除全部历史记录")
clearOne.connect("clicked", self.on_clear_one)
gridHistory.attach(clearOne,0,1,1,1)
gridHistory.attach(clearAll,1,1,1,1)
self.notebook.append_page(gridHistory, Gtk.Label("历史记录"))
box.add(self.notebook)

self.show_all()

def on_clear_one(self, widget = None):
"""从列表中删除一个历史记录"""
path, column = self.treeViewHistory.get_cursor()
#self.treeViewHistory.remove_column(column)
del self.history[string.atoi(path.to_string())]

def set_background_image(self, url):
self.fsBackground.set_filename(url)

imgp = GdkPixbuf.Pixbuf.new_from_file(url)
width = imgp.get_width()
height = imgp.get_height()
scale = min(320.0/float(width),400/float(height))
n_width = width*scale
n_height = height*scale
self.thumbnail.set_from_pixbuf(imgp.scale_simple(n_width,n_height,GdkPixbuf.InterpType.BILINEAR))

self.gridColor.attach(Gtk.Label("宽度:"+str(width)+" 高度:"+str(height)),0,2,2,1)
self.show_all()

def set_notebook_color(self, r,g,b,a):
self.buttonNotebookColor.set_color(Gdk.Color(r*256,g*256,b*256))
self.buttonNotebookColor.set_alpha(a*65535)

def background_selected(self, widget):
self.set_background_image(widget.get_filename())

def get_background_image(self):
"""获得背景图片的路径"""
return self.fsBackground.get_filename()

def get_notebook_RGBA(self):
"""返回标签的颜色"""
rgb = self.buttonNotebookColor.get_color()
return str(rgb.red/256)+","+str(rgb.green/256)+","+str(rgb.blue/256)+","+str(self.buttonNotebookColor.get_alpha()/65535.0)[/python]
config文件,要放在 ~/.local/share/bedit 当中:
代码:
wrap_mode WORD
width 973
height 777
/home/liu/文档/翻译/Panda3D/SPE
/home/liu/文档/翻译/Panda3D/Panda3D手册: Bullet Hello World
/home/liu/文档/翻译/Panda3D/Panda3D手册: 版权
/home/liu/文档/翻译/Panda3D/签署 p3d 文件
/home/liu/文档/翻译/PyGObject/使用

还有 gtk-widgets3.css 文件:
代码:
GtkWindow {
         background-image: url('/home/liu/图片/壁纸/thumb_d_96389.jpg');
      }
GtkNotebook {
         background-color: RGBA(200,255,203,0.349645227741);
      }
GtkScrolledWindow , GtkSourceView {
         background-color: RGBA(255,100,100,0);
      }
GtkSourceView:selected { background-color: #C80; }

background-image 中的图片必须存在,否则程序不能运行。


_________________
http://noie.name 网站改版中。


最后由 Hello World! 编辑于 2013-02-28 22:21,总共编辑了 1 次

页首
 用户资料  
 
2 楼 
 文章标题 : Re: 菜单显示不出图标,也显示不出快捷键,难道我选择恶 gtk3 选错了?
帖子发表于 : 2013-02-26 22:38 
头像

注册: 2013-02-02 10:48
帖子: 13
送出感谢: 0 次
接收感谢: 3
据说是 gnome 关了 menu 的 image
http://ubuntuforums.org/showthread.php?t=1597157

快捷键的话,在
agr = Gtk.AccelGroup()
之后加两行:
filemenu.set_accel_group(agr)
parent.add_accel_group(agr)
貌似就可以了,不过我没怎么理解 gtk accel group 的概念。

建议把code扔到共享repository上,比如github啥的。repository的管理和app的部署也算软件的必备技能。这样下code会方便点(大概)。


页首
 用户资料  
 
3 楼 
 文章标题 : Re: 菜单显示不出图标,也显示不出快捷键,难道我选择恶 gtk3 选错了?
帖子发表于 : 2013-02-27 11:16 
头像

注册: 2008-06-23 15:19
帖子: 3051
地址: 北欧某国
系统: ���������
送出感谢: 21
接收感谢: 6
weidongxu 写道:
据说是 gnome 关了 menu 的 image
http://ubuntuforums.org/showthread.php?t=1597157

快捷键的话,在
agr = Gtk.AccelGroup()
之后加两行:
filemenu.set_accel_group(agr)
parent.add_accel_group(agr)
貌似就可以了,不过我没怎么理解 gtk accel group 的概念。

建议把code扔到共享repository上,比如github啥的。repository的管理和app的部署也算软件的必备技能。这样下code会方便点(大概)。

您好,不知到是怎么弄出来的,我的 firefox 和 gedit 的菜单上都有图标。

快捷键已经就位了,真好。。。
https://github.com/NoIE/bedit ,我把代码上传到 github 上了,不过管理方面的知识,我一点不会。 :em06


_________________
http://noie.name 网站改版中。


页首
 用户资料  
 
4 楼 
 文章标题 : Re: 菜单显示不出图标,也显示不出快捷键,难道我选择恶 gtk3 选错了?
帖子发表于 : 2013-02-27 22:07 
头像

注册: 2013-02-02 10:48
帖子: 13
送出感谢: 0 次
接收感谢: 3
如果这样是能显示menu的image的

new.set_use_stock(True)
new.set_always_show_image(True)

但是这时不能用 set_label 设 label 了,如果设了 label 那个 image 貌似就显示大叉了。


页首
 用户资料  
 
5 楼 
 文章标题 : Re: 菜单显示不出图标,也显示不出快捷键,难道我选择恶 gtk3 选错了?
帖子发表于 : 2013-02-28 11:16 
头像

注册: 2013-02-02 10:48
帖子: 13
送出感谢: 0 次
接收感谢: 3
不过我用的是 gtk2 + unity (ubuntu 12.10),不确定 gtk3 是怎样了。


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 5 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译