Reputation: 96
I have problem with loading column title for wxListCtrl which are defined in xrc file. According to XRC file format description (http://docs.wxwidgets.org/trunk/overview_xrcformat...) it shall be possible to define column names for wxLC_REPORT style for this control by class. Below you can find code which I need to run (gui.xml is a xrc file with desired layout). Unfortunately in my script I need to add column title manually so they are shown in GUI (commented lines 22, 23 in my_gui.rb). Is there a way to force wxRuby to load column titles from xrc or am I doing something wrong?
I'm using ruby 1.9.3p327 (2012-11-10) [i386-mingw32] with wxruby-ruby19 (2.0.1 x86-mingw32).
here is my_gui.rb:
require 'wx'
class My_frame < Wx::Frame
def initialize(parent)
# To load a layout defined in XRC into a Ruby subclass of Dialog,
# first call the empty constructor. All the details of size,
# title, position and so on are loaded from the XRC by the call to
# load_frame_subclass. Using a non-empty constructor will cause
# errors on GTK.
super()
# Load the dialog from XRC. We define $xml in on_init.
# We could use XmlResource.get() over and over again, but
# honestly, thats just too much work.
$xml.load_frame_subclass(self, nil, 'Gui')
@list_ctrl = find_window_by_name('MY_LIST')
puts "inspect list: " + @list_ctrl.inspect + " ID: " + Wx::xrcid('MY_LIST').to_s
#columnn names are shown only if you uncomment following 2 lines
# @list_ctrl.insert_column(0, 'col1_from_code', Wx::LIST_FORMAT_LEFT, 100)
# @list_ctrl.insert_column(1, 'col2_from_code', Wx::LIST_FORMAT_LEFT, 100)
end
end
class My_app < Wx::App
def on_init
#create GUI from xrc
xrc_file = File.join( File.dirname(__FILE__), 'gui.xml' )
$xml = Wx::XmlResource.new(xrc_file)
@frame = My_frame.new(self)
@frame.show(true)
end
end
app = My_app.new
app.main_loop()
and here is gui.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resource version="2.3.0.1">
<!-- Created by build 7.4.2.569 -->
<object class="wxFrame" name="Gui">
<title>GUI</title>
<IDident>ID_MAIN_FRM</IDident>
<ID>1000</ID>
<pos>8,8</pos>
<size>640,480</size>
<style>wxDEFAULT_FRAME_STYLE</style>
<object class="wxStaticBox" name="MY_SBOX">
<IDident>ID_MY_SBOX</IDident>
<ID>1005</ID>
<size>610,320</size>
<pos>5,120</pos>
<label>Label</label>
</object>
<object class="wxListCtrl" name="MY_LIST">
<IDident>ID_MY_LIST</IDident>
<ID>1008</ID>
<size>590,120</size>
<pos>15,270</pos>
<style>wxLC_REPORT</style>
<object class="listcol">
<text>Col1</text>
<width>100</width>
<align>wxLIST_FORMAT_LEFT</align>
</object>
<object class="listcol">
<text>Col2</text>
<width>100</width>
<align>wxLIST_FORMAT_LEFT</align>
</object>
</object>
</object>
</resource>
Thx in advance for support.
Upvotes: 0
Views: 158