[Gtk-sharp-list] New (stupid) application :)
David Makovský (Yakeen)
yakeen@sannyas-on.net
Wed, 12 Nov 2003 18:50:41 +0100
--=-1Yjr8zimj87H5SnTZrub
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi Philip and all
V =C3=9At, 11. 11. 2003 v 16:23, Philip Van Hoof p=C3=AD=C5=A1e:=20
> Hi there,
>=20
> Two weeks ago two friends on mine asked me whether I could learn them
> about C# and Gtk-Sharp. During the same time I was reading the website
> of Fedora which claimed that there was not a dhcpd.conf GUI available
> yet. So I decided to teach them gtk-sharp by real-life example: I let
> them build (with my help of course) a SharpDhcpdConf GUI :)
>=20
> I've finished a dhcpd.conf parser and made a glade-2 file. They
> connected the events and some widgets and thats where the project is at
> this moment. We have now plans to finish it to something that is
> actually usefull.
Sounds good and useful
> Because the project is for educational purposes (and, perhaps, for
> actual use later) I want it to be as perfect as possible. So far the
> build procedure its as perfect as I can get it. It would be great if
> other people, with better knowledge of stuff like autoconf than me,
> could take a look at it. Perhaps create patches and help me and those
> friends of mine to create a complete gtk-sharp application.
>=20
> With complete I mean:=20
> - Multi languages support (po)
As You already readed you know that there is System.Resources
I don't know where I found it but I'm using it. Originaly it comes from
Gonzalo Paniagua Javier (gonzalo@ximian.com)
namespace MyClass{
using System;
using System.Collections;
using System.Reflection;
using System.Resources;
public class ResMan {
=09
public static string ResourceName =3D "strings";
public static Assembly Assembly =3D typeof (ResMan).Assembly;
static ResourceManager rm;
static Hashtable mangled;
static char [] invalidChars =3D new Char [] {'=3D', ' '};
private ResMan () {}
=09
static ResourceManager RM {
get {
if (rm =3D=3D null)
rm =3D new ResourceManager (ResourceName, Assembly);
return rm;
}
}
static string _ (string key) {
return GetString (key);
}
static string GetMangled (string key) {
if (mangled =3D=3D null)
mangled =3D new Hashtable ();
if (mangled.Contains (key))
return (string) mangled [key];
string k =3D key.Replace ('=3D', '_');
k =3D k.Replace (' ', '_');
mangled [key] =3D k;
return k;
}
=09
public static string GetString (string key) {=09
if (key =3D=3D null)
throw new ArgumentNullException ("key");
if (key =3D=3D "")
throw new ArgumentException ("Empty key", "key");
string k =3D key;
if (k.IndexOfAny (invalidChars) !=3D -1)
k =3D GetMangled (k);
string result =3D RM.GetString (k);
if (result =3D=3D null) {
Console.Error.WriteLine ("ResMan: Warning: no value for '{0}'", k);
result =3D key;
}
return result;
}
}
}
you have to use ResMan._("...");
or you have to use in all your classes you want to define:
static string _ (string key) {
return ResMan.GetString (key);
}
There is a perl script....
#!/usr/bin/perl
my $fname =3D $ARGV[0];
my $linenum =3D 0;
while (<ARGV>) {
if ($fname !=3D $ARGV) {
$linenum =3D 1;
$fname =3D $ARGV;
} else {
$linenum++;
}
=09
if (/_\(".*"\)/) {
@array =3D split ("\"", $_);
$k =3D $array[1];
$v =3D $k;
$k =3D~ s/ /_/g;
$k =3D~ s/=3D/_/g;
=09
print "# $ARGV: $linenum\n";
print "$k =3D $v\n\n";
}
}
should be more inteligent for numbering lines, but I don't understand
perl so much
And in your build script you use
MONORESGEN=3D/usr/bin/monoresgen
./getstrings.pl *.cs > resources/strings.txt #you can have others like stri=
ngs.de.txt strings.cs.txt ....
$(MONORESGEN) $< || (echo -e "\nERROR: cannot convert resources" && exit
1)=20
/resource:resources/strings.txt #to your build line
As a read somewhere monoresgen shoud be able to convert to .po format
(it's very similar)
Hope this help to lot people, cause I was serching for it long time
> - A correct build procedure with automake/autogen/autoconf
Yes I know, I'm using makefile this but should be interesting see NAnt
solution.
> - The right files in CVS, the right files in .cvsignore
> - The correct programming methods for
> - Glade-Sharp
that's easy to understand and learn from examples
nice and clear solution
> - OO techniques and GUI programming with Gtk-Sharp
> - HIG correct
read HIG doc, but it's good to look to some glade files of GNOME 2.4
progs to see how they are doing it with glade
I recommend it to you, that's was good combination for me to understand
it (hope;)
> Basically I want this application to be as correct as humanly possible
> and I want it to be like a sample application for Gtk-Sharp projects. So
> that I can use it to teach people how to actually correctly prepare and
> create Gtk-Sharp projects succesfully.
> http://cvs.freax.be/cgi-bin/cvsweb/SharpDhcpdConf/
>=20
> On the URL you can find information about how to checkout the sources as
> anonymous user from the CVS. If you want me to create a writable
> account, then first send me some patches as prove that you are actually
> going to use it professionally :-), and not to add a bulkload of warez
> on my cvs repos.
Kind Regards=20
--=20
David Makovsk=C3=BD (Yakeen) <yakeen@sannyas-on.net>
--=-1Yjr8zimj87H5SnTZrub
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.0.9">
</HEAD>
<BODY>
<PRE>Hi Philip and all</PRE>
<BR>
V Út, 11. 11. 2003 v 16:23, Philip Van Hoof píše:
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#555050"><I>Hi there,
Two weeks ago two friends on mine asked me whether I could learn them
about C# and Gtk-Sharp. During the same time I was reading the website
of Fedora which claimed that there was not a dhcpd.conf GUI available
yet. So I decided to teach them gtk-sharp by real-life example: I let
them build (with my help of course) a SharpDhcpdConf GUI :)
I've finished a dhcpd.conf parser and made a glade-2 file. They
connected the events and some widgets and thats where the project is at
this moment. We have now plans to finish it to something that is
actually usefull.</I></FONT></PRE>
</BLOCKQUOTE>
<BR>
Sounds good and useful<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#555050"><I>Because the project is for educational purposes (and, perhaps, for
actual use later) I want it to be as perfect as possible. So far the
build procedure its as perfect as I can get it. It would be great if
other people, with better knowledge of stuff like autoconf than me,
could take a look at it. Perhaps create patches and help me and those
friends of mine to create a complete gtk-sharp application.
With complete I mean:
- Multi languages support (po)</I></FONT></PRE>
</BLOCKQUOTE>
<BR>
As You already readed you know that there is System.Resources<BR>
I don't know where I found it but I'm using it. Originaly it comes from Gonzalo Paniagua Javier (<A HREF="mailto:gonzalo@ximian.com"><U>gonzalo@ximian.com</U></A>)<BR>
<BR>
<PRE>namespace MyClass{
using System;
using System.Collections;
using System.Reflection;
using System.Resources;
public class ResMan {
public static string ResourceName = "strings";
public static Assembly Assembly = typeof (ResMan).Assembly;
static ResourceManager rm;
static Hashtable mangled;
static char [] invalidChars = new Char [] {'=', ' '};
private ResMan () {}
static ResourceManager RM {
get {
if (rm == null)
rm = new ResourceManager (ResourceName, Assembly);
return rm;
}
}
static string _ (string key) {
return GetString (key);
}
static string GetMangled (string key) {
if (mangled == null)
mangled = new Hashtable ();
if (mangled.Contains (key))
return (string) mangled [key];
string k = key.Replace ('=', '_');
k = k.Replace (' ', '_');
mangled [key] = k;
return k;
}
public static string GetString (string key) {
if (key == null)
throw new ArgumentNullException ("key");
if (key == "")
throw new ArgumentException ("Empty key", "key");
string k = key;
if (k.IndexOfAny (invalidChars) != -1)
k = GetMangled (k);
string result = RM.GetString (k);
if (result == null) {
Console.Error.WriteLine ("ResMan: Warning: no value for '{0}'", k);
result = key;
}
return result;
}
}
}
you have to use ResMan._("...");
or you have to use in all your classes you want to define:
static string _ (string key) {
return ResMan.GetString (key);
}</PRE>
<B>There is a perl script....</B>
<PRE>#!/usr/bin/perl
my $fname = $ARGV[0];
my $linenum = 0;
while (<ARGV>) {
if ($fname != $ARGV) {
$linenum = 1;
$fname = $ARGV;
} else {
$linenum++;
}
if (/_\(".*"\)/) {
@array = split ("\"", $_);
$k = $array[1];
$v = $k;
$k =~ s/ /_/g;
$k =~ s/=/_/g;
print "# $ARGV: $linenum\n";
print "$k = $v\n\n";
}
}</PRE>
should be more inteligent for numbering lines, but I don't understand perl so much<BR>
<B>And in your build script you use</B>
<PRE>MONORESGEN=/usr/bin/monoresgen
./getstrings.pl *.cs > resources/strings.txt #you can have others like strings.de.txt strings.cs.txt ....</PRE>
$(MONORESGEN) $< || (echo -e "\nERROR: cannot convert resources" && exit 1)
<PRE>/resource:resources/strings.txt #to your build line</PRE>
As a read somewhere monoresgen shoud be able to convert to .po format (it's very similar)<BR>
Hope this help to lot people, cause I was serching for it long time<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#555050"><I>- A correct build procedure with automake/autogen/autoconf</I></FONT></PRE>
</BLOCKQUOTE>
<BR>
Yes I know, I'm using makefile this but should be interesting see NAnt solution.<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#555050"><I>- The right files in CVS, the right files in .cvsignore
- The correct programming methods for
- Glade-Sharp</I></FONT></PRE>
</BLOCKQUOTE>
<BR>
that's easy to understand and learn from examples<BR>
nice and clear solution<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#555050"><I> - OO techniques and GUI programming with Gtk-Sharp
- HIG correct</I></FONT></PRE>
</BLOCKQUOTE>
<BR>
read HIG doc, but it's good to look to some glade files of GNOME 2.4 progs to see how they are doing it with glade<BR>
I recommend it to you, that's was good combination for me to understand it (hope;)<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#555050"><I>Basically I want this application to be as correct as humanly possible
and I want it to be like a sample application for Gtk-Sharp projects. So
that I can use it to teach people how to actually correctly prepare and
create Gtk-Sharp projects succesfully.</FONT>
<A HREF="http://cvs.freax.be/cgi-bin/cvsweb/SharpDhcpdConf/"><U>http://cvs.freax.be/cgi-bin/cvsweb/SharpDhcpdConf/</U></A>
<FONT COLOR="#555050">
On the URL you can find information about how to checkout the sources as
anonymous user from the CVS. If you want me to create a writable
account, then first send me some patches as prove that you are actually
going to use it professionally :-), and not to add a bulkload of warez
on my cvs repos.</I></FONT></PRE>
</BLOCKQUOTE>
<BR>
Kind Regards
<PRE><TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
</TR>
<TR>
</TR>
<TR>
<TD>
<BR>
-- <BR>
David Makovský (Yakeen) <<A HREF="mailto:yakeen@sannyas-on.net"><U>yakeen@sannyas-on.net</U></A>>
</TD>
</TR>
</TABLE>
</PRE>
</BODY>
</HTML>
--=-1Yjr8zimj87H5SnTZrub--