Can't use a glade xml file with haskell - haskell

I'm not sure if I should say hi or not, being this my first post here.
Anyway, I am following the glade tutorial from the gtk2hs website. The code compiled properly but when I try to execute it I get this error.
(hellogtk2hs:8670): libglade-WARNING **: Expected <glade-interface>. Got <interface>.
(hellogtk2hs:8670): libglade-WARNING **: did not finish in PARSER_FINISH state
hellogtk2hs: user error (Pattern match failure in do expression at HelloGtk2Hs.hs:8:8-15)
This is my glade file.
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Write your name here: </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-apply</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
The glade file is in the same directory as my source code. The source code is an exact copy from the one in the tutorial. I have never worked with glade before, so I have no idea of whats going wrong.
I had to downgrade ghc from 7.6 to 7.4.2. I'm using glade 3.14.1, all other packages were installed via cabal so they are on their current version.
If I switch interface with glade-interface, at the beginning and at the end it still complains.
(hellogtk2hs:9636): libglade-WARNING **: Unexpected element <object> inside <glade-interface>.
hellogtk2hs: user error (glade.xmlGetWidget: no object named "window1" in the glade file)
And if change all object tags with widget I get this
(hellogtk2hs:9668): GLib-GObject-ERROR **: cannot create instance of abstract (non-instantiatable) type `GtkBox'
`trap' para punto de parada/seguimiento
I get less errors by doing this but it still does not work.

The problem was that gtk2hs does not support gtk3, and the file I was creating was for gtk3.
Glade can generate either a libglade file or gtkbuilder file. Both are xml files, and the main difference between them is that the first starts with <glade-interface> and the later starts with <interface>. Also in gtkbuilder files the <object> tag is used instead of the <widget> tag.
The Graphics.UI.Gtk.Glade package makes use of the libglade files, and the problem is that these are obsolete and deprecated.
At the Glade download page there are two versions available. The newer of them generates gtkbuilders meant to be used with gtk3, but since gtk2hs does not support gtk3, you'll have to download version 3.8, which generates both libglade and gtkbuilder files for gtk2.
The best thing to do is to stop using libglade files and use the gtkbuilder files instead. To do this you must import Graphics.UI.Gtk.Builder instead of Graphics.UI.Gtk.Glade
I found this tutorial which makes use of gtkbuilder instead of libglade.
This program creates a window with a button, and every time you click the button you'll get a "hello world" on your terminal until the window is closed.
import Graphics.UI.Gtk
import Graphics.UI.Gtk.Builder
main = do
initGUI
builder <- builderNew
builderAddFromFile builder "windowbuilder.glade"
mainWindow <- builderGetObject builder castToWindow "main_window"
onDestroy mainWindow mainQuit
helloWorldButton <- builderGetObject builder castToButton "hello_world_button"
onClicked helloWorldButton (putStrLn "Hello, World!")
widgetShowAll mainWindow
mainGUI
This is pulling the gui from the windowbuilder.glade file. I created that file using glade-3. Here it is.
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="main_window">
<property name="width_request">210</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">This is a window</property>
<property name="resizable">False</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Click the button!!</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="hello_world_button">
<property name="label">gtk-ok</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="border_width">7</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Another good reason to switch to gtkbuilder files is that the haskell glade package won't compile with ghc >= 7.6.

Related

Gtk4: How to specify rows and columns of a GtkGrid object within a GtkBuilder ui file

I would like to use a GtkBuilder ui file to declare a GtkGrid with 3 rows and 2 columns. The ui file should be usable with gtk4-rs (https://github.com/gtk-rs/gtk4-rs). Initially I used glade to get a first sketch of the ui file, but unfortunately gtk4-rs did fail to load it. Therefore I striped it down until I could start my app. How can I assign the elements into columns, so that gtk4-rs will still be able to load it?
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.4"/>
<object class="GtkApplicationWindow" id="window">
<child>
<object class="GtkGrid">
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Label1</property>
</object>
</child>
<child>
<object class="GtkButton" id="src_button">
<property name="label" translatable="yes">Source</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Label2</property>
</object>
</child>
<child>
<object class="GtkButton" id="trg_button">
<property name="label" translatable="yes">Target</property>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Start</property>
<property name="receives-default">True</property>
</object>
</child>
</object>
</child>
</object>
</interface>
Where do I find the DTD for GtkGrind or other Gtk4 objects??
I don't know, did you found it out or not, but someone probably will come across to this post looking for the answer. Solution is to use <layout> inside child <object>. In your example it will be:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.4"/>
<object class="GtkApplicationWindow" id="window">
<child>
<object class="GtkGrid">
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Label1</property>
<layout>
<property name="row">0</property>
<property name="column">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="src_button">
<property name="label" translatable="yes">Source</property>
<layout>
<property name="row">0</property>
<property name="column">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Label2</property>
<layout>
<property name="row">1</property>
<property name="column">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="trg_button">
<property name="label" translatable="yes">Target</property>
<layout>
<property name="row">1</property>
<property name="column">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Start</property>
<property name="receives-default">True</property>
<layout>
<property name="row">3</property>
<property name="column">0</property>
</layout>
</object>
</child>
</object>
</child>
</object>
</interface>

Need help on starting the Ignite cache in 2 node cluster

I am novice in Ignite and trying to utilize Ignite to setup in-memory cache. I did some basic configuration and started the Ignite based pluggable persistence work on single node. Now, I am planning to test the performance on 2 node cluster and setting up the ignite configuration as per below:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="countryCacheStoreFactory" class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
<constructor-arg><value>com.xyz.exploreignite.cache.CustomCacheStore</value></constructor-arg>
</bean>
<bean id="stateCacheStoreFactory" class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
<constructor-arg><value>com.xyz.exploreignite.cache.CustomStateCacheStore</value></constructor-arg>
</bean>
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="peerClassLoadingEnabled" value="false"/>
<property name="clientMode" value="true"/>
<property name="gridName" value="clusterGrid"/>
<property name="cacheConfiguration">
<list>
<!-- Partitioned cache example configuration (Atomic mode). -->
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="atomicityMode" value="ATOMIC"/>
<property name="backups" value="1"/>
<property name="name" value="customCountryCache"/>
<property name="readThrough" value="true"/>
<property name="writeThrough" value="true"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="writeBehindEnabled" value="true"/>
<property name="copyOnRead" value="true"/>
<property name="memoryMode" value="OFFHEAP_TIERED"/>
<property name="atomicWriteOrderMode" value="PRIMARY"/>
<property name="indexedTypes" >
<list>
<value>java.lang.Integer</value>
<value>com.xyz.exploreignite.pojo.Country</value>
</list>
</property>
<!-- Cache store. -->
<property name="cacheStoreFactory" ref="countryCacheStoreFactory"/>
</bean>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="atomicityMode" value="ATOMIC"/>
<property name="backups" value="1"/>
<property name="name" value="customStateCache"/>
<property name="readThrough" value="true"/>
<property name="writeThrough" value="true"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="writeBehindEnabled" value="true"/>
<property name="copyOnRead" value="true"/>
<property name="memoryMode" value="OFFHEAP_TIERED"/>
<property name="atomicWriteOrderMode" value="PRIMARY"/>
<property name="indexedTypes" >
<list>
<value>java.lang.Integer</value>
<value>com.xyz.exploreignite.pojo.State</value>
</list>
</property>
<!-- Cache store. -->
<property name="cacheStoreFactory" ref="stateCacheStoreFactory"/>
</bean>
</list>
</property>
<!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<!--
Ignite provides several options for automatic discovery that can be used
instead os static IP based discovery. For information on all options refer
to our documentation: http://apacheignite.readme.io/docs/cluster-config
-->
<!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">-->
<property name="addresses">
<list>
<value>127.0.0.1:47500..47509</value>
<value>172.26.49.1:47500..47509</value>
<!-- In distributed environment, replace with actual host IP address. -->
<value>172.26.49.2:47500..47509</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
Now, while starting ignite with "bin/ignite.sh " on both the nodes it shows failed to connect to server. While running only "bin/ignite.sh" in parallel to above one, both the individual ignite config instance starts in standalone mode with only 1 client. I need to have both of them utilizing the shared instance. Please suggest possible issues in my deployment/execution.
Try to remove <value>127.0.0.1:47500..47509</value> line from the discovery configuration. It doesn't make much for a distributed cluster.
That configuration is in <property name="clientMode" value="true"/> You need to have at least one node set to <property name="clientMode" value="false"/> or else your clients won't have any server nodes to connect to.

health check before processing file stream in xd

I am pulling files from s3 and processing them using spring xd. I have one processor http client component where i do some RESTful request .Now the problem with this approach is if my webservice is down the files get accumulated in rabbit mq transport .Hence before pulling a individual file from s3 I want to do a health check on my rest service.How can I tackle this my configuration file looks something like this.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/aws http://www.springframework.org/schema/integration/aws/spring-integration-aws-1.0.xsd">
<int:poller fixed-delay="${fixed-delay}" default="true"/>
<bean id="credentials" class="org.springframework.integration.aws.core.BasicAWSCredentials">
<property name="accessKey" value="${accessKey}"/>
<property name="secretKey" value="${secretKey}"/>
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>dms-aws-s3-nonprod.properties</value>
</property>
</bean>
<bean id="clientConfiguration" class="com.amazonaws.ClientConfiguration">
<property name="proxyHost" value="${proxyHost}"/>
<property name="proxyPort" value="${proxyPort}"/>
<property name="preemptiveBasicProxyAuth" value="false"/>
</bean>
<bean id="s3Operations" class="org.springframework.integration.aws.s3.core.CustomC1AmazonS3Operations">
<constructor-arg index="0" ref="credentials"/>
<constructor-arg index="1" ref="clientConfiguration"/>
<property name="awsEndpoint" value="s3.amazonaws.com"/>
<property name="temporaryDirectory" value="${temporaryDirectory}"/>
<property name="awsSecurityKey" value="${awsSecurityKey}"/>
</bean>
<!-- aws-endpoint="https://s3.amazonaws.com" -->
<int-aws:s3-inbound-channel-adapter aws-endpoint="s3.amazonaws.com"
bucket="${bucket}"
s3-operations="s3Operations"
credentials-ref="credentials"
file-name-wildcard="${file-name-wildcard}"
remote-directory="${remote-directory}"
channel="splitChannel"
local-directory="${local-directory}"
accept-sub-folders="false"
delete-source-files="true"
archive-bucket="${archive-bucket}"
archive-directory="${archive-directory}">
</int-aws:s3-inbound-channel-adapter>
int-file:splitter input-channel="splitChannel" output-channel="output" markers="true"/>
<int:channel id="output"/>
My stream defination
xd-shell>stream create feedTest16 --definition "aws-s3-source |processor-http-client| log" --deploy
Starting with Spring Integration 4.1, the PollSkipAdvice has been introduced.
Implement your own ServiceHealthCheckPollSkipStrategy and inject it into the <advice-chain> of the <poller> for your <int-aws:s3-inbound-channel-adapter> and you're good with the requirement!
Only one issue is there that your s3-source is tied with the target service for the http-client...

spring integration aws s3 delete local file

I am using spring integration to read file from s3 however this works but my local directory is getting full I want to delete files from local directory after files are processed from s3?
<bean id="credentials" class="org.springframework.integration.aws.core.BasicAWSCredentials">
<property name="accessKey" value="${accessKey}"/>
<property name="secretKey" value="${secretKey}"/>
</bean>
<bean id="clientConfiguration" class="com.amazonaws.ClientConfiguration">
<property name="proxyHost" value="${proxyHost}"/>
<property name="proxyPort" value="${proxyPort}"/>
<property name="preemptiveBasicProxyAuth" value="false"/>
</bean>
<bean id="s3Operations" class="org.springframework.integration.aws.s3.core.CustomC1AmazonS3Operations">
<constructor-arg index="0" ref="credentials"/>
<constructor-arg index="1" ref="clientConfiguration"/>
<property name="awsEndpoint" value="s3.amazonaws.com"/>
<property name="temporaryDirectory" value="${temporaryDirectory}"/>
<property name="awsSecurityKey" value="${awsSecurityKey}"/>
</bean>
<!-- aws-endpoint="https://s3.amazonaws.com" -->
<int-aws:s3-inbound-channel-adapter aws-endpoint="s3.amazonaws.com"
bucket="${bucket}"
s3-operations="s3Operations"
credentials-ref="credentials"
file-name-wildcard="${fileNameWildcard}"
remote-directory="${remoteDirectory}"
channel="splitChannel"
local-directory="${localDirectory}"
accept-sub-folders="false"
delete-source-files="true"
archive-bucket="${archiveBucket}"
archive-directory="${archiveDirectory}">
</int-aws:s3-inbound-channel-adapter>
Looks like you are looking for ExpressionEvaluatingRequestHandlerAdvice.
Please, find Retry and More. There is something like <property name="onSuccessExpression" value="payload.delete()" /> in the expression-advice-context.xml config to take care about the local file after the proper finish of the process.

Add webparts to sitedefinition

I created a custom sitedefinition. In my sitedefition i want to activate a custom feature (i add the guid into my onet.xml).
My custom feature for adding the webpart to the page is creating an error. The error is default.aspx is not found. I thought a page in a sitedefition is created first. After that feature will be activate. Why i receive an error?
SPLimitedWebPartManager collWebParts = web.GetLimitedWebPartManager("default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
collWebParts.AddWebPart(CustomWebPart, "MainLeft", 1);
collWebParts.SaveChanges(CustomWebPart);
collWebParts.Web.Dispose();
You'd better add you webparts in modules in onet.xml. Just add the tag and use the tag to provision your particular webparts.
A simple sample:
<Modules>
<Module Name="DefaultBlank" Url="" Path="">
<File Url="default.aspx" Path="default.aspx">
<AllUsersWebPart WebPartOrder="0" WebPartZoneID="Right" ID="g_bdef0b56_c2f4_4c5a_bc39_2908a0f61410">
<![CDATA[<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="***.LatestDiscussionsWebPart.LatestDiscussionsWebPart, ***, Version=1.0.0.0, Culture=neutral, PublicKeyToken=20cca094e7d0240a" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="AllowZoneChange" type="bool">True</property>
<property name="ExportMode" type="exportmode">All</property>
<property name="HelpUrl" type="string" />
<property name="Hidden" type="bool">False</property>
<property name="TitleUrl" type="string" />
<property name="Description" type="string">Latest Discussions WebPart</property>
<property name="AllowHide" type="bool">True</property>
<property name="AllowMinimize" type="bool">True</property>
<property name="Title" type="string">Latest Discussions </property>
<property name="ChromeType" type="chrometype">Default</property>
<property name="AllowConnect" type="bool">True</property>
<property name="Width" type="unit" />
<property name="Height" type="unit" />
<property name="HelpMode" type="helpmode">Navigate</property>
<property name="CatalogIconImageUrl" type="string" />
<property name="AllowEdit" type="bool">True</property>
<property name="TitleIconImageUrl" type="string" />
<property name="Direction" type="direction">NotSet</property>
<property name="AllowClose" type="bool">True</property>
<property name="ChromeState" type="chromestate">Normal</property>
</properties>
</data>
</webPart>
</webParts>]]>
</AllUsersWebPart>
</File>
</Module>
Good luck.

Resources