Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shoes.app do
- t = para "Not clicked!"
- button "The Label" do
- alert "You clicked the button!" # when clicked, make an alert
- t.replace "Clicked!" # ..and replace the label's text
- end
- end
- def Shoeless(Shoes.app):
- self.t = para("Not clicked!")
- def on_click_func(self):
- alert("You clicked the button!")
- self.t.replace("clicked!")
- b = button("The label", click=self.on_click_func)
- class BaseControl:
- def __init__(self):
- self.func = None
- def clicked(self, func):
- self.func = func
- def __call__(self):
- if self.func is not None:
- self.func()
- class Button(BaseControl):
- pass
- class Label(BaseControl):
- pass
- # The actual applications code (that the end-user would write)
- class MyApp:
- ok = Button()
- la = Label()
- @ok.clicked
- def clickeryHappened():
- print "OK Clicked!"
- if __name__ == '__main__':
- a = MyApp()
- a.ok() # trigger the clicked action
- ## All you need is this class:
- class MainWindow(Window):
- my_button = Button('Click Me')
- my_paragraph = Text('This is the text you wish to place')
- my_alert = AlertBox('What what what!!!')
- @my_button.clicked
- def my_button_clicked(self, button, event):
- self.my_paragraph.text.append('And now you clicked on it, the button that is.')
- @my_paragraph.text.changed
- def my_paragraph_text_changed(self, text, event):
- self.button.text = 'No more clicks!'
- @my_button.text.changed
- def my_button_text_changed(self, text, event):
- self.my_alert.show()
- ## The Style class is automatically gnerated by the framework
- ## but you can override it by defining it in the class:
- ##
- ## class MainWindow(Window):
- ## class Style:
- ## my_blah = {'style-info': 'value'}
- ##
- ## or like you see below:
- class Style:
- my_button = {
- 'background-color': '#ccc',
- 'font-size': '14px'}
- my_paragraph = {
- 'background-color': '#fff',
- 'color': '#000',
- 'font-size': '14px',
- 'border': '1px solid black',
- 'border-radius': '3px'}
- MainWindow.Style = Style
- ## The layout class is automatically generated
- ## by the framework but you can override it by defining it
- ## in the class, same as the Style class above, or by
- ## defining it like this:
- class MainLayout(Layout):
- def __init__(self, style):
- # It takes the custom or automatically generated style class upon instantiation
- style.window.pack(HBox().pack(style.my_paragraph, style.my_button))
- MainWindow.Layout = MainLayout
- if __name__ == '__main__':
- run(App(main=MainWindow))
- with Shoes():
- t = Para("Not clicked!")
- with Button("The Label"):
- Alert("You clicked the button!")
- t.replace("Clicked!")
- context = None
- class Nestable(object):
- def __init__(self,caption=None):
- self.caption = caption
- self.things = []
- global context
- if context:
- context.add(self)
- def __enter__(self):
- global context
- self.parent = context
- context = self
- def __exit__(self, type, value, traceback):
- global context
- context = self.parent
- def add(self,thing):
- self.things.append(thing)
- print "Adding a %s to %s" % (thing,self)
- def __str__(self):
- return "%s(%s)" % (self.__class__.__name__, self.caption)
- class Shoes(Nestable):
- pass
- class Button(Nestable):
- pass
- class Alert(Nestable):
- pass
- class Para(Nestable):
- def replace(self,caption):
- Command(self,"replace",caption)
- class Command(Nestable):
- def __init__(self, target, command, caption):
- self.command = command
- self.target = target
- Nestable.__init__(self,caption)
- def __str__(self):
- return "Command(%s text of %s with "%s")" % (self.command, self.target, self.caption)
- def execute(self):
- self.target.caption = self.caption
- class w(Wndw):
- title='Hello World'
- class txt(Txt): # either a new class
- text='Insert name here'
- lbl=Lbl(text='Hello') # or an instance
- class greet(Bbt):
- text='Greet'
- def click(self): #on_click method
- self.frame.lbl.text='Hello %s.'%self.frame.txt.text
- app=w()
- class MyWindow(GladeWrapper):
- GladeWrapper.__init__(self, "my_glade_file.xml", "mainWindow")
- self.GtkWindow.show()
- def button_click_event (self, *args):
- self.button1.set_label("CLICKED")
- from Boots import App, Para, Button, alert
- def Shoeless(App):
- t = Para(text = 'Not Clicked')
- b = Button(label = 'The label')
- def on_b_clicked(self):
- alert('You clicked the button!')
- self.t.text = 'Clicked!'
- class MyWindow(Window):
- class VBox:
- entry = Entry()
- bigtext = TextView()
- def on_entry_accepted(text):
- bigtext.value = eval(text).__doc__
- class MyWindow(Window):
- contents = (
- para('Hello World!'),
- button('Click Me', id='ok'),
- para('Epilog'),
- )
- def __init__(self):
- self['#ok'].click(self.message)
- self['para'].hover(self.blend_in, self.blend_out)
- def message(self):
- print 'You clicked!'
- def blend_in(self, object):
- object.background = '#333333'
- def blend_out(self, object):
- object.background = 'WindowBackground'
- MAIN_WINDOW.my_layout.my_edit.text
Add Comment
Please, Sign In to add comment