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()
|
|
|
|
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
|
|
|
|
|
|
|
w = Label(self.root, text="Onionr", width=10)
|
|
|
|
w.config(font=("Sans-Serif", 22))
|
|
|
|
w.pack()
|
|
|
|
scrollbar = Scrollbar(self.root)
|
|
|
|
scrollbar.pack(side=RIGHT, fill=Y)
|
|
|
|
|
|
|
|
self.listedBlocks = []
|
|
|
|
|
|
|
|
idText = open('./data/hs/hostname', 'r').read()
|
|
|
|
idLabel = Label(self.root, text="ID: " + idText)
|
|
|
|
idLabel.pack(pady=5)
|
|
|
|
|
2018-02-02 08:30:50 +00:00
|
|
|
self.sendEntry = Entry(self.root)
|
|
|
|
sendBtn = Button(self.root, text='Send Message', command=self.sendMessage)
|
|
|
|
self.sendEntry.pack()
|
|
|
|
sendBtn.pack()
|
|
|
|
|
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))
|
|
|
|
self.listbox.pack(fill=BOTH)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
self.root.after(10000, self.update)
|