Exemplo n.º 1
0
def random_wallpaper_files(directory, minnumber=0, maxnumber=100):
    """Generates random wallpaper files in the specified directory
    @returns: a list of filenames (the basenames including the extension)
    """

    names=[gen_string(minlength=10, maxlength=50) for i in range(random.randrange(minnumber, maxnumber))]
    print "Generating",len(names),"wallpaper files"

    from wxPython.lib import colourdb
    colourdb.updateColourDB()
    colours=colourdb.getColourList()

    penstyles=[ wx.SOLID, wx.DOT, wx.LONG_DASH, wx.SHORT_DASH, wx.CROSS_HATCH ]
    types=[ (wx.BITMAP_TYPE_BMP, ".bmp"), (wx.BITMAP_TYPE_JPEG, ".jpg"), (wx.BITMAP_TYPE_PNG, ".png")]

    
    for n in range(len(names)):
        width=random.randrange(1,200)
        height=random.randrange(1,200)
        bitmap=wx.EmptyBitmap(width, height)
        mdc=wx.MemoryDC()
        mdc.SelectObject(bitmap)
        mdc.Clear()
        for i in range(random.randrange(1,200)):
            pen=wx.Pen(random.choice(colours), random.randrange(1,10), random.choice(penstyles))
            mdc.SetPen(pen)
            mdc.DrawLine(random.randrange(0,width), random.randrange(0,height), random.randrange(0,width), random.randrange(0, height))
        t,e=random.choice(types)
        names[n]=names[n]+e
        mdc.SelectObject(wx.NullBitmap)
        bitmap.SaveFile(os.path.join(directory, names[n]), t)
    
    print "  ... generation complete"
    return names
Exemplo n.º 2
0
	def coerce(cls, value):
		"""Attempt to convert the given value to a wx.Colour

		Accepted Values:
			wx.Colour(Ptr)
			'#FFFFFF' style strings
			'black' string colour names
			3-tuple or 3-list of 0-255 integers
			None -- (gives black)
		"""
		if cls.check( value ):
			return value
		elif isinstance( value, (str,unicode) ):
			if value and value[0] == '#':
				rest = value[1:]
				if rest:
					value = int( rest, 16)
					return wx.Colour( value >> 16  & 255, value >> 8  & 255, value & 255 )
				else:
					return wx.Colour( 0,0,0)
			else:
				try:
					obj = wx.Colour( value )
				except (ValueError,TypeError):
					global COLOUR_DB_INITIALISED
					if not COLOUR_DB_INITIALISED:
						COLOUR_DB_INITIALISED = 1
						colourdb.updateColourDB()
					obj = wx.NamedColour( value )
					if not obj.Ok():
						raise ValueError( """Unrecognised string value %r for Colour value"""%(value))
		elif isinstance( value, (tuple,list) ):
			if len(value) == 3:
				obj = wx.Colour( *value )
			else:
				raise ValueError( """Unable to create wx.Colour from %r, incorrect length"""%( value ))
		elif value is None:
			return wx.Colour( 0,0,0)
		else:
			raise TypeError( """Unable to convert value %r (type %s) to wx.Colour object"""%( value, type(value)))
		return obj
Exemplo n.º 3
0
def random_wallpaper_files(directory, minnumber=0, maxnumber=100):
    """Generates random wallpaper files in the specified directory
    @returns: a list of filenames (the basenames including the extension)
    """

    names = [
        gen_string(minlength=10, maxlength=50)
        for i in range(random.randrange(minnumber, maxnumber))
    ]
    print "Generating", len(names), "wallpaper files"

    from wxPython.lib import colourdb
    colourdb.updateColourDB()
    colours = colourdb.getColourList()

    penstyles = [wx.SOLID, wx.DOT, wx.LONG_DASH, wx.SHORT_DASH, wx.CROSS_HATCH]
    types = [(wx.BITMAP_TYPE_BMP, ".bmp"), (wx.BITMAP_TYPE_JPEG, ".jpg"),
             (wx.BITMAP_TYPE_PNG, ".png")]

    for n in range(len(names)):
        width = random.randrange(1, 200)
        height = random.randrange(1, 200)
        bitmap = wx.EmptyBitmap(width, height)
        mdc = wx.MemoryDC()
        mdc.SelectObject(bitmap)
        mdc.Clear()
        for i in range(random.randrange(1, 200)):
            pen = wx.Pen(random.choice(colours), random.randrange(1, 10),
                         random.choice(penstyles))
            mdc.SetPen(pen)
            mdc.DrawLine(random.randrange(0,
                                          width), random.randrange(0, height),
                         random.randrange(0, width),
                         random.randrange(0, height))
        t, e = random.choice(types)
        names[n] = names[n] + e
        mdc.SelectObject(wx.NullBitmap)
        bitmap.SaveFile(os.path.join(directory, names[n]), t)

    print "  ... generation complete"
    return names