-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEddy.py
67 lines (59 loc) · 2.56 KB
/
Eddy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import wpf
from System.Windows import Application, Window
from System.Windows.Controls import DockPanel, Canvas
from Microsoft.Win32 import OpenFileDialog
from System.Windows.Input import Mouse, MouseButton, MouseButtonState, MouseButtonEventArgs
from Text import split, combine
from Chains import Chain, ChainGroup
class Eddy(Window):
def __init__(self):
wpf.LoadComponent(self, 'Window.xaml')
self.knob.Children.Add(self.Knob())
self.chain = ChainGroup()
class Knob(Canvas):
def __init__(self):
wpf.LoadComponent(self, 'Knob.xaml')
self.slider.ValueChanged += self.tweaked
def hover(self, sender, event):
if (event.LeftButton == MouseButtonState.Pressed and not event.MouseDevice.Captured):
click = MouseButtonEventArgs(event.MouseDevice, event.Timestamp, MouseButton.Left)
click.RoutedEvent = Mouse.MouseDownEvent
sender.RaiseEvent(click)
def tweaked(self, *args):
self.gauge.CurrentValue = self.slider.Value
def load(self, *args):
dialog = OpenFileDialog()
dialog.Filter = "Text|*.txt"
if dialog.ShowDialog():
with open(dialog.FileName, encoding="utf-8") as data:
if self.Slider(dialog.SafeFileName, self.sliders, self.tweak):
words = split(data.read())
self.chain.append(Chain(words))
class Slider(DockPanel):
limit = 15
def __new__(cls, name, parent, tweaked):
if len(parent.Children) >= cls.limit: return None
return super().__new__(cls)
def __init__(self, name, parent, tweaked):
wpf.LoadComponent(self, 'Slider.xaml')
self.name.Text = name
self.slider.Value = 5
self.slider.Tag = len(parent.Children)
self.slider.ValueChanged += tweaked
self.value.Text = " 1.0"
parent.Children.Add(self)
def tweak(self, slider, *args):
weight = slider.Value / (10.1 - slider.Value)
slider.Parent.value.Text = "{:5.1f}".format(weight)
self.chain[slider.Tag].weight = weight
def speak(self, *args):
words, word = [], "."
energy = self.knob.Children[0].gauge.CurrentValue
while len(words) <= energy or word != ".":
word = self.chain(word)
if word == "": break
words.append(word)
self.textbox.Text += "\n" + "Eddy : " + combine(words) + "\n"
self.textbox.ScrollToEnd()
if __name__ == '__main__':
Application().Run(Eddy())