summaryrefslogtreecommitdiff
path: root/cad/src/ne1_ui/help/help.py
blob: a88e2b82e738bbe9a28e715987b69c2dafdd13af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Copyright 2004-2007 Nanorex, Inc.  See LICENSE file for details.
"""
help.py - help dialog used for mouse controls and keyboard shortcuts

$Id$

History:

Rewritten by Mark as a minimal help facility for Alpha 6.

bruce 071214 renamed class Help -> Ne1HelpDialog,
so uses are findable by text search. The name HelpDialog
was taken (as the module from which we import Ui_HelpDialog).

TODO:

The module should also be renamed, in case we want to use "help"
in a more general way, e.g. as a package name. [bruce 071214 comment]
"""

__author__ = "Josh"


import os, sys

from PyQt4.Qt import QWidget
from PyQt4.Qt import SIGNAL

from ne1_ui.help.HelpDialog import Ui_HelpDialog
from utilities.icon_utilities import geticon

class Ne1HelpDialog(QWidget, Ui_HelpDialog):
    """
    The Help dialog used for mouse controls and keyboard shortcuts
    """
    def __init__(self):
        QWidget.__init__(self)
        self.setupUi(self)
        self.connect(self.help_tab,SIGNAL("currentChanged(int)"),self.setup_current_page)
        self.connect(self.close_btn,SIGNAL("clicked()"),self.close)

        self.setWindowIcon(geticon('ui/border/MainWindow.png'))

        self._setup_mouse_controls_page()
        self.help_tab.setCurrentIndex(0)

        return

    def showDialog(self, pagenum):
        """
        Display the Help dialog with either the Mouse Controls or Keyboard Shortcuts page
        pagenum is the page number, where:
        0 = Mouse Controls
        1 = Keyboard Shortcuts
        2 = Selection Shortcuts
        """
        self.help_tab.setCurrentIndex(pagenum) # Sends signal to setup_current_page()

        # To make sure the Help dialog is displayed on top, we hide, then show it.
        self.hide() # Mark 2007-06-01
        self.show() # Non-modal
        return

    ###### Private methods ###############################

    def _setup_mouse_controls_page(self):
        """
        Setup the Mouse Controls help page.
        """
        filePath = os.path.dirname(os.path.abspath(sys.argv[0]))
        if sys.platform == 'darwin':
            htmlDoc = os.path.normpath(filePath + '/../doc/mousecontrols-mac.htm')
        else:
            htmlDoc = os.path.normpath(filePath + '/../doc/mousecontrols.htm')

        # Make sure help document exists.  If not, display msg in textbrowser.
        if os.path.exists(htmlDoc):
            self.mouse_controls_textbrowser.setHtml(open(htmlDoc).read())
        else:
            msg =  "Help file " + htmlDoc + " not found."
            self.mouse_controls_textbrowser.setPlainText(msg)

    def _setup_keyboard_shortcuts_page(self):
        """
        Setup the Keyboard Shortcuts help page.
        """
        filePath = os.path.dirname(os.path.abspath(sys.argv[0]))

        if sys.platform == 'darwin':
            htmlDoc = os.path.normpath(filePath + '/../doc/keyboardshortcuts-mac.htm')
        else:
            htmlDoc = os.path.normpath(filePath + '/../doc/keyboardshortcuts.htm')

        # Make sure help document exists.  If not, display msg in textbrowser.
        if os.path.exists(htmlDoc):
            self.keyboard_shortcuts_textbrowser.setHtml(open(htmlDoc).read())
        else:
            msg =  "Help file " + htmlDoc + " not found."
            self.keyboard_shortcuts_textbrowser.setPlainText(msg)

    def _setup_selection_shortcuts_page(self):
        """
        Setup the Selection Shortcuts help page.
        """
        filePath = os.path.dirname(os.path.abspath(sys.argv[0]))

        if sys.platform == 'darwin':
            htmlDoc = os.path.normpath(filePath + '/../doc/selectionshortcuts-mac.htm')
        else:
            htmlDoc = os.path.normpath(filePath + '/../doc/selectionshortcuts.htm')

        # Make sure help document exists.  If not, display msg in textbrowser.
        if os.path.exists(htmlDoc):
            self.selection_shortcuts_textbrowser.setHtml(open(htmlDoc).read())
        else:
            msg =  "Help file " + htmlDoc + " not found."
            self.selection_shortcuts_textbrowser.setPlainText(msg)

    def setup_current_page(self, currentTabIndex):
        pagenumber = currentTabIndex
        if pagenumber is 0:
            self._setup_mouse_controls_page()
        elif pagenumber is 1:
            self._setup_keyboard_shortcuts_page()
        elif pagenumber is 2:
            self._setup_selection_shortcuts_page()
        else:
            print 'Error: Help page unknown: ', pagenumber