530
531
self.__runWmctrl(["-r", title, "-b" + action + ',' + prop])
533
def get_active_geometry(self):
535
Get the geometry of the currently active window
537
Usage: C{window.get_active_geometry()}
539
Returns a 4-tuple containing the x-origin, y-origin, width and height of the window (in pixels)
541
active = self.mediator.interface.get_window_title()
542
result, output = self.__runWmctrl(["-l", "-G"])
544
for line in output.split('\n'):
545
if active in line[34:].split(' ', 1)[-1]:
548
if matchingLine is not None:
549
output = matchingLine[14:].split(' ')[0:3]
550
return map(int, output)
532
554
def __runWmctrl(self, args):
533
555
p = subprocess.Popen(["wmctrl"] + args, stdout=subprocess.PIPE)
534
556
retCode = p.wait()
535
557
output = p.stdout.read()[:-1] # Drop trailing newline
537
559
return (retCode, output)
564
Provides access to the internals of AutoKey.
566
Note that any configuration changes made using this API while the configuration window
567
is open will not appear until it is closed and re-opened.
570
def __init__(self, configManager, runner):
571
self.configManager = configManager
574
def get_folder(self, title):
576
Retrieve a folder by its title
578
Usage: C{engine.get_folder(title)}
580
Note that if more than one folder has the same title, only the first match will be
583
for folder in self.configManager.allFolders:
584
if folder.title == title:
588
def create_phrase(self, folder, description, contents):
592
Usage: C{engine.create_phrase(folder, description, contents)}
594
A new phrase with no abbreviation or hotkey is created in the specified folder
596
@param folder: folder to place the abbreviation in, retrieved using C{engine.get_folder()}
597
@param description: description for the phrase
598
@param contents: the expansion text
600
p = model.Phrase(description, contents)
602
self.configManager.config_altered()
604
def create_abbreviation(self, folder, description, abbr, contents):
606
Create a text abbreviation
608
Usage: C{engine.create_abbreviation(folder, description, abbr, contents)}
610
When the given abbreviation is typed, it will be replaced with the given
613
@param folder: folder to place the abbreviation in, retrieved using C{engine.get_folder()}
614
@param description: description for the phrase
615
@param abbr: the abbreviation that will trigger the expansion
616
@param contents: the expansion text
617
@raises Exception: if the specified abbreviation is not unique
619
if not self.configManager.check_abbreviation_unique(abbr, None):
620
raise Exception("The specified abbreviation is already in use")
622
p = model.Phrase(description, contents)
623
p.modes.append(model.TriggerMode.ABBREVIATION)
624
p.abbreviation = abbr
626
self.configManager.config_altered()
628
def create_hotkey(self, folder, description, modifiers, key, contents):
630
Create a text hotkey.
632
Usage: C{engine.create_hotkey(folder, description, modifiers, key, contents)}
634
When the given hotkey is pressed, it will be replaced with the given
635
text. Modifiers must be given as a list of strings, with the following
643
The key must be an unshifted character (i.e. lowercase)
645
@param folder: folder to place the abbreviation in, retrieved using C{engine.get_folder()}
646
@param description: description for the phrase
647
@param modifiers: modifiers to use with the hotkey (as a list)
648
@param key: the hotkey
649
@param contents: the expansion text
650
@raises Exception: if the specified hotkey is not unique
653
if not self.configManager.check_hotkey_unique(modifiers, key, None):
654
raise Exception("The specified hotkey and modifier combination is already in use")
656
p = model.Phrase(description, contents)
657
p.modes.append(model.TriggerMode.HOTKEY)
658
p.set_hotkey(modifiers, key)
660
self.configManager.config_altered()
662
def run_script(self, description):
664
Run an existing script using its description to look it up
666
Usage: C{engine.run_script(description)}
668
@param description: description of the script to run
669
@raises Exception: if the specified script does not exist
672
for item in self.configManager.allItems:
673
if item.description == description and isinstance(item, Script):
676
if targetScript is not None:
677
self.runner.execute(targetScript, "")
679
raise Exception("No script with description '%s' found" % description)