Skip to content

Instantly share code, notes, and snippets.

@ashwani-rathee
Created June 28, 2021 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwani-rathee/d382f6578054f7b6510fac8b3de9519c to your computer and use it in GitHub Desktop.
Save ashwani-rathee/d382f6578054f7b6510fac8b3de9519c to your computer and use it in GitHub Desktop.
using Gtk
win = GtkWindow("Skyring", 300, 350)
set_gtk_property!(win,:resizable,false)
grid = GtkGrid()
set_gtk_property!(grid,:margin,20)
text = ""
b1 = GtkButton("1")
b2 = GtkButton("2")
b3 = GtkButton("3")
b_plus = GtkButton("+")
b4 = GtkButton("4")
b5 = GtkButton("5")
b6 = GtkButton("6")
b_minus = GtkButton("-")
b7 = GtkButton("7")
b8 = GtkButton("8")
b9 = GtkButton("9")
b_multiply = GtkButton("x")
b_clear = GtkButton("clear")
set_gtk_property!(b_clear,:tooltip_text,"Clears the text area")
b0 = GtkButton("0")
b_equalto = GtkButton("=")
set_gtk_property!(b_equalto,:tooltip_text,"To get the output")
b_divide = GtkButton("÷")
label = GtkEntry()
set_gtk_property!(label,:text,text)
GAccessor.text(label, "")
set_gtk_property!(label,:editable,false)
# set_gtk_property!(label,:margin,0)
set_gtk_property!(label,:vexpand,true)
# set_gtk_property!(label,:hexpand,false)
b_sqrt = GtkButton("√x")
set_gtk_property!(b_sqrt,:tooltip_text,"To get square root")
b_sqre = GtkButton("x^2")
set_gtk_property!(b_sqre,:tooltip_text,"To get square")
b_brac1 = GtkButton("(")
b_brac2 = GtkButton(")")
b_expo = GtkButton("x ^ y")
set_gtk_property!(b_sqrt,:tooltip_text,"To get exponential")
b_dot = GtkButton(".")
b_mod = GtkButton("%")
set_gtk_property!(b_mod,:tooltip_text,"To get mod")
b_pi = GtkButton("π")
set_gtk_property!(b_pi,:tooltip_text,"Our Beloved π")
b_e = GtkButton("ℯ")
set_gtk_property!(b_e,:tooltip_text,"Our Beloved ℯ")
# trignometric functions
b_sin = GtkButton("sin()")
b_cos = GtkButton("cos()")
b_tan = GtkButton("tan()")
b_sinh = GtkButton("sinh()")
b_cosh = GtkButton("cosh()")
b_tanh = GtkButton("tanh()")
# rounding functions
b_round = GtkButton("round()")
b_floor = GtkButton("floor()")
b_ceil = GtkButton("ceil()")
b_trunc = GtkButton("trunc()")
grid[1:7, 1] = label
grid[1, 2] = b1
grid[2, 2] = b2
grid[3, 2] = b3
grid[4, 2] = b_plus
grid[5, 2] = b_sin
grid[6, 2] = b_cos
grid[7, 2] = b_tan
grid[1, 3] = b4
grid[2, 3] = b5
grid[3, 3] = b6
grid[4, 3] = b_minus
grid[5, 3] = b_sinh
grid[6, 3] = b_cosh
grid[7, 3] = b_tanh
grid[1, 4] = b7
grid[2, 4] = b8
grid[3, 4] = b9
grid[4, 4] = b_multiply
grid[5, 4] = b_round
grid[6, 4] = b_floor
grid[7, 4] = b_ceil
grid[1, 5] = b_clear
grid[2, 5] = b0
grid[3, 5] = b_equalto
grid[4, 5] = b_divide
grid[5, 5] = b_brac1
grid[6, 5] = b_brac2
grid[7, 5] = b_trunc
grid[1, 6] = b_pi
grid[2, 6] = b_dot
grid[3, 6] = b_e
grid[4, 6] = b_mod
grid[5, 6] = b_sqrt
grid[6, 6] = b_sqre
grid[7, 6] = b_expo
set_gtk_property!(grid, :column_homogeneous, true)
set_gtk_property!(grid, :column_spacing, 5) # introduce a 15-pixel gridp between columns
set_gtk_property!(grid, :row_spacing, 5)
push!(win, grid)
function calculate(s)
parsedexp = Meta.parse(s)
final = eval(parsedexp)
println("Eval: $parsedexp ,", "Result:", final)
return string(final)
end
function button_clicked_callback(widget)
if widget == b1
global text = text * "1"
GAccessor.text(label, text)
elseif widget == b2
global text = text * "2"
GAccessor.text(label, text)
elseif widget == b3
global text = text * "3"
GAccessor.text(label, text)
elseif widget == b4
global text = text * "4"
GAccessor.text(label, text)
elseif widget == b5
global text = text * "5"
GAccessor.text(label, text)
elseif widget == b6
global text = text * "6"
GAccessor.text(label, text)
elseif widget == b7
global text = text * "7"
GAccessor.text(label, text)
elseif widget == b8
global text = text * "8"
GAccessor.text(label, text)
elseif widget == b9
global text = text * "9"
GAccessor.text(label, text)
elseif widget == b_plus
global text = text * " + "
GAccessor.text(label, text)
elseif widget == b_minus
global text = text * " - "
GAccessor.text(label, text)
elseif widget == b_multiply
global text = text * " * "
GAccessor.text(label, text)
elseif widget == b_divide
global text = text * " / "
GAccessor.text(label, text)
elseif widget == b0
global text = text * "0"
GAccessor.text(label, text)
elseif widget == b_clear
global text = ""
GAccessor.text(label, text)
elseif widget == b_sqrt
global text = text * " √ "
GAccessor.text(label, text)
elseif widget == b_sqre
global text = text * " ^2 "
GAccessor.text(label, text)
elseif widget == b_brac1
global text = text * " ( "
GAccessor.text(label, text)
elseif widget == b_brac2
global text = text * " ) "
GAccessor.text(label, text)
elseif widget == b_expo
global text = text * " ^ "
GAccessor.text(label, text)
elseif widget == b_dot
global text = text * "."
GAccessor.text(label, text)
elseif widget == b_mod
global text = text * " % "
GAccessor.text(label, text)
elseif widget == b_pi
global text = text * " π "
GAccessor.text(label, text)
elseif widget == b_e
global text = text * " ℯ "
GAccessor.text(label, text)
elseif widget == b_sin
global text = text * " sin( "
GAccessor.text(label, text)
elseif widget == b_cos
global text = text * " cos( "
GAccessor.text(label, text)
elseif widget == b_tan
global text = text * " tan( "
GAccessor.text(label, text)
elseif widget == b_sinh
global text = text * " sinh( "
GAccessor.text(label, text)
elseif widget == b_cosh
global text = text * " cosh( "
GAccessor.text(label, text)
elseif widget == b_tanh
global text = text * " tanh( "
GAccessor.text(label, text)
# rounding functions
elseif widget == b_round
global text = text * "round("
GAccessor.text(label, text)
elseif widget == b_floor
global text = text * "floor("
GAccessor.text(label, text)
elseif widget == b_ceil
global text = text * "ceil("
GAccessor.text(label, text)
elseif widget == b_trunc
global text = text * "trunc("
GAccessor.text(label, text)
elseif widget == b_equalto
global text = calculate(text)
GAccessor.text(label, text)
end
end
id1 = signal_connect(button_clicked_callback, b1, "clicked")
id2 = signal_connect(button_clicked_callback, b2, "clicked")
id3 = signal_connect(button_clicked_callback, b3, "clicked")
id4 = signal_connect(button_clicked_callback, b4, "clicked")
id5 = signal_connect(button_clicked_callback, b5, "clicked")
id6 = signal_connect(button_clicked_callback, b6, "clicked")
id7 = signal_connect(button_clicked_callback, b7, "clicked")
id8 = signal_connect(button_clicked_callback, b8, "clicked")
id9 = signal_connect(button_clicked_callback, b9, "clicked")
id10 = signal_connect(button_clicked_callback, b0, "clicked")
id11 = signal_connect(button_clicked_callback, b_plus, "clicked")
id12 = signal_connect(button_clicked_callback, b_minus, "clicked")
id13 = signal_connect(button_clicked_callback, b_multiply, "clicked")
id14 = signal_connect(button_clicked_callback, b_divide, "clicked")
id15 = signal_connect(button_clicked_callback, b_clear, "clicked")
id16 = signal_connect(button_clicked_callback, b_equalto, "clicked")
id17 = signal_connect(button_clicked_callback, b_sqrt, "clicked")
id18 = signal_connect(button_clicked_callback, b_sqre, "clicked")
id19 = signal_connect(button_clicked_callback, b_brac1, "clicked")
id20 = signal_connect(button_clicked_callback, b_brac2, "clicked")
id21 = signal_connect(button_clicked_callback, b_expo, "clicked")
id22 = signal_connect(button_clicked_callback, b_dot, "clicked")
id23 = signal_connect(button_clicked_callback, b_mod, "clicked")
id24 = signal_connect(button_clicked_callback, b_pi, "clicked")
id25 = signal_connect(button_clicked_callback, b_e, "clicked")
id26 = signal_connect(button_clicked_callback, b_sin, "clicked")
id27 = signal_connect(button_clicked_callback, b_cos, "clicked")
id28 = signal_connect(button_clicked_callback, b_tan, "clicked")
id29 = signal_connect(button_clicked_callback, b_sinh, "clicked")
id30 = signal_connect(button_clicked_callback, b_cosh, "clicked")
id31 = signal_connect(button_clicked_callback, b_tanh, "clicked")
# rounding functions
id32 = signal_connect(button_clicked_callback, b_round, "clicked")
id33 = signal_connect(button_clicked_callback, b_floor, "clicked")
id34 = signal_connect(button_clicked_callback, b_ceil, "clicked")
id35 = signal_connect(button_clicked_callback, b_trunc, "clicked")
showall(win)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment