Exemplo n.º 1
0
 def init1(self):  #e might be merged into end of __init__
     """
     Do what we might do in __init__ except that it might be too early during assy.__init__ then (see also _initial_checkpoint)
     """
     assy = self.assy
     self.archive = AssyUndoArchive(assy)
     ## assy._u_archive = self.archive ####@@@@ still safe in 060117 stub code?? [guess 060223: not needed anymore ###@@@]
     # [obs??] this is how model objects in assy find something to report changes to (typically in their __init__ methods);
     # we do it here (not in caller) since its name and value are private to our API for model objects to report changes
     ##        self.archive.subscribe_to_checkpoints( self.remake_UI_menuitems )
     ##        self.remake_UI_menuitems() # so it runs for initial checkpoint and disables menu items, etc
     if is_macintosh():
         win = assy.w
         from PyQt4.Qt import Qt
         win.editRedoAction.setShortcut(
             Qt.CTRL + Qt.SHIFT +
             Qt.Key_Z)  # set up incorrectly (for Mac) as "Ctrl+Y"
         # note: long before 060414 this is probably no longer needed
         # (since now done in gui.WhatsThisText_for_MainWindow.py),
         # but it's safe and can be left in as a backup.
     # exercise the debug-only old pref (deprecated to use it):
     self.auto_checkpoint_pref(
     )  # exercise this, so it shows up in the debug-prefs submenu right away
     # (fixes bug in which the pref didn't show up until the first undoable change was made) [060125]
     # now look at the official pref for initial state of autocheckpointing [060314]
     ## done later -- set_initial_AutoCheckpointing_enabled( ... )
     return
Exemplo n.º 2
0
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)
    return
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)
    return
Exemplo n.º 4
0
    def init1(self): #e might be merged into end of __init__
        """
        Do what we might do in __init__ except that it might be too early during assy.__init__ then (see also _initial_checkpoint)
        """
        assy = self.assy
        self.archive = AssyUndoArchive(assy)
        ## assy._u_archive = self.archive ####@@@@ still safe in 060117 stub code?? [guess 060223: not needed anymore ###@@@]
            # [obs??] this is how model objects in assy find something to report changes to (typically in their __init__ methods);
            # we do it here (not in caller) since its name and value are private to our API for model objects to report changes
##        self.archive.subscribe_to_checkpoints( self.remake_UI_menuitems )
##        self.remake_UI_menuitems() # so it runs for initial checkpoint and disables menu items, etc
        if is_macintosh(): 
            win = assy.w
            from PyQt4.Qt import Qt
            win.editRedoAction.setShortcut(Qt.CTRL+Qt.SHIFT+Qt.Key_Z) # set up incorrectly (for Mac) as "Ctrl+Y"
                # note: long before 060414 this is probably no longer needed
                # (since now done in gui.WhatsThisText_for_MainWindow.py),
                # but it's safe and can be left in as a backup.
        # exercise the debug-only old pref (deprecated to use it):
        self.auto_checkpoint_pref() # exercise this, so it shows up in the debug-prefs submenu right away
            # (fixes bug in which the pref didn't show up until the first undoable change was made) [060125]
        # now look at the official pref for initial state of autocheckpointing [060314]
        ## done later -- set_initial_AutoCheckpointing_enabled( ... )
        return
Exemplo n.º 5
0
"""

from PyQt4.Qt import QAction
from PyQt4.Qt import QWidget
from PyQt4.Qt import QMenu
from PyQt4.Qt import QMenuBar

import os

from utilities.icon_utilities import image_directory

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

# ===
Exemplo n.º 6
0
def fix_whatsthis_text_and_links(parent):
    #bruce 080509 removed old debug code for bugs 1421 and 1721; other cleanup
    #bruce 060319 renamed this from fix_whatsthis_text_for_mac
    #bruce 060120 revised this as part of fixing bug 1295
    #bruce 051227-29 revised this
    """
    [public]
    Fix tooltips and whatsthis text and objects (for all OSes, not just macs
    as this function once did).

    This function does two things:
    
    1. If the system is a Mac, this replaces all occurrences of 'Ctrl'
    with 'Cmd' in all the tooltip and whatsthis text for all QAction or
    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.

    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
    or more), to call it more than once on the main window. If you call it again
    on something else, as of 060319 this would have caused bugs by clearing 
    _objects_and_text_that_need_fixing_later, but that can be easily fixed when
    we need to support repeated calls on smaller widgets. (As of the next day,
    that global list was no longer used, and on 080509 the code to maintain it
    is being removed -- whether repeated calls would still cause any bugs ought
    to be reviewed. I notice that there *are* repeated calls -- the main call
    in ne1_ui/Ui_MainWindow.py is followed immediately by another one on a
    smaller widget. So it's probably ok.)

    Calling this on a single QAction works, but doesn't do enough to fix the
    text again for toolbuttons (and I think menuitems) made by Qt from that
    action (re bug 1421).

    See also refix_whatsthis_text_and_links, which can be called to restore
    tooltips and/or whatsthis text which Qt messed up for some reason, as
    happens when you set tooltips or menutext for Undo and Redo actions
    (bug 1421). (Note that it hardcodes the set of actions which need this.)
    """
    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:
        # 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 
        objList = filter(lambda x: isinstance(x, QAction), parent.children())
        for obj in objList:
            fix_QAction_whatsthis(obj, mac)            
            continue
        pass
    if ENABLE_WHATSTHIS_LINKS:
        # 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
        #  happens as of 060120)
        objList = filter(lambda x: isinstance(x, QWidget), parent.children())
            # this includes QMenuBar, QPopupMenu for each main menu and cmenu
            # (I guess), but not menuitems themselves. (No hope of including 
            # dynamic cmenu items, but since we make those, we could set their
            # whatsthis text and process it the same way using separate code 
            # (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...
        for obj in objList:
            # note: the following code is related to
            # fix_QAction_whatsthis(obj, mac)
            # but differs in several ways
            text = whatsthis_text_for_widget(obj) # could be either "" or None
            if text:
                # in case text doesn't come from a QAction, modify it in the 
                # same ways as above, and store it again or pass it to the
                # 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:
                    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
            else:
                text = None # turn "" into None
            ## ismenu = isinstance(obj, QPopupMenu)
            ismenu = isinstance(obj, QMenu)
            try:
                ismenubar = isinstance(obj, QMenuBar)
            except:
                # usual for non-Macs, I presume
                ismenubar = False
            if text is not None and (ismenu or ismenubar):
                # assume any text (even if not changed here) might contain 
                # hyperlinks, so any widget with text might need a MyWhatsThis 
                # object; the above code (which doesn't bother storing 
                # mac-modified text) also assumes we're doing this
                # [REVIEW: what code creates such an object? Is the above
                #  old comment still accurate? bruce 080509 questions]
                print text
                obj.setWhatsThis(text)
                pass
            continue
    return # from fix_whatsthis_text_and_links
"""

from PyQt4.Qt import QAction
from PyQt4.Qt import QWidget
from PyQt4.Qt import QMenu
from PyQt4.Qt import QMenuBar

import os

from utilities.icon_utilities import image_directory

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

# ===
def fix_whatsthis_text_and_links(parent):
    #bruce 080509 removed old debug code for bugs 1421 and 1721; other cleanup
    #bruce 060319 renamed this from fix_whatsthis_text_for_mac
    #bruce 060120 revised this as part of fixing bug 1295
    #bruce 051227-29 revised this
    """
    [public]
    Fix tooltips and whatsthis text and objects (for all OSes, not just macs
    as this function once did).

    This function does two things:
    
    1. If the system is a Mac, this replaces all occurrences of 'Ctrl'
    with 'Cmd' in all the tooltip and whatsthis text for all QAction or
    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.

    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
    or more), to call it more than once on the main window. If you call it again
    on something else, as of 060319 this would have caused bugs by clearing 
    _objects_and_text_that_need_fixing_later, but that can be easily fixed when
    we need to support repeated calls on smaller widgets. (As of the next day,
    that global list was no longer used, and on 080509 the code to maintain it
    is being removed -- whether repeated calls would still cause any bugs ought
    to be reviewed. I notice that there *are* repeated calls -- the main call
    in ne1_ui/Ui_MainWindow.py is followed immediately by another one on a
    smaller widget. So it's probably ok.)

    Calling this on a single QAction works, but doesn't do enough to fix the
    text again for toolbuttons (and I think menuitems) made by Qt from that
    action (re bug 1421).

    See also refix_whatsthis_text_and_links, which can be called to restore
    tooltips and/or whatsthis text which Qt messed up for some reason, as
    happens when you set tooltips or menutext for Undo and Redo actions
    (bug 1421). (Note that it hardcodes the set of actions which need this.)
    """
    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:
        # 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
        objList = filter(lambda x: isinstance(x, QAction), parent.children())
        for obj in objList:
            fix_QAction_whatsthis(obj, mac)
            continue
        pass
    if ENABLE_WHATSTHIS_LINKS:
        # 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
        #  happens as of 060120)
        objList = filter(lambda x: isinstance(x, QWidget), parent.children())
        # this includes QMenuBar, QPopupMenu for each main menu and cmenu
        # (I guess), but not menuitems themselves. (No hope of including
        # dynamic cmenu items, but since we make those, we could set their
        # whatsthis text and process it the same way using separate code
        # (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...
        for obj in objList:
            # note: the following code is related to
            # fix_QAction_whatsthis(obj, mac)
            # but differs in several ways
            text = whatsthis_text_for_widget(obj)  # could be either "" or None
            if text:
                # in case text doesn't come from a QAction, modify it in the
                # same ways as above, and store it again or pass it to the
                # 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:
                    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
            else:
                text = None  # turn "" into None
            ## ismenu = isinstance(obj, QPopupMenu)
            ismenu = isinstance(obj, QMenu)
            try:
                ismenubar = isinstance(obj, QMenuBar)
            except:
                # usual for non-Macs, I presume
                ismenubar = False
            if text is not None and (ismenu or ismenubar):
                # assume any text (even if not changed here) might contain
                # hyperlinks, so any widget with text might need a MyWhatsThis
                # object; the above code (which doesn't bother storing
                # mac-modified text) also assumes we're doing this
                # [REVIEW: what code creates such an object? Is the above
                #  old comment still accurate? bruce 080509 questions]
                print text
                obj.setWhatsThis(text)
                pass
            continue
    return  # from fix_whatsthis_text_and_links