Add files via upload
This commit is contained in:
@@ -15,15 +15,16 @@ from tkinter.ttk import Frame, Label, Button, Progressbar, Entry
|
||||
from tkinter import scrolledtext
|
||||
|
||||
if GUI == GUI_WIN:
|
||||
from multiprocessing import Process, Manager, Queue
|
||||
from multiprocessing import Process, Manager, Queue, Value
|
||||
from queue import Empty
|
||||
else:
|
||||
from multiprocessing import Queue, Process
|
||||
import queue
|
||||
|
||||
from decimal import Decimal, getcontext
|
||||
from time import sleep
|
||||
|
||||
DELAY1 = 80
|
||||
DELAY1 = 20
|
||||
DELAY2 = 20
|
||||
|
||||
if GUI == GUI_WIN:
|
||||
@@ -38,6 +39,10 @@ class commonUI(Frame):
|
||||
|
||||
def initUI(self):
|
||||
|
||||
self.val = Value('i', 0)
|
||||
self.dig = Value('i', 4000)
|
||||
self.acc = Value('i', 100)
|
||||
|
||||
self.parent.title("Pi computation")
|
||||
self.pack(fill=BOTH, expand=True)
|
||||
|
||||
@@ -48,22 +53,23 @@ class commonUI(Frame):
|
||||
lbl1.grid(row=0, column=0, sticky=E, padx=10, pady=10)
|
||||
|
||||
self.ent1 = Entry(self, width=10)
|
||||
self.ent1.insert(END, "4000")
|
||||
self.ent1.insert(END, self.dig.value)
|
||||
self.ent1.grid(row=0, column=1, sticky=W)
|
||||
|
||||
lbl2 = Label(self, text="Accuracy:")
|
||||
lbl2.grid(row=0, column=2, sticky=E, padx=10, pady=10)
|
||||
|
||||
self.ent2 = Entry(self, width=10)
|
||||
self.ent2.insert(END, "100")
|
||||
self.ent2.insert(END, self.acc.value)
|
||||
self.ent2.grid(row=0, column=3, sticky=W)
|
||||
|
||||
self.startBtn = Button(self, text="Start", command=self.onStart)
|
||||
self.startBtn.grid(row=1, column=0, padx=10, pady=5, sticky=W)
|
||||
|
||||
self.pbar = Progressbar(self, mode='indeterminate')
|
||||
self.pbar = Progressbar(self, mode='determinate')
|
||||
self.pbar.grid(row=1, column=1, columnspan=3, sticky=W+E)
|
||||
|
||||
self.pbar.config(value=0, maximum=self.dig.value)
|
||||
|
||||
self.txt = scrolledtext.ScrolledText(self)
|
||||
self.txt.grid(row=2, column=0, rowspan=4, padx=10, pady=5, columnspan=5, sticky=E+W+S+N)
|
||||
|
||||
@@ -77,14 +83,14 @@ class commonUI(Frame):
|
||||
|
||||
self.p1 = Process(target=generatePi, args=(q, digits, accuracy))
|
||||
self.p1.start()
|
||||
self.pbar.start(DELAY2)
|
||||
self.after(DELAY1, self.onGetValue)
|
||||
|
||||
|
||||
def onGetValue(self):
|
||||
|
||||
if (self.p1.is_alive()):
|
||||
|
||||
self.val.value += 1000
|
||||
self.update_pbar()
|
||||
self.after(DELAY1, self.onGetValue)
|
||||
return
|
||||
else:
|
||||
@@ -93,12 +99,14 @@ class commonUI(Frame):
|
||||
|
||||
self.txt.insert('end', q.get(0))
|
||||
self.txt.insert('end', "\n")
|
||||
self.pbar.stop()
|
||||
self.startBtn.config(state=NORMAL)
|
||||
|
||||
except Empty:
|
||||
print("queue is empty")
|
||||
|
||||
def update_pbar(self):
|
||||
self.pbar.config(value=self.val.value)
|
||||
|
||||
class win_Example(Frame):
|
||||
|
||||
def __init__(self, parent):
|
||||
@@ -120,8 +128,8 @@ if GUI == GUI_WIN:
|
||||
(Decimal(2)/(8*k+4)) - (Decimal(1)/(8*k+5))- \
|
||||
(Decimal(1)/(8*k+6)))
|
||||
k += 1
|
||||
|
||||
q.put(pi)
|
||||
time.sleep(1)
|
||||
|
||||
class linux_Example(Frame):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user