Site Sponsors:
Python: Colorized Textual User Interfaces on Windows and POSIX 
With the advent of Windows 10, for the first time in history we could do - installed by default - what everyone else had been doing for over 50 years: Create colorized applications right-out of the box!

(PyCharm IDE)


While the use of drivers such as `ANSI.SYS` or `VT100.SYS` had come and gone over the decades, those of us who wanted to create cool looking Textual User Interfaces (TUIs) were encouraged by the fact that we could finally use simple "ESCAPE SEQUENCES" once again!



And then - in the infinite "wisdom" of corporate-think, the zombies disabled it... once again! (sigh)

Oh well: Different millennium... same 'ol Microsoft! (lol)

Cygwin


Yet we should understand that STANDARD terminal support STILL works fine on Microsoft Windows when using things like Cygwin:



Standards


So - as ever - in the STANDARDS BASED world creating cool TUIs remains precisely as it has ever been on Linux, OS X, and everywhere else:



Hence, for those who like to use PREDICTABLE operating systems ;) here is the code I created today:


class Console:
color = {
'black': 30,
'red': 31,
'green': 32,
'yellow': 33,
'blue': 34,
'magenta': 35,
'cyan': 36,
'white': 37,
# 'extended': 38,
'default': 39
}

@staticmethod
def _esc(zint, zmode):
return u"\u001b[{}{}".format(zint, zmode)

@staticmethod
def get_colors():
return sorted(Console.color.keys())

@staticmethod
def get_color(key):
if key in Console.color:
return Console._esc(Console.color[key], 'm')
return Console._esc(Console.color['default'], 'm')

@staticmethod
def get_color_back(key):
if key in Console.color:
return Console._esc(Console.color[key] + 10, 'm')
return Console._esc(Console.color['default'] + 10, 'm')


@staticmethod
def get_color_back_bright(key):
if key in Console.color:
return Console._esc(Console.color[key] + 70, 'm')
return Console._esc(Console.color['default'] + 70, 'm')


@staticmethod
def get_color_bright(key):
if key in Console.color:
return Console._esc(Console.color[key] + 60, 'm')
return Console._esc(Console.color['default'] + 60, 'm')

@staticmethod
def has_color():
import os
if os.name is 'posix':
return True
if os.name is 'nt':
import platform
ver = platform.version()
if ver is None or len(ver) is 0:
return False
ver = ver.split('.')
if ver[0] == '10':
return True
return False

if Console.has_color() is False:
print("Sorry, at the moment only POSIX has default VT100 / ANSI support.")
print("Some versions of DOS use ANSY.SYS / VT100.sys. 'Google it.")
exit(-1)

for color in Console.get_colors():
print(Console.get_color(color), color, end="...")
print(Console.get_color_bright(color), "bright", color, end="...")
print(Console.get_color('default'), end="")
print(Console.get_color_back_bright(color), "back", color, end="...")
print(Console.get_color_back('default'))



Please note that most people will have to update the above to return 'False' when the OS is 'nt.' But if you are lucky enough to be running the Bourne-Again Shell (bash) under Windows, then you've hit a home-run ... omit the platform checking, all together?

etc ...


For what its worth:




Google Keywords: Free Source Code Public Domain Roguelike Console Terminal TTY DOS Prompt



[ view entry ] ( 521 views )   |  permalink  |  related link
PR1000.02: The Hex Dumper Project 
From banners to ASCII tables, in Python 1000 we created allot of useful data representations. Putting it all together however, when our review team was having difficulty creating the password encoder, we decided to cobble together a review exercise.



Moving forward, if you have ever wanted to know how to create a hex-dump, then click here for a "Developer's Review" of how to do so in Python.

Those who need an introduction to the UML (at least enough to understand the core diagrams) might enjoy our YouTube UML Primer (video link).

[ view entry ] ( 326 views )   |  permalink  |  related link
PyGame Example - The Lazy Star 
Had a chance to teach a bunch of wonderful new Python students this month.

Several were interested in using pygame, so we put together the following demonstration.

Thought we would share it.

Note that - before running pygame - that we will need to use pip (or pip3) to install the pygame package (e.g: pip3 install pygame)

Linux folks should install packages using PIP as to get those Super Cow Powers (i.e either su, or sudo should moo nicely.)

import pygame

pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Hackin' Around!")

back_color = (128, 45, 100) # Ubuntu Default

clock = pygame.time.Clock()

def stat(zEvent):
screen.fill(back_color)
if zEvent is None:
return
try:
loc = zEvent.__dict__['pos']
basicfont = pygame.font.SysFont(None, 72)
text = basicfont.render('*', True, (255, 0, 0), back_color)
screen.blit(text, loc)
except Exception as ex:
print("Exceptional:", zEvent)


stat(None)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT: # closing the window
break
stat(event)
pygame.display.update()
clock.tick(12) # fps
pygame.quit()

Note that 'fps' in the above stands for "frames per second." The lower, the slower. -You can set it to 1000 or so to speed things up ... allot!

Sharing is caring!

-Rn

p.s. If you want to learn more about programing in Python 3, then here is a discount coupon to my on-line training.

[ view entry ] ( 443 views )   |  permalink  |  related link

<<First <Back | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Next> Last>>