[Solved] Card Suit Symbol Shortcuts in OpenOffice For Bridge

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jinglenose
Posts: 3
Joined: Wed May 28, 2014 4:00 pm

[Solved] Card Suit Symbol Shortcuts in OpenOffice For Bridge

Post by jinglenose »

I'm going to explain how to create suit symbol macros in openoffice and assign them to a short cut key combination. In this case I'm going to assign them to alt-c, alt-d, alt-h and alt-s for clubs, diamonds, hearts and spades. You just need to press alt and c to get a club symbol for instance.

Go to the menu item...

Tools >> Macros >> Organise Macros >> Openoffice.orb basic and the following window should turn up...


Click edit and a text editor should appear that contain the macro code. All you need to do is move to the end and past in this code...

Code: Select all

sub Club

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♣"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())

end sub

sub Diamond

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♦"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())

end sub

sub Heart

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♥"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())

end sub

sub Spade

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "♠"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())

end sub
Close the text editor and it should save the changes.

Now we need to assign these to a short cut. Choose the menu item...

Tools >> Customise

Then choose the keyboard tab. Scroll down the key combinations list box until you see the alt-c option etc.
You then choose openoffice.org macros >> user >> standard >> module and choose the appropriate function. Lets start with the "Club" function. Select alt-c in the shortcuts list and the click modify. This will then associate alt-c with the clubs function. Do this for each suit shortcut you want and then click OK.

Good luck!
Last edited by Hagar Delest on Mon Jan 25, 2021 2:38 pm, edited 1 time in total.
Reason: tagged solved.
OpenOffice 4.1 on Windows 7
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Creating Card Suit Symbol Shortcuts in OpenOffice For Br

Post by John_Ha »

My bridge playing colleague did this by AutoCorrect, where he told AOO to AutoCorrect, say, [c] to a black ♣ (and removing the square brackets), where you have already created the ♣ (Insert > Special character ...) and you copy and paste it into the Replace field. Similarly for diamonds, hearts and clubs. If you want the number to be red/black, then AutoCorrect [6h] to a red 6♥ etc.
Attachments
Clipboard01.png
Last edited by John_Ha on Thu May 26, 2016 11:29 am, edited 1 time in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Creating Card Suit Symbol Shortcuts in OpenOffice For Br

Post by acknak »

You could also define autotexts for the suits (or cards). For example, (once you've configured it) type csh and press F3 to get the suit symbol.
AOO4/LO5 • Linux • Fedora 23
dcleal
Posts: 1
Joined: Mon Jan 25, 2021 1:44 am

Re: Creating Card Suit Symbol Shortcuts in OpenOffice For Br

Post by dcleal »

Quiet in here, but as I came here before I eventually solved the problem, here's my answer. A Python macro that does what the OP asked for (none of the other routes worked nicely for me).

Code: Select all

import uno

BLACK = 0
RED = 16711680

def insert_club():
    return insert(BLACK, '♣')

def insert_diamond():
    return insert(RED, '♦')

def insert_heart():
    return insert(RED, '♥')

def insert_spade():
    return insert(BLACK, '♠')

def insert(textColor, text):
    model = XSCRIPTCONTEXT.getDesktop().getCurrentComponent()
    cursor = model.CurrentController.ViewCursor
    oldColor = cursor.getPropertyValue('CharColor')
    cursor.setPropertyValue('CharColor', textColor)
    model.getText().insertString(cursor, text, False)
    cursor.setPropertyValue('CharColor', oldColor)
    return None
OpenOffice 4 on MacOS 10.15.7
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Creating Card Suit Symbol Shortcuts in OpenOffice For Br

Post by John_Ha »

AutoHotKey does it too and in any application.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [Solved] Card Suit Symbol Shortcuts in OpenOffice For Br

Post by robleyd »

Not any application - any application running under Windows only.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: [Solved] Card Suit Symbol Shortcuts in OpenOffice For Br

Post by John_Ha »

Good point! The penalty of hijacking a thread - the OP used W7.

I wonder what happens running it under WINE?

I use AutoHotKey for lots of things - it's magic.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [Solved] Card Suit Symbol Shortcuts in OpenOffice For Br

Post by robleyd »

AutoKey is probably the nearest thing available for *nix; and Apple provide an application named Automator that is vaguely similar.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
Post Reply