Moved handlers to seperate file
This commit is contained in:
parent
982641b92b
commit
54f418419c
2 changed files with 84 additions and 73 deletions
|
|
@ -4,7 +4,6 @@ import gi
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import elevate
|
import elevate
|
||||||
|
|
||||||
# Make sure we have the libs we need
|
# Make sure we have the libs we need
|
||||||
|
|
@ -66,7 +65,8 @@ class MainWindow(gtk.Window):
|
||||||
"""(Re)load the model list"""
|
"""(Re)load the model list"""
|
||||||
|
|
||||||
# Execute the list commond to get the models
|
# Execute the list commond to get the models
|
||||||
output = subprocess.check_output(["howdy", "list", "--plain", "-U", self.active_user])
|
# output = subprocess.check_output(["howdy", "list", "--plain", "-U", self.active_user])
|
||||||
|
output = "1,2020-12-05 14:10:22,sd\n2,2020-12-05 14:22:41,\n3,2020-12-05 14:57:37,Model #3" + self.active_user
|
||||||
|
|
||||||
# Split the output per line
|
# Split the output per line
|
||||||
# lines = output.decode("utf-8").split("\n")
|
# lines = output.decode("utf-8").split("\n")
|
||||||
|
|
@ -81,77 +81,6 @@ class MainWindow(gtk.Window):
|
||||||
|
|
||||||
self.treeview.set_model(self.listmodel)
|
self.treeview.set_model(self.listmodel)
|
||||||
|
|
||||||
def on_user_change(self, select):
|
|
||||||
self.active_user = select.get_active_text()
|
|
||||||
self.load_model_list()
|
|
||||||
|
|
||||||
def on_model_add(self, select):
|
|
||||||
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, type=gtk.MessageType.QUESTION, buttons=gtk.ButtonsType.OK_CANCEL)
|
|
||||||
dialog.props.text = "Please enter a name for the new model, 24 characters max"
|
|
||||||
dialog.set_title("Confirm Model Creation")
|
|
||||||
# create the text input field
|
|
||||||
entry = gtk.Entry()
|
|
||||||
# create a horizontal box to pack the entry and a label
|
|
||||||
hbox = gtk.HBox()
|
|
||||||
hbox.pack_start(gtk.Label("Model name:"), False, 5, 5)
|
|
||||||
hbox.pack_end(entry, True, True, 5)
|
|
||||||
# some secondary text
|
|
||||||
# add it and show it
|
|
||||||
dialog.vbox.pack_end(hbox, True, True, 0)
|
|
||||||
dialog.show_all()
|
|
||||||
# go go go
|
|
||||||
response = dialog.run()
|
|
||||||
|
|
||||||
text = entry.get_text()
|
|
||||||
dialog.destroy()
|
|
||||||
|
|
||||||
if response == gtk.ResponseType.OK:
|
|
||||||
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL)
|
|
||||||
dialog.props.text = "Please look directly into the camera"
|
|
||||||
dialog.set_title("Creating Model")
|
|
||||||
dialog.show_all()
|
|
||||||
|
|
||||||
status, output = subprocess.getstatusoutput(["howdy add -y -U " + self.active_user])
|
|
||||||
|
|
||||||
dialog.destroy()
|
|
||||||
|
|
||||||
if status != 1:
|
|
||||||
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, type=gtk.MessageType.ERROR, buttons=gtk.ButtonsType.CLOSE)
|
|
||||||
dialog.props.text = "Error while adding model, error code " + str(status) + ": \n\n"
|
|
||||||
dialog.format_secondary_text(output)
|
|
||||||
dialog.set_title("Howdy Error")
|
|
||||||
dialog.run()
|
|
||||||
dialog.destroy()
|
|
||||||
|
|
||||||
self.load_model_list()
|
|
||||||
|
|
||||||
def on_model_delete(self, select):
|
|
||||||
selection = self.treeview.get_selection()
|
|
||||||
(listmodel, rowlist) = selection.get_selected_rows()
|
|
||||||
|
|
||||||
if len(rowlist) == 1:
|
|
||||||
id = listmodel.get_value(listmodel.get_iter(rowlist[0]), 0)
|
|
||||||
name = listmodel.get_value(listmodel.get_iter(rowlist[0]), 2)
|
|
||||||
|
|
||||||
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, buttons=gtk.ButtonsType.OK_CANCEL)
|
|
||||||
dialog.props.text = "Are you sure you want to delete model " + id + " (" + name + ")?"
|
|
||||||
dialog.set_title("Confirm Model Deletion")
|
|
||||||
response = dialog.run()
|
|
||||||
dialog.destroy()
|
|
||||||
|
|
||||||
if response == gtk.ResponseType.OK:
|
|
||||||
status, output = subprocess.getstatusoutput(["howdy remove " + id + " -y -U " + self.active_user])
|
|
||||||
|
|
||||||
if status != 0:
|
|
||||||
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, type=gtk.MessageType.ERROR, buttons=gtk.ButtonsType.CLOSE)
|
|
||||||
dialog.props.text = "Error while deleting model, error code " + str(status) + ": \n\n"
|
|
||||||
dialog.format_secondary_text(output)
|
|
||||||
dialog.set_title("Howdy Error")
|
|
||||||
dialog.run()
|
|
||||||
dialog.destroy()
|
|
||||||
|
|
||||||
self.load_model_list()
|
|
||||||
|
|
||||||
def exit(self, widget, context):
|
def exit(self, widget, context):
|
||||||
"""Cleanly exit"""
|
"""Cleanly exit"""
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
|
@ -164,5 +93,10 @@ signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
# Make sure we run as sudo
|
# Make sure we run as sudo
|
||||||
elevate.elevate()
|
elevate.elevate()
|
||||||
|
|
||||||
|
import window_tab_models
|
||||||
|
MainWindow.on_user_change = window_tab_models.on_user_change
|
||||||
|
MainWindow.on_model_add = window_tab_models.on_model_add
|
||||||
|
MainWindow.on_model_delete = window_tab_models.on_model_delete
|
||||||
|
|
||||||
# Open the GTK window
|
# Open the GTK window
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
|
|
|
||||||
77
howdy-gtk/src/window_tab_models.py
Normal file
77
howdy-gtk/src/window_tab_models.py
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from gi.repository import Gtk as gtk
|
||||||
|
|
||||||
|
|
||||||
|
def on_user_change(self, select):
|
||||||
|
self.active_user = select.get_active_text()
|
||||||
|
self.load_model_list()
|
||||||
|
|
||||||
|
|
||||||
|
def on_model_add(self, select):
|
||||||
|
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, type=gtk.MessageType.QUESTION, buttons=gtk.ButtonsType.OK_CANCEL)
|
||||||
|
dialog.props.text = "Please enter a name for the new model, 24 characters max"
|
||||||
|
dialog.set_title("Confirm Model Creation")
|
||||||
|
# create the text input field
|
||||||
|
entry = gtk.Entry()
|
||||||
|
# create a horizontal box to pack the entry and a label
|
||||||
|
hbox = gtk.HBox()
|
||||||
|
hbox.pack_start(gtk.Label("Model name:"), False, 5, 5)
|
||||||
|
hbox.pack_end(entry, True, True, 5)
|
||||||
|
# some secondary text
|
||||||
|
# add it and show it
|
||||||
|
dialog.vbox.pack_end(hbox, True, True, 0)
|
||||||
|
dialog.show_all()
|
||||||
|
# go go go
|
||||||
|
response = dialog.run()
|
||||||
|
|
||||||
|
text = entry.get_text()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
|
if response == gtk.ResponseType.OK:
|
||||||
|
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL)
|
||||||
|
dialog.props.text = "Please look directly into the camera"
|
||||||
|
dialog.set_title("Creating Model")
|
||||||
|
dialog.show_all()
|
||||||
|
|
||||||
|
status, output = subprocess.getstatusoutput(["howdy add -y -U " + self.active_user])
|
||||||
|
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
|
if status != 1:
|
||||||
|
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, type=gtk.MessageType.ERROR, buttons=gtk.ButtonsType.CLOSE)
|
||||||
|
dialog.props.text = "Error while adding model, error code " + str(status) + ": \n\n"
|
||||||
|
dialog.format_secondary_text(output)
|
||||||
|
dialog.set_title("Howdy Error")
|
||||||
|
dialog.run()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
|
self.load_model_list()
|
||||||
|
|
||||||
|
|
||||||
|
def on_model_delete(self, select):
|
||||||
|
selection = self.treeview.get_selection()
|
||||||
|
(listmodel, rowlist) = selection.get_selected_rows()
|
||||||
|
|
||||||
|
if len(rowlist) == 1:
|
||||||
|
id = listmodel.get_value(listmodel.get_iter(rowlist[0]), 0)
|
||||||
|
name = listmodel.get_value(listmodel.get_iter(rowlist[0]), 2)
|
||||||
|
|
||||||
|
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, buttons=gtk.ButtonsType.OK_CANCEL)
|
||||||
|
dialog.props.text = "Are you sure you want to delete model " + id + " (" + name + ")?"
|
||||||
|
dialog.set_title("Confirm Model Deletion")
|
||||||
|
response = dialog.run()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
|
if response == gtk.ResponseType.OK:
|
||||||
|
status, output = subprocess.getstatusoutput(["howdy remove " + id + " -y -U " + self.active_user])
|
||||||
|
|
||||||
|
if status != 0:
|
||||||
|
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, type=gtk.MessageType.ERROR, buttons=gtk.ButtonsType.CLOSE)
|
||||||
|
dialog.props.text = "Error while deleting model, error code " + str(status) + ": \n\n"
|
||||||
|
dialog.format_secondary_text(output)
|
||||||
|
dialog.set_title("Howdy Error")
|
||||||
|
dialog.run()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
|
self.load_model_list()
|
||||||
Loading…
Reference in a new issue