Hi Massimo, <br><br><div class="gmail_quote">On Fri, Sep 10, 2010 at 12:10 AM, Massimo Di Stefano <span dir="ltr"><<a href="mailto:massimodisasha@yahoo.it">massimodisasha@yahoo.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi All,<br>
<br>
i'm tring to start some coding on the qgis api<br>
i'm on osx 10.6.4 running qgis 1.6<br>
<br>
following the example from :<br>
<br>
<br>
<a href="http://mapserver.sk/%7Ewonder/qgis/html/canvas.html#using-map-tools-with-canvas" target="_blank">http://mapserver.sk/~wonder/qgis/html/canvas.html#using-map-tools-with-canvas</a><br>
<br>
it works fine if i call it from a qgis-python shell<br>
<br>
but i tried to make small changes to have it running as a standalone application,<br>
<br>
i eliminated the "layer" from the init line :<br>
<br>
QMainWindow.__init__(self)<br>
<br>
used a custom extent :<br>
<br>
self.canvas.setExtent('15.1845401903089403,40.6214856769878665 : 15.2339879807105998,40.6477493100907381')<br>
<br>
and commented out the line :<br>
<br>
#self.canvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )<br>
<br>
then from a standard python shell, i tried :<br>
<br>
>>> import mywnd<br>
>>> dir(mywnd)<br>
['MyWnd', 'QAction', 'QMainWindow', 'QString', 'QgisInterface', 'QgsAnnotationItem', 'QgsColorButton', 'QgsColorButtonV2', 'QgsComposerView', 'QgsEncodingFileDialog', 'QgsFormAnnotationItem', 'QgsGenericProjectionSelector', 'QgsLegendInterface', 'QgsMapCanvas', 'QgsMapCanvasItem', 'QgsMapCanvasLayer', 'QgsMapCanvasMap', 'QgsMapCanvasSnapper', 'QgsMapOverviewCanvas', 'QgsMapTip', 'QgsMapTool', 'QgsMapToolEmitPoint', 'QgsMapToolPan', 'QgsMapToolZoom', 'QgsMessageViewer', 'QgsProjectBadLayerGuiHandler', 'QgsProjectionSelector', 'QgsQuickPrint', 'QgsRendererV2PropertiesDialog', 'QgsRendererV2Widget', 'QgsRubberBand', 'QgsStyleV2ManagerDialog', 'QgsSymbolLayerV2Widget', 'QgsSymbolV2PropertiesDialog', 'QgsSymbolV2SelectorDialog', 'QgsTextAnnotationItem', 'QgsVertexMarker', 'Qt', 'SIGNAL', '__builtins__', '__doc__', '__file__', '__name__', '__package__']<br>
>>> w = mywnd.MyWnd()<br>
QWidget: Must construct a QApplication before a QPaintDevice<br>
Abort trap<br></blockquote><div>the MyWnd is a QWidget. <br><br>You must create a QApplication instance and only after this you can <br>show widgets within it. <br><br>Here an example (main.py):<br><span style="font-family: courier new,monospace;"><br>
<br>from PyQt4.QtGui import QApplication</span><br><span style="font-family: courier new,monospace;">from mywdg import </span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">MyWdg</span><br>
<span style="font-family: courier new,monospace;"><br>class MainApp(QApplication):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> def __init__(self, args):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> QApplication.__init__(self, args)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> wdg = </span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">MyWdg()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> wdg.show()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> self.exec_()</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if __name__ == "__main__":</span><br> import sys<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> app = </span><span style="font-family: courier new,monospace;">MainApp(</span><span style="font-family: courier new,monospace;">sys.args)</span><br>
<br><br>Then open a terminal and run<span style="font-family: courier new,monospace;">: python main.py<br></span>and if all went fine you can see your widget<span style="font-family: courier new,monospace;">.<br><br>Cheers.<br style="font-family: courier new,monospace;">
</span><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
<br>
it give me a python crash ... obviously i'm missing something basilar,<br>
<br>
have you any clue on what i need to change to have the example working outside qgis ?<br>
<br>
<br>
thanks a lot !!!<br>
<br>
regards,<br>
<br>
Massimo<br>
<br>
_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Giuseppe Sucameli<br>