OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """PyAuto: Python Interface to Chromium's Automation Proxy. | 7 """PyAuto: Python Interface to Chromium's Automation Proxy. |
8 | 8 |
9 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 9 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
10 For complete documentation on the functionality available, | 10 For complete documentation on the functionality available, |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 """Returns info about translate for the given page. | 684 """Returns info about translate for the given page. |
685 | 685 |
686 If the translate bar is showing, also returns information about the bar. | 686 If the translate bar is showing, also returns information about the bar. |
687 | 687 |
688 Args: | 688 Args: |
689 tab_index: The tab index, default is 0. | 689 tab_index: The tab index, default is 0. |
690 window_index: The window index, default is 0. | 690 window_index: The window index, default is 0. |
691 | 691 |
692 Returns: | 692 Returns: |
693 A dictionary of information about translate for the page. Example: | 693 A dictionary of information about translate for the page. Example: |
694 { u'can_translate_page': True, | 694 { u'always_translate_lang_button_showing': False, |
| 695 u'never_translate_lang_button_showing': False, |
| 696 u'can_translate_page': True, |
695 u'original_language': u'es', | 697 u'original_language': u'es', |
696 u'page_translated': False, | 698 u'page_translated': False, |
697 # The below will only appear if the translate bar is showing. | 699 # The below will only appear if the translate bar is showing. |
698 u'translate_bar': { u'bar_state': u'BEFORE_TRANSLATE', | 700 u'translate_bar': { u'bar_state': u'BEFORE_TRANSLATE', |
699 u'original_lang_code': u'es', | 701 u'original_lang_code': u'es', |
700 u'target_lang_code': u'en'}} | 702 u'target_lang_code': u'en'}} |
701 """ | 703 """ |
702 cmd_dict = { # Prepare command for the json interface | 704 cmd_dict = { # Prepare command for the json interface |
703 'command': 'GetTranslateInfo', | 705 'command': 'GetTranslateInfo', |
704 'tab_index': tab_index | 706 'tab_index': tab_index |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 def SelectTranslateOption(self, option, tab_index=0, window_index=0): | 819 def SelectTranslateOption(self, option, tab_index=0, window_index=0): |
818 """Selects one of the options in the drop-down menu for the translate bar. | 820 """Selects one of the options in the drop-down menu for the translate bar. |
819 | 821 |
820 Args: | 822 Args: |
821 option: One of 'never_translate_language', 'never_translate_site', or | 823 option: One of 'never_translate_language', 'never_translate_site', or |
822 'toggle_always_translate'. See notes on each below. | 824 'toggle_always_translate'. See notes on each below. |
823 tab_index: The index of the tab, default is 0. | 825 tab_index: The index of the tab, default is 0. |
824 window_index: The index of the window, default is 0. | 826 window_index: The index of the window, default is 0. |
825 | 827 |
826 *Notes* | 828 *Notes* |
827 never translate language: Selecting this means that no sites in this | 829 never_translate_language: Selecting this means that no sites in this |
828 language will be translated. This dismisses the infobar. | 830 language will be translated. This dismisses the infobar. |
829 never translate site: Selecting this means that this site will never be | 831 never_translate_site: Selecting this means that this site will never be |
830 translated, regardless of the language. This dismisses the infobar. | 832 translated, regardless of the language. This dismisses the infobar. |
831 toggle always translate: This does not dismiss the infobar or translate the | 833 toggle_always_translate: This does not dismiss the infobar or translate the |
832 page. See ClickTranslateBarTranslate and PerformActioOnInfobar to do | 834 page. See ClickTranslateBarTranslate and PerformActioOnInfobar to do |
833 those. If a language is selected to be always translated, then whenver | 835 those. If a language is selected to be always translated, then whenver |
834 the user visits a page with that language, the infobar will show the | 836 the user visits a page with that language, the infobar will show the |
835 'This page has been translated...' message. | 837 'This page has been translated...' message. |
| 838 decline_translation: Equivalent to selecting 'Nope' on the translate bar. |
| 839 click_never_translate_lang_button: This button appears when the user has |
| 840 declined translation of this language several times. Selecting it causes |
| 841 the language to never be translated. Look at GetTranslateInfo to |
| 842 determine if the button is showing. |
| 843 click_always_translate_lang_button: This button appears when the user has |
| 844 accepted translation of this language several times. Selecting it causes |
| 845 the language to always be translated. Look at GetTranslateInfo to |
| 846 determine if the button is showing. |
836 | 847 |
837 Raises: | 848 Raises: |
838 pyauto_errors.JSONInterfaceError if the automation returns an error. | 849 pyauto_errors.JSONInterfaceError if the automation returns an error. |
839 """ | 850 """ |
840 cmd_dict = { # Prepare command for the json interface | 851 cmd_dict = { # Prepare command for the json interface |
841 'command': 'SelectTranslateOption', | 852 'command': 'SelectTranslateOption', |
842 'option': option, | 853 'option': option, |
843 'tab_index': tab_index | 854 'tab_index': tab_index |
844 } | 855 } |
845 self._GetResultFromJSONRequest(cmd_dict, windex=window_index) | 856 self._GetResultFromJSONRequest(cmd_dict, windex=window_index) |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 if self._options.verbose: | 1496 if self._options.verbose: |
1486 verbosity = 2 | 1497 verbosity = 2 |
1487 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) | 1498 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) |
1488 del loaded_tests # Need to destroy test cases before the suite | 1499 del loaded_tests # Need to destroy test cases before the suite |
1489 del pyauto_suite | 1500 del pyauto_suite |
1490 sys.exit(not result.wasSuccessful()) | 1501 sys.exit(not result.wasSuccessful()) |
1491 | 1502 |
1492 | 1503 |
1493 if __name__ == '__main__': | 1504 if __name__ == '__main__': |
1494 Main() | 1505 Main() |
OLD | NEW |