summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Smith <bruce@nanorex.com>2008-12-09 22:07:11 +0000
committerBruce Smith <bruce@nanorex.com>2008-12-09 22:07:11 +0000
commit2209917035ba04cb2d9affb368c8c84005c80447 (patch)
tree1cdac99bd187441389cbcdb55c9e8ba8f99e7083
parent3707bc92fba5a9f569178f45d0a011c3ac48504b (diff)
downloadnanoengineer-theirix-2209917035ba04cb2d9affb368c8c84005c80447.tar.gz
nanoengineer-theirix-2209917035ba04cb2d9affb368c8c84005c80447.zip
cleanup and comments in wiki_help, whatsthis text processing
-rwxr-xr-xcad/src/foundation/whatsthis_utilities.py80
-rwxr-xr-xcad/src/foundation/wiki_help.py67
-rwxr-xr-xcad/src/ne1_ui/Ui_PartWindow.py15
-rw-r--r--cad/src/ne1_ui/WhatsThisText_for_CommandToolbars.py4
-rwxr-xr-xcad/src/ne1_ui/WhatsThisText_for_MainWindow.py10
-rw-r--r--cad/src/ne1_ui/prefs/WhatsThisText_for_PreferencesDialog.py10
-rwxr-xr-xcad/src/ne1_ui/toolbars/Ui_CommandToolbar.py3
-rwxr-xr-xcad/src/platform_dependent/PlatformDependent.py3
8 files changed, 140 insertions, 52 deletions
diff --git a/cad/src/foundation/whatsthis_utilities.py b/cad/src/foundation/whatsthis_utilities.py
index 079591b50..b2516befa 100755
--- a/cad/src/foundation/whatsthis_utilities.py
+++ b/cad/src/foundation/whatsthis_utilities.py
@@ -16,13 +16,21 @@ import os
from utilities.icon_utilities import image_directory
-# more imports below; todo: move them to toplevel
+import foundation.env as env
+
+from platform_dependent.PlatformDependent import is_macintosh
+
+_IS_MACINTOSH = is_macintosh()
#bruce 051227-29 code for putting hyperlinks into most WhatsThis texts
# (now finished enough for release, though needs testing and perhaps cleanup
# and documentation)
ENABLE_WHATSTHIS_LINKS = True # also used in an external file
+ # note: if this is False, it now disables not only whatsthis links,
+ # but the fixing of img tag pathnames in whatsthis text.
+ # Probably we should just remove the flag, inlining it as True.
+ # [bruce 081209 comment]
_DEBUG_WHATSTHIS_LINKS = False # DO NOT COMMIT with True # only used in this file
@@ -50,8 +58,9 @@ def fix_whatsthis_text_and_links(parent):
QWidget objects that are children of parent.
2. For all systems, it replaces certain whatsthis text patterns with
- hyperlinks, and adds MyWhatsThis objects to widgets with text modified
- that way (or that might contain hyperlinks) or that are QPopupMenus.
+ hyperlinks, and [obsolete comment] adds MyWhatsThis objects to widgets
+ with text modified that way (or that might contain hyperlinks) or that
+ are QPopupMenus.
This should be called after all widgets (and their whatsthis text)
in the UI have been created. It's ok, but slow (up to 0.2 seconds per call
@@ -76,21 +85,21 @@ def fix_whatsthis_text_and_links(parent):
"""
if _DEBUG_WHATSTHIS_LINKS:
print "running fix_whatsthis_text_and_links"
- from platform_dependent.PlatformDependent import is_macintosh
- mac = is_macintosh()
- if mac or ENABLE_WHATSTHIS_LINKS:
+ if _IS_MACINTOSH or ENABLE_WHATSTHIS_LINKS:
# fix text in 1 or 2 ways for all QAction objects
# (which are not widgets)
# ATTENTION:
# objList only includes QAction widgets that appear in the Main Menu
# bar. This is a bug since some widgets only appear in toolbars on the
- # Main Window, but not the main menu bar. --Mark and Tom 2007-12-19
+ # Main Window, but not the main menu bar. --Mark and Tom 2007-12-19
objList = filter(lambda x: isinstance(x, QAction), parent.children())
for obj in objList:
- fix_QAction_whatsthis(obj, mac)
+ fix_QAction_whatsthis(obj)
continue
pass
if ENABLE_WHATSTHIS_LINKS:
+ # partly obsolete comment (class MyWhatsThis no longer exists,
+ # instead see class QToolBar_WikiHelp):
# add MyWhatsThis objects to all widgets that might need them
# (and also fix their text if it's not fixed already --
# needed in case it didn't come from a QAction; maybe that never
@@ -103,9 +112,11 @@ def fix_whatsthis_text_and_links(parent):
# (nim ###@@@).) [bruce 060120] In fact there is no menu item
# class in Qt that I can find! You add items as QActions or as
# sets of attrs. QActions also don't show up in this list...
+ if isinstance(parent, QWidget):
+ objList.append(parent) #bruce 081209
for obj in objList:
# note: the following code is related to
- # fix_QAction_whatsthis(obj, mac)
+ # fix_QAction_whatsthis(obj)
# but differs in several ways
text = whatsthis_text_for_widget(obj) # could be either "" or None
if text:
@@ -114,11 +125,18 @@ def fix_whatsthis_text_and_links(parent):
# MyWhatsThis object; both our mods are ok if they happen
# twice -- if some hyperlink contains 'ctrl', so did the text
# before it got command names converted to links.
- if mac:
+ if _IS_MACINTOSH:
text = replace_ctrl_with_cmd(text)
text = turn_featurenames_into_links(text)
assert text # we'll just feed it to a MyWhatsThis object so we
# don't have to store it here
+ # BUG: since that was written, the code has been revised;
+ # there is no longer a class MyWhatsThis, and it's unclear
+ # whether it's *ever* ok to discard this text, as we are doing.
+ # The only known bug from this is for the GLPane's whatsthis text
+ # (about that, see the kluges and comments in the def and call
+ # of whats_this_text_for_glpane), but there might be others.
+ # [bruce 081209 comment]
else:
text = None # turn "" into None
## ismenu = isinstance(obj, QPopupMenu)
@@ -141,19 +159,23 @@ def fix_whatsthis_text_and_links(parent):
continue
return # from fix_whatsthis_text_and_links
-def fix_QAction_whatsthis(obj, mac):
+def fix_QAction_whatsthis(obj):
"""
+ [public, though external calls are rare]
+
Modify the Qt whatsthis and tooltip text assigned to obj
(which should be a QAction; not sure if that's required)
- based on the mac flag (an argument) and on the global flag
- ENABLE_WHATSTHIS_LINKS.
+ based on whether we're running on a Macintosh (determines
+ whether to replace Ctrl with Cmd in the texts),
+ and on the global flag ENABLE_WHATSTHIS_LINKS.
Also save info into the global map_from_id_QAction_to_featurename.
+
+ @see: our main caller, fix_whatsthis_text_and_links
"""
- # fyi: only used in this file, as of 080509
text = str(obj.whatsThis())
tooltip = str(obj.toolTip())
- if mac:
+ if _IS_MACINTOSH:
text = replace_ctrl_with_cmd(text)
tooltip = replace_ctrl_with_cmd(tooltip)
if ENABLE_WHATSTHIS_LINKS:
@@ -169,12 +191,9 @@ def refix_whatsthis_text_and_links( ): #bruce 060319 part of fixing bug 1421
"""
[public]
"""
- import foundation.env as env
win = env.mainwindow()
- from platform_dependent.PlatformDependent import is_macintosh
- mac = is_macintosh()
- fix_QAction_whatsthis(win.editUndoAction, mac)
- fix_QAction_whatsthis(win.editRedoAction, mac)
+ fix_QAction_whatsthis(win.editUndoAction)
+ fix_QAction_whatsthis(win.editRedoAction)
return
def replace_ctrl_with_cmd(text):
@@ -241,6 +260,11 @@ def turn_featurenames_into_links(text, savekey = None, saveplace = None):
"""
# make all img source pathnames absolute, if they are not already.
# [bruce 081205 per mark]
+ #
+ # TODO: if this was improved to call get_image_path on the pathnames,
+ # it would catch errors in the pathnames at load time rather than
+ # only when they are first used to display images in whatsthis text.
+ #
# POSSIBLE BUGS: the current implementation will fail if the pathnames
# contain characters that don't encode themselves when parsed
# (by Qt) in this HTML-tag-attribute context -- at least true
@@ -293,12 +317,16 @@ def turn_featurenames_into_links(text, savekey = None, saveplace = None):
print "web help name: %r" % (featurename,)
if saveplace is not None:
saveplace[savekey] = featurename
- link = "Feature:" + featurename.replace(' ','_')
- # maybe we can't let ' ' remain in it, otherwise replacement
- # not needed since will be done later anyway
- ## from wiki_help import wiki_prefix
- ## text = "<a href=\"%s%s\">%s</a>" % \
- ## (wiki_prefix(), link, name) + rest
+ link = "Feature:" + featurename.replace(' ', '_')
+ # note: partly duplicates code in def wiki_help_url in wiki_help.py
+ # note: this link will only work if it's interpreted by
+ # class QToolBar_WikiHelp, which prepends wiki_prefix().
+ # Before we used Qt 4, this was done by the following code:
+ # ## from wiki_help import wiki_prefix
+ # ## text = "<a href=\"%s%s\">%s</a>" % \
+ # ## (wiki_prefix(), link, name) + rest
+ # working with class MyWhatsThis, which is still mentioned
+ # in some old comments. [bruce 081209 guess]
text = "<a href=\"%s\">%s</a>" % (link, name) + rest
return text
return text
diff --git a/cad/src/foundation/wiki_help.py b/cad/src/foundation/wiki_help.py
index fd4d9ed94..11a6b619a 100755
--- a/cad/src/foundation/wiki_help.py
+++ b/cad/src/foundation/wiki_help.py
@@ -1,4 +1,4 @@
-# Copyright 2005-2007 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2005-2008 Nanorex, Inc. See LICENSE file for details.
"""
wiki_help.py -- associate webpages (typically in a wiki) with program features,
and provide access to them. Pages typically contain feature-specific help info,
@@ -6,7 +6,15 @@ FAQ, forum, etc.
@author: Will, Bruce
@version: $Id$
-@copyright: 2005-2007 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2005-2008 Nanorex, Inc. See LICENSE file for details.
+
+
+Code cleanup needed:
+
+There are two parallel systems of code which do similar things
+(e.g. prepending "Feature:" and wiki_prefix()) for different kinds
+of UI access; see duplicated code warnings below.
+
Module classification: [bruce 080101]
@@ -32,6 +40,7 @@ But we use "wiki help" in history messages, since we want people to think of
the wiki (rather than a rarely-changing web page) as an integral part of the
idea.
+
History:
idea from Eric D
@@ -68,6 +77,8 @@ from utilities.Log import redmsg
from utilities.prefs_constants import wiki_help_prefix_prefs_key
def webbrowser_open(url):
+ """
+ """
if len(webbrowser._tryorder) == 0:
# Sometimes webbrowser.py does not find a web browser. Also, its list
# of web browsers is somewhat antiquated. Give it some help.
@@ -180,8 +191,13 @@ def open_wiki_help_URL(url, whosdoingthis = "Wiki help"): #bruce 051229 split th
def wiki_prefix():
"""
- Return the prefix to which wiki page titles should be appended, to form their urls.
+ Return the prefix to which wiki page titles should be appended,
+ to form their urls. By default, these reference the Nanorex
+ public wiki, but the prefix can be overridden by a user preference.
"""
+ # note: public, but only used in this file;
+ # but has three callers, all of which do related things
+ # for different kinds of UI access. [bruce 081209 comment]
prefix = env.prefs[wiki_help_prefix_prefs_key]
return prefix
@@ -199,6 +215,7 @@ def wiki_help_url( featurename):
# (The same would be true for wiki pages about specific features whose featurenames are changed.)
prefix = wiki_prefix()
title = "Feature:" + featurename.replace(' ', '_') # e.g. Feature:Build_Mode
+ # note: partly duplicates code in turn_featurenames_into_links in whatsthis_utilities.py
return prefix + title # assume no URL-encoding needed in title, since featurenames so far are just letters and spaces
# ==
@@ -248,15 +265,31 @@ def wiki_help_menuspec_for_featurename( featurename):
# ==
class QToolBar_WikiHelp(NE1_QToolBar):
+ """
+ A subclass of NE1_QToolBar to be used when whatsthis text
+ in the toolbar might contain "wiki help" links.
+
+ It overrides the event method to interpret a QWhatsThisClickedEvent
+ by prepending the event's href with wiki_prefix() and opening
+ that url in a webbrowser.
+ """
# Any widget can be extended this way. Wherever we need to have wiki help
# active (presumably in a container with buttons or some such) we should
# feel free to extend other container widgets as needed.
def event(self, evt):
if isinstance(evt, QWhatsThisClickedEvent):
url = wiki_prefix() + evt.href()
+ # note: I'm guessing that in older code, this was done
+ # by the class MyWhatsThis (still mentioned in some old
+ # comments) [bruce 081209 comment]
webbrowser_open(str(url)) # Must be string. mark 2007-05-10
+ # REVIEW: should we call its caller open_wiki_help_URL instead?
+ # This would add a history message and some exception catching.
+ # Guess: yes, perhaps with a flag to turn off history
+ # except when there are errors. [bruce 081209 question]
return True
- return NE1_QToolBar.event(self, evt)
+ else:
+ return NE1_QToolBar.event(self, evt)
class WikiHelpBrowser(QDialog):
"""
@@ -299,30 +332,34 @@ class WikiHelpBrowser(QDialog):
pass
-def wiki_url_for_topic(topic, wikiprefix = None):
- wikiprefix = wikiprefix or "http://www.nanoengineer-1.net/mediawiki/index.php?title="
+def HTML_link(url, text):
+ #e might need to do some encoding in url, don't know;
+ # certainly needs to in text, in principle
+ return "<a href=\"" + url + "\">" + text + "</a>"
+
+# == test code
+
+def __wiki_url_for_topic(topic, wikiprefix = None):
+ wikiprefix = wikiprefix or \
+ "http://www.nanoengineer-1.net/mediawiki/index.php?title="
+ # note: this is a hardcoded version of the default value
+ # of wiki_prefix(); maybe it should be a named constant
topic1 = topic[:1].upper() + topic[1:]
topic1 = topic1.replace(" ", "_") # assume no additional url-encoding is needed
url = wikiprefix + topic1
return url
-def wikiPageHtmlLink(topic, text = None, wikiprefix = None):
- url = wiki_url_for_topic(topic, wikiprefix = wikiprefix)
+def __wikiPageHtmlLink(topic, text = None, wikiprefix = None):
+ url = __wiki_url_for_topic(topic, wikiprefix = wikiprefix)
if text is None:
text = topic
return HTML_link(url, text)
-def HTML_link(url, text): #e might need to do some encoding in url, don't know; certainly needs to in text, in principle
- # this is being used in real code as of bruce 051215
- return "<a href=\"" + url + "\">" + text + "</a>"
-
-# == test code
-
def __testWikiHelpBrowser():
import sys
app = QApplication(sys.argv)
w = WikiHelpBrowser("Here is a wiki page about " +
- wikiPageHtmlLink("QWhatsThis and web links") +
+ __wikiPageHtmlLink("QWhatsThis and web links") +
" to click.")
w.show()
app.connect(app, SIGNAL("lastWindowClosed()"),
diff --git a/cad/src/ne1_ui/Ui_PartWindow.py b/cad/src/ne1_ui/Ui_PartWindow.py
index 5fb0aa519..f94d0cf07 100755
--- a/cad/src/ne1_ui/Ui_PartWindow.py
+++ b/cad/src/ne1_ui/Ui_PartWindow.py
@@ -282,10 +282,23 @@ class Ui_PartWindow(QWidget):
# In this code's old location, Mark wrote [2007-06-01]: "Problem -
# I don't believe this text is processed by fix_whatsthis_text_and_links()
# in whatsthis_utilities.py." Now that this code is here, I don't know
- # whether that's still true.]
+ # whether that's still true. ]
from ne1_ui.WhatsThisText_for_MainWindow import whats_this_text_for_glpane
self.glpane.setWhatsThis( whats_this_text_for_glpane() )
+ # update [re the above comment], bruce 081209:
+ # I added the following explicit call of fix_whatsthis_text_and_links,
+ # but it doesn't work to replace Ctrl with Cmd on Mac;
+ # see today's comment in fix_whatsthis_text_and_links for likely reason.
+ # So I will leave this here, but also leave in place the kluges
+ # in whats_this_text_for_glpane to do that replacement itself.
+ # The wiki help link in this whatsthis text doesn't work,
+ # but I guess that is an independent issue, related to lack
+ # of use of class QToolBar_WikiHelp or similar code, for GLPane
+ # or this class or the main window class.
+ from foundation.whatsthis_utilities import fix_whatsthis_text_and_links
+ fix_whatsthis_text_and_links(self.glpane) # doesn't yet work
+
self.pwProjectTabWidget.KLUGE_setGLPane(self.glpane)
# help fix bug 2522 [bruce 070829]
qt4warnDestruction(self.glpane, 'GLPane of PartWindow')
diff --git a/cad/src/ne1_ui/WhatsThisText_for_CommandToolbars.py b/cad/src/ne1_ui/WhatsThisText_for_CommandToolbars.py
index c284c483b..6e8d5dbe7 100644
--- a/cad/src/ne1_ui/WhatsThisText_for_CommandToolbars.py
+++ b/cad/src/ne1_ui/WhatsThisText_for_CommandToolbars.py
@@ -1,4 +1,4 @@
-# Copyright 2004-2007 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2008 Nanorex, Inc. See LICENSE file for details.
"""
WhatsThisText_for_CommandToolbars.py
@@ -7,7 +7,7 @@ for widgets (typically QActions) in the Command Toolbar.
@author: Mark
@version:$Id$
-@copyright: 2004-2007 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2008 Nanorex, Inc. See LICENSE file for details.
"""
from foundation.whatsthis_utilities import fix_whatsthis_text_and_links
diff --git a/cad/src/ne1_ui/WhatsThisText_for_MainWindow.py b/cad/src/ne1_ui/WhatsThisText_for_MainWindow.py
index b1c695f2a..295854c19 100755
--- a/cad/src/ne1_ui/WhatsThisText_for_MainWindow.py
+++ b/cad/src/ne1_ui/WhatsThisText_for_MainWindow.py
@@ -22,7 +22,6 @@ pages as well.
"""
import os
-from utilities.icon_utilities import get_image_path
from PyQt4.Qt import QWhatsThis
def createWhatsThisTextForMainWindowWidgets(win):
@@ -45,7 +44,7 @@ def createWhatsThisTextForMainWindowWidgets(win):
_text = \
"<u><b>Open File</b></u> (Ctrl + O)"\
- "<p><img source=\"" + get_image_path("ui/actions/File/Open.png") + "\"><br> "\
+ "<p><img source=\"ui/actions/File/Open.png\"><br> "\
"Opens a new file."\
"</p>"
@@ -105,7 +104,7 @@ def createWhatsThisTextForMainWindowWidgets(win):
win.fileSaveAsAction.setWhatsThis( fileSaveAsText )
- # Import Molcular Machine Part
+ # Import Molecular Machine Part
fileInsertMmpActionText = \
"<b> Molecular Machine Part</b>"\
@@ -2175,6 +2174,11 @@ def whats_this_text_for_glpane():
#bruce 080912 moved this here from part of a method in class GLPane
import sys
if sys.platform == "darwin":
+ # TODO: figure out how to get fix_whatsthis_text_and_links to handle
+ # this for us (like it does for most whatsthis text).
+ # The href link herein also doesn't work (at least on my Mac).
+ # For more info see comments from today in other files.
+ # [bruce 081209 comment]
ctrl_or_cmd = "Cmd"
else:
ctrl_or_cmd = "Ctrl"
diff --git a/cad/src/ne1_ui/prefs/WhatsThisText_for_PreferencesDialog.py b/cad/src/ne1_ui/prefs/WhatsThisText_for_PreferencesDialog.py
index bb57665fc..db6540d6c 100644
--- a/cad/src/ne1_ui/prefs/WhatsThisText_for_PreferencesDialog.py
+++ b/cad/src/ne1_ui/prefs/WhatsThisText_for_PreferencesDialog.py
@@ -1,4 +1,4 @@
-# Copyright 2007 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2007-2008 Nanorex, Inc. See LICENSE file for details.
"""
WhatsThisText_for_PreferencesDialog.py
@@ -9,7 +9,7 @@ Edit WhatsThisText_for_MainWindow.py to set "What's This" and tooltip text
for widgets in the Main Window.
@version: $Id$
-@copyright: 2008 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2007-2008 Nanorex, Inc. See LICENSE file for details.
"""
import sys
@@ -20,10 +20,16 @@ def whatsThis_PreferencesDialog(preferencesDialog):
"""
_pd = preferencesDialog
+
if sys.platform == 'darwin':
+ # TODO: figure out how to get fix_whatsthis_text_and_links to handle
+ # this for us (like it does for most whatsthis text).
+ # For more info see comments from today in other files.
+ # [bruce 081209 comment]
_keyString = "<b>(Cmd + C and Cmd + V)</b> respectively"
else:
_keyString = "<b>(Ctrl + C and Ctrl + V)</b> respectively"
+
#General preference
_text = """<b>Offset scale factor for pasting chunks</b>
<p>When one or more chunks, that are placed as independent nodes in the
diff --git a/cad/src/ne1_ui/toolbars/Ui_CommandToolbar.py b/cad/src/ne1_ui/toolbars/Ui_CommandToolbar.py
index b6c0f3316..0c132a243 100755
--- a/cad/src/ne1_ui/toolbars/Ui_CommandToolbar.py
+++ b/cad/src/ne1_ui/toolbars/Ui_CommandToolbar.py
@@ -237,7 +237,8 @@ class Ui_CommandToolbar( QWidget ):
# Convert all "img" tags in the button's "What's This" text
# into abs paths (from their original rel paths).
# Partially fixes bug 2943. --mark 2008-12-07
- fix_QAction_whatsthis(btn, False)
+ # [bruce 081209 revised this -- removed mac = False]
+ fix_QAction_whatsthis(btn)
return
def truncateText(self, text, length = 12, truncateSymbol = '...'):
diff --git a/cad/src/platform_dependent/PlatformDependent.py b/cad/src/platform_dependent/PlatformDependent.py
index 92462be73..980834f99 100755
--- a/cad/src/platform_dependent/PlatformDependent.py
+++ b/cad/src/platform_dependent/PlatformDependent.py
@@ -18,7 +18,6 @@ A mix of things. Some are platform dependent. Some are utilities
(and of those, some would make sense within utilities.Log).
Some are io.
"""
-__author__ = "bruce" # and others
import sys, os, time
from PyQt4.Qt import Qt, QDesktopWidget, QRect
@@ -54,7 +53,7 @@ def mkdirs_in_filename(filename):
def is_macintosh():
#e we might need to update this, since I suspect some mac pythons
# have a different value for sys.platform
- return sys.platform in ['darwin']
+ return sys.platform == 'darwin'
def filter_key(key, debug_keys = 0): #bruce revised this 070517 to fix Mac-specific delete key bug which resurfaced in Qt4
"""