nobody at rubyforge.org
2006-Dec-23 03:20 UTC
[Wxruby-development] [796] trunk/wxruby2/samples/xrc/xrc_sample.rb: Simplify some method calls, rubyify and add a little more explanation
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type"
content="text/html; charset=utf-8" /><style
type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:'':'';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family:
verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;
font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding:
6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid;
padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family:
verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch
.binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[796] trunk/wxruby2/samples/xrc/xrc_sample.rb: Simplify some method
calls, rubyify and add a little more explanation</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>796</dd>
<dt>Author</dt> <dd>brokentoy</dd>
<dt>Date</dt> <dd>2006-12-22 22:20:14 -0500 (Fri, 22 Dec
2006)</dd>
</dl>
<h3>Log Message</h3>
<pre>Simplify some method calls, rubyify and add a little more
explanation</pre>
<h3>Modified Paths</h3>
<ul>
<li><a
href="#trunkwxruby2samplesxrcxrc_samplerb">trunk/wxruby2/samples/xrc/xrc_sample.rb</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwxruby2samplesxrcxrc_samplerb"></a>
<div class="modfile"><h4>Modified:
trunk/wxruby2/samples/xrc/xrc_sample.rb (795 => 796)</h4>
<pre class="diff"><span>
<span class="info">---
trunk/wxruby2/samples/xrc/xrc_sample.rb        2006-12-23
03:09:28 UTC (rev 795)
+++
trunk/wxruby2/samples/xrc/xrc_sample.rb        2006-12-23
03:20:14 UTC (rev 796)
</span><span class="lines">@@ -51,47 +51,30 @@
</span><span class="cx">
        
</span><span class="cx"> end
</span><span class="cx">
</span><del>-#
-# Dialog subclass. Uses XRC for the dialog definition
-#
</del><ins>+# Dialog subclass. The components within the dialog are
loaded from XRC.
</ins><span class="cx"> class SimpleDialog < Wx::Dialog
</span><del>-
</del><span class="cx">
        def
initialize(parent)
</span><span class="cx">
                super()
</span><span class="cx">
                
</span><del>-                #
</del><span class="cx">
                #
Load the dialog from XRC. We define $xml in on_init.
</span><span class="cx">
                #
We could use XmlResource.get() over and over again, but
</span><span class="cx">
                #
honestly, thats just too much work.
</span><del>-                #
</del><span class="cx">
                $xml.load_dialog_subclass(self,parent,''SAMPLE_DIALOG'')
</span><del>-                
-                #
-                #
Get the buttons. Note we use ''xrcid'' much like the XRCID macro
-                #
in C++. Make sure the id''s actually exist, or your program will crash!
-                #
-
-                @ok
= Wx::Window.find_window_by_id(Wx::xrcid(''wxID_OK''),self)
- @cancel =
Wx::Window.find_window_by_id(Wx::xrcid(''wxID_CANCEL''),self)
-                @message
=
Wx::Window.find_window_by_id(Wx::xrcid(''SAMPLE_MESSAGE''),self)
-                
-                #
</del><ins>+
+                #
Get the buttons. The xrcid method turns a string identifier
+ # used in an xml file into a numeric identifier as used in
+ # wxruby.
+ @ok = find_window_by_id( Wx::xrcid(''wxID_OK'') )
+ @cancel = find_window_by_id(
Wx::xrcid(''wxID_CANCEL'') )
+ @message = find_window_by_id(
Wx::xrcid(''SAMPLE_MESSAGE'') )
+
</ins><span class="cx">
                #
Bind the buttons to event handlers
</span><del>-                #
-                evt_button(Wx::xrcid(''wxID_OK''))
do
-                        end_modal(Wx::ID_OK)
</del><ins>+ evt_button( @ok.get_id ) { end_modal(Wx::ID_OK)
}
+ evt_button( @cancel.get_id ) { end_modal(Wx::ID_CANCEL) }
+                evt_button(
@message.get_id ) do
+ Wx::message_box("And now a message from our sponsors.")
</ins><span class="cx">
                end
</span><del>-                
-                evt_button(Wx::xrcid(''wxID_CANCEL''))
do
-                        end_modal(Wx::ID_CANCEL)
-                end
-                
-                evt_button(Wx::xrcid(''SAMPLE_MESSAGE''))
do
-                        Wx::message_box("And
now a message from our sponsors.")
-                end
-                
</del><span class="cx">
        end
</span><del>-        
</del><span class="cx"> end
</span><span class="cx">
</span><span class="cx"> #
</span><span class="lines">@@ -100,27 +83,20 @@
</span><span class="cx"> class XrcApp < Wx::App
</span><span class="cx">
</span><span class="cx">
        def
on_init
</span><del>-                #
</del><span class="cx">
                #
Create a resource handler
</span><del>-                #
</del><span class="cx">
                $xml
= Wx::XmlResource.get();
</span><span class="cx">
                $xml.init_all_handlers();
</span><span class="cx">
</span><del>-                #
</del><ins>+
</ins><span class="cx">
                #
Load a resource file
</span><del>-                #
</del><span class="cx"> xrc_file = File.join(
File.dirname(__FILE__), ''samples.xrc'' )
</span><span class="cx">
                $xml.load(xrc_file)
</span><span class="cx">
</span><del>-                #
</del><span class="cx">
                #
Show the main frame.
</span><del>-                #
-                $main
= SimpleFrame.new()
-                $main.show(true)
</del><ins>+                main
= SimpleFrame.new()
+                main.show(true)
</ins><span class="cx">
        end
</span><span class="cx">
</span><span class="cx"> end
</span><del>-                
-                
</del><span class="cx">
</span><del>-XrcApp.new().main_loop()
</del><ins>+XrcApp.new.main_loop()
</ins></span></pre>
</div>
</div>
</body>
</html>
Seemingly Similar Threads
- [988] branches/wxruby2/wxwidgets_282/samples/xrc/xrc_sample.rb: Explanatory note on use of default constructor with XRC
- 'Are you sure?' custom dialog not exiting cleanly
- Stuck noobie: XRC/xrcise woes
- XRC Problem
- [838] trunk/wxruby2/doc/textile/artprovider.txtl: Add methods listing; rubyify examples; distinguish class methods
