Zim

No text input window on startup

Bug #1492624 reported by Zachary
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zim
Confirmed
Undecided
Unassigned

Bug Description

Running on Linux Mint 17 KDE 64-bit. Things were fine, I closed the application once, decided to open it again a few minutes later, and the bug was in effect. I don't know if it's my system or not. I tried rebooting and re-installing the program and got the same error with both steps...

On startup, I get this error:

Looks like you found a bug

TypeError: GtkTextBuffer.insert_at_cursor() argument 1 must be string or read-only buffer, not None

When reporting this bug please include the information from the text box below:

This is zim 0.60
Python version is sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)
Gtk version is (2, 24, 23)
Pygtk version is (2, 24, 0)
Platform is posix
Zim revision is:
  branch: pyzim-trunk
  revision: 672 <email address hidden>
  date: 2013-04-30 19:27:20 +0200

======= Traceback =======
  File "/usr/lib/python2.7/dist-packages/zim/gui/pageview.py", line 4659, in set_page
    self.set_parsetree(tree, bool(template))
  File "/usr/lib/python2.7/dist-packages/zim/gui/pageview.py", line 4750, in set_parsetree
    buffer.set_parsetree(tree)
  File "/usr/lib/python2.7/dist-packages/zim/gui/pageview.py", line 605, in set_parsetree
    self.insert_parsetree_at_cursor(tree)
  File "/usr/lib/python2.7/dist-packages/zim/gui/pageview.py", line 672, in insert_parsetree_at_cursor
    self._insert_element_children(root, raw=raw)
  File "/usr/lib/python2.7/dist-packages/zim/gui/pageview.py", line 745, in _insert_element_children
    self._insert_element_children(element, list_level=list_level, raw=raw) # recurs
  File "/usr/lib/python2.7/dist-packages/zim/gui/pageview.py", line 786, in _insert_element_children
    self.insert_link_at_cursor(element.text, **element.attrib)
  File "/usr/lib/python2.7/dist-packages/zim/gui/pageview.py", line 846, in insert_link_at_cursor
    self.insert_at_cursor(text)
TypeError: GtkTextBuffer.insert_at_cursor() argument 1 must be string or read-only buffer, not None

The error only appears when I try to open the following file, found under "3) DCS:Knowledge Base:Scripting:Bash:Bash Logic". It's a .txt file, and contains:

Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.4
Creation-Date: 2015-09-04T22:37:24-06:00

====== Bash Logic ======
Created Friday 04 September 2015

===== If you just want an 'and' comparator in bash... =====
'''
foo='a'
var='b'
if [[ $foo == 'a' && ( $var == 'b' ) ]] ; then echo 'x' ; fi
x
'''

===== Simple logical operators in BASH =====

I have a couple of variables and I want to check the following condition (written out in words, then my failed attempt at bash scripting):

'''
if varA EQUALS 1 AND ( varB EQUALS "t1" OR varB EQUALS "t2" ) then
do something
done.
'''

And in my failed attempt, I came up with:

'''
if (($varA == 1)) && ( (($varB == "t1")) || (($varC == "t2")) );
  then
    scale=0.05
  fi
'''

What you've written actually almost works (it would work if all the variables were numbers), but it's not an idiomatic way at all.

(…) parentheses indicate a subshell. What's inside them isn't an expression like in many other languages. It's a list of commands (just like outside parentheses). These commands are executed in a separate subprocess, so any redirection, assignment, etc. performed inside the parentheses has no effect outside the parentheses.
With a leading dollar sign, $(…) is a command substitution: there is a command inside the parentheses, and the output from the command is used as part of the command line (after extra expansions unless the substitution is between double quotes, but that's another story).
{ … } braces are like parentheses in that they group commands, but they only influence parsing, not grouping. The program x=2; { x=4; }; echo $x prints 4, whereas x=2; (x=4); echo $x prints 2. (Also braces require spaces around them and a semicolon before closing, whereas parentheses don't. That's just a syntax quirk.)
With a leading dollar sign, ${VAR} is a parameter expansion, expanding to the value of a variable, with possible extra transformations.
((…)) double parentheses surround an arithmetic instruction, that is, a computation on integers, with a syntax resembling other programming languages. This syntax is mostly used for assignments and in conditionals.
The same syntax is used in arithmetic expressions $((…)), which expand to the integer value of the expression.
[[…]] double brackets surround conditional expressions. Conditional expressions are mostly built on operators such as -n $variable to test if a variable is empty and -e $file to test if a file exists. There are also string equality operators: "$string1" = "$string2" (beware that the right-hand side is a pattern, e.g. [[ $foo = a* ]] tests if $foo starts with a while [[ $foo = "a*" ]] tests if $foo is exactly a*), and the familiar !, && and || operators for negation, conjunction and disjunction as well as parentheses for grouping. Note that you need a space around each operator (e.g. [[ "$x" = "$y" ]], not [[ "$x"="$y" ]]), and a space or a character like ; both inside and outside the brackets (e.g. [[ -n $foo ]], not [[-n $foo]]).
[ … ] single brackets are an alternate form of conditional expressions with more quirks (but older and more portable). Don't write any for now; start worrying about them when you find scripts that contain them.
This is the idiomatic way to write your test in bash:

if [[ $varA = 1 && ($varB = "t1" || $varC = "t2") ]]; then
If you need portability to other shells, this would be the way (note the additional quoting and the separate sets of brackets around each individual test):

if [ "$varA" = 1 ] && { [ "$varB" = "t1" ] || [ "$varC" = "t2" ]; } then

I have no clue how just this note makes this part of the program crash, but it causes the main text editor window not to initialize--there is just a blank gray GTK space there, no editing interface. I can click out of that note and into others just fine, though.

Hope that helps! Thanks!

Tags: 2min testcase
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Key to this issue is that your text contains quite often the pattern "[[ ... ]]". This same sequence is used in zim to code links in the wiki text.

Will add this file to test suite and make sure that where parsing fails, it is at least handled gracefully

tags: added: 2min testcase
Changed in zim:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.