当前位置: 首页>>代码示例>>Python>>正文


Python Drawing.asString方法代码示例

本文整理汇总了Python中reportlab.graphics.shapes.Drawing.asString方法的典型用法代码示例。如果您正苦于以下问题:Python Drawing.asString方法的具体用法?Python Drawing.asString怎么用?Python Drawing.asString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.graphics.shapes.Drawing的用法示例。


在下文中一共展示了Drawing.asString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getCaptcha

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import asString [as 别名]
def getCaptcha(n=5,fontName='Courier',fontSize=14,text=None,fillColor=None):
    '''return n random chars in a string and in a byte string structured
    as a GIF image'''
    from reportlab.graphics.shapes import Drawing, Group, String, \
        rotate, skewX, skewY, mmult, translate, Rect
    if not text:
        from random import randint, uniform
        text=''.join([_allowed[randint(0,_mx)] for i in range(n)])
    else:
        uniform = lambda l,h: 0.5*(l+h)
        n = len(text)
    baseline = 0
    x = 0
    G0 = Group()
    for c in text:
        x += 1
        A = translate(x,uniform(baseline-5,baseline+5))
        A = mmult(A,rotate(uniform(-15,15)))
        A = mmult(A,skewX(uniform(-8,8)))
        A = mmult(A,skewY(uniform(-8,8)))
        G = Group(transform=A)
        G.add(String(0,0,c,fontname=fontName,fontSize=fontSize))
        G0.add(G)
        x0,y0,x1,y1 = G0.getBounds()
        x = 1+x1
    G0.transform=translate(2-x0,2-y0)
    W = 4+x1-x0
    H = 4+y1-y0
    D = Drawing(W,H)
    if fillColor:
        from reportlab.lib.colors import toColor
        D.add(Rect(0,0,W,H, fillColor = toColor(fillColor),strokeColor=None))
    D.add(G0)
    return text, D.asString('gif')
开发者ID:AndyKovv,项目名称:hostel,代码行数:36,代码来源:captcha.py

示例2: get_actual_status_img

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import asString [as 别名]
def get_actual_status_img(request, output_format='png', width=600, height=600):
    if reportlab is None:
        messages.error(request, _("Module") + " reportlab " + _("is not available"))
        try:
            redirect_to = request.META['HTTP_REFERER']
        except KeyError:
            redirect_to = '/'
        return HttpResponseRedirect(redirect_to)
    status_list = Status.objects.all()
    
    drawing = Drawing(width, height)
    pie = Pie3d()
    pie.x = 100
    pie.y = 100
    pie.width = width / 2
    pie.height = height / 2

    pie.labels = [ s.name for s in status_list ]
    pie.data = [ s.task_set.count() for s in status_list ]
    pie.slices[3].fontColor = colors.red
    pie.slices[0].fillColor = colors.darkcyan
    pie.slices[1].fillColor = colors.blueviolet
    pie.slices[2].fillColor = colors.blue
    pie.slices[3].fillColor = colors.cyan
    pie.slices[4].fillColor = colors.aquamarine
    pie.slices[5].fillColor = colors.cadetblue
    pie.slices[6].fillColor = colors.lightcoral
        
    drawing.add(pie)
    image = drawing.asString(output_format)
    response = HttpResponse(image, mimetype='image/%s' % output_format.lower())
    return response
开发者ID:dekoza,项目名称:django-projector,代码行数:34,代码来源:reports.py

示例3: img

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import asString [as 别名]
def img(code, value, scale):
    try:
        dr = createBarcodeDrawing(code, value=str(value), humanReadable=True)
        dr.renderScale = scale
        d = Drawing(dr.width*scale, dr.height*scale)
        d.add(dr)
        d.renderScale = scale
        response = make_response(d.asString('png'))
        response.mimetype = 'image/png'
        return response
    except:
        return send_from_directory(os.path.join(app.root_path, 'static'),
                                   'error.png', mimetype='image/png')
开发者ID:gitu,项目名称:furry-barcode,代码行数:15,代码来源:barcode.py

示例4: run

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import asString [as 别名]
def run(self, include_sub_survey=False, dimensions=[]):

    # Build data set
    averages = []
    category_names = []
    
    for dimension in self.getDimensions():
        averages.append(self.get_average_score_for_dimension(
            include_sub_survey=include_sub_survey,
            dimension=dimension))
        category_names.append(dimension)
        
    drawing = Drawing(600, 300)
    
    bc = VerticalBarChart()         
    bc.x = 20
    bc.y = 20  
    bc.height = 260
    bc.width = 580
    bc.data = [averages]
    bc.categoryAxis.categoryNames = category_names
    bc.categoryAxis.labels.fontName = 'Helvetica'
    bc.categoryAxis.labels.fontSize = 10
    bc.categoryAxis.labels.textAnchor = 'middle'
    bc.categoryAxis.visibleTicks = 0
    bc.valueAxis.valueMax = 100.0
    bc.valueAxis.valueMin = min(averages, 0)
    bc.valueAxis.labels.fontName = 'Helvetica'
    bc.valueAxis.labels.fontSize = 10
    bc.valueAxis.labels.textAnchor = 'middle'
    bc.barLabelFormat = '%.0f'
    bc.barLabels.dy = 8
    bc.barLabels.fontName = 'Helvetica'
    bc.barLabels.fontSize = 10
    bc.barWidth = len(averages)
    bc.fillColor = None

    drawing.add(bc)
    
    # Write out
    data = drawing.asString('png')
    request = self.REQUEST
    response = request.RESPONSE
    response.setHeader('Content-Type', 'image/png')
    response.setHeader('Content-Disposition','inline; filename=%s.png' % self.getId())
    response.setHeader('Content-Length', len(data))           
    response.setHeader('Cache-Control', 's-maxage=0')
    
    return data
开发者ID:UPCnet,项目名称:Products.PloneSurvey,代码行数:51,代码来源:results_dimensions.py

示例5: test

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import asString [as 别名]

#.........这里部分代码省略.........

        ('Siena Web Service Architecture', 'Marc-Andre Lemburg', 1, 1, 10.5, 1.5),
        ('Extreme Programming in Python', 'Chris Withers', 2, 1, 10.5, 1.5),
        ('Pattern Experiences in C++', 'Mark Radford', 3, 1, 10.5, 1.5),
        ('What is the Type of std::toupper()', 'Gabriel Dos Reis', 4, 1, 10.5, 1.5),
        ('Linguistic Variables: Clear Thinking with Fuzzy Logic ', 'Walter Banks', 5, 1, 10.5, 1.5),

        ('lunch, short presentations, vendor presentations', '', None, 1, 12.0, 2.0),

        ("CORBA? Isn't that obsolete", 'Duncan Grisby', 1, 1, 14.0, 1.5),
        ("Python Design Patterns", 'Duncan Booth', 2, 1, 14.0, 1.5),
        ("Inside Security Checks and Safe Exceptions", 'Brandon Bray', 3, 1, 14.0, 1.5),
        ("Studying at a Distance", 'Panel Discussion, Panel to include Alan Lenton & Francis Glassborow', 4, 1, 14.0, 1.5),
        ("Coding Standards - Given the ANSI C Standard why do I still need a coding Standard", 'Randy Marques', 5, 1, 14.0, 1.5),

        ("RESTful Python", 'Hamish Lawson', 1, 1, 16.0, 1.5),
        ("Parsing made easier - a radical old idea", 'Andrew Koenig', 2, 1, 16.0, 1.5),
        ("C++ & Multimethods", 'Julian Smith', 3, 1, 16.0, 1.5),
        ("C++ Threading", 'Kevlin Henney', 4, 1, 16.0, 1.5),
        ("The Organisation Strikes Back", 'Alan Griffiths & Sarah Lees', 5, 1, 16.0, 1.5),

        ('Birds of a Feather meeting', '', None, 1, 17.5, 2.0),

        ('Keynote: In the Spirit of C',  'Greg Colvin', None, 2, 9.0, 1.0),

        ('The Infinite Filing Cabinet - object storage in Python', 'Jacob Hallen', 1, 2, 10.5, 1.5),
        ('Introduction to Python and Jython for C++ and Java Programmers', 'Alex Martelli', 2, 2, 10.5, 1.5),
        ('Template metaprogramming in Haskell', 'Simon Peyton Jones', 3, 2, 10.5, 1.5),
        ('Plenty People Programming: C++ Programming in a Group, Workshop with a difference', 'Nico Josuttis', 4, 2, 10.5, 1.5),
        ('Design and Implementation of the Boost Graph Library', 'Jeremy Siek', 5, 2, 10.5, 1.5),

        ('lunch, short presentations, vendor presentations', '', None, 2, 12.0, 2.0),

        ("Building GUI Applications with PythonCard and PyCrust", 'Andy Todd', 1, 2, 14.0, 1.5),
        ("Integrating Python, C and C++", 'Duncan Booth', 2, 2, 14.0, 1.5),
        ("Secrets and Pitfalls of Templates", 'Nicolai Josuttis & David Vandevoorde', 3, 2, 14.0, 1.5),
        ("Being a Mentor", 'Panel Discussion, Panel to include Alan Lenton & Francis Glassborow', 4, 2, 14.0, 1.5),
        ("The Embedded C Extensions to C", 'Willem Wakker', 5, 2, 14.0, 1.5),

        ("Lightning Talks", 'Paul Brian', 1, 2, 16.0, 1.5),
        ("Scripting Java Applications with Jython", 'Anthony Eden', 2, 2, 16.0, 1.5),
        ("Metaprogramming and the Boost Metaprogramming Library", 'David Abrahams', 3, 2, 16.0, 1.5),
        ("A Common Vendor ABI for C++ -- GCC's why, what and not", 'Nathan Sidwell & Gabriel Dos Reis', 4, 2, 16.0, 1.5),
        ("The Timing and Cost of Choices", 'Hubert Matthews', 5, 2, 16.0, 1.5),

        ('Birds of a Feather meeting', '', None, 2, 17.5, 2.0),

        ('Keynote: The Cost of C & C++ Compatibility', 'Andy Koenig', None, 3, 9.0, 1.0),

        ('Prying Eyes: Generic Observer Implementations in C++', 'Andrei Alexandrescu', 1, 2, 10.5, 1.5),
        ('The Roadmap to Generative Programming With C++', 'Ulrich Eisenecker', 2, 2, 10.5, 1.5),
        ('Design Patterns in C++ and C# for the Common Language Runtime', 'Brandon Bray', 3, 2, 10.5, 1.5),
        ('Extreme Hour (XH): (workshop) - Jutta Eckstein and Nico Josuttis', 'Jutta Ecstein', 4, 2, 10.5, 1.5),
        ('The Lambda Library : Unnamed Functions for C++', 'Jaako Jarvi', 5, 2, 10.5, 1.5),

        ('lunch, short presentations, vendor presentations', '', None, 3, 12.0, 2.0),

        ('Reflective Metaprogramming', 'Daveed Vandevoorde', 1, 3, 14.0, 1.5),
        ('Advanced Template Issues and Solutions (double session)', 'Herb Sutter',2, 3, 14.0, 3),
        ('Concurrent Programming in Java (double session)', 'Angelika Langer', 3, 3, 14.0, 3),
        ('What can MISRA-C (2nd Edition) do for us?', 'Chris Hills', 4, 3, 14.0, 1.5),
        ('C++ Metaprogramming Concepts and Results', 'Walter E Brown', 5, 3, 14.0, 1.5),

        ('Binding C++ to Python with the Boost Python Library', 'David Abrahams', 1, 3, 16.0, 1.5),
        ('Using Aspect Oriented Programming for Enterprise Application Integration', 'Arno Schmidmeier', 4, 3, 16.0, 1.5),
        ('Defective C++', 'Marc Paterno', 5, 3, 16.0, 1.5),

        ("Speakers' Banquet & Birds of a Feather meeting", '', None, 3, 17.5, 2.0),

        ('Keynote: The Internet, Software and Computers - A Report Card', 'Alan Lenton',  None, 4, 9.0, 1.0),

        ('Multi-Platform Software Development; Lessons from the Boost libraries', 'Beman Dawes', 1, 5, 10.5, 1.5),
        ('The Stability of the C++ ABI', 'Steve Clamage', 2, 5, 10.5, 1.5),
        ('Generic Build Support - A Pragmatic Approach to the Software Build Process', 'Randy Marques', 3, 5, 10.5, 1.5),
        ('How to Handle Project Managers: a survival guide', 'Barb Byro',  4, 5, 10.5, 1.5),

        ('lunch, ACCU AGM', '', None, 5, 12.0, 2.0),

        ('Sauce: An OO recursive descent parser; its design and implementation.', 'Jon Jagger', 1, 5, 14.0, 1.5),
        ('GNIRTS ESAC REWOL -  Bringing the UNIX filters to the C++ iostream library.', 'JC van Winkel', 2, 5, 14.0, 1.5),
        ('Pattern Writing: Live and Direct', 'Frank Buschmann & Kevlin Henney',  3, 5, 14.0, 3.0),
        ('The Future of Programming Languages - A Goldfish Bowl', 'Francis Glassborow and friends',  3, 5, 14.0, 1.5),

        ('Honey, I Shrunk the Threads: Compile-time checked multithreaded transactions in C++', 'Andrei Alexandrescu', 1, 5, 16.0, 1.5),
        ('Fun and Functionality with Functors', 'Lois Goldthwaite', 2, 5, 16.0, 1.5),
        ('Agile Enough?', 'Alan Griffiths', 4, 5, 16.0, 1.5),
        ("Conference Closure: A brief plenary session", '', None, 5, 17.5, 0.5),

        ]

    #return cal
    cal.day = 1

    d.add(cal)


    for format in ['pdf']:#,'gif','png']:
        out = d.asString(format)
        open('eventcal.%s' % format, 'wb').write(out)
        print 'saved eventcal.%s' % format
开发者ID:tschalch,项目名称:pyTray,代码行数:104,代码来源:eventcal.py

示例6: run

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import asString [as 别名]

#.........这里部分代码省略.........
                # Lookup the integer weight of this answer
                if value in answeroptions:
                    index = answeroptions.index(value)
                    weight = weights[index]
            # Always add to the list. ReportLab deals with None.    
            if counter == 0:
                dimension_one_values.append(weight)
            else:
                dimension_two_values.append(weight)
                
        counter += 1

    # Set minmax
    absmax = max(abs(minval), abs(maxval)) * 1.1    
    lc.xValueAxis.valueMin = -absmax
    lc.xValueAxis.valueMax = absmax    
    lc.yValueAxis.valueMin = -absmax
    lc.yValueAxis.valueMax = absmax
       
    # Zip to create data
    data = [zip(dimension_one_values, dimension_two_values)]
    if not len(data[0]):
        return
    
    lc.x = 0
    lc.y = 0
    # Misc setup
    lc.height = 300
    lc.width = 300
    lc.data = data
    lc.joinedLines = 0
    lc.fillColor = None
    lc.lines[0].strokeColor = colors.red
    lc.lines[0].symbol = makeMarker('FilledCircle')

    # Add a grid
    grid = DoubleGrid()
    lc.background = grid
    setupGrid(lc)    
    lc.background = None
    # Finetune the grid
    grid.grid0.strokeWidth = 0.2
    grid.grid1.strokeWidth = 0.2
    # Add to drawing else it overwrites the center Y axis
    drawing.add(grid)
   
    # Add a Y axis to pass through the origin
    yaxis = YValueAxis()
    yaxis.setPosition(lc.width/2, 0, lc.height)
    yaxis.configure([(0,-absmax),(0,absmax)])
    yaxis.strokeColor = colors.blue
    drawing.add(yaxis)

    # Color X-Axis
    lc.xValueAxis.strokeColor = colors.green

    drawing.add(lc)

    # Legend for Dimension One
    drawing.add(String(lc.width+20, lc.height-12, 'Dimension One (X-Axis):', 
        fontName='Helvetica', fontSize=12, fillColor=colors.green))
    legend = Legend()
    legend.alignment = 'right'
    legend.x = lc.width + 20
    legend.y = lc.height - 20
    legend.fontName = 'Helvetica'
    legend.fontSize = 12
    legend.columnMaximum = 7
    items = []
    for ob in dimension_one_answeroptions_as_objects:
        items.append( ( StringWidget(ob.getWeight()), ob() ) )
    legend.colorNamePairs = items
    drawing.add(legend, 'legend1')

    # Legend for Dimension Two
    drawing.add(String(lc.width+20, lc.height/2-12, 'Dimension Two (Y-Axis):', 
        fontName='Helvetica', fontSize=12, fillColor=colors.blue))
    legend = Legend()
    legend.alignment = 'right'
    legend.x = lc.width + 20
    legend.y = lc.height/2 - 20
    legend.fontName = 'Helvetica'
    legend.fontSize = 12
    legend.columnMaximum = 7
    items = []
    for ob in dimension_two_answeroptions_as_objects:
        items.append( ( StringWidget(ob.getWeight()), ob() ) )
    legend.colorNamePairs = items
    drawing.add(legend, 'legend2')

    # Write out
    data = drawing.asString('png')
    request = self.REQUEST
    response = request.RESPONSE
    response.setHeader('Content-Type', 'image/png')
    response.setHeader('Content-Disposition','inline; filename=%s.png' % self.getId())
    response.setHeader('Content-Length', len(data))           
    response.setHeader('Cache-Control', 's-maxage=0')
    
    return data
开发者ID:UPCnet,项目名称:Products.PloneSurvey,代码行数:104,代码来源:get_2d_chart.py


注:本文中的reportlab.graphics.shapes.Drawing.asString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。