Example #1
0
###############################################

# This is the default sponsor image (and text) for the PM sponsor button.

_nanorexText = """\
Nanorex created NanoEngineer-1, the program you're using right now.
<p>
See the <A HREF="http://www.nanoengineer-1.net/">NanoEngineer-1 wiki </A>
for tutorials and other information.</p>
<p>
See <A HREF="http://www.nanorex.com/">www.nanorex.com</A> for more information
about Nanorex.</p>
"""
from utilities.icon_utilities import image_directory
_sponsorImagePath = os.path.join( image_directory(), "ui/sponsors/nanorex.png")
_defaultSponsor = _Sponsor('Nanorex',
                           _fixHtml(_nanorexText), _sponsorImagePath)


###############################################

class SponsorableMixin:
    """
    To use this mixin class, instances of a main class which inherits it
    (which is typically a QDialog or PM_Dialog) should provide:

        - an attribute sponsor_keyword, which can be None, or a keyword
          string, or a list or tuple of sponsor keyword strings.
        - an attribute sponsor_btn, which must be a QPushButton object
          whose pixmap will be replaced with a sponsor logo during this
def turn_featurenames_into_links(text, savekey=None, saveplace=None):
    #bruce 051229; revised/renamed 060120; save args 060121; img tags 081205
    """
    [public]
    Given some nonempty whatsthis text, return identical or modified text
    (e.g. containing a web help URL).
    If savekey and saveplace are passed, and if the text contains a
    featurename, set saveplace[savekey] to that featurename.
    """
    # 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
    # for '"' and r'\' (fortunately rare in pathnames), perhaps for
    # other chars. This could probably be fixed by encoding them somehow.
    # I also don't know whether unicode characters will be permitted.
    # If not, this might be fixable by encoding them and/or by replacing
    # this approach with one in which we supply a callback to Qt for
    # interpreting these relative pathnames when they're needed.
    # (Does Qt call that callback an "icon factory"??)
    # WARNING: if these are real bugs, they'll prevent NE1 from starting
    # when it's installed under certain pathnames.
    # [bruce 081206 comments]
    PAT1 = "<img source=\"ui/"
    if PAT1 in text:
        ui_dir = os.path.join(os.path.normpath(image_directory()), "ui")
        ### TODO: use the named constant for "ui" here
        # (but not elsewhere in this function)
        # replace "ui" with ui_dir in all occurrences of PAT1 in text
        PAT2 = PAT1.replace("ui/", ui_dir + '/')
        text = text.replace(PAT1, PAT2)
        pass

    # look for words between <u><b> and </b></u> to replace with a web help link
    if text.startswith("<u><b>"):  # require this at start, not just somewhere
        # like debracket would
        split1 = debracket(text, "<u><b>", "</b></u>")
        if split1:
            junk, name, rest = split1
            featurename = name  # might be changed below
            if "[[Feature:" in rest:  # it's an optim to test this first,
                #since usually false
                #Extract feature name to use in the link, when this differs
                #from name shown in WhatsThis text; this name is usually given
                #in an HTML comment but we use it w/o modifying the text
                #whether or not it's in one.
                # We use it in the link but not in the displayed WhatsThis text.
                split2 = debracket(rest, "[[Feature:", "]]")
                if not split2:
                    print "syntax error in Feature: link for WhatsThis text \
                    for %r" % name
                    return text
                junk, featurename, junk2 = split2
            #e should verify featurename is one or more capitalized words
            # separated by ' '; could use split, isalpha (or so) ###@@@
            if _DEBUG_WHATSTHIS_LINKS:
                if featurename != name:
                    print "web help name for %r: %r" % (
                        name,
                        featurename,
                    )
                else:
                    print "web help name: %r" % (featurename, )
            if saveplace is not None:
                saveplace[savekey] = featurename
            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
Example #3
0
    vv = _attrholder()
    vv.tex_name = 0
    vv.tex_data = None
    vv.have_mipmaps = False

# == constants related to our single hardcoded texture-font

# (these should be turned into instance attributes of a texture-font object)

# Font image file (same image file is used in other modules, but for different
# purposes.)
## ## CAD_SRC_PATH = os.path.dirname(__file__)
## from constants import CAD_SRC_PATH
## courierfile = os.path.join(CAD_SRC_PATH,
##     "experimental/textures/courier-128.png")
courierfile = os.path.join(image_directory(),
                           "ui/exprs/text/courier-128.png")  ### TODO: RENAME

#e put these into an object for a texture font!
tex_width = 6  # pixel width of 1 char within the texture image
tex_height = 10  # pixel height (guess)
"""
()()
()()(8)
8888 -- there's one more pixel of vertical space between the chars, here in
idlehack, than in my courier-128.png image file!
"""

# ==

Example #4
0
###############################################

# This is the default sponsor image (and text) for the PM sponsor button.

_nanorexText = """\
Nanorex created NanoEngineer-1, the program you're using right now.
<p>
See the <A HREF="http://www.nanoengineer-1.net/">NanoEngineer-1 wiki </A> 
for tutorials and other information.</p>
<p>
See <A HREF="http://www.nanorex.com/">www.nanorex.com</A> for more information
about Nanorex.</p>
"""
from utilities.icon_utilities import image_directory
_sponsorImagePath = os.path.join(image_directory(), "ui/sponsors/nanorex.png")
_defaultSponsor = _Sponsor('Nanorex', _fixHtml(_nanorexText),
                           _sponsorImagePath)

###############################################


class SponsorableMixin:
    """
    To use this mixin class, instances of a main class which inherits it
    (which is typically a QDialog or PM_Dialog) should provide:
    
        - an attribute sponsor_keyword, which can be None, or a keyword
          string, or a list or tuple of sponsor keyword strings.
        - an attribute sponsor_btn, which must be a QPushButton object
          whose pixmap will be replaced with a sponsor logo during this
Example #5
0
    vv = _attrholder()
    vv.tex_name = 0
    vv.tex_data = None
    vv.have_mipmaps = False

# == constants related to our single hardcoded texture-font

# (these should be turned into instance attributes of a texture-font object)

# Font image file (same image file is used in other modules, but for different
# purposes.)
## ## CAD_SRC_PATH = os.path.dirname(__file__)
## from constants import CAD_SRC_PATH
## courierfile = os.path.join(CAD_SRC_PATH,
##     "experimental/textures/courier-128.png")
courierfile = os.path.join( image_directory(),
                            "ui/exprs/text/courier-128.png")  ### TODO: RENAME

#e put these into an object for a texture font!
tex_width = 6 # pixel width of 1 char within the texture image
tex_height = 10 # pixel height (guess)

"""
()()
()()(8)
8888 -- there's one more pixel of vertical space between the chars, here in
idlehack, than in my courier-128.png image file!
"""

# ==
Example #6
0
def canon_image_filename( filename):
    """
    Figure out (or guess) the right absolute pathname for loading the given image file into OpenGL.

    @warning: the answer depends on what files are found on your disk, so it might differ for different users!

    [Note: It's not yet clear whether that's merely a development kluge, or a feature, or some of each;
     someday there might even be user prefs for image search paths, except that plugins can provide their own images.... ##e]
    """
    orig_filename = filename # for debug prints or warnings
##    #stub, might work for now:
##    thisdir = os.path.dirname(__file__) # dir of exprs module
##    CAD_SRC_PATH = os.path.dirname( thisdir)
    from utilities.constants import CAD_SRC_PATH
        # [note: in a built Mac release, this might be Contents/Resources/Python/site-packages.zip, or
        #  a related pathname; see comments near its definition.]
    cad = os.path.dirname( CAD_SRC_PATH) # used below for cad/images

    # image file path extensively revised 070604, mainly so testmode can work in a built release package
    from platform_dependent.PlatformDependent import path_of_Nanorex_subdir

    # main exprs-package image directory
    cad_src_ui_exprs = os.path.join( image_directory(), "ui/exprs") # not necessarily really in cad/src (in a built release)

    # list of dirs in which to search for filename (#e could precompute; doesn't matter much)
    path = [
        # first, search in a user-controlled dir, so they can override UI image files
        # (if those are accessed using the exprs module).
        path_of_Nanorex_subdir("UI"),

        # next, let the code specify the name exactly, relative to cad_src_ui_exprs
        cad_src_ui_exprs,

        # next, to support older code in this exprs package,
        # let it leave out the subdir component if it's one of these:
        os.path.join( cad_src_ui_exprs, "text" ),
        os.path.join( cad_src_ui_exprs, "widgets" ),
        os.path.join( cad_src_ui_exprs, "textures" ),
        os.path.join( cad_src_ui_exprs, "test" ),

        # next, permit access to anything in image_directory()
        # using the same relative path (starting with "ui/")
        # as typical code in cad/src does (e.g. when calling geticon)
        # (this means we could rewrite geticon to call this routine,
        #  if we wanted it to be user-overridable someday #e)
        image_directory(),

        # for experimental things, let developers refer to things in cad/src/experimental --
        # I guess they can do that using the image_directory() entry (which for developers is .../cad/src)
        # by using filenames starting with "experimental", which is not a big restriction
        # given that we're not doing this early enough to override built-in images
        # (so, no path entry needed for that)

        # we no longer support the old experimental/textures directory
##        os.path.join( CAD_SRC_PATH, "experimental/textures"), # [not supported by autoBuild.py, and never will be]

        # but we do still support the obsolete cad/images dir, since some test code uses it
        # and it was still present in cvs (I think -- at least it's in my checkouts) as of 070604.
        os.path.join( cad, "images"),
    ]
    tries = map( lambda dir: os.path.join(dir, filename), path)
    lastresort = courierfile
        #e replace with some error-indicator image, or make one with the missing filename as text (on demand, or too slow)
    ## tries.append(lastresort)
    tries.append(-1)
    for filename in tries:
        if filename == -1:
            filename = lastresort
            if 'too important to not tell all users for now' or debug_flags.atom_debug:
                print "bug: image file %r not found, using last-resort image file %r" % (orig_filename, lastresort) ###
        filename = os.path.abspath(os.path.normpath(filename)) # faster to do this on demand
        if os.path.isfile(filename):
            if DEBUG_IMAGE_SEARCH:
                print "                found:",filename
            return filename
        if DEBUG_IMAGE_SEARCH:
            print "didn't find:", filename
    assert 0, "lastresort file %r should always be present" % os.path.abspath(os.path.normpath(lastresort))
    pass # end of canon_image_filename
Example #7
0
# NOTE: the following code contains some hardcoded "ui" which
# should be UI_SUBDIRECTORY_COMPONENT
## from icon_utilities import UI_SUBDIRECTORY_COMPONENT

# ImageUtils.py class nEImageOps -- see following comment

# TODO: find out if the functions we need from texture_helpers could be imported here at toplevel:
import graphics.drawing.texture_helpers as texture_helpers
    # Note: from texture_helpers we use:
    #   function create_PIL_image_obj_from_image_file, a trivial glue function into ImageUtils.py class nEImageOps,
    #   function loadTexture.

from utilities.icon_utilities import image_directory # for finding texture & cursor files

# last-resort image file (same image file is used in other modules, but for different purposes)
courierfile = os.path.join( image_directory(), "ui/exprs/text/courier-128.png") ### TODO: RENAME

# old comment about testdraw.py, not sure if still relevant as of 071017:
    # and we copy & modify other funcs from it into this file, but they also remain in testdraw for now, in some cases still used.
    # At some point we'll need to clean up the proper source file of our helper functions from testdraw...
    # when the time comes, the only reliable way to sort out & merge duplicated code (some in other cad/src files too)
    # is to search for all uses of the GL calls being used here.

debug_glGenTextures = True #070308 #####

class _texture_holder(object):
    """
    [private class for use in a public MemoDict]
    From a filename and other data, create on demand, and cache, a PIL Image object and an optional OpenGL texture object;
    objects of this class are meant to be saved as a memoized dict value with the filename being the dict key
    """
def turn_featurenames_into_links(text, savekey = None, saveplace = None):
    #bruce 051229; revised/renamed 060120; save args 060121; img tags 081205
    """
    [public]
    Given some nonempty whatsthis text, return identical or modified text
    (e.g. containing a web help URL).
    If savekey and saveplace are passed, and if the text contains a
    featurename, set saveplace[savekey] to that featurename.
    """
    # 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
    # for '"' and r'\' (fortunately rare in pathnames), perhaps for
    # other chars. This could probably be fixed by encoding them somehow.
    # I also don't know whether unicode characters will be permitted.
    # If not, this might be fixable by encoding them and/or by replacing
    # this approach with one in which we supply a callback to Qt for
    # interpreting these relative pathnames when they're needed.
    # (Does Qt call that callback an "icon factory"??)
    # WARNING: if these are real bugs, they'll prevent NE1 from starting
    # when it's installed under certain pathnames.
    # [bruce 081206 comments]
    PAT1 = "<img source=\"ui/"
    if PAT1 in text:
        ui_dir = os.path.join( os.path.normpath( image_directory() ), "ui" )
            ### TODO: use the named constant for "ui" here
            # (but not elsewhere in this function)
        # replace "ui" with ui_dir in all occurrences of PAT1 in text
        PAT2 = PAT1.replace("ui/", ui_dir + '/')
        text = text.replace(PAT1, PAT2)
        pass

    # look for words between <u><b> and </b></u> to replace with a web help link
    if text.startswith("<u><b>"): # require this at start, not just somewhere
                                  # like debracket would
        split1 = debracket(text, "<u><b>", "</b></u>")
        if split1:
            junk, name, rest = split1
            featurename = name # might be changed below
            if "[[Feature:" in rest: # it's an optim to test this first,
                #since usually false
                #Extract feature name to use in the link, when this differs
                #from name shown in WhatsThis text; this name is usually given
                #in an HTML comment but we use it w/o modifying the text
                #whether or not it's in one.
                # We use it in the link but not in the displayed WhatsThis text.
                split2 = debracket(rest, "[[Feature:", "]]")
                if not split2:
                    print "syntax error in Feature: link for WhatsThis text \
                    for %r" % name
                    return text
                junk, featurename, junk2 = split2
            #e should verify featurename is one or more capitalized words
            # separated by ' '; could use split, isalpha (or so) ###@@@
            if _DEBUG_WHATSTHIS_LINKS:
                if featurename != name:
                    print "web help name for %r: %r" % (name, featurename,)
                else:
                    print "web help name: %r" % (featurename,)
            if saveplace is not None:
                saveplace[savekey] = featurename
            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
Example #9
0
def canon_image_filename(filename):
    """
    Figure out (or guess) the right absolute pathname for loading the given image file into OpenGL.

    @warning: the answer depends on what files are found on your disk, so it might differ for different users!

    [Note: It's not yet clear whether that's merely a development kluge, or a feature, or some of each;
     someday there might even be user prefs for image search paths, except that plugins can provide their own images.... ##e]
    """
    orig_filename = filename  # for debug prints or warnings
    ##    #stub, might work for now:
    ##    thisdir = os.path.dirname(__file__) # dir of exprs module
    ##    CAD_SRC_PATH = os.path.dirname( thisdir)
    from utilities.constants import CAD_SRC_PATH
    # [note: in a built Mac release, this might be Contents/Resources/Python/site-packages.zip, or
    #  a related pathname; see comments near its definition.]
    cad = os.path.dirname(CAD_SRC_PATH)  # used below for cad/images

    # image file path extensively revised 070604, mainly so testmode can work in a built release package
    from platform_dependent.PlatformDependent import path_of_Nanorex_subdir

    # main exprs-package image directory
    cad_src_ui_exprs = os.path.join(
        image_directory(),
        "ui/exprs")  # not necessarily really in cad/src (in a built release)

    # list of dirs in which to search for filename (#e could precompute; doesn't matter much)
    path = [
        # first, search in a user-controlled dir, so they can override UI image files
        # (if those are accessed using the exprs module).
        path_of_Nanorex_subdir("UI"),

        # next, let the code specify the name exactly, relative to cad_src_ui_exprs
        cad_src_ui_exprs,

        # next, to support older code in this exprs package,
        # let it leave out the subdir component if it's one of these:
        os.path.join(cad_src_ui_exprs, "text"),
        os.path.join(cad_src_ui_exprs, "widgets"),
        os.path.join(cad_src_ui_exprs, "textures"),
        os.path.join(cad_src_ui_exprs, "test"),

        # next, permit access to anything in image_directory()
        # using the same relative path (starting with "ui/")
        # as typical code in cad/src does (e.g. when calling geticon)
        # (this means we could rewrite geticon to call this routine,
        #  if we wanted it to be user-overridable someday #e)
        image_directory(),

        # for experimental things, let developers refer to things in cad/src/experimental --
        # I guess they can do that using the image_directory() entry (which for developers is .../cad/src)
        # by using filenames starting with "experimental", which is not a big restriction
        # given that we're not doing this early enough to override built-in images
        # (so, no path entry needed for that)

        # we no longer support the old experimental/textures directory
        ##        os.path.join( CAD_SRC_PATH, "experimental/textures"), # [not supported by autoBuild.py, and never will be]

        # but we do still support the obsolete cad/images dir, since some test code uses it
        # and it was still present in cvs (I think -- at least it's in my checkouts) as of 070604.
        os.path.join(cad, "images"),
    ]
    tries = map(lambda dir: os.path.join(dir, filename), path)
    lastresort = courierfile
    #e replace with some error-indicator image, or make one with the missing filename as text (on demand, or too slow)
    ## tries.append(lastresort)
    tries.append(-1)
    for filename in tries:
        if filename == -1:
            filename = lastresort
            if 'too important to not tell all users for now' or debug_flags.atom_debug:
                print "bug: image file %r not found, using last-resort image file %r" % (
                    orig_filename, lastresort)  ###
        filename = os.path.abspath(
            os.path.normpath(filename))  # faster to do this on demand
        if os.path.isfile(filename):
            if DEBUG_IMAGE_SEARCH:
                print "                found:", filename
            return filename
        if DEBUG_IMAGE_SEARCH:
            print "didn't find:", filename
    assert 0, "lastresort file %r should always be present" % os.path.abspath(
        os.path.normpath(lastresort))
    pass  # end of canon_image_filename
Example #10
0
# NOTE: the following code contains some hardcoded "ui" which
# should be UI_SUBDIRECTORY_COMPONENT
## from icon_utilities import UI_SUBDIRECTORY_COMPONENT

# ImageUtils.py class nEImageOps -- see following comment

# TODO: find out if the functions we need from texture_helpers could be imported here at toplevel:
import graphics.drawing.texture_helpers as texture_helpers
    # Note: from texture_helpers we use:
    #   function create_PIL_image_obj_from_image_file, a trivial glue function into ImageUtils.py class nEImageOps,
    #   function loadTexture.

from utilities.icon_utilities import image_directory # for finding texture & cursor files

# last-resort image file (same image file is used in other modules, but for different purposes)
courierfile = os.path.join( image_directory(), "ui/exprs/text/courier-128.png") ### TODO: RENAME

# old comment about testdraw.py, not sure if still relevant as of 071017:
    # and we copy & modify other funcs from it into this file, but they also remain in testdraw for now, in some cases still used.
    # At some point we'll need to clean up the proper source file of our helper functions from testdraw...
    # when the time comes, the only reliable way to sort out & merge duplicated code (some in other cad/src files too)
    # is to search for all uses of the GL calls being used here.

debug_glGenTextures = True #070308 #####

class _texture_holder(object):
    """
    [private class for use in a public MemoDict]
    From a filename and other data, create on demand, and cache, a PIL Image object and an optional OpenGL texture object;
    objects of this class are meant to be saved as a memoized dict value with the filename being the dict key
    """