add query.py
remove duplicated code
add feature to tab by query (currently this feature replace add tab by name, fix it later)