Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tk.TclError "unknown option" tab escape sequence. #120

Closed
Ismael-VC opened this issue Apr 21, 2016 · 0 comments
Closed

Tk.TclError "unknown option" tab escape sequence. #120

Ismael-VC opened this issue Apr 21, 2016 · 0 comments

Comments

@Ismael-VC
Copy link

Ismael-VC commented Apr 21, 2016

I don't understand, Tk treats literal TAB escape sequence inside strings, passed in an AbstractString[] to TreeView, but only when not surrounded by spaces on either side. I red in the documentation that this widget can also be used to make grids/tables, but there is no example. Is it trying to make a grid with the tab separated values? It's always the second word of tab separated words, from the last string in the array, the one that appears to be passed to tcl_eval (can't understand how) as an argument:

julia> using Tk

julia> w = Toplevel()
Tk widget of type Tk.Tk_Toplevel

julia> f = Frame(w)
Tk widget of type Tk.Tk_Frame

julia> Treeview(f, ["a\tb", "c\td"])
ERROR: Tk.TclError
Tk.TclError("unknown option \"b\"")
 in tcl_eval at /home/richit/.julia/v0.4/Tk/src/tkwidget.jl:96
 in tcl_eval at /home/richit/.julia/v0.4/Tk/src/tkwidget.jl:90
 in tcl at /home/richit/.julia/v0.4/Tk/src/core.jl:48
 in set_items at /home/richit/.julia/v0.4/Tk/src/widgets.jl:472
 in Treeview at /home/richit/.julia/v0.4/Tk/src/widgets.jl:454
 in Treeview at /home/richit/.julia/v0.4/Tk/src/widgets.jl:460

julia> Treeview(f, ["a\t b", "c\td"])
ERROR: Tk.TclError("unknown option \"d\"")
 in tcl_eval at /home/richit/.julia/v0.4/Tk/src/tkwidget.jl:96
 in tcl_eval at /home/richit/.julia/v0.4/Tk/src/tkwidget.jl:90
 in tcl at /home/richit/.julia/v0.4/Tk/src/core.jl:48
 in set_items at /home/richit/.julia/v0.4/Tk/src/widgets.jl:472
 in Treeview at /home/richit/.julia/v0.4/Tk/src/widgets.jl:454
 in Treeview at /home/richit/.julia/v0.4/Tk/src/widgets.jl:460

julia> Treeview(f, ["a\t b", "c\t d"])
Tk widget of type Tk.Tk_Treeview

julia> Treeview(f, ["a \tb", "c\td"])
ERROR: Tk.TclError("unknown option \"d\"")
 in tcl_eval at /home/richit/.julia/v0.4/Tk/src/tkwidget.jl:96
 in tcl_eval at /home/richit/.julia/v0.4/Tk/src/tkwidget.jl:90
 in tcl at /home/richit/.julia/v0.4/Tk/src/core.jl:48
 in set_items at /home/richit/.julia/v0.4/Tk/src/widgets.jl:472
 in Treeview at /home/richit/.julia/v0.4/Tk/src/widgets.jl:454
 in Treeview at /home/richit/.julia/v0.4/Tk/src/widgets.jl:460

julia> Treeview(f, ["a \tb", "c \td"])
Tk widget of type Tk.Tk_Treeview

julia> Treeview(f, ["a b", "c d"])
Tk widget of type Tk.Tk_Treeview

julia> VERSION
v"0.4.5"

julia> Pkg.status("Tk")
 - Tk                            0.3.7+             master

My case was even more weird since it worked at first. I was just testing Tk and ODBC (total GUI noob here). I put it here in case it's useful.

I have an app like this:

#!/usr/bin/env julia


using ODBC, Tk, DataFrames


function update_app(w)
    info("Actualizando!")
    datos = query("SELECT * FROM alertas;")
    registros = AbstractString[]
    for dato in eachrow(datos)
        id             = dato[:id]
        ip             = dato[:ip]
        lugar          = dato[:lugar]
        fecha          = dato[:fecha_hora]
        latitud        = dato[:latitud]
        longitud       = dato[:longitud]
        atendido       = dato[:atendido]
        fecha_atendido = dato[:fecha_hora_atendido]
        registro = [id, ip, lugar, fecha, latitud, longitud, atendido, fecha_atendido]
        registro = join(registro, "\t")   # Booom!!!
        push!(registros, registro)
    end

    pop!(w.children)
    f = Frame(w)
    pack(f, expand = true, fill = "both")
    f1 = Frame(f)    # need internal frame for use with scrollbars
    lb = Treeview(f1, reverse(registros))
    scrollbars_add(f1, lb)
    pack(f1, expand = true, fill = "both")
    b = Button(f, "Ok")
    pack(b)
    bind(b, "command") do path
        ip_addr = match(r"^.*?(\d+\.\d+\.\d+\.\d+)\s*.*$", get_value(lb)[1]).captures[1]
        run(`firefox "http://$(ip_addr):9000"`)
    end
    sleep(5)
    forget(f)
    update_app(w)
end

function c5_app()
    w = Toplevel("Consola C5")
    set_size(w, 500, 300)
    tcl("pack", "propagate", w, false)
    Frame(w)
    update_app(w)
end

ODBC.connect("c5db")
c5_app()

And the table looks like this:

MariaDB [c5db]> select * from alertas;
+----+---------------+-----------------+---------------------+-----------+----------+----------+---------------------+
| id | ip            | lugar           | fecha_hora          | latitud   | longitud | atendido | fecha_hora_atendido |
+----+---------------+-----------------+---------------------+-----------+----------+----------+---------------------+
|  1 | 192.168.1.113 | chazaro's house | 2016-04-12 00:00:00 | 13.000467 | 17.00234 |        0 | NULL                |
|  2 | 192.168.1.113 | chazaro's house | 2016-04-13 00:00:00 | 19.000467 | 19.00234 |        0 | NULL                |
|  3 | 192.168.1.113 | chazaro's house | 2016-04-13 13:20:00 | 13.000467 | 17.00234 |        0 | NULL                |
|  4 | 192.168.1.113 | chazaro's house | 2016-04-15 19:00:10 | 13.000467 | 17.00234 |        0 | NULL                |
|  5 | 192.168.1.113 | chazaro's house | 2016-04-13 19:05:30 | 13.000467 | 17.00234 |        0 | NULL                |
|  6 | 192.168.1.113 | chazaros house  | 2016-04-13 13:20:10 | 13.000467 | 17.00234 |        0 | NULL                |
|  7 | 192.168.1.113 | chazaros house  | 2016-04-13 13:20:10 | 13.000467 | 17.00234 |        0 | NULL                |
|  8 | 192.168.1.113 | cazaros house   | 2016-04-18 11:16:07 | 13.000467 | 17.00234 |        0 | NULL                |
|  9 | 192.168.1.113 | cazaros house   | 2016-04-18 11:16:07 | 13.000467 | 17.00234 |        0 | NULL                |
| 10 | 192.168.1.113 | cazaros house   | 2016-04-18 11:16:07 | 13.000467 | 17.00234 |        0 | NULL                |
| 11 | 192.168.1.132 | cazaros house   | 2016-04-18 12:09:00 | 13.000467 | 17.00234 |        0 | NULL                |
| 12 | 192.168.1.132 | cazaros house   | 2016-04-18 12:09:00 | 13.000467 | 17.00234 |        0 | NULL                |
| 13 | 192.168.1.132 | cazaros house   | 2016-04-18 12:09:00 | 13.000467 | 17.00234 |        0 | NULL                |
| 14 | 192.168.1.132 | cazaros house   | 2016-04-18 12:09:00 | 13.000467 | 17.00234 |        0 | NULL                |
| 15 | 192.168.1.132 | cazaros house   | 2016-04-18 12:09:00 | 13.000467 | 17.00234 |        0 | NULL                |
| 16 | 192.168.1.132 | cazaros house   | 2016-04-18 12:09:00 | 13.000467 | 17.00234 |        0 | NULL                |
| 17 | 192.168.1.132 | cazaros house   | 2016-04-18 12:09:00 | 13.000467 | 17.00234 |        0 | NULL                |
| 18 | 192.168.1.132 | cazaros house   | 2016-04-18 12:09:00 | 13.000467 | 17.00234 |        0 | NULL                |
+----+---------------+-----------------+---------------------+-----------+----------+----------+---------------------+
18 rows in set (0.01 sec)

It works!

screenshot_20160421_014031

But oddly if add a new register to the database, it breaks, and only the last entry is an error now!

MariaDB [c5db]> insert into alertas (id, ip, lugar, fecha_hora, latitud, longitud, atendido, fecha_hora_atendido)
 values (19, "Booom!!!", "test", NOW(), 13.1416, 13.1416, 0, now());
Query OK, 1 row affected (0.02 sec)

Now it's broken:

screenshot_20160421_015442

[richit@alertas ~]$ julia c5_app.jl 
INFO: Actualizando!
ERROR: LoadError: Tk.TclError("unknown option \"Booom!!!\"")
 in tcl_eval at /home/richit/.julia/v0.4/Tk/src/tkwidget.jl:96
 in tcl_eval at /home/richit/.julia/v0.4/Tk/src/tkwidget.jl:90
 in tcl at /home/richit/.julia/v0.4/Tk/src/core.jl:48
 in set_items at /home/richit/.julia/v0.4/Tk/src/widgets.jl:472
 in Treeview at /home/richit/.julia/v0.4/Tk/src/widgets.jl:454
 in update_app at /home/richit/c5_app.jl:29
 in c5_app at /home/richit/c5_app.jl:48
 in include at ./boot.jl:261
 in include_from_node1 at ./loading.jl:320
 in process_options at ./client.jl:280
 in _start at ./client.jl:378
while loading /home/richit/c5_app.jl, in expression starting on line 52

So I finally understood that changing \t for spaces solves the issue, but why? And why only when I inserted a new record with sql? (I'll have to look the exact SQL code used by my friend who populated the database and adds records via clicks on a RaspberryPi button, still I really can't see why this matters), if I add more registers to the table, it only fails from now on with the last register, second word between tabs, ie: ["OK\tOK\tOK", "OK\tOK\tOK", "OK\tBooom!!!\tOK?"]
here ---------------------------------------------------------^

I seem to be good as long as I change the tabs for spaces, ie: registro = join(registro, "\t") for registro = join(registro, " ").

@Ismael-VC Ismael-VC changed the title Tk.TclError "unknown option" tab escape secuence. Tk.TclError "unknown option" tab escape sequence. Apr 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant