Falcon GTK, small periodic table, as buttons

A small Falcon script to display an interactive periodic table of the elements using GTK buttons. …

Well met,

I had a chance to play around with Falcon again, modified a GTK example to create a periodic table of the elements as buttons in a table grid. Needs colour and a pretty display on click, but the foundation is in.


#!/usr/local/bin/falcon
/*#
@main A Falcon/GTK periodic table, as buttons.
click 'em.

@code
Tectonics:
$ falcon periodictable.fal
or
$ chmod +x periodictable.fal
$ ./periodictable.fal
@endcode

@note Atomic weights from wikipedia
*/

/*#
@page about_atomic About the Periodic Table of the Elements

Elementary

One of the cool ones is Au
*/

/*
Falcon-GTK Periodic Table of the Elements
=========================================

The atomic chart, as buttons.

*/

// Using GTK
load gtk

m = GtkMain()
w = GtkWindow()

// a callback for the window to quit the main loop
function _quit()
m.quit()
return false
end
w.signal_delete_event().connect(_quit)

/* Describe the elements */

elements = [
[1, "H", "Hydrogen", 1, 1, "nonmetal", "gas", 1.00794, [1]],
[2, "He", "Helium", 1, 18, "noble", "gas", 4.002602, [2]],
[3, "Li", "Lithium", 2, 1, "alkali-metal", "solid", 6.941, [2, 1]],
[4, "Be", "Beryllium", 2,2, "alkaline-earth-metal", "solid", 9.01218, [2, 2]],
[5, "B", "Boron", 2, 13, "metalloid", "solid", 10.811, [2, 3]],
[6, "C", "Carbon", 2, 14, "nonmetal", "solid", 12.011, [2, 4]],
[7, "N", "Nitrogen", 2, 15, "nonmetal", "gas", 14.00674, [2, 5]],
[8, "O", "Oxygen", 2, 16, "nonmetal", "gas", 15.9994, [2, 6]],
[9, "F", "Fluorine", 2, 17, "halogen", "gas", 18.998403, [2, 7]],
[10, "Ne", "Neon", 2, 18, "noble", "gas", 20.1797, [2, 8]],
[11, "Na", "Sodium", 3, 1, "alkali-metal", "solid", 22.989768, [2, 8, 1]],
[12, "Mg", "Magnesium", 3, 2, "alkaline-earth-metal", "solid", 24.305, [2, 8, 2]],
[13, "Al", "Aluminum", 3, 13, "poor-metal", "solid", 26.981539, [2, 8, 3]],
[14, "Si", "Silicon", 3, 14, "metalloid", "solid", 28.0855, [2, 8, 4]],
[15, "P", "Phosphorus", 3, 15, "nonmetal", "solid", 30.973762, [2, 8, 5]],
[16, "S", "Sulphur", 3, 16, "nonmetal", "solid", 32.066, [2, 8, 6]],
[17, "Cl", "Chlorine", 3, 17, "halogen", "gas", 35.4527, [2, 8, 7]],
[18, "Ar", "Argon", 3, 18, "noble", "gas", 39.948, [2, 8, 8]],
[19, "K", "Potassium", 4, 1, "alkali-metal", "solid", 39.0983, [2, 8, 8, 1]],
[20, "Ca", "Calcium", 4, 2, "alkaline-earth-metal", "solid", 40.078, [2, 8, 8, 2]],
[21, "Sc", "Scandium", 4, 3, "transition-metal", "solid", 44.95591, [2, 8, 9, 2]],
[22, "Ti", "Titanium", 4, 4, "transition-metal", "solid", 47.88, [2, 8, 10, 2]],
[23, "V", "Vanadium", 4, 5, "transition-metal", "solid", 50.9415, [2, 8, 11, 2]],
[24, "Cr", "Chromium", 4, 6, "transition-metal", "solid", 51.9961, [2, 8, 13, 1]],
[25, "Mn", "Manganese", 4, 7, "transition-metal", "solid", 54.93805, [2, 8, 13, 2]],
[26, "Fe", "Iron", 4, 8, "transition-metal", "solid", 55.847, [2, 8, 14, 2]],
[27, "Co", "Cobalt", 4, 9, "transition-metal", "solid", 58.9332, [2, 8, 15, 2]],
[28, "Ni", "Nickel", 4, 10, "transition-metal", "solid", 58.6934, [2, 8, 16, 2]],
[29, "Cu", "Copper", 4, 11, "transition-metal", "solid", 63.546, [2, 8, 18, 1]],
[30, "Zn", "Zinc", 4, 12, "transition-metal", "solid", 65.39, [2, 8, 18, 2]],
[31, "Ga", "Gallium", 4, 13, "poor-metal", "solid", 69.723, [2, 8, 18, 3]],
[32, "Ge", "Germanium", 4, 14, "metalloid", "solid", 72.61, [2, 8, 18, 4]],
[33, "As", "Arsenic", 4, 15, "metalloid", "solid", 74.92159, [2, 8, 18, 5]],
[34, "Se", "Selenium", 4, 16, "nonmetal", "solid", 78.96, [2, 8, 18, 6]],
[35, "Br", "Bromine", 4, 17, "halogen", "liquid", 79.904, [2, 8, 18, 7]],
[36, "Kr", "Krypton", 4, 18, "noble", "gas", 83.8, [2, 8, 18, 8]],
[37, "Rb", "Rubidium", 5, 1, "alkali-metal", "solid", 85.4678, [2, 8, 18, 8, 1]],
[38, "Sr", "Strontium", 5, 2, "alkaline-earth-metal", "solid", 87.62, [2, 8, 18, 8, 2]],
[39, "Y", "Yttrium", 5, 3, "transition-metal", "solid", 88.90585, [2, 8, 18, 9, 2]],
[40, "Zr", "Zirconium", 5, 4, "transition-metal", "solid", 91.224, [2, 8, 18, 10, 2]],
[41, "Nb", "Niobium", 5, 5, "transition-metal", "solid", 92.90638, [2, 8, 18, 12, 1]],
[42, "Mo", "Molybdenum", 5, 6, "transition-metal", "solid", 95.94, [2, 8, 18, 13, 1]],
[43, "Tc", "Technetium", 5, 7, "transition-metal", "solid", 97.9072, [2, 8, 18, 13, 2]],
[44, "Ru", "Ruthenium", 5, 8, "transition-metal", "solid", 101.07, [2, 8, 18, 15, 1]],
[45, "Rh", "Rhodium", 5, 9, "transition-metal", "solid", 102.9055, [2, 8, 18, 16, 1]],
[46, "Pd", "Palladium", 5, 10, "transition-metal", "solid", 106.42, [2, 8, 18, 18, 0]],
[47, "Ag", "Silver", 5, 11, "transition-metal", "solid", 107.8682, [2, 8, 18, 18, 1]],
[48, "Cd", "Cadmium", 5, 12, "transition-metal", "solid", 112.411, [2, 8, 18, 18, 2]],
[49, "In", "Indium", 5, 13, "poor-metal", "solid", 114.818, [2, 8, 18, 18, 3]],
[50, "Sn", "Tin", 5, 14, "poor-metal", "solid", 118.71, [2, 8, 18, 18, 4]],
[51, "Sb", "Antimony", 5, 15, "metalloid", "solid", 121.760, [2, 8, 18, 18, 5]],
[52, "Te", "Tellurium", 5, 16, "metalloid", "solid", 127.6, [2, 8, 18, 18, 6]],
[53, "I", "Iodine", 5, 17, "halogen", "solid", 126.90447, [2, 8, 18, 18, 7]],
[54, "Xe", "Xenon", 5, 18, "noble", "gas", 131.29, [2, 8, 18, 18, 8]],
[55, "Cs", "Cesium", 6, 1, "alkali-metal", "solid", 132.90543, [2, 8, 18, 18, 8, 1]],
[56, "Ba", "Barium", 6, 2, "alkaline-earth-metal", "solid", 137.327, [2, 8, 18, 18, 8, 2]],
[57, "La", "Lanthanum", 9, 3, "lanthanide", "solid", 138.9055, [2, 8, 18, 18, 9, 2]],
[58, "Ce", "Cerium", 9, 4, "lanthanide", "solid", 140.115, [2, 8, 18, 20, 8, 2]],
[59, "Pr", "Praseodymium", 9, 5, "lanthanide", "solid", 140.90765, [2, 8, 18, 21, 8, 2]],
[60, "Nd", "Noedymium", 9, 6, "lanthanide", "solid", 144.24, [2, 8, 18, 22, 8, 2]],
[61, "Pm", "Promethium", 9, 7, "lanthanide", "solid", 144.9127, [2, 8, 18, 23, 8, 2]],
[62, "Sm", "Samarium", 9, 8, "lanthanide", "solid", 150.36, [2, 8, 18, 24, 8, 2]],
[63, "Eu", "Europium", 9, 9, "lanthanide", "solid", 151.965, [2, 8, 18, 25, 8, 2]],
[64, "Gd", "Gadolinium", 9, 10, "lanthanide", "solid", 157.25, [2, 8, 18, 25, 9, 2]],
[65, "Tb", "Terbium", 9, 11, "lanthanide", "solid", 158.92534, [2, 8, 18, 27, 8, 2]],
[66, "Dy", "Dysprosium", 9, 12, "lanthanide", "solid", 162.50, [2, 8, 18, 28, 8, 2]],
[67, "Ho", "Holmium", 9, 13, "lanthanide", "solid", 164.93032, [2, 8, 18, 29, 8, 2]],
[68, "Er", "Erbium", 9, 14, "lanthanide", "solid", 167.26, [2, 8, 18, 30, 8, 2]],
[69, "Tm", "Thulium", 9, 15, "lanthanide", "solid", 168.93421, [2, 8, 18, 31, 8, 2]],
[70, "Yb", "Ytterbium", 9, 16, "lanthanide", "solid", 173.04, [2, 8, 18, 32, 8, 2]],
[71, "Lu", "Lutetium", 9, 17, "lanthanide", "solid", 174.967, [2, 8, 18, 32, 9, 2]],
[72, "Hf", "Hafnium", 6, 4, "transition-metal", "solid", 178.49, [2, 8, 18, 32, 10, 2]],
[73, "Ta", "Tantalum", 6, 5, "transition-metal", "solid", 180.9479, [2, 8, 18, 32, 11, 2]],
[74, "W", "Tungsten", 6, 6, "transition-metal", "solid", 183.84, [2, 8, 18, 32, 12, 2]],
[75, "Re", "Rhenium", 6, 7, "transition-metal", "solid", 186.207, [2, 8, 18, 32, 13, 2]],
[76, "Os", "Osmium", 6, 8, "transition-metal", "solid", 190.23, [2, 8, 18, 32, 14, 2]],
[77, "Ir", "Iridium", 6, 9, "transition-metal", "solid", 192.22, [2, 8, 18, 32, 15, 2]],
[78, "Pt", "Platinum", 6, 10, "transition-metal", "solid", 195.08, [2, 8, 18, 32, 17, 1]],
[79, "Au", "Gold", 6, 11, "transition-metal", "solid", 196.96654, [2, 8, 18, 32, 18, 1]],
[80, "Hg", "Mercury", 6, 12, "transition-metal", "liquid", 200.59, [2, 8, 18, 32, 18, 2]],
[81, "Tl", "Thallium", 6, 13, "poor-metal", "solid", 204.3833, [2, 8, 18, 32, 18, 3]],
[82, "Pb", "Lead", 6, 14, "poor-metal", "solid", 207.2, [2, 8, 18, 32, 18, 4]],
[83, "Bi", "Bismuth", 6, 15, "poor-metal", "solid", 208.98037, [2, 8, 18, 32, 18, 5]],
[84, "Po", "Polonium", 6, 16, "metalloid", "solid", 208.9824, [2, 8, 18, 32, 18, 6]],
[85, "At", "Astatine", 6, 17, "halogen", "solid", 209.9871, [2, 8, 18, 32, 18, 7]],
[86, "Rn", "Radon", 6, 18, "noble", "gas", 222.0176, [2, 8, 18, 32, 18, 8]],
[87, "Fr", "Francium", 7, 1, "alkali-metal", "solid", 223.0197, [2, 8, 18, 32, 18, 8, 1]],
[88, "Ra", "Radium", 7, 2, "alkaline-earth-metal", "solid", 226.0254, [2, 8, 18, 32, 18, 8, 2]],
[89, "Ac", "Actinium", 10, 3, "actinide", "solid", 227.0278, [2, 8, 18, 32, 18, 9, 2]],
[90, "Th", "Thorium", 10, 4, "actinide", "solid", 232.0381, [2, 8, 18, 32, 18, 10, 2]],
[91, "Pa", "Protactinium", 10, 5, "actinide", "solid", 231.03588, [2, 8, 18, 32, 20, 9, 2]],
[92, "U", "Uranium", 10, 6, "actinide", "solid", 238.0289, [2, 8, 18, 32, 21, 9, 2]],
[93, "Np", "Neptunium", 10, 7, "actinide", "solid", 237.048, [2, 8, 18, 32, 22, 9, 2]],
[94, "Pu", "Plutonium", 10, 8, "actinide", "solid", 244.0642, [2, 8, 18, 32, 24, 8, 2]],
[95, "Am", "Americium", 10, 9, "actinide", "solid", 243.0614, [2, 8, 18, 32, 25, 8, 2]],
[96, "Cm", "Curium", 10, 10, "actinide", "solid", 247.0703, [2, 8, 18, 32, 25, 9, 2]],
[97, "Bk", "Berkelium", 10, 11, "actinide", "solid", 247.0703, [2, 8, 18, 32, 26, 9, 2]],
[98, "Cf", "Californium", 10, 12, "actinide", "solid", 251.0796, [2, 8, 18, 32, 28, 8, 2]],
[99, "Es", "Einsteinium", 10, 13, "actinide", "solid", 252.083, [2, 8, 18, 32, 29, 8, 2]],
[100, "Fm", "Fermium", 10, 14, "actinide", "solid", 257.0951, [2, 8, 18, 32, 30, 8, 2]],
[101, "Md", "Mendelevium", 10, 15, "actinide", "solid", 258.1, [2, 8, 18, 32, 31, 8, 2]],
[102, "No", "Nobelium", 10, 16, "actinide", "solid", 259.1009, [2, 8, 18, 32, 32, 8, 2]],
[103, "Lr", "Lawrencium", 10, 17, "actinide", "solid", 262.11, [2, 8, 18, 32, 32, 9, 2]],
[104, "Rf", "Rutherfordium", 7, 4, "transition-metal", "solid", 261, [2, 8, 18, 32, 32, 10, 2]],
[105, "Db", "Dubnium", 7, 5, "transition-metal", "solid", 262, [2, 8, 18, 32, 32, 11, 2]],
[106, "Sg", "Seaborgium", 7, 6, "transition-metal", "solid", 266, [2, 8, 18, 32, 32, 12, 2]],
[107, "Bh", "Bohrium", 7, 7, "transition-metal", "solid", 264, [2, 8, 18, 32, 32, 13, 2]],
[108, "Hs", "Hassium", 7, 8, "transition-metal", "solid", 269, [2, 8, 18, 32, 32, 14, 2]],
[109, "Mt", "Meitnerium", 7, 9, "transition-metal", "solid", 268, [2, 8, 18, 32, 32, 15, 2]],
[110, "Ds", "Darmstadmium", 7, 10, "transition-metal", "solid", 269, [2, 8, 18, 32, 32, 17, 1]],
[111, "Rg", "Roentgenium", 7, 11, "transition-metal", "solid", 272, [2, 8, 18, 32, 32, 18, 1]],
[112, "Cn", "Copernicium", 7, 12, "transition-metal", "liquid", 285, [2, 8, 18, 32, 32, 18, 2]],
[113, "Uut", "Ununtrium", 7, 13, "poor-metal", "solid", "n/a", [2, 8, 18, 32, 32, 18, 3]],
[114, "Fl", "Flerovium", 7, 14, "poor-metal", "solid", 289, [2, 8, 18, 32, 32, 18, 4]],
[115, "Uup", "Ununpentium", 7, 15, "poor-metal", "solid", "n/a", [2, 8, 18, 32, 32, 18, 5]],
[116, "Lv", "Livermorium", 7, 16, "poor-metal", "solid", "293", [2, 8, 18, 32, 32, 18, 6]],
[117, "Uus", "Ununseptium", 7, 17, "halogen", "solid", "n/a", [2, 8, 18, 32, 32, 18, 7]],
[118, "Uuo", "Ununoctium", 7, 18, "noble", "gas", "n/a", [2, 8, 18, 32, 32, 18, 8]]
]

/* pretty print element info */
function displayElement(ele)
return describe(ele)
end

/* Elements as buttons */
class ElementButton(ele, row, col) from GtkButton
_row = 0
_col = 0
_ele = []
init
self._ele = ele
self._row = row
self._col = col
self.set_label(@ "$self._ele[1]")
self.signal_clicked().connect(self)
end
function on_clicked()
> "Clicked ", self._row, " ", self._col, " ", displayElement(self._ele)
end
end

/*
Subclass GtkTable (and create a table of ElementButton).
*/
class ElementTable( numrows, numcols ) from GtkTable
init
self.resize( numrows, numcols )
self.set_homogeneous(true)
for ele in elements
row = ele[3]
col = ele[4]
b = ElementButton(ele, row, col)
self.attach_defaults(b, col-1, col, row-1, row)
end
end
end


// Create a table of 180 cells, most are buttons
tab = ElementTable(10, 18)

// Run the GTK window
w.add(tab)
m.run(w)

Fun.

Early screen shot (without colour):

and a few clicks,


Clicked 4 11 [ 29, "Cu", "Copper", 4, 11, "transition-metal", "solid", 63.546, [ 2, 8, 18, 1]]
Clicked 5 11 [ 47, "Ag", "Silver", 5, 11, "transition-metal", "solid", 107.868, [ 2, 8, 18, 18, 1]]
Clicked 6 11 [ 79, "Au", "Gold", 6, 11, "transition-metal", "solid", 196.967, [ 2, 8, 18, 32, 18, 1]]

Cheers,
Brian

Leave a Reply

Your email address will not be published. Required fields are marked *