Requesting following features

Discussion in 'Civ4 - SDK/Python' started by j_mie6, Oct 23, 2010.

  1. j_mie6

    j_mie6 Deity

    Joined:
    Dec 20, 2009
    Messages:
    2,963
    Location:
    Bristol (uni)/Swindon (home)
    works with multiple lines... I added a scroll bar option to it for the list (which will be 133 lines long in the end)

    Code:
    def Popup(name, text, button, bScroll = False, iWidth = 50):
        def exit():
            popup.destroy()    
        popup = Tk()
    
        popup.title(name)
        font10 = tkFont.Font(family="Comic Sans MS", size=10)
    
        if bScroll:
            scroll = Scrollbar(popup)
            text2 = Text(popup, yscrollcommand=scroll.set, width=iWidth, font=font10, bg="light yellow")
            scroll.pack(side=RIGHT, fill=Y)
            for x in text: text2.insert(END, x + "\n")
            text2.pack(side=LEFT, fill=BOTH)
            scroll.config(command=text2.yview)
    
        if not bScroll:
            body = Label(popup, text=text, font=font10, bg="light yellow")
            body.pack(side=TOP, fill=X)
            btn = Button(popup, text=button, command=exit)
            btn.pack(side=BOTTOM, fill=X)
    
    one problem though, the font=font10 isn't working...
    any ideas? works for the main program window...
     
  2. Nitram15

    Nitram15 Pro Libertate!

    Joined:
    Sep 15, 2009
    Messages:
    1,855
    Location:
    Hungary
    Sadly, I have no idea. :( No idea... yet.
     
  3. stolenrays

    stolenrays Deity

    Joined:
    Aug 2, 2009
    Messages:
    2,061
  4. j_mie6

    j_mie6 Deity

    Joined:
    Dec 20, 2009
    Messages:
    2,963
    Location:
    Bristol (uni)/Swindon (home)
    hey, it's been a while how are things going?

    a question. A while ago you made this code to make sure rebels only declared war with their rival... unfortunately this made slaves at war with nobody. So I took matters into my own hands and this is the change I made:

    Code:
    def resetRebelCiv(pCivPlayer):
            pCivPlayer.get(CyPlayer).killAllDeals()
            pTeam = pCivPlayer.get(CyTeam)
            for eRivalTeam in CivPlayer.getPlayers(True, teamID):
                    if eRivalTeam == pCivPlayer.get(teamID): continue
                    elif eRivalTeam == getMajorCiv(pCivPlayer).get(teamID)[B] or pCivPlayer == instance(pointer("Slaves", playerID))[/B]:
                            if not pTeam.isAtWar(eRivalTeam):
                                    pTeam.declareWar(eRivalTeam, False, -1)
                    elif pTeam.isAtWar(eRivalTeam):
                            pTeam.makePeace(eRivalTeam)
    
    is that going to work?
     
  5. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I'm about to enjoy some of my brothers cooking at this very moment, but the way you wrote the expression seems overly complicated. Perhaps you could have a look at the CivPlayer module documentation to see what alternative ways there are to looking up CivPlayer class instances. Because there are several.
     
  6. j_mie6

    j_mie6 Deity

    Joined:
    Dec 20, 2009
    Messages:
    2,963
    Location:
    Bristol (uni)/Swindon (home)
    well it should still work. the reason eSlaves is not in the instance() is because it was never defined and when a eCiv is defined it uses pointer....
     
  7. j_mie6

    j_mie6 Deity

    Joined:
    Dec 20, 2009
    Messages:
    2,963
    Location:
    Bristol (uni)/Swindon (home)
    btw I fixed the event error... I fixed the problem a lot of times but you made 2 functions with the same name and so I only fixed 1 of them :rolleyes:
     
  8. j_mie6

    j_mie6 Deity

    Joined:
    Dec 20, 2009
    Messages:
    2,963
    Location:
    Bristol (uni)/Swindon (home)
    been working on a logging system recently for my own programs (if they go wrong). It's pretty nice, and uses things I didn't think possible (adding code to other python files with file.write() and stuff)

    Spoiler :
    Code:
    from datetime import *
    class log:
        def __init__(self, debug, exception, minor, number, time = datetime.now().strftime("%d/%m/%y - %H:%M")):
            self.debug = debug
            self.exception = exception
            self.minor = minor
            self.number = number
            self.time = time
            self.debug = writeString(self.debug, "DEBUG")
            self.minor = writeString(self.minor, "MINOR")
            if not self.exception == '': self.exception = writeString([self.exception], "EXCEPTION")
            else: self.exception = "No exceptions\n"
            if self.debug == '': self.debug = "No debug logs\n"
            if self.minor == '': self.minor = "No minor errors\n"
            
        def getDebug(self):
            return self.debug
    
        def getException(self):
            return self.exception
    
        def getMinor(self):
            return self.minor
    
        def getNumber(self):
            return self.number
    
        def getTime(self):
            return self.time
    
        def readLog(self):
            print "##Debug##\n%s\n##Exceptions##\n%s\n##Minor Errors##\n%s\n" % (self.debug, self.exception, self.minor)
    
        def writeLog(self, fileName = "Program"):
            f = open("SavedLogs.txt", "a")
            f.write('##Log Data for %s##\n\nLog created: %s\n\n#Debug#\n%s\n#Exceptions#\n%s\n#Minor Errors#\n%s\n\n\n' % (fileName, self.time, self.debug, self.exception, self.minor))
            f.close
    
    def writeString(lData, eType):
        string = ""
        if eType == "DEBUG":
             for data in lData:
                 string = string + "DebugEvent: %s\n" % data
        elif eType == "EXCEPTION":
             for data in lData:
                 string = string + "FatalError: %s\n" % data
        elif eType == "MINOR":
             for data in lData:
                 string = string + "MinorError: %s\n" % data
        return string
        
    
    def initLog(pythonProgram, debugData = [],minorError = [], exceptionData = '', numberData = 0):
        Log = open(pythonProgram + ".py", "a")
        Log.write('log = logData_%s\n' % pythonProgram)
        Log.close
    
        Log = open("logging.py", "a")
        Log.write('logData_%s = log(%s, "%s", %s, %s)\n' % (pythonProgram, debugData, exceptionData, minorError, numberData))
        Log.close
    
    ##LogData##
    


    Called with

    Code:
    initLog('logtest', ['Program launched', 'Event passed'], ["Number wasn't as expected (0)"], "IOError")
    The one thing I wonder though (having learnt how to use %s) is how civ4 makes it so that %s1 and %s2 can be used (and therfore be repeated as: the %s1 city of %s2 is in rebellion. the %s1 government is furious). When I try it comes out as either not enough values to format string or the roman1 city of rome2... Do you know how it is done?
     
  9. j_mie6

    j_mie6 Deity

    Joined:
    Dec 20, 2009
    Messages:
    2,963
    Location:
    Bristol (uni)/Swindon (home)
    urg... I was just getting some looks at the mod and found that those stupid peace messages are still there in the replays, so while I look for asafs comments on where his comments are I found the senate code that you made that I completely forgot about!!! I am going to look through it in a minute but can you remember what we were actually doing/was it ready?

    Also, how is everything going :p
     
  10. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I'm actually back at my computer now. Since yesterday, actually. Good timing!

    But now its Eurovision time ;)
     
  11. j_mie6

    j_mie6 Deity

    Joined:
    Dec 20, 2009
    Messages:
    2,963
    Location:
    Bristol (uni)/Swindon (home)
    When I heard that eurovison was on I thought "Baldyr is gonna be watching that" :lol:

    Are you back completely now then?
     

Share This Page