nobody at rubyforge.org
2007-Jul-04 16:11 UTC
[Wxruby-development] [1098] trunk/wxruby2: Test return value from XmlResource#load and raise an exception on failure
<!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>[1098] trunk/wxruby2: Test return value from XmlResource#load and
raise an exception on failure</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>1098</dd>
<dt>Author</dt> <dd>brokentoy</dd>
<dt>Date</dt> <dd>2007-07-04 12:11:23 -0400 (Wed, 04 Jul
2007)</dd>
</dl>
<h3>Log Message</h3>
<pre>Test return value from XmlResource#load and raise an exception on
failure</pre>
<h3>Modified Paths</h3>
<ul>
<li><a
href="#trunkwxruby2doctextilexmlresourcetxtl">trunk/wxruby2/doc/textile/xmlresource.txtl</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a
href="#trunkwxruby2libwxclassesxmlresourcerb">trunk/wxruby2/lib/wx/classes/xmlresource.rb</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwxruby2doctextilexmlresourcetxtl"></a>
<div class="modfile"><h4>Modified:
trunk/wxruby2/doc/textile/xmlresource.txtl (1097 => 1098)</h4>
<pre class="diff"><span>
<span class="info">---
trunk/wxruby2/doc/textile/xmlresource.txtl        2007-06-28
23:53:47 UTC (rev 1097)
+++
trunk/wxruby2/doc/textile/xmlresource.txtl        2007-07-04
16:11:23 UTC (rev 1098)
</span><span class="lines">@@ -147,7 +147,7 @@
</span><span class="cx">
</span><span class="cx"> Returns a numeric ID that is
equivalent to the string ID used in an XML
</span><span class="cx"> resource. To be used in event
tables.
</span><del>-The macro @XRCID(name)@ is provided for convenience.
</del><ins>+The module method @Wx::xrcid(name)@ is provided for
convenience.
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> h3(#XmlResource_initallhandlers).
XmlResource#init_all_handlers
</span><span class="lines">@@ -161,12 +161,12 @@
</span><span class="cx">
</span><span class="cx"> h3(#XmlResource_load).
XmlResource#load
</span><span class="cx">
</span><del>- Boolean *load*(%(arg-type)String% filemask)
</del><ins>+ Boolean *load*(%(arg-type)String% file)
</ins><span class="cx">
</span><del>-Loads resources from XML files that match given
filemask.
-This method understands VFS (see filesys.h).
</del><ins>+Loads resources from the XML file @file@. If this file
does not exist,
+or contains invalid XML, an exception will be raised; if successful, the
+loaded file name will be returneed.
</ins><span class="cx">
</span><del>-
</del><span class="cx"> h3(#XmlResource_loadbitmap).
XmlResource#load_bitmap
</span><span class="cx">
</span><span class="cx"> "Bitmap":bitmap.html
*load_bitmap*(%(arg-type)String% name)
</span></span></pre></div>
<a id="trunkwxruby2libwxclassesxmlresourcerb"></a>
<div class="addfile"><h4>Added:
trunk/wxruby2/lib/wx/classes/xmlresource.rb (0 => 1098)</h4>
<pre class="diff"><span>
<span class="info">---
trunk/wxruby2/lib/wx/classes/xmlresource.rb        
(rev 0)
+++
trunk/wxruby2/lib/wx/classes/xmlresource.rb        2007-07-04
16:11:23 UTC (rev 1098)
</span><span class="lines">@@ -0,0 +1,16 @@
</span><ins>+class Wx::XmlResource
+ # The standard .load method returns a boolean indicating success or
+ # failure. Failure might result from bad XML, or a non-existent
+ # file. In ruby, in these circumstances, it''s more natural to raise
an
+ # Exception than expect the user to test the return value.
+ wx_load = self.instance_method(:load)
+ define_method(:load) do | fname |
+ result = wx_load.bind(self).call(fname)
+ if not result
+ Kernel.raise( RuntimeError,
+ "Failed to load XRC from ''#{fname}'';
" +
+ "check the file exists and is valid XML")
+ end
+ fname
+ end
+end
</ins></span></pre>
</div>
</div>
</body>
</html>
Maybe Matching Threads
- [962] branches/wxruby2/wxwidgets_282/doc/textile/xmlresource.txtl: Fixed the documentation for load_*_subclass, where * is [Dialog, Panel, Frame].
- [1099] trunk/wxruby2/swig/classes/XmlResource.i: Permit Dialogs and Frames with no parents to be created via XRC; add comments
- [796] trunk/wxruby2/samples/xrc/xrc_sample.rb: Simplify some method calls, rubyify and add a little more explanation
- [965] branches/wxruby2/wxwidgets_282/doc/textile: Misc.
- [ wxruby-Bugs-16760 ] src/XmlResource.h:19: error: expected class-name before '', '' token
