def data(self, index): d = slew.DataSpecifier() if index.column == 0: d.text = self._data[index.row][0] d.icon = slew.Bitmap(size=(16, 16)) d.icon.bgcolor = (0, 255, 0) d.icon.rect((0, 0), (15, 15)) d.flags |= slew.DataSpecifier.CLICKABLE_ICON d.completer = slew.Completer(model=CompleterModel()) # d.flags = slew.DataSpecifier.READONLY # d.completer = slew.Completer(model=CompletionModel(10))#self._icons) # elif index.column == 1: # d.flags = slew.DataSpecifier.CHECKBOX # d.selection = self._data[index.row][1] # elif index.column == 2: # d.flags = slew.DataSpecifier.COMBOBOX # d.choices = ('Pippo', 'Pluto', 'Paperino') # d.selection = self._data[index.row][2] elif index.column == 3: d.text = self._data[index.row][3] elif index.column == 4: d.text = self._data[index.row][4] d.icon = slew.Bitmap(size=(16, 16)) d.icon.bgcolor = (255, 0, 0) d.icon.rect((0, 0), (15, 15)) d.datatype = slew.DATATYPE_TIME if (index.row % 2 == 0): d.format = "HMr" else: d.format = "HM" d.flags |= slew.DataSpecifier.HTML # print "data: ", d d.flags |= slew.DataSpecifier.DEFAULT | slew.DataSpecifier.DRAGGABLE | slew.DataSpecifier.DROP_TARGET if (index.column != 3): d.flags &= ~slew.DataSpecifier.READONLY return d
class IconsModel(slew.DataModel): ICON = slew.Bitmap(resource="nuova_scheda.png") def row_count(self, index): if index is None: return 3 return 0 def data(self, index): d = slew.DataSpecifier() d.icon = self.ICON d.text = "Icon %d" % index.row d.align = slew.ALIGN_CENTER d.flags |= d.DRAGGABLE if index.row > 0: d.flags |= d.DROP_TARGET return d
def Print_Callback(dc, page, userdata): if (page == 2): dc.size = (3000, 3000) elif (page == 3): dc.dpi = (100, 100) elif (page == 4): dc.set_size((2100, 2970)) print 'Printer DPI: ', dc.get_printer_dpi() print 'size: ', dc.size print 'dpi: ', dc.dpi pageRect = dc.get_page_rect() print 'page: ', pageRect # paperRect = dc.get_paper_rect() # print 'paper: ', paperRect s = dc.size.w - 1 dc.color = (0, 255, 0) print dc.color, dc.bgcolor dc.rect((0, 0), (s, s)) dc.line((0, 0), (s, s)) dc.line((s, 0), (0, s)) dc.rect((3, 10), (5, 12)) dc.color = (255, 0, 0) dc.bgcolor = None text = "La pagina รจ: %d" % page dc.font = slew.Font(size=40) dc.text(text, (100, 50)) dc.rect((100, 50), slew.Vector(100, 50) + dc.text_extent(text)) families = { slew.Font.FAMILY_ROMAN: 'Roman', slew.Font.FAMILY_SCRIPT: 'Script', slew.Font.FAMILY_SANS_SERIF: 'Sans-serif', slew.Font.FAMILY_FIXED_PITCH: 'Fixed pitch', slew.Font.FAMILY_TELETYPE: 'Teletype', } # pos = slew.Vector(100, 200) # dc.color = (0,0,0) # for (key, value) in families.iteritems(): # dc.font = slew.Font(size=12, family=key) # dc.text(value, pos) # pos += (0, dc.text_extent(value).h) # print str(a) dc.rect(pageRect[1] - (2, 2), pageRect[1]) dc.color = (0, 255, 0) dc.point(pageRect[1]) dc.color = (0, 0, 0) left = (float(pageRect[0].x) * 2.54) / dc.dpi.x top = (float(pageRect[0].y) * 2.54) / dc.dpi.y right = (float(pageRect[1].x) * 2.54) / dc.dpi.x bottom = (float(pageRect[1].y) * 2.54) / dc.dpi.y print left, top, right, bottom def cm(cm): return (cm / 2.54) * dc.dpi.x dc.color = (0, 0, 255) dc.line((cm(5) - pageRect[0].x, cm(10)), (cm(5) - pageRect[0].x, cm(20))) dc.line((cm(5) - pageRect[0].x, cm(20)), (cm(15) - pageRect[0].x, cm(20))) dc.font = slew.Font(size=int(cm(1))) dc.text("10x10 cm", (cm(6), cm(18))) bmp = slew.Bitmap(resource=os.path.join(os.getenv( 'REPOSITORY'), "trunk", "data", 'tango', 'battery.png')) dc.blit(bmp, (cm(5), cm(21))) bmp.color = (255, 0, 0) bmp.bgcolor = None bmp.rect((0, 0), (31, 31)) bmp.color = (0, 255, 0) bmp.line((0, 0), (31, 31)) bmp.line((31, 0), (0, 31)) dc.blit(bmp, (cm(7), cm(20) + 1)) dc.color = (0, 255, 0) text = "%s dpi, %s size" % (str(dc.dpi), str(dc.size)) s = dc.text_extent(text) print "Text extent for '%s': %s" % (text, str(s)) dc.text(text, ((pageRect[1].x - pageRect[0].x - s.w + 1) / 2, cm(22)))
<sizeritem flags="expand" bordersize="10"> <button name="preview" label="Preview" pos="30,80" size="120,20" /> </sizeritem> <sizeritem flags="expand" bordersize="10"> <button name="print" label="Print" pos="30,110" size="120,20" /> </sizeritem> <sizeritem flags="expand" bordersize="10"> <button name="pdf" label="Save as PDF" pos="30,140" size="120,20" /> </sizeritem> <sceneview name="view" style="opengl|nofocus" size="400,400" /> </sizer> </frame> """ kong = slew.Bitmap(resource="about_logo.png").resized((1000, 1000)) class Handler(slew.EventHandler): def onClick(self, e): name = e.widget.name if name == 'setup': slew.get_application().PageSetup() elif name == 'preview': slew.print_document(slew.PRINT_PREVIEW, 'Test', slew.get_application().Print_Callback, 4, settings=slew.get_application().print_settings) elif name == 'print': slew.print_document(slew.PRINT_PAPER,
import slew logo = slew.Bitmap(resource='python-logo.png') size = logo.get_size() class Logo(slew.SceneItem): def onPaint(self, e): e.dc.blit(logo, (0,0)) class Item(slew.SceneItem): def __init__(self, i): subitem = Logo() subitem.set_size(size) subitem.set_pos((20,20)) self.append(subitem) self.set_size(size + (40,40)) self.set_pos(((i % 10) * (size.w + 100), (i / 10) * (size.h + 100))) def onPaint(self, e): e.dc.bgcolor = (255,255,255) e.dc.rect((0,0), self.get_size()) class Application(slew.Application): def run(self): self.frame = slew.Frame() scene = slew.SceneView(bgcolor=(64,64,64)) for i in xrange(0, 100): scene.append(Item(i)) self.frame.append(slew.VBox().append(scene)) self.frame.show() slew.run(Application())
def __init__(self): self.bitmap = slew.Bitmap(resource="about_logo.png")