# Path: reggata/helpers.py
# def is_none_or_empty(s):
#     '''
#         Returns True, if given string s is None or "" (empty string).
#     If s is and instance of class different from str, function raises TypeError.
#     '''
#     if s is None:
#         return True
#     else:
#         if not isinstance(s, str):
#             raise TypeError("is_none_or_empty() can be applied only to str objects.")
#         return True if s == "" else False
# 
# Path: reggata/data/commands.py
# class GetNamesOfAllTagsAndFields(AbstractCommand):
#     def _execute(self, uow):
#         self._session = uow.session
#         return self.__getNamesOfAllTagsAndFields()
# 
#     def __getNamesOfAllTagsAndFields(self):
#         sql = '''
#         select distinct name from tags
#         UNION
#         select distinct name from fields
#         ORDER BY name
#         '''
#         try:
#             return self._session.query("name").from_statement(sql).all()
#         except ResourceClosedError:
#             return []


import os
import logging
import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore
import reggata.parsers as parsers
import reggata.consts as consts
from PyQt4.QtCore import Qt
from reggata.helpers import is_none_or_empty
from reggata.data.commands import GetNamesOfAllTagsAndFields

        elif event.key() in [Qt.Key_Right]:
            cursor = self.widget.textCursor()
            #cursor.setVisualNavigation(True)
            cursor.movePosition(QtGui.QTextCursor.Right)
            self.widget.setTextCursor(cursor)

        else:
            text = event.text()
            cursor = self.widget.textCursor()
            cursor.insertText(text)


    def submit_word(self, item):
        if self.widget is not None and item is not None:
            cursor = self.widget.textCursor()
            cursor.select(QtGui.QTextCursor.WordUnderCursor)
            word = item.text()
            if parsers.query_tokens.needs_quote(word):
                word = parsers.util.quote(word)
            cursor.insertText(word + self.end_str)
        self.hide()


    def populate_words(self):
        if self.repo is None:
            raise ValueError(self.tr("Completer does'n connected to repository."))

        uow = self.repo.createUnitOfWork()
        try:

# Path: reggata/helpers.py
# def is_none_or_empty(s):
#     '''
#         Returns True, if given string s is None or "" (empty string).
#     If s is and instance of class different from str, function raises TypeError.
#     '''
#     if s is None:
#         return True
#     else:
#         if not isinstance(s, str):
#             raise TypeError("is_none_or_empty() can be applied only to str objects.")
#         return True if s == "" else False
# 
# Path: reggata/data/commands.py
# class GetNamesOfAllTagsAndFields(AbstractCommand):
#     def _execute(self, uow):
#         self._session = uow.session
#         return self.__getNamesOfAllTagsAndFields()
# 
#     def __getNamesOfAllTagsAndFields(self):
#         sql = '''
#         select distinct name from tags
#         UNION
#         select distinct name from fields
#         ORDER BY name
#         '''
#         try:
#             return self._session.query("name").from_statement(sql).all()
#         except ResourceClosedError:
#             return []


# Path: reggata/gui/common_widgets.py
import os
import logging
import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore
import reggata.parsers as parsers
import reggata.consts as consts
from PyQt4.QtCore import Qt
from reggata.helpers import is_none_or_empty
from reggata.data.commands import GetNamesOfAllTagsAndFields


        elif event.key() in [Qt.Key_Right]:
            cursor = self.widget.textCursor()
            #cursor.setVisualNavigation(True)
            cursor.movePosition(QtGui.QTextCursor.Right)
            self.widget.setTextCursor(cursor)

        else:
            text = event.text()
            cursor = self.widget.textCursor()
            cursor.insertText(text)


    def submit_word(self, item):
        if self.widget is not None and item is not None:
            cursor = self.widget.textCursor()
            cursor.select(QtGui.QTextCursor.WordUnderCursor)
            word = item.text()
            if parsers.query_tokens.needs_quote(word):
                word = parsers.util.quote(word)
            cursor.insertText(word + self.end_str)
        self.hide()


    def populate_words(self):
        if self.repo is None:
            raise ValueError(self.tr("Completer does'n connected to repository."))

        uow = self.repo.createUnitOfWork()
        try:

            self.words = uow.executeCommand(GetNamesOfAllTagsAndFields())