2017-12-26 07:25:29 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
'''
|
|
|
|
Onionr - P2P Microblogging Platform & Social network
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-02-02 05:39:55 +00:00
|
|
|
'''
|
|
|
|
from tkinter import *
|
|
|
|
import os, sqlite3, core
|
|
|
|
class OnionrGUI:
|
|
|
|
def __init__(self, myCore):
|
|
|
|
self.root = Tk()
|
2018-04-16 02:22:19 +00:00
|
|
|
|
2018-02-02 05:39:55 +00:00
|
|
|
self.myCore = myCore # onionr core
|
2018-02-02 08:30:50 +00:00
|
|
|
self.root.title("PyOnionr")
|
2018-02-02 05:39:55 +00:00
|
|
|
|
2018-04-16 02:22:19 +00:00
|
|
|
self.runningCheckDelay = 5
|
2018-04-18 07:17:04 +00:00
|
|
|
self.runningCheckDelayCount = 5
|
2018-04-16 02:22:19 +00:00
|
|
|
|
2018-02-02 05:39:55 +00:00
|
|
|
scrollbar = Scrollbar(self.root)
|
|
|
|
scrollbar.pack(side=RIGHT, fill=Y)
|
|
|
|
|
|
|
|
self.listedBlocks = []
|
|
|
|
|
2018-04-16 02:22:19 +00:00
|
|
|
self.nodeInfo = Frame(self.root)
|
|
|
|
self.keyInfo = Frame(self.root)
|
|
|
|
|
2018-02-02 05:39:55 +00:00
|
|
|
idText = open('./data/hs/hostname', 'r').read()
|
2018-04-16 02:22:19 +00:00
|
|
|
#idLabel = Label(self.info, text="Node Address: " + idText)
|
|
|
|
#idLabel.pack(pady=5)
|
|
|
|
|
|
|
|
idEntry = Entry(self.nodeInfo)
|
|
|
|
Label(self.nodeInfo, text="Node Address: ").pack(side=LEFT)
|
|
|
|
idEntry.pack()
|
|
|
|
idEntry.insert(0, idText.strip())
|
|
|
|
idEntry.configure(state="readonly")
|
|
|
|
|
|
|
|
self.nodeInfo.pack()
|
|
|
|
|
|
|
|
pubKeyEntry = Entry(self.keyInfo)
|
|
|
|
|
|
|
|
Label(self.keyInfo, text="Public key: ").pack(side=LEFT)
|
|
|
|
|
|
|
|
pubKeyEntry.pack()
|
|
|
|
pubKeyEntry.insert(0, self.myCore._crypto.pubKey)
|
|
|
|
pubKeyEntry.configure(state="readonly")
|
|
|
|
|
|
|
|
self.keyInfo.pack()
|
2018-02-02 05:39:55 +00:00
|
|
|
|
2018-02-02 08:30:50 +00:00
|
|
|
self.sendEntry = Entry(self.root)
|
|
|
|
sendBtn = Button(self.root, text='Send Message', command=self.sendMessage)
|
2018-04-16 02:22:19 +00:00
|
|
|
self.sendEntry.pack(side=TOP, pady=5)
|
|
|
|
sendBtn.pack(side=TOP)
|
2018-02-02 08:30:50 +00:00
|
|
|
|
2018-02-04 09:20:43 +00:00
|
|
|
self.listbox = Listbox(self.root, yscrollcommand=scrollbar.set, height=15)
|
2018-02-02 05:39:55 +00:00
|
|
|
|
|
|
|
#listbox.insert(END, str(i))
|
2018-04-16 02:22:19 +00:00
|
|
|
self.listbox.pack(fill=BOTH, pady=25)
|
|
|
|
|
|
|
|
self.daemonStatus = Label(self.root, text="Onionr Daemon Status: unknown")
|
|
|
|
self.daemonStatus.pack()
|
2018-02-02 05:39:55 +00:00
|
|
|
|
|
|
|
scrollbar.config(command=self.listbox.yview)
|
|
|
|
self.root.after(2000, self.update)
|
|
|
|
self.root.mainloop()
|
|
|
|
|
2018-02-02 08:30:50 +00:00
|
|
|
def sendMessage(self):
|
2018-02-02 09:15:28 +00:00
|
|
|
messageToAdd = '-txt-' + self.sendEntry.get()
|
2018-02-02 08:30:50 +00:00
|
|
|
addedHash = self.myCore.setData(messageToAdd)
|
|
|
|
self.myCore.addToBlockDB(addedHash, selfInsert=True)
|
|
|
|
self.myCore.setBlockType(addedHash, 'txt')
|
|
|
|
self.sendEntry.delete(0, END)
|
|
|
|
|
2018-02-02 05:39:55 +00:00
|
|
|
def update(self):
|
|
|
|
for i in self.myCore.getBlocksByType('txt'):
|
|
|
|
if i.strip() == '' or i in self.listedBlocks:
|
|
|
|
continue
|
|
|
|
blockFile = open('./data/blocks/' + i + '.dat')
|
|
|
|
self.listbox.insert(END, str(blockFile.read().replace('-txt-', '')))
|
|
|
|
blockFile.close()
|
|
|
|
self.listedBlocks.append(i)
|
2018-02-04 09:20:43 +00:00
|
|
|
self.listbox.see(END)
|
2018-02-02 05:39:55 +00:00
|
|
|
blocksList = os.listdir('./data/blocks/') # dir is your directory path
|
|
|
|
number_blocks = len(blocksList)
|
2018-04-16 02:22:19 +00:00
|
|
|
self.runningCheckDelayCount += 1
|
2018-02-02 05:39:55 +00:00
|
|
|
|
2018-04-16 02:22:19 +00:00
|
|
|
if self.runningCheckDelayCount == self.runningCheckDelay:
|
|
|
|
if self.myCore._utils.localCommand('ping') == 'pong':
|
|
|
|
self.daemonStatus.config(text="Onionr Daemon Status: Running")
|
|
|
|
else:
|
|
|
|
self.daemonStatus.config(text="Onionr Daemon Status: Not Running")
|
|
|
|
self.runningCheckDelayCount = 0
|
2018-02-02 05:39:55 +00:00
|
|
|
self.root.after(10000, self.update)
|