Skip to content

Commit

Permalink
started shiny ui
Browse files Browse the repository at this point in the history
  • Loading branch information
cnvogelg committed Sep 26, 2014
1 parent cc5dabd commit db4901e
Show file tree
Hide file tree
Showing 37 changed files with 977 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pimill/pimill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python2.7

import os
import sys
import inspect

# add .. to module path
my_dir = os.path.split(inspect.getfile( inspect.currentframe() ))[0]
tools_dir = os.path.realpath(os.path.abspath(os.path.join(my_dir,"..")))
if tools_dir not in sys.path:
sys.path.insert(0, tools_dir)

import shiny

# size of touch screen
screen_size = (1024, 600)
screen = shiny.Screen(screen_size)

def handler(button):
print button

# setup jog pane
jog_pane = shiny.Pane("Jogger")
lx = shiny.Label(jog_pane, (2,0,4,1), "000.0000")
ly = shiny.Label(jog_pane, (2,1,4,1), "000.0000")
lz = shiny.Label(jog_pane, (2,2,4,1), "000.0000")
bxp = shiny.Button(jog_pane, (0,0,2,1), "X+", handler)
bxn = shiny.Button(jog_pane, (6,0,2,1), "X-", handler)
byp = shiny.Button(jog_pane, (0,1,2,1), "Y+", handler)
byn = shiny.Button(jog_pane, (6,1,2,1), "Y-", handler)
bzp = shiny.Button(jog_pane, (0,2,2,1), "Z+", handler)
bzn = shiny.Button(jog_pane, (6,2,2,1), "Z-", handler)

# status bar
statusbar = shiny.Statusbar("Jogger")
screen.set_statusbar(statusbar)

# icon bar
iconbar = shiny.Iconbar()
screen.set_iconbar(iconbar)

# set first pane
screen.set_pane(jog_pane)

main = shiny.Shiny(screen)
main.run()
8 changes: 8 additions & 0 deletions shiny/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from shiny import Shiny
from screen import Screen
from fonts import Fonts
from button import Button
from label import Label
from pane import Pane
from statusbar import Statusbar
from iconbar import Iconbar
59 changes: 59 additions & 0 deletions shiny/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import pygame
import control
import textsurface
import event

class Button(control.Control):
def __init__(self, pane, rect, text, handler=None):
control.Control.__init__(self, pane, rect)
self.text = text
self.active = False
self.handler = handler

def __str__(self):
return "[Button:%s]" % (self.text)

def setup(self, shiny):
super(Button, self).setup(shiny)
# get font
font = shiny.fonts.get_font(shiny.fonts.BUTTON_FONT)
# get colors
self.fg = shiny.colors.get_color(shiny.colors.BUTTON_FG_COLOR)
self.bg = shiny.colors.get_color(shiny.colors.BUTTON_BG_COLOR)
self.bd = shiny.colors.get_color(shiny.colors.BUTTON_BD_COLOR)
self.fga = shiny.colors.get_color(shiny.colors.BUTTON_FG_ACTIVE_COLOR)
self.bga = shiny.colors.get_color(shiny.colors.BUTTON_BG_ACTIVE_COLOR)
self.bda = shiny.colors.get_color(shiny.colors.BUTTON_BD_ACTIVE_COLOR)
# render text surfaces
self.surf = textsurface.TextSurface(self.text, font, self.fg, self.bg)
self.surfa = textsurface.TextSurface(self.text, font, self.fga, self.bga)
# map button
r = self.rect_map
self.trect_map = pygame.Rect(r[0]+1, r[1]+1, r[2]-2, r[3]-2)

def draw(self):
if self.active:
bg = self.bga
bd = self.bda
s = self.surfa
else:
bg = self.bg
bd = self.bd
s = self.surf
# draw background, border, and blit text
pygame.draw.rect(self.shiny.main_surface, bg, self.rect_map)
pygame.draw.rect(self.shiny.main_surface, bd, self.rect_map, 1)
s.renderInRect(self.shiny.main_surface, self.trect_map)

def handle_event(self, ev):
if ev.type == event.Event.BUTTON_DOWN:
if not self.active:
self.active = True
if self.handler is not None:
self.handler(self)
return True
elif ev.type == event.Event.BUTTON_UP:
if self.active:
self.active = False
return True
return False
26 changes: 26 additions & 0 deletions shiny/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Colors:
BUTTON_FG_COLOR = 0
BUTTON_BG_COLOR = 1
BUTTON_BD_COLOR = 2
BUTTON_FG_ACTIVE_COLOR = 3
BUTTON_BG_ACTIVE_COLOR = 4
BUTTON_BD_ACTIVE_COLOR = 5

LABEL_FG_COLOR = 10
LABEL_BG_COLOR = 11

def __init__(self):
self.color_map = {
self.BUTTON_FG_COLOR : (0x16, 0x7F, 0xFC),
self.BUTTON_BG_COLOR : (0xf8, 0xf8, 0xf8),
self.BUTTON_BD_COLOR : (0xd8, 0xd8, 0xd8),
self.BUTTON_FG_ACTIVE_COLOR: (0x50, 0x90, 0xff),
self.BUTTON_BG_ACTIVE_COLOR: (0xff, 0xff, 0xff),
self.BUTTON_BD_ACTIVE_COLOR: (0xdf, 0xdf, 0xdf),

self.LABEL_FG_COLOR : (0, 0, 0),
self.LABEL_BG_COLOR : (0xf8, 0xf8, 0xf8)
}

def get_color(self, i):
return self.color_map[i]
9 changes: 9 additions & 0 deletions shiny/control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import widget

class Control(widget.Widget):
def __init__(self, pane, rect):
super(Control, self).__init__(pane, rect)

def handle_event(self, event):
pass

28 changes: 28 additions & 0 deletions shiny/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Event(object):

BUTTON_DOWN = 1
BUTTON_UP = 2
MOUSE_MOVE = 3

def __init__(self, event_type, pos):
self.type = event_type
self.pos = pos

def __str__(self):
return "[type=%s, pos=%s]" % (self.type, self.pos)

def is_in_rect(self, rect):
x = self.pos[0]
y = self.pos[1]

x1 = rect[0]
y1 = rect[1]
if (x < x1) or (y < y1):
return False

x2 = rect[0] + rect[2]
y2 = rect[1] + rect[3]
if (x >= x2) or (y >= y2):
return False

return True
29 changes: 29 additions & 0 deletions shiny/fonts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pygame
import os
import sys
import inspect

class Fonts:
BUTTON_FONT = 0
LABEL_FONT = 1
STATUS_FONT = 2

def __init__(self):
my_dir = os.path.split(inspect.getfile( inspect.currentframe() ))[0]
self.dir = os.path.realpath(os.path.abspath(os.path.join(my_dir,"fonts")))
self.font_desc = {
self.BUTTON_FONT : ("Roboto/Roboto-Medium.ttf", 36),
self.LABEL_FONT : ("Roboto/Roboto-Light.ttf", 36),
self.STATUS_FONT : ("Roboto/Roboto-Regular.ttf", 18)
}

def setup(self):
self.fonts = {}
# create fonts
for i in self.font_desc:
(name, size) = self.font_desc[i]
path = os.path.join(self.dir, name)
self.fonts[i] = pygame.font.Font(path, size)

def get_font(self, i):
return self.fonts[i]
2 changes: 2 additions & 0 deletions shiny/fonts/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
http://developer.android.com/design/style/typography.html

Loading

0 comments on commit db4901e

Please sign in to comment.