Skip to content

Instantly share code, notes, and snippets.

@mattwigway
Created November 26, 2012 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwigway/4146037 to your computer and use it in GitHub Desktop.
Save mattwigway/4146037 to your computer and use it in GitHub Desktop.
Control the pen with the keyboard in LibreOffice Impress
# Hide and show the pen tool and change its color using the keyboard in
# LibreOffice Impress.
# Copyright 2012 Matt Conway
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Here's how this works: near the top of the file there are a bunch of
# functions that call setColor with a hex color code. All the functions
# in this file show up as separate macros in LibreOffice. So, just copy the
# file into your LibreOffice macros directory and then assign keyboard shortcuts
# to the colors you care about, as well as to showPen and hidePen. If you want
# to add colors, just copy one of the functions and change the color code.
import uno
# define colors here, just copy a function,
# change its name, and change the color. They're in
# HTML hex color format, first two bytes are red, then green,
# then blue
# each function shows up as an individual macro under My Macros -> Pen in
# LibreOffice
def red():
setColor(0xff0000)
def green():
setColor(0x00ff00)
def blue():
setColor(0x0000ff)
def black():
setColor(0x000000)
def white():
setColor(0xffffff)
def purple():
setColor(0xbb00bb)
def yellow():
setColor(0xfff000)
def cyan():
setColor(0x00ffd8)
def orange():
setColor(0xff5e00)
## End definitions of colors
def getPresentation():
return XSCRIPTCONTEXT.getDesktop().getCurrentComponent().getPresentation()
def setColor(color):
if color < 0 or color > 0xffffff:
return
# TODO: What if it's not a presentation?
pres = getPresentation()
if pres.isRunning():
pres.getController().PenColor = color
def showPen():
pres = getPresentation()
if pres.isRunning():
pres.getController().UsePen = True
def hidePen():
pres = getPresentation()
if pres.isRunning():
pres.getController().UsePen = False
@vinyanalista
Copy link

Congratulations for the good work! This macro is going to be useful for me! :)

I installed it using the instructions given here, so I can find it on Tools -> Macros -> Organize macros -> Python. Also, I assigned key shortcuts to some of its functions, as seen here, but I can't get them to work... =/

Do you know whether your macro works on LibreOffice 4.3.5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment