Code Monkey home page Code Monkey logo

ui.py's Introduction

UI.py

Simple UI module for Python

Installation

  1. Clone repository from GitHub
  2. Place UI.py file with your program
  3. Then write such code line:
import UI

How to use

The following example creates presized screen with some text labels

import UI

hello = UI.Text('Hello', verticalOffset=2)
world = UI.Text('World!', horizontalOffset=5)

mainScreen = UI.Screen(hello, world, horizontalOffset=5, width=30, height=10)
mainScreen.draw()

Opportunities

You can create some objects, such as:

  1. Screens, use them when you need to combine any objects.
mainScreen = UI.Screen(width=120, height=30)
anotherScreen = UI.Screen(verticalOffset=5, horizontalOffset=10)
  1. Labels or text
hello = UI.Text('Hello', verticalOffset=5)
world = UI.Text('World', horizontalOffset=10)
  1. Buttons, to use buttons you have to create Commands and combine buttons in Menu
command1 = UI.Command(application, method)
button1 = UI.Button('Button', command1)
  1. Menu and MenuHandler, Menu handler helps you to control your menu
command1 = UI.Command(application, method)
button1 = UI.Button('Button1', command1)
command2 = UI.Command(application, method)
button2 = UI.Button('Button2', command2)

menu = UI.Menu(button1, button2)
# You can change keys by adding arguments in constructor
# menuHandler UI.MenuHandler(menu, goUpKey=119) # W letter
menuHandler = UI.MenuHandler(menu)

menuHandler.hanlde(key)

Small example of code

Creates small application with little menu:

import UI
from msvcrt import getch

class Application:
    def sayHello(self):
        print('Hello!')
        input('Press any key')

    def sayGoodBye(self):
        print('Goodbye!')
        input('Press any key')

    def start(self):
        mainScreen = UI.Screen(width=100, height=20, verticalOffset=2, horizontalOffset=10)

        title = UI.Text('Greet-o-machine')

        helloCommand = UI.Command(self, self.sayHello)
        helloButton = UI.Button('Hello', helloCommand)

        goodByeCommand = UI.Command(self, self.sayGoodBye)
        goodByeButton = UI.Button('Good bye', goodByeCommand)

        mainMenu = UI.Menu(helloButton, goodByeButton, horizontalOffset=5)
        menuHandler = UI.MenuHandler(mainMenu)

        mainScreen.appendElement(title)
        mainScreen.appendElement(mainMenu)
        mainScreen.start()
        while mainScreen.running:
            mainScreen.draw()
            key = ord(getch())
            menuHandler.handle(key)

app = Application()
app.start()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.