move a lot of codes out of ui_gtk/utils.py