Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

92
LINES

< > BotCompany Repo | #471 - forjoe.Print

Java source code

package de.tinybrain.forjoe;

import ai.d.ai17.*;

public class Print {
  public static void main(String[] args) {
    Automation auto = new Automation();

    try {
      doIt(auto);
      auto.showDoneAndSystemExit();
    } catch (Throwable e) {
      auto.handleException(e);
    }
  }

  public static void doIt(Automation auto) {
    auto.status("Waiting for LibreOffice Writer window");
    IconHandle window = new IconHandle(
      new IH("#1000140", "3,2,17,18", "0078fad9", "LibreOffice window icon", "joe"),
      new IH("#1000141", "2,3,18,22", "0053d610", "LibreOffice window icon", "s"));
    auto.waitFor(window);

    // TODO: rather check for color of title text (active window)
    /*if (!auto.hasHash("00135410"))
      abort("'Close document' icon not found");*/

    System.out.println("LibreOffice window found, pressing Ctrl+P");

    auto.status("Opening print dialog");
    auto.ctrlX('p');

    IconHandle tab_options = new IconHandle(
      new IH("#1000137", "553,53,607,67", "00b7519f", "Options (tab)", "s"),
      new IH("#1000136", "493,47,536,58", "007cf02a", "Options (tab)", "joe"));
    IconHandle button_printToFile = new IconHandle(
      new IH("#1000146", "839,572,880,581", "003a9f72", "Print to (file) (button)", "joe"),
      new IH("#1000139", "423,452,538,483", "05f2d28a", "Print to file... (button)", "s"));
    IconHandle button_ok = new IconHandle(
      new IH("#1000138", "513,452,598,483", "016a6a00", "OK (button)", "s"),
      new IH("#1000136", "578,462,594,472", "00025a07", "OK (button)", "joe"));
    IconHandle checkbox_printToFile = new IconHandle(
      new IH("#1000157", "434,131,468,144", "00cbcc87", "Print (to file) (checkbox)", "s"),
      new IH("#1000146", "572,172,1035,545", "03842078", "Print to file (checkbox, focused)", "joe"),
      new IH("#1000142", "643,117,719,131", "01466aaf", "Print to file (checkbox)", "s"),
      new IH("#1000138", "308,103,387,121", "03113dd6", "Print to file (checkbox)", "s"));

    // Select options tab

    auto.status("Waiting for print dialog");
    auto.waitFor(tab_options, checkbox_printToFile);
    if (!auto.has(checkbox_printToFile))
      auto.clickInTheMiddleOf(tab_options);

    // wait for options to load
    auto.status("Waiting for options tab");
    auto.waitFor(checkbox_printToFile);

    if (auto.has(button_ok)) {
      // Need to select "print to file"
      auto.clickInTheMiddleOf(checkbox_printToFile);
    }

    auto.pause("Continue");

    auto.waitFor(button_printToFile);
    auto.status("Clicking 'Print to file'...");
    auto.clickInTheMiddleOf(button_printToFile);

    auto.status("Waiting for file dialog");
    IconHandle dialogTitle_save = new IconHandle(
      new IH("#1000144", "664,7,701,15", "0025e5da", "Save as (dialog title)", "joe"),
      new IH("#1000143", "653,52,684,61", "000c9d24", "Save (dialog title)", "s"));
    auto.waitFor(dialogTitle_save);

    // Make file name
    String fileName = new MakeFileName().make();

    // Type file name
    auto.status("Typing...");
    auto.type(fileName, 50);

    auto.pause("Actually save the file");

    // Save the file
    auto.status("Saving the file");
    auto.type("\n", 50);

    auto.status("Waiting for file dialog to disappear");
    auto.waitForDisappearance(dialogTitle_save);
  }
}

Author comment

See https://www.youtube.com/watch?v=2aBE7R_cuDM (Automating LibreOffice with Aibo)

download  show line numbers   

Travelled to 8 computer(s): aoiabmzegqzx, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #471
Snippet name: forjoe.Print
Eternal ID of this version: #471/1
Text MD5: 9a56138f0fe79e6147fb820bf79b18ea
Author: stefan
Category: image recognition
Type: Java source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-17 21:48:51
Source code size: 3392 bytes / 92 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 465 / 87
Referenced in: [show references]

Formerly at http://tinybrain.de/471 & http://471.tinybrain.de