GTK UI从捆绑运行和从Xamarin Studio运行时看起来有所不同 [英] GTK UI Looks different when running from bundle and when running from Xamarin Studio
问题描述
我有使用Mono框架的C#应用程序和用于UI的GTK。当我从Xamarin Studio运行它时,它看起来像这样
$ b
哪一个看起来更适合OSX平台?如果它是第一个,那么我怎样才能在捆绑的应用程序中获得相同的外观和感觉。
GTK 2主题选项: ul> GTK 2主题 主题通常以名为'gtkrc'的主文件通过资源文件在GTK 2中处理。这些资源文件可以是独立的,包括其他资源文件和引用外部图像(图标)等....基于
〜/ .gtkrc
gtkrc
的内部文件超出了范围这里,但是网上有很多关于GTK 2.0资源/主题的参考资料。
Mono w / GTK 2:
Mono在OS-X上安装默认的GTK2主题( gtkrc
)和几个替代主题:
位置: / Library / Frameworks / Mono.framework / Versions / 4.2.1
find。 -namegtkrc
./etc/gtk-2.0/gtkrc
./share/themes/bubble/gtk-2.0/gtkrc
./share/themes/Clearlooks/gtk-2.0 / gtkrc
./share/themes/Mac/gtk-2.0-key/gtkrc
./share/themes/Quartz/gtk-2.0/gtkrc
./share/themes/Xamarin/ gtk-2.0 / gtkrc
位于< Mono / Version> ; /etc/gtk-2.0
是默认的(Tango风格),而其中一个替代方案是'Xamarin',并且是用于风格化Xamarin Studio的内部方案(内部命名为Xamarian的Mac主题 )。
至于控制哪个主题应用于您的应用程序,您可以允许用户通过$ HOME目录控制它,该目录基于 .gtkrc
文件(恕我直言:有多少用户真的知道如何做到这一点,甚至是'专家'最终用户调整用户界面的做法和支持噩梦,我更愿意将UIX经验锁定为统一的用户,但是,这只是我的选择)。
你应该能够设置环境var GTK2_RC_FILES
在你的应用启动脚本中,但是我从来没有碰到过这种情况。
注意:env 。变种。 GTK_THEME
可以在GTK3中工作(但Mono是GTK2绑定的)
通过GTK API应用主题: 通过应用程序,您可以将GTK分配给使用Mono安装的主题之一或应用程序提供的主题。 BEFORE 如果您有自己的主题,请将文件(gtkrc,其他包含gtkrc文件,图标,图片,等等......)在你的 对于独立的exe文件,我也使用了一个嵌入的gtkrc文件,并将它解压缩到一个tmp文件的运行时: I have C# App using Mono framework and GTK for UI.When i run it from Xamarin Studio it looks like this I have bundled Mono and GTK into a standalone bundle.When running from it it looks different. Which one looks more native to the OSX Platform? If its the first one,then how can i get the same look and feel in the bundled App. GTK 2 Theming Options: GTK 2 Theming: Theming is handled in GTK 2 via resource files with the master normally named 'gtkrc'. These resources files can be standalone, include other resources files and reference external images (icons), etc.... The internals of Mono w/ GTK 2: Mono on OS-X installs a default GTK2 theme ( Location : The one located in the As for controlling which theme is applied to your application, you can allow the user to control it via $HOME directory based You are supposed to be able to set environment var Note: The env. var. Application theming via GTK api: With your application you can assign GTK to use one of the Mono installed themes or one that your application provides. BEFORE the If you have your own theme, bundle the files (gtkrc, other included gtkrc files, icons, images, etc...) inside your For standalone exe's I have also have used an embedded gtkrc file and extract it to a tmp file a runtime:
这篇关于GTK UI从捆绑运行和从Xamarin Studio运行时看起来有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
Gtk.Application.Init )
您可以执行以下操作来分配gtkrc文件:
Gtk.Rc.AddDefaultFile({ gtkrcFile});
Gtk.Rc.Parse({gtkrcFile});
.app
中。通常这些将被捆绑在 Contents \Resource目录中,并使用上面的代码来分配捆绑包中的
gtkrc`。
使用系统;
使用System.Reflection;
使用System.IO;
使用Gtk;
命名空间主题
{
class MainClass
{
public static void Main(string [] args)
{
InitGlobalResourceFile ();
Application.Init();
MainWindow win = new MainWindow();
win.Show();
Application.Run();
}
static void InitGlobalResourceFile()
{
String gtkResouceFile;
汇编myAssembly = Assembly.GetExecutingAssembly();
string [] names = myAssembly.GetManifestResourceNames();
foreach(名称中的字符串名称){
Console.WriteLine(name);
if(name.Contains(GtkThemeResource.rc)){
gtkResouceFile = name;
休息;
}
Console.WriteLine(在清单中未找到Gtk主题资源);
}
var tmpFile = Path.GetTempFileName();
var stream = myAssembly.GetManifestResourceStream(gtkResouceFile);
字符串gtkrc;
using(StreamReader reader = new StreamReader(stream)){
gtkrc = reader.ReadToEnd();
using(StreamWriter outputFile = new StreamWriter(tmpFile)){
outputFile.WriteLine(gtkrc);
}
Rc.AddDefaultFile(tmpFile);
Rc.Parse(tmpFile);
}
}
}
~/.gtkrc
gtkrc
-based files are out-of-scope here, but there are plenty of references on the web for GTK 2.0 resources/theming. gtkrc
) and few alternative themes:/Library/Frameworks/Mono.framework/Versions/4.2.1
find . -name "gtkrc"
./etc/gtk-2.0/gtkrc
./share/themes/bubble/gtk-2.0/gtkrc
./share/themes/Clearlooks/gtk-2.0/gtkrc
./share/themes/Mac/gtk-2.0-key/gtkrc
./share/themes/Quartz/gtk-2.0/gtkrc
./share/themes/Xamarin/gtk-2.0/gtkrc
<Mono/Version>/etc/gtk-2.0
is the default (Tango style) while one of the alternatives is 'Xamarin' and is the one that is used to stylize Xamarin Studio (internally named "Mac Theme for Xamarian")..gtkrc
files (IMHO: how many users really know how to do that or would even what to and the support nightmares of 'expert' end-users tweaking the UI, I prefer locking the UIX experience to something uniform to all users, but, again, that is just my opition).GTK2_RC_FILES
in your app startup script, but I never had any luck with this.GTK_THEME
does work in GTK3 (but Mono is GTK2 bound)
Gtk.Application.Init()
you can do the following to assign the gtkrc file:Gtk.Rc.AddDefaultFile ({gtkrcFile});
Gtk.Rc.Parse ({gtkrcFile});
.app
. Normally these would be bundled inside the Contents\Resource directory and use the above code to assign the
gtkrc` that is in your bundle.using System;
using System.Reflection;
using System.IO;
using Gtk;
namespace themes
{
class MainClass
{
public static void Main (string[] args)
{
InitGlobalResourceFile ();
Application.Init ();
MainWindow win = new MainWindow ();
win.Show ();
Application.Run ();
}
static void InitGlobalResourceFile ()
{
String gtkResouceFile;
Assembly myAssembly = Assembly.GetExecutingAssembly ();
string[] names = myAssembly.GetManifestResourceNames ();
foreach (string name in names) {
Console.WriteLine (name);
if (name.Contains ("GtkThemeResource.rc")) {
gtkResouceFile = name;
break;
}
Console.WriteLine ("Gtk Theme Resource not found in manifest");
}
var tmpFile = Path.GetTempFileName ();
var stream = myAssembly.GetManifestResourceStream (gtkResouceFile);
string gtkrc;
using (StreamReader reader = new StreamReader (stream)) {
gtkrc = reader.ReadToEnd ();
}
using (StreamWriter outputFile = new StreamWriter (tmpFile)) {
outputFile.WriteLine (gtkrc);
}
Rc.AddDefaultFile (tmpFile);
Rc.Parse (tmpFile);
}
}
}