on_press: root.upd()
self.ids['fer'].text = ':<'
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
Builder.load_string("""
<Gex>:
orientation: 'vertical'
Button:
text: 'UwU'
on_press: root.upd()
Label:
id: fer
text: ' '
""")
class Gex(BoxLayout):
def upd(self):
self.ids['fer'].text = ':<'
class FakeApp(App):
def build(self):
return Gex()
FakeApp().run()
import sys
import inspect
class My_Context(object):
def __init__(self,mode=0):
"""
if mode = 0, proceed as normal
if mode = 1, do not execute block
"""
self.mode=mode
def __enter__(self):
if self.mode==1:
print 'Met block-skipping criterion ...'
# Do some magic
sys.settrace(lambda *args, **keys: None)
frame = inspect.currentframe(1)
frame.f_trace = self.trace
def trace(self, frame, event, arg):
raise
def __exit__(self, type, value, traceback):
print 'Exiting context ...'
return True
with My_Context(mode=1):
print 'Executing block of code ...'
import sys
class SkipWithBlock(Exception):
pass
class SkipContextManager:
def __init__(self, skip = True):
self.skip = skip
def __enter__(self):
if self.skip:
sys.settrace(lambda *args, **keys: None)
frame = sys._getframe(1)
frame.f_trace = self.trace
def trace(self, frame, event, arg):
raise SkipWithBlock()
def __exit__(self, type, value, traceback):
if type is None:
return # No exception
if issubclass(type, SkipWithBlock):
return True # Suppress special SkipWithBlock exception
with SkipContextManager():
print('In the with block') # Won't be called
print('Out of the with block')
from kivy.lang import Builder
from kivy.app import App
from kivy.properties import ListProperty, NumericProperty
KV = '''
#:import RGBA kivy.utils.rgba
<Row@BoxLayout>:
text: ''
rv_key: 0
CheckBox:
active: root.rv_key in app.current_selection
on_active: app.select_row(root.rv_key, self.active)
Label:
text: root.text
FloatLayout:
RecycleView:
size_hint: .8, .8
pos_hint: {'center': (.5, .5)}
data: app.data
viewclass: 'Row'
canvas.before:
Color:
rgba: RGBA('#212121')
Rectangle:
pos: self.pos
size: self.size
RecycleBoxLayout:
orientation: 'vertical'
size: self.minimum_size
size_hint_y: None
default_size_hint: 1, None
default_size: 0, 50
'''
class TestApp(App):
data = ListProperty()
current_selection = ListProperty([])
def build(self):
self.data = [
dict(
text='key {}'.format(i),
rv_key=i,
)
for i in range(100)
]
return Builder.load_string(KV)
def select_row(self, rv_key, active):
if active and rv_key not in self.current_selection:
self.current_selection.append(rv_key)
elif not active and rv_key in self.current_selection:
self.current_selection.remove(rv_key)
if __name__ == '__main__':
TestApp().run()
!git clone https://github.com/tomlepaine/fast-wavenet.git
%cd fast-wavenet/wavenet
from time import time
from utils import make_batch
from models import Model, Generator
from IPython.display import Audio
%matplotlib inline