Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ repos:
- --license-filepath
- .github/workflows/license-templates/LICENSE.txt
- --fuzzy-match-generates-todo
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.9.0
hooks:
- id: black
name: run black
description: format Python files with black
files:
(?x)^(
main/pyuno/demo/swriter\.py|
main/solenv/inc/lldb4aoo\.py|
main/ucb/source/ucp/ftp/test\.py
)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
Expand Down
94 changes: 50 additions & 44 deletions main/pyuno/demo/swriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,58 +31,60 @@
from com.sun.star.awt import Size


def insertTextIntoCell( table, cellName, text, color ):
tableText = table.getCellByName( cellName )
def insertTextIntoCell(table, cellName, text, color):
tableText = table.getCellByName(cellName)
cursor = tableText.createTextCursor()
cursor.setPropertyValue( "CharColor", color )
tableText.setString( text )
cursor.setPropertyValue("CharColor", color)
tableText.setString(text)


localContext = uno.getComponentContext()

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

smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" )
remoteContext = smgr.getPropertyValue( "DefaultContext" )
smgr = resolver.resolve(
"uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
)
remoteContext = smgr.getPropertyValue("DefaultContext")

#remoteContext = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
#smgr = remoteContext.ServiceManager
# remoteContext = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
# smgr = remoteContext.ServiceManager

desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", remoteContext)

# open a writer document
doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () )
doc = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, ())

text = doc.Text
cursor = text.createTextCursor()
text.insertString( cursor, "The first line in the newly created text document.\n", 0 )
text.insertString( cursor, "Now we are in the second line.\n" , 0 )
text.insertString(cursor, "The first line in the newly created text document.\n", 0)
text.insertString(cursor, "Now we are in the second line.\n", 0)

# create a text table
table = doc.createInstance( "com.sun.star.text.TextTable" )
table = doc.createInstance("com.sun.star.text.TextTable")

# with 4 rows and 4 columns
table.initialize( 4,4)
table.initialize(4, 4)

text.insertTextContent( cursor, table, 0 )
text.insertTextContent(cursor, table, 0)
rows = table.Rows

table.setPropertyValue( "BackTransparent", uno.Bool(0) )
table.setPropertyValue( "BackColor", 13421823 )
table.setPropertyValue("BackTransparent", uno.Bool(0))
table.setPropertyValue("BackColor", 13421823)
row = rows.getByIndex(0)
row.setPropertyValue( "BackTransparent", uno.Bool(0) )
row.setPropertyValue( "BackColor", 6710932 )
row.setPropertyValue("BackTransparent", uno.Bool(0))
row.setPropertyValue("BackColor", 6710932)

textColor = 16777215

insertTextIntoCell( table, "A1", "FirstColumn", textColor )
insertTextIntoCell( table, "B1", "SecondColumn", textColor )
insertTextIntoCell( table, "C1", "ThirdColumn", textColor )
insertTextIntoCell( table, "D1", "SUM", textColor )
insertTextIntoCell(table, "A1", "FirstColumn", textColor)
insertTextIntoCell(table, "B1", "SecondColumn", textColor)
insertTextIntoCell(table, "C1", "ThirdColumn", textColor)
insertTextIntoCell(table, "D1", "SUM", textColor)

values = ( (22.5,21.5,121.5),
(5615.3,615.3,-615.3),
(-2315.7,315.7,415.7) )
values = ((22.5, 21.5, 121.5), (5615.3, 615.3, -615.3), (-2315.7, 315.7, 415.7))
table.getCellByName("A2").setValue(22.5)
table.getCellByName("B2").setValue(5615.3)
table.getCellByName("C2").setValue(-2315.7)
Expand All @@ -99,27 +101,31 @@ def insertTextIntoCell( table, cellName, text, color ):
table.getCellByName("D4").setFormula("sum <A4:C4>")


cursor.setPropertyValue( "CharColor", 255 )
cursor.setPropertyValue( "CharShadowed", uno.Bool(1) )
cursor.setPropertyValue("CharColor", 255)
cursor.setPropertyValue("CharShadowed", uno.Bool(1))

text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
text.insertString( cursor, " This is a colored text - blue with shadow\n" , 0 )
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)
text.insertString(cursor, " This is a colored text - blue with shadow\n", 0)
text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)

textFrame = doc.createInstance( "com.sun.star.text.TextFrame" )
textFrame.setSize( Size(15000,400))
textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER )
textFrame = doc.createInstance("com.sun.star.text.TextFrame")
textFrame.setSize(Size(15000, 400))
textFrame.setPropertyValue("AnchorType", AS_CHARACTER)


text.insertTextContent( cursor, textFrame, 0 )
text.insertTextContent(cursor, textFrame, 0)

textInTextFrame = textFrame.getText()
cursorInTextFrame = textInTextFrame.createTextCursor()
textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 )
textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the frame raises.",0)
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )

cursor.setPropertyValue( "CharColor", 65536 )
cursor.setPropertyValue( "CharShadowed", uno.Bool(0) )

text.insertString( cursor, " That's all for now!" , 0 )
textInTextFrame.insertString(
cursorInTextFrame, "The first line in the newly created text frame.", 0
)
textInTextFrame.insertString(
cursorInTextFrame, "\nWith this second line the height of the frame raises.", 0
)
text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)

cursor.setPropertyValue("CharColor", 65536)
cursor.setPropertyValue("CharShadowed", uno.Bool(0))

text.insertString(cursor, " That's all for now!", 0)
192 changes: 109 additions & 83 deletions main/solenv/inc/lldb4aoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,106 +16,132 @@
# under the License.

# to activate the AOO-LLDB helper script type the line below into LLDB
# command script import path-to-script/lldb4aoo.py
# command script import path-to-script/lldb4aoo.py
# or activate it automatically by adding the line to ~/.lldbinit

def __lldb_init_module( dbg, dict):
# the list of AOO specific types
aoo_types = ['rtl_String', 'rtl_uString', '_ByteStringData', '_UniStringData']
pimpl_types = ['rtl::OString', 'rtl::OUString', 'ByteString', 'UniString']
# register a helper function for each non-trivial type
for t in aoo_types:
f = 'getinfo_for_' + t.replace( '::', '_')
if f in globals():
dbg.HandleCommand( 'type summary add %s -v -C yes -F %s.%s' % (t,__name__,f))
else:
print( 'AOO-LLDB helper function "%s" is not yet defined: '
'"%s" types cannot be displayed properly!' % (f,t))
# register a generic helper function for pimpl types
dbg.HandleCommand( 'type summary add -F %s.%s -v -C yes -n PIMPL %s' % ( __name__,'get_pimpl_info', ' '.join(pimpl_types)))

# add info about specific helper methods
# assume functions with docstrings are available for general consumption
helper_funcs = [v for (k,v) in globals().iteritems() if( not k.startswith('_') and callable(v) and v.__doc__)]
if helper_funcs:
print( 'Available AOO-specific helper functions:')
for hfunc in helper_funcs:
shortdesc = hfunc.__doc__.splitlines()[0]
print( '\t%s\t# "%s"' %(hfunc.__name__, shortdesc))
print( 'Run them with:')
for hfunc in helper_funcs[:4]:
print( '\tscript %s.%s()' %(__name__, hfunc.__name__))

def __lldb_init_module(dbg, dict):
# the list of AOO specific types
aoo_types = ["rtl_String", "rtl_uString", "_ByteStringData", "_UniStringData"]
pimpl_types = ["rtl::OString", "rtl::OUString", "ByteString", "UniString"]
# register a helper function for each non-trivial type
for t in aoo_types:
f = "getinfo_for_" + t.replace("::", "_")
if f in globals():
dbg.HandleCommand(
"type summary add %s -v -C yes -F %s.%s" % (t, __name__, f)
)
else:
print(
'AOO-LLDB helper function "%s" is not yet defined: '
'"%s" types cannot be displayed properly!' % (f, t)
)
# register a generic helper function for pimpl types
dbg.HandleCommand(
"type summary add -F %s.%s -v -C yes -n PIMPL %s"
% (__name__, "get_pimpl_info", " ".join(pimpl_types))
)

# add info about specific helper methods
# assume functions with docstrings are available for general consumption
helper_funcs = [
v
for (k, v) in globals().iteritems()
if (not k.startswith("_") and callable(v) and v.__doc__)
]
if helper_funcs:
print("Available AOO-specific helper functions:")
for hfunc in helper_funcs:
shortdesc = hfunc.__doc__.splitlines()[0]
print('\t%s\t# "%s"' % (hfunc.__name__, shortdesc))
print("Run them with:")
for hfunc in helper_funcs[:4]:
print("\tscript %s.%s()" % (__name__, hfunc.__name__))


# some helpers for use from interactive LLDB sessions

import lldb


def add_breakpoints():
'Setup breakpoints useful for AOO debugging'
dbg = lldb.debugger
if dbg.GetNumTargets() == 0:
return
# the list of interesting function breakpoints
aoo_breakfn = ['main', '__cxa_call_unexpected', 'objc_exception_throw']
aoo_breakfn += ['__cxa_throw']
# register breakpoints for function basenames
for b in aoo_breakfn:
dbg.HandleCommand( 'breakpoint set -b ' + b)
"Setup breakpoints useful for AOO debugging"
dbg = lldb.debugger
if dbg.GetNumTargets() == 0:
return
# the list of interesting function breakpoints
aoo_breakfn = ["main", "__cxa_call_unexpected", "objc_exception_throw"]
aoo_breakfn += ["__cxa_throw"]
# register breakpoints for function basenames
for b in aoo_breakfn:
dbg.HandleCommand("breakpoint set -b " + b)


# local functions for use by the AOO-type summary providers

def walk_ptrchain( v):
info = ''
while v.TypeIsPointerType():
n = v.GetValueAsUnsigned()
if n == 0:
info += 'NULL'
return (None, info)
info += '0x%04X-> ' % (n)
v = v.Dereference()
return (v, info)

def ret_strdata_info( v, refvar, lenvar, aryvar):
(v, info) = walk_ptrchain( v)
if not v:
return info
r = v.GetChildMemberWithName( refvar).GetValueAsSigned()
l = v.GetChildMemberWithName( lenvar).GetValueAsSigned()
c = v.GetChildMemberWithName( aryvar)
if (r < 0) or (l < 0):
info += 'CORRUPT_STR={refs=%d, len=%d}' % (r,l)
return info
L = min(l,128)
d = c.AddressOf().GetPointeeData( 0, L)
if c.GetByteSize() == 1: # assume UTF-8
s = ''.join([chr(x) for x in d.uint8s])
else: # assume UTF-16
s = (u''.join([unichr(x) for x in d.uint16s])).encode('utf-8')
info += ('{refs=%d, len=%d, str="%s"%s}' % (r, l, s.encode('string_escape'), '...'if(l!=L)else''))
return info

def walk_ptrchain(v):
info = ""
while v.TypeIsPointerType():
n = v.GetValueAsUnsigned()
if n == 0:
info += "NULL"
return (None, info)
info += "0x%04X-> " % (n)
v = v.Dereference()
return (v, info)


def ret_strdata_info(v, refvar, lenvar, aryvar):
(v, info) = walk_ptrchain(v)
if not v:
return info
r = v.GetChildMemberWithName(refvar).GetValueAsSigned()
l = v.GetChildMemberWithName(lenvar).GetValueAsSigned()
c = v.GetChildMemberWithName(aryvar)
if (r < 0) or (l < 0):
info += "CORRUPT_STR={refs=%d, len=%d}" % (r, l)
return info
L = min(l, 128)
d = c.AddressOf().GetPointeeData(0, L)
if c.GetByteSize() == 1: # assume UTF-8
s = "".join([chr(x) for x in d.uint8s])
else: # assume UTF-16
s = ("".join([unichr(x) for x in d.uint16s])).encode("utf-8")
info += '{refs=%d, len=%d, str="%s"%s}' % (
r,
l,
s.encode("string_escape"),
"..." if (l != L) else "",
)
return info


# definitions for our individual LLDB type summary providers

def get_pimpl_info( valobj, dict):
(v, info) = walk_ptrchain( valobj)
p = v.GetChildAtIndex(0)
pname = p.GetName()
n = p.GetValueAsUnsigned()
if n == 0:
return '%s(%s==NULL)' % (info, pname)
info = '%s(%s=0x%04X)-> ' % (info, pname, n)
return info + p.Dereference().GetSummary()

def get_pimpl_info(valobj, dict):
(v, info) = walk_ptrchain(valobj)
p = v.GetChildAtIndex(0)
pname = p.GetName()
n = p.GetValueAsUnsigned()
if n == 0:
return "%s(%s==NULL)" % (info, pname)
info = "%s(%s=0x%04X)-> " % (info, pname, n)
return info + p.Dereference().GetSummary()


def getinfo_for_rtl_String(valobj, dict):
return ret_strdata_info(valobj, "refCount", "length", "buffer")


def getinfo_for_rtl_uString(valobj, dict):
return ret_strdata_info(valobj, "refCount", "length", "buffer")

def getinfo_for_rtl_String( valobj, dict):
return ret_strdata_info( valobj, 'refCount', 'length', 'buffer')

def getinfo_for_rtl_uString( valobj, dict):
return ret_strdata_info( valobj, 'refCount', 'length', 'buffer')
def getinfo_for__ByteStringData(valobj, dict):
return ret_strdata_info(valobj, "mnRefCount", "mnLen", "maStr")

def getinfo_for__ByteStringData( valobj, dict):
return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr')

def getinfo_for__UniStringData( valobj, dict):
return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr')
def getinfo_for__UniStringData(valobj, dict):
return ret_strdata_info(valobj, "mnRefCount", "mnLen", "maStr")
Loading