Skip to content

Commit

Permalink
Tutorial on first run
Browse files Browse the repository at this point in the history
  • Loading branch information
DoTheEvo committed Mar 7, 2015
1 parent ad8dfce commit 9db1c17
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions angrysearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


# QTHREAD FOR ASYNC SEARCHES IN THE DATABASE
# CALLED ON EVERY KEYPRESS
# RETURNS FIRST 500 RESULTS MATCHING THE QUERY
class thread_db_query(QThread):
db_query_signal = pyqtSignal(dict)
Expand Down Expand Up @@ -124,7 +125,7 @@ def replace_old_db_with_new(self):
con = sqlite3.connect(self.db_path, check_same_thread=False)


# THE PRIMARY GUI WIDGET WITHIN THE MAINWINDOW
# THE PRIMARY GUI, WIDGET WITHIN THE MAINWINDOW
class center_widget(QWidget):
def __init__(self):
super(center_widget, self).__init__()
Expand All @@ -134,7 +135,6 @@ def initUI(self):
self.search_input = QLineEdit()
self.main_list = QListView()
self.upd_button = QPushButton('updatedb')
self.upd_button.setToolTip('run sudo updated & update local database')

grid = QGridLayout()
grid.setSpacing(10)
Expand All @@ -158,8 +158,6 @@ def closeEvent(self, event):
self.settings.setValue('geometry', self.saveGeometry())
self.settings.setValue("window_state", self.saveState())
event.accept()
#event.ignore()
#self.hide()

def read_settings(self):
if self.settings.value('geometry'):
Expand Down Expand Up @@ -197,14 +195,14 @@ def init_GUI(self):
self.center.upd_button.clicked.connect(self.clicked_button_updatedb)

self.show()
self.initialisation()
self.show_first_500()
self.make_sys_tray()
self.detect_file_manager()

def make_sys_tray(self):
if QSystemTrayIcon.isSystemTrayAvailable():
menu = QMenu()
menu.addAction("v1.0.0")
menu.addAction("v0.9.0")
menu.addSeparator()
exitAction = menu.addAction("Quit")
exitAction.triggered.connect(sys.exit)
Expand Down Expand Up @@ -242,23 +240,23 @@ def get_icon(self):

def on_input_change(self, input):
if input == '':
self.initialisation()
self.show_first_500()
return
search_terms = input.split(' ')
t = '*'
for x in search_terms:
t += x + '*'
self.new_thread_new_query(t)
self.new_query_new_thread(t)

def new_thread_new_query(self, input):
def new_query_new_thread(self, input):
if len(self.threads) > 30:
del self.threads[0:9]
self.threads.append({'input': input, 'thread': thread_db_query(input)})
self.threads[-1]['thread'].start()
self.threads[-1]['thread'].db_query_signal.connect(
self.database_query_done, Qt.QueuedConnection)

# CHECKS IF THE QUERY IS THE LAST ONE BEFORE SHOWING DATA
# CHECK IF THE QUERY IS THE LAST ONE BEFORE SHOWING DATA
def database_query_done(self, db_query_result):
if (db_query_result['input'] != self.threads[-1]['input']):
return
Expand All @@ -271,12 +269,14 @@ def update_file_list_results(self, data):
self.status_bar.showMessage(total)

# RUNS ON START OR ON EMPTY INPUT
def initialisation(self):
def show_first_500(self):
cur = con.cursor()
cur.execute('SELECT name FROM sqlite_master WHERE '
'type="table" AND name="locate_data_table"')
if cur.fetchone() is None:
self.status_bar.showMessage('Update the database')
self.status_bar.showMessage('0')
self.tutorial()
self.center.upd_button.setFocus()
return

cur.execute('SELECT file_path_col FROM locate_data_table LIMIT 500')
Expand All @@ -293,7 +293,7 @@ def initialisation(self):
def single_click(self, QModelIndex):
path = QModelIndex.data()
if not os.path.exists(path):
self.status_bar.showMessage('not found - update database')
self.status_bar.showMessage('not found or access denied')
return

mime = subprocess.check_output(['xdg-mime', 'query', 'filetype', path])
Expand All @@ -305,7 +305,7 @@ def double_click(self, QModelIndex):
return
path = QModelIndex.data()
if not os.path.exists(path):
self.status_bar.showMessage('not found - update database')
self.status_bar.showMessage('not found or access denied')
return

dolphin = re.compile("^.*dolphin.*$", re.IGNORECASE)
Expand Down Expand Up @@ -336,10 +336,27 @@ def detect_file_manager(self):
self.file_manager = False
print(err)

def tutorial(self):
chat = ['', ' ANGRYsearch', '',
' • uses "locate" command to create own database',
' • locate uses "updatedb" command for its own database',
' • configuration can be find in /etc/updatedb.conf',
' • there you can exclude/include paths for searching',
' • for btrfs users, you really want to exclude snapshots',
' • add ".snapshots" to PRUNENAMES if you use snapper',
' • learn more about locate on its manpage',
' • learn more about updatedb on its manpage',
' • ANGRYsearch database is in /var/lib/angrysearch/',
'',
' time to press the updatedb button in the top right corner'
]
model = QStringListModel(chat)
self.center.main_list.setModel(model)

def clicked_button_updatedb(self):
self.sud = sudo_dialog(self)
self.sud.exec_()
self.initialisation()
self.show_first_500()


# UPDATE DATABASE DIALOG WITH PROGRESS SHOWN
Expand Down

0 comments on commit 9db1c17

Please sign in to comment.