Skip to content

Commit

Permalink
added function that resets the GUI in a more elegant way
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsgalore committed Dec 4, 2018
1 parent 752db32 commit 4cb07d4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
5 changes: 3 additions & 2 deletions tapeimgr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def main():
if myCLI.tape.tapeDeviceIOError:
# Tape device not accessible
msg = ('Cannot access tape device ' + myCLI.tape.tapeDevice +
'. Check that device exists, and that tapeimgr is run as root')
'. Check that device exists, and that current user has permission ' +
'to access it')
errorExit(msg)
elif myCLI.tape.successFlag:
# Tape extraction completed with no errors
Expand All @@ -209,7 +210,7 @@ def main():
else:
# Tape extraction resulted in errors
msg = ('One or more errors occurred while processing tape, '
'check log file for details')
'check log file for details')
errorExit(msg)
except Exception as e:
# Unexpected error
Expand Down
41 changes: 39 additions & 2 deletions tapeimgr/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def build_gui(self):
tk.Label(self, text='Files (comma-separated list)').grid(column=0, row=8, sticky='w')
self.files_entry = tk.Entry(self, width=20)
self.files_entry['background'] = 'white'
self.files_entry.insert(tk.END, self.tape.files)
self.files_entry.grid(column=1, row=8, sticky='w')

# Prefix
Expand Down Expand Up @@ -259,6 +260,33 @@ def build_gui(self):
"Run '(sudo) tapeimgr-config' to fix this.")
errorExit(msg)

def reset_gui(self):
"""Reset the GUI"""
# Create new tape instance
self.tape = Tape()
# Read configuration
self.tape.getConfiguration()
# Logging stuff
self.logger = logging.getLogger()
# Create a logging handler using a queue
self.log_queue = queue.Queue(-1)
self.queue_handler = QueueHandler(self.log_queue)
# Reset all entry widgets
self.outDirLabel['text'] = self.tape.dirOut
self.tapeDevice_entry.delete(0, tk.END)
self.tapeDevice_entry.insert(tk.END, self.tape.tapeDevice)
self.initBlockSize_entry.delete(0, tk.END)
self.initBlockSize_entry.insert(tk.END, self.tape.initBlockSize)
self.files_entry.delete(0, tk.END)
self.files_entry.insert(tk.END, self.tape.files)
self.prefix_entry.delete(0, tk.END)
self.prefix_entry.insert(tk.END, self.tape.prefix)
self.extension_entry.delete(0, tk.END)
self.extension_entry.insert(tk.END, self.tape.extension)
self.fillblocks_entry.variable = self.tape.fillBlocks
self.start_button.config(state='normal')
self.quit_button.config(state='normal')

def setupLogger(self):
"""Set up logger configuration"""

Expand Down Expand Up @@ -343,6 +371,13 @@ def main():
time.sleep(0.1)
if myGUI.tape.finishedFlag:
myGUI.t1.join()
#myGUI.logger.removeHandler(myGUI.queue_handler)
#myGUI.queue_handler.close()
handlers = myGUI.logger.handlers[:]
for handler in handlers:
handler.close()
myGUI.logger.removeHandler(handler)

if myGUI.tape.tapeDeviceIOError:
# Tape device not accessible
msg = ('Cannot access tape device ' + myGUI.tape.tapeDevice +
Expand All @@ -359,8 +394,10 @@ def main():
tkMessageBox.showwarning("Errors occurred", msg)

# Restart the program
python = sys.executable
os.execl(python, python, * sys.argv)
#python = sys.executable
#os.execl(python, python, * sys.argv)
# Reset the GUI
myGUI.reset_gui()

except Exception as e:
# Unexpected error
Expand Down
2 changes: 1 addition & 1 deletion tapeimgr/tapeimgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .gui import main as guiLaunch
from . import config

__version__ = '0.2.6'
__version__ = '0.2.7'

def main():
"""Launch GUI if no command line arguments were given; otherwise launch CLI"""
Expand Down

0 comments on commit 4cb07d4

Please sign in to comment.