Example #1
0
def hush_with_pog(pog, printer):
    """
    The printer func is under dev - aiming for a way to use this
    same func from the gui and cli

    The existence of the fontconfig conf.d directory must be
    confirmed before code gets here.

    See cli2.py, for example. It happens in a probeAllErrors call.
    """
    bugs = []
    printer(_("Trying to hush..."), key="starting")
    if isPog(pog):
        hushpog = fontcontrol.Pog(pog)
        ## gen and install it!
        printer(_("Installing \"{}\".").format(pog), key="installing")
        try:
            hushpog.genList()
            ## Aside: it is not an error to
            ## install again ( > once) - hence I don't need
            ## to worry about toggling this hush/unhush
            ## thing.
            hushpog.install()
            ##TESTING: raise fontybugs.PogInvalid
        except (fontybugs.PogInvalid, fontybugs.PogEmpty,
                fontybugs.PogAllFontsFailedToInstall,
                fontybugs.PogSomeFontsDidNotInstall, fontybugs.NoFontsDir), e:
            bugs.append(e.get_error_string())
Example #2
0
def instantiateTargetPog(newpog_name):
    """
    The app could begin with NO TARGET POG chosen.
    After that (in the gui) either a pog is chosen or NO POG is chosen (i.e. None)
    Therefore - there can NEVER BE a targetobject called EMPTY

    The CLI install/uninstall/purge DO NOT use this routine.
    """
    if state.targetobject: del state.targetobject
    ipog = fontcontrol.Pog(newpog_name)
    ## Must gen the Pog to get a count of items:
    ipog.genList()  # Raises fontybugs.PogInvalid error THIS ENDS THE APP.
    ## TEST the viewobject which is the stuff being
    ## LOOKED AT IN THE MIDDLE OF THE SCREEN (which could be a Pog OR a Folder)
    ## If it's a Pog then we may have chosen the same Pog (on the right)
    ## that we are looking at, so check that:
    state.samepogs = False
    if isinstance(state.viewobject, fontcontrol.Pog):
        if state.viewobject.name == newpog_name:
            ## The pog clicked in the TARGET is the same as what's ALREADY selected in the VIEW
            state.samepogs = True

    quickinstalledflag = False
    if ipog.isInstalled(): quickinstalledflag = True
    state.targetpattern = "P"
    state.targetobject = ipog
    markInactive()
    flushTicks()
    return quickinstalledflag
Example #3
0
    def fillPogList(self):
        """
        This is among the very FIRST things we do.
        Fill the list with pogs.
        This will CULL any bad pogs (i.e. those with 
        malformed content)
        Thus the PogInvalid error should not happen 
        any more after a run.
        """
        # pl will always be a BYTE STRING list
        pl = fpsys.iPC.getPogNames()

        for p in pl:  # 'p' is a byte string.
            ipog = fontcontrol.Pog(p)
            try:  #catch pogs that are not properly formed
                # isInstalled opens the pog file.
                if ipog.isInstalled():
                    i = self.icon_installed  #1
                else:
                    i = self.icon_normal  #0
            except fontybugs.PogInvalid, eInst:
                ## An "invalid" pog is one that does not have
                ## installed/not installed on the first line.
                print _("\"{}\" skipped. It's an invalid Pog.").format([p])
                continue

            ## Let's try to make a unicode of p so li.SetText(p)
            ## can display it:
            try:
                p = fpsys.LSP.to_unicode(p)
            except UnicodeDecodeError:
                ## We can't convert it under this locale
                ## This print hurts my brain. :(
                print _("\"{}\" skipped. I can't display this name "\
                        "under your locale.").format([p]) # Irony in print!
                continue
            ## Okay, we have a valid pog name to use:
            li = wx.ListItem()
            li.SetImage(i)
            li.SetText(p)

            ## June 25, 2016: Something in wxPython changed
            ## and li now needs an Id>0 (Capital "I"d. Weird)
            li.Id = 1

            id = wx.NewId()
            PogChooser.__poglistCopy[id] = p  # record the pog name
            row = self.InsertItem(li)
            # associate back to __poglistCopy
            self.SetItemData(row, id)
Example #4
0
def purgepog(pogtopurge):
    ##Handle purge
    if fpsys.isPog(pogtopurge):
        pog = fontcontrol.Pog(pogtopurge)
        try:
            #raise fontybugs.PogInvalid #testing
            pog.genList()
        except fontybugs.PogInvalid, e:
            e.print_error_and_quit()
        try:
            ## pog.purge() Raises
            ##   PogEmpty
            ##   PogInstalled
            pog.purge()
        except (fontybugs.PogEmpty, fontybugs.PogInstalled), e:
            e.print_error()
Example #5
0
def instantiateViewPog(newpog_name):
    """
    Given a Pog Name string, make a Pog object.

    This is the VIEW - i.e. what you are looking at.

    A VIEW Pog can be EMPTY. This happens on the first run when there is no config file.
    There are other arcane situations too, but I forget.
    """
    if state.viewobject: state.viewobject = None

    if newpog_name == "EMPTY":
        ipog = fontcontrol.EmptyView()
    else:
        ipog = fontcontrol.Pog(newpog_name)
    ## Test TARGETPOG to see if this is the same pogname
    ## The not None test is for first run - there is no targetobject yet just after cli.py calls us, so we
    ## do not want to access it or we get NoneType errors.
    if state.targetobject is not None and state.targetobject.name == newpog_name:
        state.samepogs = True
    else:
        state.samepogs = False
    ## Must gen the Pog to get a count of items:
    ## Errors raised in genList (and company):
    ## fontybugs.PogInvalid (only valid from cli pov)
    ##
    ## We 'handle' this by NOT catching it, pass it up.
    ipog.genList()

    ## Continue if all ok.
    state.viewobject = ipog
    ## Because we have a new view object, we must reset the last filteredViewObject
    state.filteredViewObject = None

    config.lastview = newpog_name
    if len(state.viewobject) == 0:
        empty = True
        state.viewpattern = "E"
    else:
        empty = False
        state.viewpattern = "P"
        markInactive()
        flushTicks()

    return empty  # this return is only used in cli.py
Example #6
0
def zip( pog ):
    ## Sep 2009 : ZIP
    ## Nov 2017: Much fixing of error handling.
    if fpsys.isPog( pog ):
        todir = os.curdir #always where we run this
        ipog = fontcontrol.Pog( pog )
        (bugs, fail, emsgs) = ipog.zip( todir )

        if fail: 
            print _("I could not create the zip at all.")
            print emsgs[0]
        else:
            print _("Zipped as \"{}.fonts.zip\" in the \"{}\" directory.").format( pog, os.getcwd())
            if bugs:
                print _("Some bugs happened:")
                for m in emsgs: print m
    else:
        print _("I can't find a Pog named \"{}\".").format(pog)
Example #7
0
def uninstallpogs( listofpogs ):
    ## uninstall
    for pogtouninstall in listofpogs:
        if fpsys.isPog(pogtouninstall):
            pog = fontcontrol.Pog(pogtouninstall )
            try:
                pog.genList()
            except fontybugs.PogInvalid, e:
                e.print_error_and_quit()
            try:
            ## Raises:
            ##   PogEmpty
            ##   PogLinksRemain
            ##   PogNotInstalled
                print _("Removing \"{}\".").format(pogtouninstall)
                pog.uninstall()
            except (fontybugs.PogEmpty,
                fontybugs.PogNotInstalled,
                fontybugs.PogLinksRemain), e:
                e.print_error()
Example #8
0
def installpogs( listofpogs ):
    #### 
    ## Install:
    for pogtoinstall in listofpogs:
        if fpsys.isPog(pogtoinstall):
            pog = fontcontrol.Pog( pogtoinstall )
            try:
                pog.genList()
            except fontybugs.PogInvalid, e:
                e.print_error_and_quit()
            try:
            ## pog.install() Raises:
            ##   PogEmpty
            ##   PogAllFontsFailedToInstall
            ##   PogSomeFontsDidNotInstall
            ##   NoFontsDir
                print _("Installing \"{}\".").format(pogtoinstall)
                pog.install()
            except ( fontybugs.PogEmpty,
                    fontybugs.PogAllFontsFailedToInstall,
                    fontybugs.PogSomeFontsDidNotInstall,
                    fontybugs.NoFontsDir ), e:
                e.print_error()
Example #9
0

def installall( FOLDERNAME, POGNAME, recurseflag ):
    ## Install all fonts in folder to given pog.
    ## May 2009 : Based on code by another author (names lost in email crash).
    count = 0
    existingPog = False
    try:
        folder = fontcontrol.Folder(FOLDERNAME, recurse=recurseflag)
    except fontybugs.FolderHasNoFonts, e:
        e.print_error_and_quit()
    except Exception, e:
        print e
        raise SystemExit

    ipog = fontcontrol.Pog( POGNAME ) # whether it exists or not.

    ## If it's an unknown POGNAME, make it and write it:
    if not fpsys.isPog(POGNAME):
        print _("Creating a new Pog named \"{}\".").format(POGNAME)
        try:
            ipog.write()
        except fontybugs.PogWriteError, e:
            e.print_error_and_quit()

    ## Fill it with fontitems.
    ipog.genList()

    ## get a list of what (in the folder) is NOT already in the ipog (assuming it's non-empty)
    fl = [fi for fi in folder if str(fi) not in [str(fi2) for fi2 in ipog]] #str(fontItem) returns glyphpaf which has been decoded already.
Example #10
0
    # If it's not a pog and it's not "EMPTY",then it's a weirdo.
    if not fpsys.isPog(A) and A != "EMPTY":
        print _("Sorry, \"{}\" does not exist. Try --list").format(A)
        raise SystemExit

## Disallow Folder in arg B
if B and fpsys.isFolder(B):
    print _("You cannot use a folder as the target argument. Try --help")
    raise SystemExit

## Let's ensure that B exists, else we must make it.
## This is because when you call VIEW TARGET and
## TARGET gets created (the file) if it's not there.
##TODO: Why? FIXME
if B and not fpsys.isPog(B):
    ipog = fontcontrol.Pog(B)
    try:
        ipog.write()
    except fontybugs.PogWriteError, e:
        e.print_error_and_quit()
    del ipog

## Build the fpsys structure
## Calls to instantiateXYZ are vital. They are where the View or Target Objects get
## generated - i.e. where all their fontItems are built-up.
## One arg:
if A and not B:
    if fpsys.isFolder(A):
        try:
            fpsys.instantiateViewFolder(
                A)  # creates a state.viewobject globally.