Skip to content

Commit

Permalink
server gui stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
blawar committed Feb 17, 2019
1 parent a4f2539 commit ea3229f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 10 additions & 1 deletion nut/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def __init__(self):
jsonOutput = False
isRunning = True

autolaunchBrowser = True

titleBlacklist = []
titleWhitelist = []

Expand All @@ -128,7 +130,6 @@ def __init__(self):
def set(j, paths, value):
last = paths.pop()
for path in paths:
print(path)
if not path in j:
j[path] = {}
j = j[path]
Expand All @@ -147,6 +148,8 @@ def save(confFile = 'conf/nut.conf'):
set(j, ['server', 'hostname'], server.hostname)
set(j, ['server', 'port'], server.port)

set(j, ['autolaunchBrowser'], autolaunchBrowser)

with open(confFile, 'w', encoding='utf-8') as f:
json.dump(j, f, indent=4)

Expand All @@ -156,6 +159,7 @@ def load(confFile):
global titleUrls
global region
global language
global autolaunchBrowser

with open(confFile, encoding="utf8") as f:
j = json.load(f)
Expand All @@ -170,6 +174,11 @@ def load(confFile):
except:
pass

try:
autolaunchBrowser = j['autolaunchBrowser']
except:
pass

try:
paths.titleImages = j['paths']['titleImages']
except:
Expand Down
2 changes: 0 additions & 2 deletions nut/Nsps.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def scan(base, force = False):
nsp = Fs.Nsp(path, None)

files[nsp.path] = nsp
#files[nsp.path].readMeta()

i = i + 1
if i % 20 == 0:
Expand All @@ -73,7 +72,6 @@ def scan(base, force = False):
raise
except BaseException as e:
Print.info('An error occurred processing file: ' + str(e))
status.close()

save()
status.close()
Expand Down
21 changes: 19 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import re
import pathlib
import urllib3
import urllib
import json
import webbrowser
import Server

import nut
Expand All @@ -28,7 +30,7 @@
import socket

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget,QTableWidgetItem,QVBoxLayout,QDesktopWidget, QTabWidget, QProgressBar, QLabel,QHBoxLayout, QLineEdit, QPushButton
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget,QTableWidgetItem,QVBoxLayout,QDesktopWidget, QTabWidget, QProgressBar, QLabel,QHBoxLayout, QLineEdit, QPushButton, QCheckBox
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot,Qt,QTimer
from PyQt5 import QtWidgets
Expand Down Expand Up @@ -57,6 +59,11 @@ def __init__(self, app):
self.scan.clicked.connect(app.on_scan)
self.layout.addWidget(self.scan)

self.autolaunchBrowser = QCheckBox("Auto-Launch Web Browser?", app)
self.autolaunchBrowser.setChecked(Config.autolaunchBrowser)
self.autolaunchBrowser.stateChanged.connect(self.onCheck)
self.layout.addWidget(self.autolaunchBrowser)

self.serverInfo = QLabel("IP: %s Port: %s User: %s Password: %s" % (getIpAddress(), str(Config.server.port), Users.first().id, Users.first().password))
self.serverInfo.setFixedWidth(600)
self.serverInfo.setAlignment(Qt.AlignCenter)
Expand All @@ -75,6 +82,16 @@ def __init__(self, app):

Users.export()

if Config.autolaunchBrowser:
webbrowser.open_new_tab('http://' + urllib.parse.quote_plus(Users.first().id) + ':' + urllib.parse.quote_plus(Users.first().password) + '@' + getIpAddress() + ':' + str(Config.server.port))

def onCheck(self, state):
if state == Qt.Checked:
Config.autolaunchBrowser = True
else:
Config.autolaunchBrowser = False
Config.save()

def updatePath(self):
Config.paths.scan = self.textbox.text()
Config.save()
Expand Down Expand Up @@ -131,7 +148,7 @@ def __init__(self):
super().__init__()
self.setWindowIcon(QIcon('public_html/images/logo.jpg'))
screen = QDesktopWidget().screenGeometry()
self.title = 'NUT USB / Web Server'
self.title = 'NUT USB / Web Server v1.1'
self.left = screen.width() / 4
self.top = screen.height() / 4
self.width = screen.width() / 2
Expand Down

0 comments on commit ea3229f

Please sign in to comment.