Martin Fowler coins the phrase
http://martinfowler.com/bliki/FluentInterface.html
Wikipedia
http://en.wikipedia.org/wiki/Fluent_interface
SE Radio 652: Christian Mesh on OpenTofu
5 days ago
js / python / linux / .NET C# F# / MS-SQL / postgresql / maths / data / logic / thought / SmartCard / EMV / django / HTML
Register Types Implementing Specified Interface:
container.Register(
AllTypes.
FromThisAssembly(). // register all types from parent assembly
BasedOn). // that inherit/implement interface IDialogService
WithService.FromInterface(). // allow resolution based on interface
Configure(c => c.LifeStyle.Is(LifestyleType.Transient)) // construct new
);
Resolve Instance of Class by Interface
IDialogService dialogService = container.Resolve();
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------0---------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------00--------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------00--------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------00--------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------0---------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------000000-------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------000000-------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------000000000------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------0000000000-----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------000000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------0000000000-----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------0000000000-----------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------000000000-----------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------00000000------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------0000000------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------00000-------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------0--0---------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------0---0-0-0000000000000---0-----------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------00--0000000000000000000-0-----------------------------------------------------
-------------------------------------------------------------------------------------------------------------0------------00-0000000000000000000000--00-------------------------------------------------
----------------------------------------------------------------------------------------------------------------0---------00000000000000000000000000-00-------------------------------------------------
----------------------------------------------------------------------------------------------------------------0-00-------00000000000000000000000000-0-------------------------------------------------
-----------------------------------------------------------------------------------------------------------------000-----000000000000000000000000000000-------------------------------------------------
-----------------------------------------------------------------------------------------------------------------0000---00000000000000000000000000000000------------------------------------------------
----------------------------------------------------------------------------------------------------------------00000--00000000000000000000000000000000000----00000-------------------------------------
----------------------------------------------------------------------------------------------------------------00000-000000000000000000000000000000000000----00000-------------------------------------
----------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000--00000--------------------------------------
-----------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000--00000--------------------------------------
-----------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000-00000--------------------------------------
-------------------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000---------------------------------------
----------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000---------------------------------------
----------------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000-----------------------------------------
---------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000-----------------------------------------
---------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000----------------------------------------
---------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000----------------------------------------
----------------------------------------------------------------------------------------------------------000-000000000000000000000000000000000000000000000000000---------------------------------------
-----------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000---------------------------------------
-----------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000---------------------------------------
-----------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000000000000-------------------------------------
------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000--------------------------------------
-----------------------------------------------------------------------0-----------------------------------00000000000000000000000000000000000000000000000000000000-------------------------------------
----------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000-------------------------------------
-----------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000000000000--0----------------------------------
----------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000-00----------------------------------
--------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000000000---------------------------------
--------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000000000000000000----------------------------------
---------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000000000000000----------------------------------
---------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000000000000000------------------------------------
--------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000000------------------------------------
--------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000000------------------------------------
-------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000000000000000------------------------------------
-----------------------------------------------------------------------------0-------00-----------------0000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------00------00-----------------0000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------000-----0-0--0------------00000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------000--000000000-----------000000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------000000000000000-----------000000000000000000000000000000000000000000000000000000000000000----------------------------------
-----------------------------------------------------------------------------00000000000000000--------0000000000000000000000000000000000000000000000000000000000000000----------------------------------
------------------------------------------------------------------------------0000000000000000--------00000000000000000000000000000000000000000000000000000000000000000---------------------------------
------------------------------------------------------------------------------000000000000000000------000000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------0000000000000000000------000000000000000000000000000000000000000000000000000000000000000-----------------------------------
----------------------------------------------------------------------------000000000000000000000-----000000000000000000000000000000000000000000000000000000000000000-----------------------------------
----------------------------------------------------------------------------000000000000000000000-----000000000000000000000000000000000000000000000000000000000000000-----------------------------------
-------------------------------------------------------------------------000000000000000000000000-----000000000000000000000000000000000000000000000000000000000000000-----------------------------------
--------------------------------------------------------------------------000000000000000000000000---0000000000000000000000000000000000000000000000000000000000000000-----------------------------------
--------------------------------------------------------------------------000000000000000000000000---00000000000000000000000000000000000000000000000000000000000000000----------------------------------
--------------------------------------------------------------------------000000000000000000000000---000000000000000000000000000000000000000000000000000000000000000------------------------------------
--------------------------------------------------------------------------0000000000000000000000000--000000000000000000000000000000000000000000000000000000000000000------------------------------------
-------------------------------------------------------------------------00000000000000000000000000--000000000000000000000000000000000000000000000000000000000000000------------------------------------
-------------------------------------------------------------------------00000000000000000000000000--00000000000000000000000000000000000000000000000000000000000000-------------------------------------
-------------------------------------------------------------------------000000000000000000000000000-00000000000000000000000000000000000000000000000000000000000000-------------------------------------
-------------------------------------------------------------------------000000000000000000000000000-00000000000000000000000000000000000000000000000000000000000000-------------------------------------
------------------------------------------------------------------------0000000000000000000000000000-00000000000000000000000000000000000000000000000000000000000000-------------------------------------
------------------------------------------------------------------0-00--0000000000000000000000000000-0000000000000000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------0000--0000000000000000000000000000-0000000000000000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------00000-0000000000000000000000000000-0000000000000000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------00000-0000000000000000000000000000-000000000000000000000000000000000000000000000000000000000000---------------------------------------
-----------------------------------------------------------------00000000000000000000000000000000000-00000000000000000000000000000000000000000000000000000000000----------------------------------------
------------------------------------------0---------------------000000000000000000000000000000000000-0000000000000000000000000000000000000000000000000000000000-----------------------------------------
-----------------------------000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000------------------------------------------
------------------------------------------0---------------------000000000000000000000000000000000000-0000000000000000000000000000000000000000000000000000000000-----------------------------------------
-----------------------------------------------------------------00000000000000000000000000000000000-00000000000000000000000000000000000000000000000000000000000----------------------------------------
------------------------------------------------------------------00000-0000000000000000000000000000-000000000000000000000000000000000000000000000000000000000000---------------------------------------
------------------------------------------------------------------00000-0000000000000000000000000000-0000000000000000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------0000--0000000000000000000000000000-0000000000000000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------0-00--0000000000000000000000000000-0000000000000000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------------0000000000000000000000000000-00000000000000000000000000000000000000000000000000000000000000-------------------------------------
-------------------------------------------------------------------------000000000000000000000000000-00000000000000000000000000000000000000000000000000000000000000-------------------------------------
-------------------------------------------------------------------------000000000000000000000000000-00000000000000000000000000000000000000000000000000000000000000-------------------------------------
-------------------------------------------------------------------------00000000000000000000000000--00000000000000000000000000000000000000000000000000000000000000-------------------------------------
-------------------------------------------------------------------------00000000000000000000000000--000000000000000000000000000000000000000000000000000000000000000------------------------------------
--------------------------------------------------------------------------0000000000000000000000000--000000000000000000000000000000000000000000000000000000000000000------------------------------------
--------------------------------------------------------------------------000000000000000000000000---000000000000000000000000000000000000000000000000000000000000000------------------------------------
--------------------------------------------------------------------------000000000000000000000000---00000000000000000000000000000000000000000000000000000000000000000----------------------------------
--------------------------------------------------------------------------000000000000000000000000---0000000000000000000000000000000000000000000000000000000000000000-----------------------------------
-------------------------------------------------------------------------000000000000000000000000-----000000000000000000000000000000000000000000000000000000000000000-----------------------------------
----------------------------------------------------------------------------000000000000000000000-----000000000000000000000000000000000000000000000000000000000000000-----------------------------------
----------------------------------------------------------------------------000000000000000000000-----000000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------0000000000000000000------000000000000000000000000000000000000000000000000000000000000000-----------------------------------
------------------------------------------------------------------------------000000000000000000------000000000000000000000000000000000000000000000000000000000000000-----------------------------------
------------------------------------------------------------------------------0000000000000000--------00000000000000000000000000000000000000000000000000000000000000000---------------------------------
-----------------------------------------------------------------------------00000000000000000--------0000000000000000000000000000000000000000000000000000000000000000----------------------------------
-----------------------------------------------------------------------------000000000000000-----------000000000000000000000000000000000000000000000000000000000000000----------------------------------
-----------------------------------------------------------------------------000--000000000-----------000000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------000-----0-0--0------------00000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------00------00-----------------0000000000000000000000000000000000000000000000000000000000000-----------------------------------
-----------------------------------------------------------------------------0-------00-----------------0000000000000000000000000000000000000000000000000000000000000-----------------------------------
-------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000000000000000------------------------------------
--------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000000------------------------------------
--------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000000------------------------------------
---------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000000000000000------------------------------------
---------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000000000000000----------------------------------
--------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000000000000000000----------------------------------
--------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000000000---------------------------------
----------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000-00----------------------------------
-----------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000000000000--0----------------------------------
----------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000000-------------------------------------
-----------------------------------------------------------------------0-----------------------------------00000000000000000000000000000000000000000000000000000000-------------------------------------
------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000--------------------------------------
------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000--------------------------------------
-----------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000000000000-------------------------------------
-----------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000---------------------------------------
-----------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000000000---------------------------------------
----------------------------------------------------------------------------------------------------------000-000000000000000000000000000000000000000000000000000---------------------------------------
---------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000----------------------------------------
---------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000----------------------------------------
---------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000-----------------------------------------
----------------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000-----------------------------------------
----------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000000000---------------------------------------
------------------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000---------------------------------------
------------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000000000--------------------------------------
-------------------------------------------------------------------------------------------------------------------00000000000000000000000000000000000000000000000--------------------------------------
-----------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000-00000--------------------------------------
-----------------------------------------------------------------------------------------------------------------000000000000000000000000000000000000000000--00000--------------------------------------
----------------------------------------------------------------------------------------------------------------0000000000000000000000000000000000000000000--00000--------------------------------------
----------------------------------------------------------------------------------------------------------------00000-000000000000000000000000000000000000----00000-------------------------------------
----------------------------------------------------------------------------------------------------------------00000--00000000000000000000000000000000000----00000-------------------------------------
-----------------------------------------------------------------------------------------------------------------0000---00000000000000000000000000000000------------------------------------------------
-----------------------------------------------------------------------------------------------------------------000-----000000000000000000000000000000-------------------------------------------------
----------------------------------------------------------------------------------------------------------------0-00-------00000000000000000000000000-0-------------------------------------------------
----------------------------------------------------------------------------------------------------------------0---------00000000000000000000000000-00-------------------------------------------------
-------------------------------------------------------------------------------------------------------------0------------00-0000000000000000000000--00-------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------00--0000000000000000000-0-----------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------0---0-0-0000000000000---0-----------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------0--0---------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------00000-------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------0000000------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------00000000------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------000000000-----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------0000000000-----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------0000000000-----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------000000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------0000000000-----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------00000000000----------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------000000000------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------000000-------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------000000-------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------0---------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------00--------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------00--------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------00--------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------0---------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------
------------------------------
--------------------00--------
--------------------00--------
-----------------0-0000-------
-----------------00000000-----
-----------------00000000-----
----------------000000000-----
------------000-000000000-----
-----------0000-000000000-----
-----0000000000000000000------
-----------0000-000000000-----
------------000-000000000-----
----------------000000000-----
-----------------00000000-----
-----------------00000000-----
-----------------0-0000-------
--------------------00--------
--------------------00--------
------------------------------
--- --- rot.py --- --- --- --- --- --- --- --- --- ---
import math
class Point2D(object):
def __init__(self, x=None,y=None):
self.x = x
self.y = y
class Point3D(object):
def __init__(self, x=None,y=None,z=None):
self.x = x
self.y = y
self.z = z
class Rot(object):
rad_const = math.pi / 180.0
def rad(self, theta):
return theta * Rot.rad_const
def __init__(self):
self.sin_table = []
self.cos_table = []
for d in range(360):
self.sin_table.append(math.sin(self.rad(d)))
self.cos_table.append(math.cos(self.rad(d)))
for i in [1]: # points
self.points = []
for i in range(24):
self.points.append(Point3D())
self.points[0].x = 10.0
self.points[0].z = 4.0
self.points[1].x = 4.0
self.points[1].z = 10.0
self.points[2].x = -4.0
self.points[2].z = 10.0
self.points[3].x = -10.0
self.points[3].z = 4.0
self.points[4].x = -10.0
self.points[4].z = -4.0
self.points[5].x = -4.0
self.points[5].z = -10.0
self.points[6].x = 4.0
self.points[6].z = -10.0
self.points[7].x = 10.0
self.points[7].z = -4.0
for i in range(8):
self.points[i].y = 30.0
for i in range(8, 16):
self.points[i].x = self.points[i - 8].x
self.points[i].z = self.points[i - 8].z
self.points[i].y = -30.0
self.points[16].x = 20.0
self.points[16].z = 20.0
self.points[17].x = -20.0
self.points[17].z = 20.0
self.points[18].x = -20.0
self.points[18].z = -20.0
self.points[19].x = 20.0
self.points[19].z = -20.0
for i in range(16, 20):
self.points[i].y = 30.0
for i in range(20, 24):
self.points[i].x = self.points[i - 4].x
self.points[i].z = self.points[i - 4].z
self.points[i].y = -30.0
self.x_off = 320.0
self.y_off = 240.0
self.z_off = 50.0
self.z_deg = 0
self.x_deg = 0
self.y_deg = 0
def flatten(self, cube):
'''
320 : 200 => 1 : 5 / 8 | a.r of 4 : 3, height = 4 / 3 of width, therefore
x : y => 1 : 5 / 6
'''
n = len(self.points)
x_scale = 100.0
y_scale = 100.0 # 83.0
flat = []
for i in range(n):
x = cube[i].x
y = cube[i].y
z = self.z_off - cube[i].z
nx = int(self.x_off + (x / z * x_scale))
ny = int(self.y_off + (y / z * y_scale))
flat.append(Point2D(nx, ny))
return flat
def rotate(self, points, z, x, y):
'''
to rotate a point (oX, oY) through Alpha radians, counter-clockwise, about
the z axis:
nX = [Cos(Alpha) * oX] - [Sin(Alpha) * oY]
nY = [Sin(Alpha) * oX] + [Cos(Alpha) * oY]
'''
rotated = []
for i in range(len(points)):
oX = points[i].x
oY = points[i].y
oZ = points[i].z
# about z axis
nX = (self.cos_table[z] * oX) - (self.sin_table[z] * oY)
nY = (self.sin_table[z] * oX) + (self.cos_table[z] * oY)
oX = nX
oY = nY
# about x axis
nZ = (self.cos_table[x] * oZ) - (self.sin_table[x] * oY)
nY = (self.sin_table[x] * oZ) + (self.cos_table[x] * oY)
oZ = nZ
# about y axis
nX = (self.cos_table[y] * oX) - (self.sin_table[y] * oZ)
nZ = (self.sin_table[y] * oX) + (self.cos_table[y] * oZ)
rotated.append(Point3D(x=nX, y=nY, z=nZ))
return rotated
def draw_to_pixmap(self, points, pixmap, gc, style):
'''
'''
# pixmap.draw_line(self.gc, x, y, self.w/2, self.h/2)
# octal inlay flush with end plate
for i in range(7):
pixmap.draw_line(gc, points[i].x, points[i].y, points[i + 1].x, points[i + 1].y)
pixmap.draw_line(gc, points[7].x, points[7].y, points[0].x, points[0].y)
# connections between octal inlays'pipe'
for i in range(8):
pixmap.draw_line(gc, points[i].x, points[i].y, points[i + 8].x, points[i + 8].y)
# octal inlay flush with end plate
for i in range(8, 15):
pixmap.draw_line(gc, points[i].x, points[i].y, points[i + 1].x, points[i + 1].y)
pixmap.draw_line(gc, points[15].x, points[15].y, points[8].x, points[8].y)
# end plate of column
for i in range(16, 19):
pixmap.draw_line(gc, points[i].x, points[i].y, points[i + 1].x, points[i + 1].y)
pixmap.draw_line(gc, points[19].x, points[19].y, points[16].x, points[16].y)
# end plate of column
for i in range(20, 23):
pixmap.draw_line(gc, points[i].x, points[i].y, points[i + 1].x,points[i + 1].y)
pixmap.draw_line(gc, points[23].x, points[23].y, points[20].x, points[20].y)
def iterate(self, pixmap, gc, style):
'''
'''
rotated = self.rotate(self.points, self.z_deg, self.x_deg, self.y_deg)
flattened = self.flatten(rotated)
self.draw_to_pixmap(flattened, pixmap, gc, style)
def move(self, x, y, z):
self.z_deg = self.z_deg + int(z)
self.x_deg = self.x_deg + int(y)
self.y_deg = self.y_deg - int(x)
self.shake()
def shake(self):
if (self.z_deg >= 360):
self.z_deg = self.z_deg - 360
if (self.z_deg < 0):
self.z_deg = self.z_deg + 360
if (self.x_deg >= 360):
self.x_deg = self.x_deg - 360
if (self.x_deg < 0):
self.x_deg = self.x_deg + 360
if (self.y_deg >= 360):
self.y_deg = self.y_deg - 360
if (self.y_deg < 0):
self.y_deg = self.y_deg + 360
--- --- run.py --- --- --- --- --- --- ---
import gtk
import gobject
import random
# ---
from rot import Rot
class Gfx(object):
'''
'''
def __init__(self):
'''
'''
self.b1_down = False
self.b2_down = False
self.b3_down = False
self.b1_x = None
self.b1_y = None
self.rot = Rot()
self.started = False
self.i = 0
self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.win.set_title('Fractured Nature')
self.gw = 640
self.gh = 480 #int(float(self.gw) / 1.618)
self.win.resize(self.gw, self.gh)
self.win.set_position(gtk.WIN_POS_CENTER)
self.win.connect('destroy', gtk.main_quit)
#self.win.realize()
self.da = gtk.DrawingArea()
self.win.add(self.da)
self.da.set_size_request(self.gw, self.gh)
self.win.set_resizable(False)
self.da.connect("expose-event", self.area_expose_cb)
self.da.connect("button_press_event", self.button_press_event)
self.da.connect("button_release_event", self.button_released_event)
self.da.connect("motion_notify_event", self.motion_notify_event)
#self.da.connect("scroll_event", self.scroll_event)
self.da.set_events(
gtk.gdk.EXPOSURE_MASK |
gtk.gdk.BUTTON_PRESS_MASK |
gtk.gdk.BUTTON_RELEASE_MASK |
gtk.gdk.POINTER_MOTION_MASK #|
# gtk.gdk.SCROLL_MASK
)
self.da.show()
self.win.show_all()
def area_expose_cb(self, area, event):
'''
'''
self.area = area
self.style = self.da.get_style()
self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
self.w, self.h = area.window.get_size()
#for i in dir(area.window): print(i)
self.started = True
return True
def button_press_event(self, widget, event):
if (event.button == 1):
self.b1_x = event.x
self.b1_y = event.y
self.b1_down = True
elif (event.button == 3):
self.b3_z = event.x
self.b3_down = True
elif (event.button == 2):
self.b2_down = True
elif (event.button == 4):
print(4)
elif (event.button == 5):
print(5)
return True
def motion_notify_event(self, widget, event):
if (self.b1_down == True):
x = event.x
y = event.y
d_x = x - self.b1_x
d_y = y - self.b1_y
d_z = 0
self.b1_x = x
self.b1_y = y
self.rot.move(d_x, d_y, d_z)
elif (self.b3_down == True):
z = event.x
d_z = z - self.b3_z
d_y = 0
d_x = 0
self.b3_z = z
self.rot.move(d_x, d_y, d_z)
return True
def button_released_event(self, widget, event):
if (event.button == 1):
self.b1_down = False
elif (event.button == 2):
self.b2_down = False
elif (event.button == 3):
self.b3_down = False
return True
def nop(self):
'''
'''
if (self.started != True):
return True
pixmap = gtk.gdk.Pixmap(self.da.window, self.gw, self.gh, depth=-1)
pixmap.draw_rectangle(self.style.white_gc, True, 0, 0, self.gw, self.gh)
self.rot.iterate(pixmap, self.gc, self.style)
self.area.window.draw_drawable(self.gc, pixmap, 0, 0, 0, 0, -1, -1)
self.area.show()
return True # repeat
g = Gfx()
delay = 50
g.timer = gobject.timeout_add(delay, g.nop)
gtk.main()
# --- --- --- --- --- --- --- --- --- --- --- ---
from optparse import OptionParser
# pyGTK --- --- --- --- --- --- --- --- ---
import pygtk
pygtk.require('2.0')
import gtk
# ElementTree - --- --- --- --- --- --- ---
import xml.etree.ElementTree as ET
# --- --- --- --- --- --- --- --- --- --- --- ---
import sys
xml_2_ns = {
'http://www.s3.org/XML/1998/namespace' : 'xml',
}
ns_2_xml = {
'xml' : 'http://www.s3.org/XML/1998/namespace',
}
def extend_tree(treestore, element, parent_node, ns_list):
'''
'''
#import pdb; pdb.set_trace()
node_label = '%s' % strip_ns_from_str(element.tag, ns_list)
if element.text != None:
element_text = element.text.strip()
if (len(element_text) > 0):
element_text = strip_ns_from_str(element_text, ns_list)
#discard = treestore.append(node, [element_text])
node_label = 'e %s : %s' % (node_label, element_text)
node = treestore.append(parent_node, [node_label])
# add attribute name/val pairs to node
for name, value in element.items():
name = strip_ns_from_str(name, ns_list)
value = strip_ns_from_str(value, ns_list)
label = 'a %s = %s' % (name, value)
treestore.append(node, [label])
# recurse over children
for child_element in element.getchildren():
child_node = extend_tree(treestore, child_element, node, ns_list)
return node
def etree_to_gtk_treestore(tree):
'''
construct gtk.TreeStore(str) from ElementTree
'''
treestore = gtk.TreeStore(str)
ns_list = ns_list_from_tree(tree)
element = tree.getroot()
node_label = '%s' % strip_ns_from_str(element.tag, ns_list)
if element.text != None:
element_text = element.text.strip()
if (len(element_text) > 0):
element_text = strip_ns_from_str(element_text, ns_list)
node_label = 'e %s : %s' % (node_label, element_text)
node = treestore.append(None, [node_label])
for child_e in element.getchildren():
extend_tree(treestore, child_e, node, ns_list)
# add attribute name/val pairs to node
for name, value in element.items():
name = strip_ns_from_str(name, ns_list)
value = strip_ns_from_str(value, ns_list)
label = '%s = %s' % (name, value)
treestore.append(None, [label])
# if ns is global
for ns in ns_list:
label = 'xmlns : %s' % ns
treestore.append(None, [label])
return treestore
def ns_from_string(s):
left = s.find('{')
right = s.find('}')
ns = s[left+1:right]
return ns
def process_potential_ns_string(s, ns_list):
if s == None:
return
if (s.find('{') != -1) and (s.find('}') != -1):
ns = ns_from_string(s)
if (ns not in ns_list):
ns_list.append(ns)
def ns_list_from_element(el, ns_list):
# tag
process_potential_ns_string(el.tag, ns_list)
# text
process_potential_ns_string(el.text, ns_list)
# attributes
for name, value in el.items():
process_potential_ns_string(name, ns_list)
process_potential_ns_string(value, ns_list)
for child_el in el.getchildren():
ns_list_from_element(child_el, ns_list)
return ns_list
def ns_list_from_tree(etree):
'''
'''
ns_list = []
root_e = etree.getroot()
# tag
process_potential_ns_string(root_e.tag, ns_list)
# text
process_potential_ns_string(root_e.text, ns_list)
# attributes
for name, value in root_e.items():
process_potential_ns_string(name, ns_list)
process_potential_ns_string(value, ns_list)
# child elements
for child_el in root_e.getchildren():
ns_list_from_element(child_el, ns_list)
return ns_list
def strip_ns_from_str(s, ns_list):
stripped = str(s)
for ns in ns_list:
token = '{%s}' % ns
loc = stripped.find(token)
if (loc != -1):
stripped = stripped[:loc] + stripped[loc + len(token):len(stripped)]
return stripped
class XMLTreeView:
'''
'''
def delete_event(widget, event, data=None):
'''
not an instance method, cuz gtk will not call as such
'''
gtk.main_quit()
return False
def __init__(self, path, title='pyxtree - python XML tree viewer', xsize=900, ysize = 500):
'''
'''
etree = ET.parse(path)
self.treestore = etree_to_gtk_treestore(etree)
self.window = gtk.Dialog()
self.window.connect("destroy", self.delete_event)
self.window.set_border_width(0)
self.swin_tree = gtk.ScrolledWindow()
self.swin_tree.set_border_width(10)
self.swin_tree.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
self.window.vbox.pack_start(self.swin_tree, True, True, 0)
self.swin_text = gtk.ScrolledWindow()
self.swin_text.set_border_width(10)
self.swin_text.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
self.window.vbox.pack_start(self.swin_text, True, True, 0)
self.window.set_title(title)
self.window.set_size_request(xsize, ysize)
self.window.connect("delete_event", self.delete_event)
# create the TreeView using treestore
self.treeview = gtk.TreeView(self.treestore)
self.tvcolumn = gtk.TreeViewColumn(path)
self.treeview.append_column(self.tvcolumn)
self.cell = gtk.CellRendererText()
# add the cell to the tvcolumn and allow it to expand
self.tvcolumn.pack_start(self.cell, True)
# set the cell "text" attribute to column 0 - retrieve text
# from that column in treestore
self.tvcolumn.add_attribute(self.cell, 'text', 0)
# make it searchable
self.treeview.set_search_column(0)
# Allow sorting on the column
#self.tvcolumn.set_sort_column_id(0)
# Allow drag and drop reordering of rows
#self.treeview.set_reorderable(True)
self.swin_tree.add_with_viewport(self.treeview)
self.swin_tree.show()
xfile = open(path, 'r')
xtext = xfile.read()
xfile.close()
label = gtk.Label(xtext)
# ns_list = ns_list_from_tree(etree)
# ns_str = ''
# for ns in ns_list:
# ns_str = ns_str + str(ns) + '\n'
# label = gtk.Label(ns_str)
label.set_alignment(xalign=0, yalign=0.5)
self.swin_text.add_with_viewport(label)
self.swin_text.show()
self.window.show_all()
def main(path = None):
'''
'''
if (path == None):
filechooser = gtk.FileChooserDialog(
title=None,
action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
filter_stdxmlfiles = gtk.FileFilter()
filter_stdxmlfiles.set_name("Std XML Files")
filter_stdxmlfiles.add_pattern("*.xml")
filter_stdxmlfiles.add_pattern("*.wsdl")
filechooser.add_filter(filter_stdxmlfiles)
filter_allfiles = gtk.FileFilter()
filter_allfiles.set_name("All files")
filter_allfiles.add_pattern("*")
filechooser.add_filter(filter_allfiles)
response = filechooser.run()
if response == gtk.RESPONSE_OK:
path = filechooser.get_filename()
elif response == gtk.RESPONSE_CANCEL:
pass
#log failure
filechooser.destroy()
if (path != None):
tree_view = XMLTreeView(path)
gtk.main()
return
def src_file_from_cmd_args(args):
'''
'''
akapy = [
'pyxtree',
'pyxtree.py',
'python',
'python.exe',
'python2.5',
'python25.exe',
]
cleaned = []
for arg in args:
washed = arg.strip().lower()
if (washed not in akapy) and (washed.find('python') == -1):
cleaned.append(washed)
if len(cleaned) == 0:
cleaned = [None]
return cleaned
def configure_logging(LOG_FILENAME='pyxtree.log'):
import logging
logging.basicConfig(filename=LOG_FILENAME,level=logging.INFO)
log = logging.getLogger()
return log
def setup_command_line_options():
'''
using optparse
define command line arguments
return target filename, None if none specified
'''
parser = OptionParser()
parser.add_option('-f', dest='filename', help='target xml file to view')
(options, args) = parser.parse_args()
return(options.filename)
if __name__ == "__main__":
print('\nPyXTree - david.barkhuizen@gmail.com')
print('help: pyxtree -h\n')
xmlfilepath = setup_command_line_options()
log = configure_logging()
log.info('target file specified at command line = %s' % xmlfilepath)
main(path=xmlfilepath)
declare @targetColumnName varchar(500)
set @targetColumnName = '%YourTargetColumnNameHere%'
select so.[name] as TableName, sc.[name] as ColumnName
from sysobjects so
inner join syscolumns sc on (so.[id] = sc.[id])
where (so.[type] = 'U') and (sc.[name] like @targetColumnName)
declare @targetTableName varchar(500)
set @targetTableName = '%Entity%'
select so.[name] as TableName
from sysobjects so
where (so.[type] = 'U') and (so.[name] like @targetTableName)
#!/usr/bin/env python
import sys
import traceback
def throws():
raise RuntimeError('error from throws')
def nested():
try:
throws()
except Exception, original_error:
try:
raise
finally:
try:
cleanup()
except:
pass # ignore errors in cleanup
def cleanup():
raise RuntimeError('error from cleanup')
def main():
try:
nested()
return 0
except Exception, err:
traceback.print_exc()
return 1
if __name__ == '__main__':
sys.exit(main())
# docpy.py - david.barkhuizn@gmail.com
# 1. module methods - signature, followed by docstring
# 2. module fields ?
# 3. module classes
# class name, parent class, __init__ method parameters & docstring
# instance fields (get from self.? refs in __init__ method)
# ---------------------------------------------------------------
# ISSUES
# need to strip out classes before extracting method info
# can't handle multi-line method signatures
# ---------------------------------------------------------------
import sys
# ---------------------------------------------------------------
single_marker = '\'\'\''
double_marker = '\"\"\"'
# ---------------------------------------------------------------
class MethodInfo:
def __init__(self, method_name, params, docstrings):
'''
method_name - string
params - list of param name strings
'''
self.method_name = method_name
self.params = params
self.docstrings = docstrings
# ---------------------------------------------------------------
def load_text_file(file_path):
'''
return list of lines in text file @ 'file_path'
'''
try:
text_file = open(file_path, 'r')
text_block = text_file.read()
lines = text_block.split('\n')
text_file.close()
return lines
except Exception, err:
print('error during reading of text file %s' % file_path)
print(err)
return []
def src_file_path_from_cmdargs():
valid_args = []
for arg in sys.argv:
if arg.lower() not in ['docpy.py', 'python']:
valid_args.append(arg.lower())
return 'docpy.py'
if len(valid_args) != 1:
return ''
else:
return valid_args[0]
def get_sig_line_idxs(lines):
'''
lines = list of lines in python source file (in sequence)
'''
token = 'def '
indices = []
for i in range(len(lines)):
if lines[i].strip()[:4] == token:
indices.append(i)
return indices
def parse_method_sig(sig):
# e.g.' def parse_methodsig(sig):#comment '
sig = sig.strip()
# e.g.'def parse_methodsig(sig):#comment'
sig = sig[4:len(sig)]
# e.g.'parse_methodsig(sig):#comment'
i = sig.find('#')
if i != -1:
sig = sig[:i-1]
# e.g.'parse_methodsig(sig):
left = sig.find('(')
right = sig.rfind(')')
meth_name = sig[:left]
params = []
if right - left != 1:
params = sig[left+1:right]
params = params.replace(',', ' ')
got_double = True
while got_double == True:
got_double = (params.find(' ') != -1)
if got_double:
params = params.replace(' ', ' ')
params = params.split(' ')
return MethodInfo(meth_name, params, [])
def extract_single_line_docstring(docstring):
'''example of single line method docstring'''
lsingle = docstring.find(single_marker)
ldouble = docstring.find(double_marker)
marker = ''
left = -1
if lsingle != -1:
marker = single_marker
left = lsingle
elif ldouble != -1:
marker = double_marker
left = ldouble
else:
return ''
right = docstring.rfind(marker)
if (right != -1) and (right != left):
return docstring[left+3:right]
else:
return ''
def strip_leading_triplequotes(line):
left = line.find(single_marker)
if left == -1:
left = line.find(double_marker)
if left == -1:
return ''
return line[left + 3:]
def strip_trailing_triplequotes(line):
right = line.rfind(double_marker)
if right == -1:
right = line.rfind(double_marker)
if right == -1:
return ''
return line[:right]
def extract_docstrings(lines, meth_sig_idx, next_meth_sig_idx):
# determine line indices of starting and ending triple quotes
start = -1
end = -1
for i in range(meth_sig_idx + 1, next_meth_sig_idx):
line = lines[i]
sidx = line.find(single_marker)
if sidx == -1:
sidx = line.find(double_marker)
if sidx != -1:
if start == -1:
start = i
else:
end = i
break
if start == -1:
return []
elif end == -1:
single_line = extract_single_line_docstring(lines[start])
if single_line != '':
return [ single_line ]
else:
return []
else:
docstrings = []
for i in range(start, end + 1):
no_whitespace = lines[i].strip()
if i == start:
stripped = strip_leading_triplequotes(no_whitespace)
if stripped != '':
docstrings.append(stripped)
elif i == end:
stripped = strip_trailing_triplequotes(no_whitespace)
if stripped != '':
docstrings.append(stripped)
else:
docstrings.append(no_whitespace)
return docstrings
def get_method_info(lines, meth_sig_idx, next_meth_sig_idx):
method_info = parse_method_sig(lines[meth_sig_idx])
method_info.docstrings = extract_docstrings(lines, meth_sig_idx, next_meth_sig_idx)
return method_info
def mock_method(one, two, three, four):
print('vokol')
def display_module_method_info(meth_info):
print(meth_info.method_name)
for p in meth_info.params:
print(' ' + p)
for docstring in meth_info.docstrings:
print(docstring)
def main():
text_file_path = src_file_path_from_cmdargs()
lines = load_text_file(text_file_path)
sig_line_idxs = get_sig_line_idxs(lines)
module_methods_info = []
for i in range(len(sig_line_idxs)):
idx = sig_line_idxs[i]
if i < len(sig_line_idxs) - 1:
next_idx = sig_line_idxs[i + 1]
else:
next_idx = len(sig_line_idxs)
module_methods_info.append( get_method_info(lines, idx, next_idx) )
for meth_info in module_methods_info:
display_module_method_info(meth_info)
if __name__ == '__main__':
main()
import httplib
httplib.HTTPConnection.debuglevel = 1
import urllib
def enc_quote(ticker, fromY, fromM, fromD, toY, toM, toD):
quote = dict()
quote['s'] = ticker
quote['a'] = fromM
quote['b'] = fromD
quote['c'] = fromY
quote['d'] = toD
quote['e'] = toM
quote['f'] = toY
quote['g'] = "d"
return urllib.urlencode(quote)
url_stem = 'http://ichart.yahoo.com/table.csv?'
quote_tokens = enc_quote('BP', '1900', '01', '01', '2010', '07', '18')
url = url_stem + "&ignore=.csv" + quote_tokens
f = urllib.urlopen(url)
body = f.read()
f.close()
try:
f = open('BP.csv', 'w')
f.write(body)
f.close()
except Exception, err:
print('ERROR: %s\n' % str(err))