<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Es Gilt Viele Mauern Abzubauen &#187; GTK</title>
	<atom:link href="http://boundary.cc/tag/gtk/feed/" rel="self" type="application/rss+xml" />
	<link>http://boundary.cc</link>
	<description>Joker Lee&#039;s Blog</description>
	<lastBuildDate>Tue, 17 Jan 2012 03:25:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Linux 下 gtkmm + glade 开发</title>
		<link>http://boundary.cc/200906/gtkmm-glade-under-linux/</link>
		<comments>http://boundary.cc/200906/gtkmm-glade-under-linux/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 18:23:54 +0000</pubDate>
		<dc:creator>Joker</dc:creator>
				<category><![CDATA[Linux与开源]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[GTK]]></category>

		<guid isPermaLink="false">http://jackaldire.com/?p=61</guid>
		<description><![CDATA[Linux下大多数软件都是将core和UI完全分离，很多程序原作者只提供了CLI接口，而图形化接口则由另一些人完成。这种做法不仅减小了开发难度，缩短了开发周期，松散的耦合使程序更容易移植。这和很多windows程序形成了鲜明对比，尤其是MFC的程序,core代码和UI代码杂糅到doc/view的框架里,完全没有可移植性。 这学期写大作业想做个GUI，就顺便看了下MFC，觉得MFC现在的现在的地位十分尴尬，大型项目几乎清一色SDK，小型应用则是.net的天下，MFC被用的最多的莫过于CString了。一个Application Framwork已经退化成一个单纯的Class Library了。 暑假前的小学期，又有一个不大不小的作业，决定完全在Linux编写，并且Core和UI完全分离，有时间的话想用GTK做GUI。直接用C代码设计一个稍微复杂点GTK界面简直就是自找苦吃，于是上glade。 随便用Glade托了一个窗口拿来测试（用的是GtkBuilder而不是libglade,因为后者不支持很多gtk特性），保存成.glade文件，实际上就是一个xml文件。由于作业是用C++写的，所以想用gtk的C++ bindings gtkmm来，想让整个代码看起来比较统一。于是开始Google。很不幸的找到了一个错误的例子，导致XML文件总是导入不完全。后来找到了gtkmm的文档，发现里面竟然有很多源码例子，找到一个GtkBuilder的例子，改了下，程序就跑起来了 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include &#60;gtkmm.h&#62; #include &#60;iostream&#62; &#160; Gtk::Window* pWindow = 0; &#160; int main &#40;int argc,<a href="http://boundary.cc/200906/gtkmm-glade-under-linux/"> <br /><br /> (Read More...)</a>]]></description>
			<content:encoded><![CDATA[<p style="text-indent: 2em;">Linux下大多数软件都是将core和UI完全分离，很多程序原作者只提供了CLI接口，而图形化接口则由另一些人完成。这种做法不仅减小了开发难度，缩短了开发周期，松散的耦合使程序更容易移植。这和很多windows程序形成了鲜明对比，尤其是MFC的程序,core代码和UI代码杂糅到doc/view的框架里,完全没有可移植性。</p>
<p style="text-indent: 2em;">这学期写大作业想做个GUI，就顺便看了下MFC，觉得MFC现在的现在的地位十分尴尬，大型项目几乎清一色SDK，小型应用则是.net的天下，MFC被用的最多的莫过于CString了。一个Application Framwork已经退化成一个单纯的Class Library了。</p>
<p style="text-indent: 2em;">暑假前的小学期，又有一个不大不小的作业，决定完全在Linux编写，并且Core和UI完全分离，有时间的话想用GTK做GUI。直接用C代码设计一个稍微复杂点GTK界面简直就是自找苦吃，于是上glade。</p>
<p><span id="more-61"></span></p>
<p style="text-indent: 2em;">随便用Glade托了一个窗口拿来测试（用的是GtkBuilder而不是libglade,因为后者不支持很多gtk特性），保存成.glade文件，实际上就是一个xml文件。由于作业是用C++写的，所以想用gtk的C++ bindings gtkmm来，想让整个代码看起来比较统一。于是开始Google。很不幸的找到了一个错误的例子，导致XML文件总是导入不完全。后来找到了<a href="http://www.gtkmm.org/docs/gtkmm-2.4/docs/" target="_blank">gtkmm的文档</a>，发现里面竟然有很多源码例子，找到一个GtkBuilder的例子，改了下，程序就跑起来了</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;gtkmm.h&gt;</span>
<span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
Gtk<span style="color: #008080;">::</span><span style="color: #007788;">Window</span><span style="color: #000040;">*</span> pWindow <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, <span style="color: #0000ff;">char</span> <span style="color: #000040;">**</span>argv<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    Gtk<span style="color: #008080;">::</span><span style="color: #007788;">Main</span> kit<span style="color: #008000;">&#40;</span>argc, argv<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Load the GtkBuilder file and instantiate its widgets:</span>
    Glib<span style="color: #008080;">::</span><span style="color: #007788;">RefPtr</span> refBuilder <span style="color: #000080;">=</span> Gtk<span style="color: #008080;">::</span><span style="color: #007788;">Builder</span><span style="color: #008080;">::</span><span style="color: #007788;">create</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">try</span>
    <span style="color: #008000;">&#123;</span>         <span style="color: #666666;">//导入Glade生成的xml文件</span>
        refBuilder<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>add_from_file<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;mygui.glade&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">catch</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> Glib<span style="color: #008080;">::</span><span style="color: #007788;">FileError</span> <span style="color: #000040;">&amp;</span> ex<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        std<span style="color: #008080;">::</span><span style="color: #0000dd;">cerr</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;FileError: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> ex.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">catch</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> Gtk<span style="color: #008080;">::</span><span style="color: #007788;">BuilderError</span> <span style="color: #000040;">&amp;</span> ex<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        std<span style="color: #008080;">::</span><span style="color: #0000dd;">cerr</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;BuilderError: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> ex.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #666666;">//Get the GtkBuilder-instantiated Window:</span>
    refBuilder<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>get_widget<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;window&quot;</span>, pWindow<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pWindow<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        kit.<span style="color: #007788;">run</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>pWindow<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000dd;">delete</span> pWindow<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><img class="size-medium wp-image-63 aligncenter" title="Screenshot-PhoneBook --By Jackal Dire" src="http://jackaldire.com/wordpress/wp-content/uploads/2009/06/Screenshot-PhoneBook-By-Jackal-Dire-300x204.png" alt="Glade-gtkmm" width="300" height="204" /></p>
<p>用G++编译</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">g++</span> phone.cpp <span style="color: #000000; font-weight: bold;">`</span>pkg-config <span style="color: #660033;">--cflags</span> <span style="color: #660033;">--libs</span> gtkmm-<span style="color: #000000;">2.4</span><span style="color: #000000; font-weight: bold;">`</span></pre></div></div>

<p>后面几天主要还是些写核心代码和CLI，主要任务完成了再来接着折腾gtk～～～</p>
]]></content:encoded>
			<wfw:commentRss>http://boundary.cc/200906/gtkmm-glade-under-linux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

