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

92
LINES

< > BotCompany Repo | #471 // forjoe.Print

Java source code

1  
package de.tinybrain.forjoe;
2  
3  
import ai.d.ai17.*;
4  
5  
public class Print {
6  
  public static void main(String[] args) {
7  
    Automation auto = new Automation();
8  
9  
    try {
10  
      doIt(auto);
11  
      auto.showDoneAndSystemExit();
12  
    } catch (Throwable e) {
13  
      auto.handleException(e);
14  
    }
15  
  }
16  
17  
  public static void doIt(Automation auto) {
18  
    auto.status("Waiting for LibreOffice Writer window");
19  
    IconHandle window = new IconHandle(
20  
      new IH("#1000140", "3,2,17,18", "0078fad9", "LibreOffice window icon", "joe"),
21  
      new IH("#1000141", "2,3,18,22", "0053d610", "LibreOffice window icon", "s"));
22  
    auto.waitFor(window);
23  
24  
    // TODO: rather check for color of title text (active window)
25  
    /*if (!auto.hasHash("00135410"))
26  
      abort("'Close document' icon not found");*/
27  
28  
    System.out.println("LibreOffice window found, pressing Ctrl+P");
29  
30  
    auto.status("Opening print dialog");
31  
    auto.ctrlX('p');
32  
33  
    IconHandle tab_options = new IconHandle(
34  
      new IH("#1000137", "553,53,607,67", "00b7519f", "Options (tab)", "s"),
35  
      new IH("#1000136", "493,47,536,58", "007cf02a", "Options (tab)", "joe"));
36  
    IconHandle button_printToFile = new IconHandle(
37  
      new IH("#1000146", "839,572,880,581", "003a9f72", "Print to (file) (button)", "joe"),
38  
      new IH("#1000139", "423,452,538,483", "05f2d28a", "Print to file... (button)", "s"));
39  
    IconHandle button_ok = new IconHandle(
40  
      new IH("#1000138", "513,452,598,483", "016a6a00", "OK (button)", "s"),
41  
      new IH("#1000136", "578,462,594,472", "00025a07", "OK (button)", "joe"));
42  
    IconHandle checkbox_printToFile = new IconHandle(
43  
      new IH("#1000157", "434,131,468,144", "00cbcc87", "Print (to file) (checkbox)", "s"),
44  
      new IH("#1000146", "572,172,1035,545", "03842078", "Print to file (checkbox, focused)", "joe"),
45  
      new IH("#1000142", "643,117,719,131", "01466aaf", "Print to file (checkbox)", "s"),
46  
      new IH("#1000138", "308,103,387,121", "03113dd6", "Print to file (checkbox)", "s"));
47  
48  
    // Select options tab
49  
50  
    auto.status("Waiting for print dialog");
51  
    auto.waitFor(tab_options, checkbox_printToFile);
52  
    if (!auto.has(checkbox_printToFile))
53  
      auto.clickInTheMiddleOf(tab_options);
54  
55  
    // wait for options to load
56  
    auto.status("Waiting for options tab");
57  
    auto.waitFor(checkbox_printToFile);
58  
59  
    if (auto.has(button_ok)) {
60  
      // Need to select "print to file"
61  
      auto.clickInTheMiddleOf(checkbox_printToFile);
62  
    }
63  
64  
    auto.pause("Continue");
65  
66  
    auto.waitFor(button_printToFile);
67  
    auto.status("Clicking 'Print to file'...");
68  
    auto.clickInTheMiddleOf(button_printToFile);
69  
70  
    auto.status("Waiting for file dialog");
71  
    IconHandle dialogTitle_save = new IconHandle(
72  
      new IH("#1000144", "664,7,701,15", "0025e5da", "Save as (dialog title)", "joe"),
73  
      new IH("#1000143", "653,52,684,61", "000c9d24", "Save (dialog title)", "s"));
74  
    auto.waitFor(dialogTitle_save);
75  
76  
    // Make file name
77  
    String fileName = new MakeFileName().make();
78  
79  
    // Type file name
80  
    auto.status("Typing...");
81  
    auto.type(fileName, 50);
82  
83  
    auto.pause("Actually save the file");
84  
85  
    // Save the file
86  
    auto.status("Saving the file");
87  
    auto.type("\n", 50);
88  
89  
    auto.status("Waiting for file dialog to disappear");
90  
    auto.waitForDisappearance(dialogTitle_save);
91  
  }
92  
}

Author comment

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

download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

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: 638 / 144
Referenced in: [show references]