Skip to content

Commit

Permalink
Add log and about tab
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandoislas committed May 8, 2017
1 parent ee59b60 commit ba4fe93
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/server/data/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

# Info
VERSION = "1.5"
VERSION = "1.6"
NAME = "DRC SIM Server"

# Port
PORT_WII_MSG = 50010
Expand Down
24 changes: 24 additions & 0 deletions src/server/ui/gui/frame/frame_about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from tkinter import Label

from src.server.data import constants
from src.server.ui.gui.frame.frame_tab import FrameTab


class FrameAbout(FrameTab):
def __init__(self, master=None, **kw):
super().__init__(master, **kw)
self.text_name = Label(self, text=constants.NAME)
self.text_version = Label(self, text="v" + constants.VERSION)

self.text_name.grid(row=0, column=0)
self.text_version.grid(row=1, column=0)
self.grid_columnconfigure(0, weight=1)

def activate(self):
pass

def deactivate(self):
pass

def kill_other_tabs(self):
return False
7 changes: 6 additions & 1 deletion src/server/ui/gui/frame/frame_get_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def activate(self):
self.getting_psk = False
self.set_code_text("")
self.progress_bar.start()
self.progress_bar.grid_remove()
if not self.wpa_supplicant or not self.wpa_supplicant.get_status():
self.progress_bar.grid_remove()
self.dropdown_wii_u["values"] = InterfaceUtil.get_wiiu_compatible_interfaces()

def deactivate(self):
Expand All @@ -142,6 +143,7 @@ def deactivate(self):
self.getting_psk = False
if self.wpa_supplicant:
self.wpa_supplicant.stop()
self.wpa_supplicant = None

@staticmethod
def get_image(location, width, height):
Expand All @@ -157,3 +159,6 @@ def set_code_text(self, text):
self.entry_pair_code.delete(0, END)
self.entry_pair_code.insert(0, text)
self.entry_pair_code.config(state="readonly")

def kill_other_tabs(self):
return True
36 changes: 36 additions & 0 deletions src/server/ui/gui/frame/frame_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import subprocess
from tkinter import Button, CENTER, messagebox

from src.server.data import constants
from src.server.ui.gui.frame.frame_tab import FrameTab


class FrameLog(FrameTab):
def __init__(self, master=None, **kw):
super().__init__(master, **kw)
self.button_log = Button(self, text="Open Log in Console")
self.button_log.bind("<Button-1>", self.button_clicked)
self.button_log.place(relx=0.5, rely=0.5, anchor=CENTER)
self.log = None

# noinspection PyUnusedLocal
def button_clicked(self, event):
tail = ["x-terminal-emulator", "-e", "tail", "-f"]
for file in ("drcsim", "cli", "gui", "wpa", "backend"):
tail.append(os.path.join(constants.PATH_LOG_DIR, file + ".log"))
self.deactivate()
try:
self.log = subprocess.Popen(tail, stdout=open(os.devnull, "w"), stderr=subprocess.PIPE)
except FileNotFoundError:
messagebox.showerror("Log Error", "Could not open log window.")

def activate(self):
pass

def deactivate(self):
if self.log and self.log.poll() is None:
self.log.kill()

def kill_other_tabs(self):
return False
11 changes: 9 additions & 2 deletions src/server/ui/gui/frame/frame_run_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ def stop_server(self, event=None):
return
if self.gamepad:
self.gamepad.close()
self.gamepad = None
if self.wpa_supplicant:
self.wpa_supplicant.stop()
self.wpa_supplicant = None
self.activate()

def activate(self):
Expand All @@ -181,8 +183,10 @@ def activate(self):
self.dropdown_wiiu_interface["values"] = InterfaceUtil.get_wiiu_compatible_interfaces()
self.dropdown_normal_interface["values"] = InterfaceUtil.get_all_interfaces()
self.dropdown_region["values"] = ["NONE", "NA"]
self.label_wpa_status["text"] = WpaSupplicant.DISCONNECTED
self.label_backend_status["text"] = Gamepad.STOPPED
self.label_wpa_status["text"] = self.wpa_supplicant.get_status() \
if self.wpa_supplicant and self.wpa_supplicant.get_status() else WpaSupplicant.DISCONNECTED
self.label_backend_status["text"] = self.gamepad.get_status() \
if self.gamepad and self.gamepad.get_status() else Gamepad.STOPPED
self.button_start.config(state="normal")
self.button_stop.config(state="normal")
self.label_interface_info.config(text="")
Expand All @@ -194,3 +198,6 @@ def deactivate(self):
"""
LoggerGui.debug("FrameRunServer deactivated")
self.stop_server()

def kill_other_tabs(self):
return True
3 changes: 3 additions & 0 deletions src/server/ui/gui/frame/frame_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ def activate(self):

def deactivate(self):
raise NotImplementedError()

def kill_other_tabs(self):
raise NotImplementedError()
16 changes: 13 additions & 3 deletions src/server/ui/gui/gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from tkinter.ttk import Notebook

from src.server.data.resource import Resource
from src.server.ui.gui.frame.frame_about import FrameAbout
from src.server.ui.gui.frame.frame_get_key import FrameGetKey
from src.server.ui.gui.frame.frame_log import FrameLog
from src.server.ui.gui.frame.frame_run_server import FrameRunServer
from src.server.util.logging.logger_gui import LoggerGui

Expand Down Expand Up @@ -33,6 +35,12 @@ def __init__(self):
# Get Key Frame
self.frame_get_key = FrameGetKey(self.notebook)
self.notebook.add(self.frame_get_key, text="Get Key")
# Log Frame
self.frame_log = FrameLog(self.notebook)
self.notebook.add(self.frame_log, text="Log")
# About Frame
self.frame_about = FrameAbout(self.notebook)
self.notebook.add(self.frame_about, text="About")

@staticmethod
def throw(*args):
Expand Down Expand Up @@ -96,7 +104,9 @@ def on_tab_changed(self, event):
tab_index = self.notebook.index(tab_id)
tab_name = self.notebook.tab(tab_index, "text")
LoggerGui.debug("Notebook tab changed to \"%s\" with id %d", tab_name, tab_index)
if self.tab_id:
self.notebook.children[self.tab_id].deactivate()
self.tab_id = tab_id.split(".")[len(tab_id.split(".")) - 1]
self.tab_id = tab_id.split(".")[len(tab_id.split(".")) - 1] # Parse notebook/tab id to only tab id
if self.notebook.children[self.tab_id].kill_other_tabs():
for tab in self.notebook.children:
if tab != self.tab_id:
self.notebook.children[tab].deactivate()
self.notebook.children[self.tab_id].activate()
7 changes: 7 additions & 0 deletions src/server/util/status_sending_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def set_status(self, status):
for listener in self.status_change_listeners:
listener(status)

def get_status(self):
"""
Status getter
:return: status string
"""
return self.status

def add_status_change_listener(self, callback):
"""
Add a callback that will be called on status change.
Expand Down

0 comments on commit ba4fe93

Please sign in to comment.