2016-05-05 8 views
0

LibreOfficeに付属のPython 3.3を使用して、Windows 10でLibreOffice 5を使用してシェイプ内にハッシュマークパターンを作成しようとしています。コードの2/3は、postと似ていますが、コードリストの最後にハッシュマークを作成することについての追加の質問があります。LibreOfficeの問題でPythonを使用したシェイプのハッシュマークを描画する

これは私が試みたPythonコードです。

import sys 
print(sys.version) 

import socket 
import uno 

# get the uno component context from the PyUNO runtime 
localContext = uno.getComponentContext() 

# create the UnoUrlResolver 
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext) 

# connect to the running office 
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext") 
smgr = ctx.ServiceManager 

# get the central desktop object 
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx) 
model = desktop.getCurrentComponent() 

# Create the shape 
def create_shape(document, x, y, width, height, shapeType): 
    shape = model.createInstance(shapeType) 
    aPoint = uno.createUnoStruct("com.sun.star.awt.Point") 
    aPoint.X, aPoint.Y = x, y 
    aSize = uno.createUnoStruct("com.sun.star.awt.Size") 
    aSize.Width, aSize.Height = width, height 
    shape.setPosition(aPoint) 
    shape.setSize(aSize) 
    return shape 

def formatShape(shape): 
    shape.setPropertyValue("FillColor", int("FFFFFF", 16)) # blue 
    shape.setPropertyValue("LineColor", int("000000", 16)) # black 

    aHatch = uno.createUnoStruct("com.sun.star.drawing.Hatch") 
    #HatchStyle = uno.createUnoStruct("com.sun.star.drawing.HatchStyle") 
    #aHatch.Style=HatchStyle.DOUBLE; 
    aHatch.Color=0x00ff00 
    aHatch.Distance=100 
    aHatch.Angle=450 

    shape.setPropertyValue("FillHatch", aHatch) 
    shape.setPropertyValue("FillStyle", "FillStyle.DOUBLE") 

shape = create_shape(model, 0, 0, 10000, 10000, "com.sun.star.drawing.RectangleShape") 
formatShape(shape) 

drawPage.add(shape) 

このコードは、矩形内部の二重クロスハッチパターンを設定する必要がなく、全くパターンが矩形内部アップを示しません。ハッチスタイルパターンを設定する

aHatch = uno.createUnoStruct("com.sun.star.drawing.Hatch") 
#HatchStyle = uno.createUnoStruct("com.sun.star.drawing.HatchStyle") 
#aHatch.Style=HatchStyle.DOUBLE; 
aHatch.Color=0x00ff00 
aHatch.Distance=100 
aHatch.Angle=450 

shape.setPropertyValue("FillHatch", aHatch) 
shape.setPropertyValue("FillStyle", "FillStyle.DOUBLE") 

ライン:

uno.RuntimeException: pyuno.getClass: 

は、次のエラー

ここ
com.sun.star.drawing.HatchStyleis a ENUM, expected EXCEPTION, 

で失敗私は参考のために使用さJavaBASIC例へのリンクです。

答えて

0

HatchStyle = uno.createUnoStruct( "com.sun.star.drawing.HatchStyle")

HatchStyleEnum、ないStructであるため、これは失敗します。 HatchStyle enumを使用するには、Enumリンクのpythonの例の3つの方法のいずれかを実行します。あなたが例から "FillStyle.HATCH" と "HatchStyle.DOUBLEを" 混乱しているように見えます

shape.setPropertyValue( "塗りつぶしスタイル"、 "FillStyle.DOUBLE")

。これは、コードはPythonでどうあるべきかです:

from com.sun.star.drawing.FillStyle import HATCH 
shape.setPropertyValue("FillStyle", HATCH) 

これは、同様に欠けているように見える:com.sun.starから:

drawPage = model.getDrawPages().getByIndex(0) 
+0

が、私はこれらの2行を追加した後、水平青いハッチマークを得ました。 drawing.FillStyle import HATCH shape.setPropertyValue( "FillStyle"、HATCH) ハッチの色、角度、スタイルを変更するには、ここで追加または変更する必要がありますか? aHatch.Color = 0x00ff00 aHatch.Distance = 100 aHatch.Angle = 450 shape.setPropertyValue( "FillHatch"、aHatch) –

+0

Iは、[基本例](試験https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Structure_of_Drawings#ハッチ)。 Ubuntu(LO 5.0.5)では、この例は宣伝されたとおりに動作し、ハッチ設定は何らかの方法で変更できます。しかし、Windows(LO 5.1.0およびAOO 4.1.2)では、 'FillStyle'の設定は有効ですが、' FillHatch'の設定は効果がありませんでした。 [バグを報告する](https://wiki.documentfoundation.org/QA/BugReport)を検討することをお勧めします。 –

+0

私はWindows 10マシンで開発しており、バグを報告する前にLinuxマシンでPythonコードを試してみます。また、LinuxマシンとWindowsマシンの両方でBASICコードをテストします。 –

関連する問題