[Mono-docs-list] MyTextEntry, code source
Alvaro A. Ramirez
alramire@syr.edu
21 Apr 2003 20:52:21 -0400
--=-QC1cG98qFCJcGywOmFEU
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
Taking a bit of inspiration from Andrés, I did the example found in
http://go-mono.com/tutorial/html/en/gnome/bindings/gtk-sharp/containerpaned.html which had C code. To tell you the truth, I do not know if someone was already working on this. If some one is, my apologies. I needed to learn it anyway, so it was not in vain :) Let me know if this is good for the tutorial. Files are attached.
Thanks,
Alvaro
On Mon, 2003-04-21 at 05:49, Andrés Sáyago wrote:
> Miguel and people!
>
> I'm new here and I'm new in the Mono world. I want to colaborate for
> this excelente project. My first colaboration is this code attachment, a
> conversion of the Entry in Gtk to Gtk#. The original code was taken from
> the official manual:
> http://go-mono.com/tutorial/html/en/gnome/bindings/gtk-sharp/misctextentries.html
>
> Please, my Eglish isn't perfect. But I receive suggests!
>
> Andrés Sáyago
>
> -------
>
>
> Hola Miguel. Este es mi primer aporte a Mono, una conversión del
> programa que usa el widget Entry en Gtk para ser usado en Gtk#. Usé el
> códido original del manual que se encuentra en:
> http://go-mono.com/tutorial/html/en/gnome/bindings/gtk-sharp/misctextentries.html
> Mi Inglés no es perfecto pero recibo sugerencias y agradezco correciones
> al texto. Me sentiría muy orgulloso y animado si incluyen mi aporte y
> los créditos en la página que Johannes Roith y Alejandro Sánchez Acosta
> tienen publicada.
> Espero comentarios!
>
>
> Portal GNU ColombiaLinux
> http://www.ColombiaLinux.org
> asath@ColombiaLinux.org
> Universidad Autónoma de Bucaramanga
> Bucaramanga, Colombia
> Tel: (57-7)6454994 Móvil: 3157632295
>
> ______________________________________________________________________
>
> // MyTextEntry.cs - GTK# Tutorial example
> //
> // Authors: Andrés Sáyago
> // asath@ColombiaLinux.org
> //
> // (C) 2003 Andrés Sáyago
> // Colombia
> //
>
> namespace GtkSharpTutorial
> {
> using Gtk;
> using GtkSharp;
> using System;
>
> public class textEntrySample
> {
> // The entry_toggle_* functions use it
> static Entry entry;
>
> static void enter_callback(object obj, EventArgs args)
> {
> string entry_text = ((Entry) obj).Text;
> Console.WriteLine("Entry contents: " + entry_text);
> }
>
> static void entry_toggle_editable(object obj, EventArgs args)
> {
> entry.Editable = ((CheckButton) obj).Active;
> }
>
> static void entry_toggle_visibility(object obj, EventArgs args)
> {
> entry.Visible = ((CheckButton) obj).Active;
> }
>
> static void window_destroy(object obj, DeleteEventArgs args)
> {
> Application.Quit();
> }
>
> static void button_close(object obj, EventArgs args)
> {
> Application.Quit();
> }
>
> // Function for the Widgets building
> static void create_text_entry()
> {
> Window window;
> VBox vbox;
> HBox hbox;
> Button button;
> CheckButton check;
> int tmp_pos;
>
> // Create a new window
> window = new Window (WindowType.Toplevel);
> window.SetDefaultSize(200, 100);
> window.Title = "GTK Entry";
> window.DeleteEvent += new DeleteEventHandler(window_destroy);
>
> vbox = new VBox(false, 0);
> window.Add(vbox);
> vbox.Show();
>
> // Box to enter text
> entry = new Entry();
> entry.MaxLength = 50;
> // When the Enter key is pressed, print a message to the console
> entry.Activated += new EventHandler(enter_callback);
> entry.Text = "hello";
> tmp_pos = entry.Text.Length;
> // Demostration of the 'InsertText' function (-1 is at end)
> entry.InsertText(" world", -1, out tmp_pos);
> // Text selected
> entry.SelectRegion(0, entry.Text.Length);
> vbox.PackStart(entry, true, true, 0);
> entry.Show();
>
> hbox = new HBox(false, 0);
> vbox.Add(hbox);
> hbox.Show();
>
> check = new CheckButton("Editable");
> hbox.PackStart(check, true, true, 0);
> check.Toggled += new EventHandler(entry_toggle_editable);
> check.Active = true;
> check.Show();
>
> check = new CheckButton("Visible");
> hbox.PackStart(check, true, true, 0);
> check.Toggled += new EventHandler(entry_toggle_visibility);
> check.Active = true;
> check.Show();
>
> button = Button.NewFromStock(Gtk.Stock.Close);
> button.Clicked += new EventHandler(button_close);
> vbox.PackStart(button, true, true, 0);
> button.CanDefault = true;
> button.GrabDefault();
> button.Show();
>
> window.Show();
> }
>
> // Main function
> public static void Main(string[] args)
> {
> Application.Init ();
> create_text_entry();
> Application.Run ();
> }
> }
> }
>
--=-QC1cG98qFCJcGywOmFEU
Content-Disposition: attachment; filename=Makefile
Content-Type: text/x-makefile; name=Makefile; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
# Paned Window Makefile
MCS=mcs
all_assemblies=-r glib-sharp.dll -r pango-sharp.dll -r atk-sharp.dll -r gdk-sharp.dll -r gtk-sharp.dll -r System.Drawing -r art-sharp.dll -r gnome-sharp.dll
paned.exe: paned.cs
$(MCS) -o paned.exe $(all_assemblies) paned.cs
--=-QC1cG98qFCJcGywOmFEU
Content-Disposition: attachment; filename=paned.cs
Content-Type: text/plain; name=paned.cs; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
// paned.cs - Gtk# Tutorial example
//
// Author: Alvaro Ramirez
//
// (c) 2002 Alvaro Ramirez
namespace GtkSharpTutorial
{
using System;
using Gtk;
using GtkSharp;
using GLib;
class PanedMain
{
static Gtk.ScrolledWindow CreatList()
{
//Declare scroll window and tree view along with all necessary
//to control th tree view
Gtk.ScrolledWindow ScrWindow;
Gtk.TreeView MyTree;
Gtk.ListStore store;
Gtk.TreeIter iter;
Gtk.CellRenderer cell;
Gtk.TreeViewColumn column;
//Create scrolled window and format it
ScrWindow = new Gtk.ScrolledWindow();
ScrWindow.SetPolicy(Gtk.PolicyType.Automatic,Gtk.PolicyType.Automatic);
//Create ListStore to be used in tree view
store= new Gtk.ListStore((int)TypeFundamentals.TypeString);
//Create treeview and format it
MyTree=new TreeView(store);
MyTree.HeadersVisible = true;
MyTree.HeadersClickable = false;
MyTree.EnableSearch = false;
//Add treeview to scrolled window
ScrWindow.AddWithViewport(MyTree);
//Create column for treeview
column = new Gtk.TreeViewColumn ();
//Create cell renderer for column
cell = new Gtk.CellRendererText();
//Format column
column.Title = "Messages";
column.PackStart (cell, true);
column.AddAttribute (cell, "text", 0);
//Add column to treeview
MyTree.AppendColumn (column);
//populate treevie
iter = new TreeIter();
for(int i = 0;i<10;i++)
{
GLib.Value value = new Value("Message "+i.ToString());
store.Append(out iter);
store.SetValue(iter,0,value);
}
return ScrWindow;
}
static Gtk.ScrolledWindow CreateText()
{
//Declare scroll window and TextView along with all necessary
//to control the TextView
Gtk.ScrolledWindow ScrWindow;
Gtk.TextView TextArea;
Gtk.TextBuffer buffer;
//Create scrolled window and format it
ScrWindow = new Gtk.ScrolledWindow(null,null);
ScrWindow.SetPolicy(Gtk.PolicyType.Automatic,Gtk.PolicyType.Automatic);
//Create text buffer use to store text in textview
buffer=new Gtk.TextBuffer(new Gtk.TextTagTable ());
//Set buffer text
buffer.Text="From: JustLinux Forums Mailer <webmaster@justlinux.com> \n"+
"To: alramire@syr.edu \n"+
"Subject: Reply to post Screen Shots......Just Because \n"+
"Date: Fri, 18 Apr 2003 19:43:16 GMT \n" +
"Hello tucolino, \n"+
"\n"+
"hecresper has just replied to a thread you have subscribed to entitled - Screen Shots.... \n";
//Create textview
TextArea=new Gtk.TextView();
//Add previous text buffer to textview
TextArea.Buffer=buffer;
//format textview
TextArea.Editable=false;
TextArea.CursorVisible=false;
TextArea.WrapMode=Gtk.WrapMode.Word;
//Add textview to scrolled window
ScrWindow.AddWithViewport(TextArea);
TextArea.ShowAll();
ScrWindow.ShowAll();
return ScrWindow;
}
static public int Main (string[] args)
{
Application.Init ();
Window window = new Window ("Paned Window");
window.DeleteEvent += new DeleteEventHandler (delete_event);
//Format main window
window.BorderWidth=10;
window.WidthRequest=450;
window.HeightRequest=400;
window.Resizable=true;
window.SetPosition(Gtk.WindowPosition.Center);
//create VPaned widget (vertical)
VPaned vpaned1 = new VPaned();
//vpaned1.Add1(CreatList());
//vpaned1.Add2(CreateText());
//Add top and bottom widgets. Last two arguments are resize and shrink (bool)
vpaned1.Pack1(CreatList(),true,true);
vpaned1.Pack2(CreateText(),true,true);
window.Add (vpaned1);
window.ShowAll();
Application.Run ();
return 0;
}
static void delete_event (object obj, DeleteEventArgs args)
{
Application.Quit ();
}
static void QuitApp (object obj, EventArgs args)
{
Application.Quit ();
}
}
}
--=-QC1cG98qFCJcGywOmFEU--