Wednesday, May 27, 2009

GTK-Sharp: Scrollable (Window) Label Example



using System;

using System.Collections;
using Gtk;

namespace gtkTest
{

public class SWinLabel
{
private Window topWin;

private static int defWidth = 400;
private static double phi = 1.6180339887;
private static int defHeight = (int)( ((double)(defWidth)) / phi);

private ScrolledWindow sWin;

private Label label;
private string labelText;

private string winTitleText;

// ==========================================================

public SWinLabel(string pWinTitleText, string rawLabelText)
{
winTitleText = pWinTitleText;
topWin = new Window(winTitleText);

topWin.SetDefaultSize(defWidth, defHeight);
topWin.SetPosition(WindowPosition.Center); // TODO

sWin = new ScrolledWindow();
sWin.SetPolicy(Gtk.PolicyType.Always, Gtk.PolicyType.Always);
topWin.Add(sWin);
sWin.Show();

labelText = rawLabelText;
label = new Label(rawLabelText);
sWin.AddWithViewport(label);
label.Show();

topWin.Show();
}

// ==========================================================

}
}

Tuesday, May 26, 2009

Terrorism & Self Worth

I was chatting with an intelligent young lady on Saturday, and over time became rather alarmed.

She was convinced of the following points:

1. The world economy is in a state of collapse.
2. Total ecological holocaust is imminent.
3. Her and her peers, raised to believe that great things were within their reach, should accept their inevitable mediocrity.

On the topic of potential and achievement, I felt that this attitude and the crisis of identity crisis it speaks of, seems to be a direct result from having a top-down / one-to-many media distribution system and the related one-to-many mass production of consumable and semi-durable goods.

This girl felt that she had to do something great, I can only think in order to acquire status or a sense of worth, in order to _justify_ her existence.

As a result of the top-down nature of society this girl does not receive animal satisfaction through co-operative interaction with members of her community, and cannot derive an immediate sense of self-worth as result of the clear and obvious benefit the ramifications of her existence, specifically the fruits of her labour, render to others whom _she_ values.

Unfortunately the likelihood of her successfully emerging from the herd to a position of rarity is made all the more unlikely by the top-down winner-takes-all nature of the current social model.

Thus, she effectively exhibits what I, knowing nothing of Marx, would guess to be classical workers alienation.

Using Gtk-Sharp in VS2008 - .DLL Path & Assembly Reference Issues

Get the .msi windows installer from the Mono project page:
http://www.mono-project.com/Gtk-Sharp_Installer_for_.NET_Framework

After running the installer, I found that it incorrectly appended the system Path variable, forgetting to add a trailing '\', resulting in VS2008 failing to find .dll's, and throwing a DllNotFoundException [Unable to load DLL 'libglib-2.0-0.dll'].

After fixing this, you're good to go.

Just remember to add references to the following assemblies

glib-sharp
atk-sharp
gtk-sharp

in your project.


Some useful links on the subject:

http://www.ondotnet.com/pub/a/dotnet/2004/08/09/gtk_mono.htm?page=last&x-order=date

Monday, May 25, 2009

GTK-Sharp: Scrollable (Window) Table Example



using System;
using Gtk;

namespace gtkTest
{

public class WinTable
{

private Gtk.ScrolledWindow sWinRef;
private Table table;

private uint rowCount, colCount, rowSpacing, colSpacing;

// ==========================================================

public WinTable(uint pRowCount, uint pColCount, uint pRowSpacing, uint pColSpacing, Gtk.ScrolledWindow pSWinRef)
{
sWinRef = pSWinRef;

rowCount = pRowCount;
colCount = pColCount;

rowSpacing = pRowSpacing;
colSpacing = pColSpacing;

bool homogeneous = true;
table = new Table (rowCount, colCount, homogeneous);

for (uint rowNum = 1; rowNum <= rowCount; rowNum++)
table.SetRowSpacing(rowNum - 1, rowSpacing);

for (uint colNum = 1; colNum <= colCount; colNum++)
table.SetColSpacing(colNum - 1, colSpacing);

sWinRef.AddWithViewport(table);
}

// ==========================================================

/* for e.g. = 2 x 2 table, say (horiz,vert), then

(0,0) (1,0) (2,0)

(0,1) (1,1) (2,1)

(0,2) (1,2) (2,2)

*/

public void PackWidgetAtXY(Widget widget, uint x, uint y)
{
uint leftAttach = x - 1;
uint rightAttach = x;
uint topAttach = y - 1;
uint bottomAttach = y;

//Gtk.AttachOptions xOptions = new Gtk.AttachOptions(); // fill, shrink, expand

table.Attach(widget, leftAttach, rightAttach, topAttach, bottomAttach);
widget.Show();
}

// ==========================================================

public void Demo()
{

for (uint rowNum = 1; rowNum <= rowCount; rowNum++)
for (uint colNum = 1; colNum <= colCount; colNum++)
{
string text = "one\ntwo\nthree\nfour";
Label label = new Label(text);
this.PackWidgetAtXY(label, rowNum, colNum);
}

this.table.Show();
}


// ==========================================================
}


//####################################################

public partial class MainWindow: Gtk.Window
{
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}

protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
}

//####################################################

class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
MainWindow mainWin = new MainWindow ();

uint rowCount = 8, colCount = 7;
uint rowSpacing = 80, colSpacing = 200;

mainWin.ShowAll();

Window priWin = new Window("Primary Window");
priWin.SetDefaultSize(250, 200);
priWin.SetPosition(WindowPosition.Center);

Gtk.ScrolledWindow sWin = new Gtk.ScrolledWindow();
sWin.SetPolicy(Gtk.PolicyType.Always, Gtk.PolicyType.Always);

priWin.Add(sWin);
sWin.Show();

WinTable winTable = new WinTable(rowCount, colCount, rowSpacing, colSpacing, sWin);
winTable.Demo();

priWin.Show();

Application.Run ();
}
}

}

Sunday, May 24, 2009

ubuntu 9.04 audio fiddling

On having trouble getting sound to work under rhythmbox after installing uBuntu 9.04 on my old Fujitsu-Siemens, I found the following directions very useful:

http://www.ubuntugeek.com/sound-solutions-for-ubuntu-904-jaunty-users.html

ubuntu 9.04 audio codecs

sudo apt-get install non-free-codecs libxine1-ffmpeg gxine mencoder mpeg2dec 

to fix skype 'problem with audio playback' in ubuntu 9.04

  • killall pulseaudio
  • sudo apt-get remove pulseaudio
  • sudo apt-get install esound
  • sudo rm /etc/X11/Xsession.d/70pulseaudio