Ejemplo n.º 1
0
def addStoryRowNew(caller,parent,ed,target):
  row = gtk.HBox()
  row.show()
  text = "Please enter the short code for this story"
  label = "Code:"
  subtext = "\
This will be what is displayed in your\n\
backend files. Once set, it cannot be\n\
changed within this program.  It may\n\
contain word characters (A-Z,0-9,_,-)\n\
only."
  code = common.askBox(ed,text,label,subtext=subtext,nospace=True)
  code = common.validateFileid(code)
  if code and len(code) > 0:
    label = gtk.Label(code)
    label.show()
    label.set_width_chars(4)
    row.pack_start(label,False,False,2)
    entry = gtk.Entry()
    entry.show()
    entry.set_width_chars(20)
    row.pack_start(entry,False,False,2)
    target.pack_start(row,False,False,2)
    entry.grab_focus()
    entry.connect("focus-out-event",setStory,code)
    refreshEd(parent,ed)
  else:
    status.push(0,"Story add cancelled.")
    return False
Ejemplo n.º 2
0
def chooseCity(parent,target,tabs,scroll,data,statef,ar,stalts,title = ""):
  global status
  global cities
  city = recordSelectBox(None,statef,title,'c')
  if city and city[1] == "city":
    cityname = ""
    citlist = getCityList(0)
    cityf = validateFileid(citlist.get(statef,["",""])[1])
    cityname = citlist.get(statef,["",""])[0]
    statename = citlist.get(statef,["","",""])[2]
    try:
      cityname = cities[city[0]]['info']['name'][0]
      cities[city[0]]['info']['state'] = [statename,True]
      cities[city[0]]['info']['statefile'] = [statef,True]
      cities[city[0]]['info']['loc'] = [cityname,True]
      cities[city[0]]['info']['locfile'] = [cityf,True]
      cities[city[0]]['changed'] = True
      saveThisC(parent,city[0])
#      reloadPlaceTab(place[0]) # TODO: Write a function like this
    except KeyError:
#      placename = getPlaceNameFromID(place[0])
      cityname = askBox("?","  Please type the city name that goes with %s" % city[0],"Name",subtext="  I tried to load this from memory, but you\ndon't have %s open. Without it open, I can't\nsynchronize its city and state values.\n  This requirement prevents unintentional\nchanges to your place records." % city[0])
      # Maybe some day, I'll make this grab the placename from the file, and automatically load its record for updating
    if cityname == "":
      status.push(0,"Registering place in %s cancelled" % cityf)
      return False
    packCity(target,scroll,data,statef,city[0],cityname,tabs,True,ar,stalts)
    status.push(0,"Registered %s in %s" % (city[1],statef))
    return True
  else:
    status.push(0,"Registering place in %s cancelled" % statef)
    return False
Ejemplo n.º 3
0
def choosePlace(parent, target, tabs, scroll, data, cityf, ar, ctalts, title=""):
    global status
    global places
    place = recordSelectBox(None, cityf, title, "l")
    if place and place[1] == "place":
        placename = ""
        citlist = getCityList(0)
        statef = validateFileid(citlist.get(cityf, ["", ""])[1])
        cityname = citlist.get(cityf, ["", ""])[0]
        statename = citlist.get(cityf, ["", "", ""])[2]
        try:
            placename = places[place[0]]["info"]["name"][0]
            places[place[0]]["info"]["state"] = [statename, True]
            places[place[0]]["info"]["statefile"] = [statef, True]
            places[place[0]]["info"]["loc"] = [cityname, True]
            places[place[0]]["info"]["locfile"] = [cityf, True]
            places[place[0]]["changed"] = True
            saveThisL(parent, place[0])
        #      reloadPlaceTab(place[0]) # TODO: Write a function like this
        except KeyError:
            #      placename = getPlaceNameFromID(place[0])
            placename = askBox(
                None,
                "  Please type the location name that goes with %s" % place[0],
                "Name",
                subtext="  I tried to load this from memory, but you\ndon't have %s open. Without it open, I can't\nsynchronize its city and state values.\n  This requirement prevents unintentional\nchanges to your place records."
                % place[0],
            )
            # Maybe some day, I'll make this grab the placename from the file, and automatically load its record for updating
        if placename == "":
            status.push(0, "Registering place in %s cancelled" % cityf)
            return False
        packPlace(target, scroll, data, cityf, place[0], placename, tabs, True, ar, ctalts)
        status.push(0, "Registered %s in %s" % (place[1], cityf))
        return True
    else:
        status.push(0, "Registering place in %s cancelled" % cityf)
        return False
Ejemplo n.º 4
0
def loadState(fileid):
  """Given an id (filename) matching an XML file in the appropriate
  directory, loads the tree from the file and pushes its data into
  a dictionary.
  """
  dinf = {}
  root = etree.Element("state")
  text = None
  statename = ""
  statefile = ""
  # TODO: put this in a global variable, and make a function to populate it from the DTD.
  tags = ["name","start","scue","end","ecue","aspects","update"]
  for tag in tags:
    dinf[tag] = ["",False]
  dinf['cities'] = {}
  dinf['m'] = {}
  dinf['m']['events'] = {}
  dinf['aspects'] = {}
  if not idExists(fileid):
    status.push(0,"new state created... '%s'" % fileid)
    return dinf
  statefile = fileid
  fn = os.path.join(config['realmdir'],"%s.xml" % fileid)
  status.push(0,"loading state from XML... '%s'" % fn)
  try:
    with codecs.open(fn,'rU','utf-8') as f:
      tree = etree.parse(f)
      f.close()
      root = tree.getroot()
  except IOError as e:
    print "c: Could not open configuration file: %s" % e

  ir = 0
  for i in range(len(root)):
    if root[i].tag is not None:
      if root[i].tag == "city":
        if len(root[i]) > 0:
          node = ""
          node = root[i].find("file")
          if node.text:
            node = node.text.strip()
            node = common.validateFileid(node)
            dinf['cities'][node] = {}
            for j in root[i]:
              if j.tag and j.text and j.tag != "file":
                dinf['cities'][node][j.tag] = [j.text.strip(),False]
            if config['debug'] > 3: printPretty(dinf['cities'][node])
          else:
            if config['debug'] > 0:
              print "Invalid city tag:"
              for c in root[i]:
                print c.tag + ': ' + c.text,
        else: # no relat length
          if config['debug'] > 0: print "Empty city tag."
      elif root[i].tag == "events":
        if len(root[i]) > 0:
          nodes = root[i]
          for node in nodes:
            k = str(len(dinf['m']['events']))
            dinf['m']['events'][k] = {}
            for j in node:
              if j.tag and j.text:
                dinf['m']['events'][k][j.tag] = [j.text.strip(),False]
              else:
                if config['debug'] > 0:
                  print "Invalid milestone tag:"
                  for c in node:
                    print c.tag + ': ' + c.text,
          if config['debug'] > 3: printPretty(dinf['m']['events'])
        else: # no relat length
          if config['debug'] > 0: print "Empty milestone tag."

      elif root[i].tag == "aspects":
        if len(root[i]) > 0:
          nodes = root[i]
          for node in nodes:
            k = str(len(dinf['aspects']))
            dinf['aspects'][k] = {}
            if node.tag and node.text:
              dinf['aspects'][k] = [node.text.strip(),False]
            else:
              if config['debug'] > 0:
                print "Invalid aspects tag:"
                print node.tag + ': ' + node.text,
        else: # no aspects length
          if config['debug'] > 0: print "Empty aspects tag."

      elif root[i].text is not None:
        dinf[root[i].tag] = [root[i].text.strip(), False]
        if config['debug'] > 2: print str(i) + " ",
  statename = dinf.get("name","")
  if len(statename) > 1: pushLoc(statefile,statename)
  return dinf
Ejemplo n.º 5
0
def loadPlace(fileid):
  """Given an id (filename) matching an XML file in the appropriate
  directory, loads the tree from the file and pushes its data into
  two dictionaries, which it returns as a tuple.
  """
  dinf = {}
  drel = {}
  root = etree.Element("place")
  text = None
  city = ""
  cityf = ""
  state = ""
  statef = ""
  placename = ""
  # TODO: put this in a global variable, and make a function to populate it from the DTD.
  tags = ["commonname","name","start","scue","end","ecue","stories","mention","desc","address","loc","locfile","state","statefile","note", "relat","update"]
  tags.remove("note")
  tags.remove("relat")
  tags.append("file")
  for tag in tags:
    dinf[tag] = ["",False]
  # if no relations or notes, leave blank
  dinf['aspects'] = {}
  if not idExists(fileid):
    status.push(0,"new place created... '%s'" % fileid)
    return (dinf,drel)
  fn = os.path.join(config['realmdir'],"%s.xml" % fileid)
  status.push(0,"loading place from XML... '%s'" % fn)
  try:
    with codecs.open(fn,'rU','utf-8') as f:
      tree = etree.parse(f)
      f.close()
      root = tree.getroot()
  except IOError as e:
    print " Could not open place file: %s" % e

  ir = 0
  for i in range(len(root)):
    if root[i].tag is not None:
      if root[i].tag == "relat":
        node = ""
        try:
          node = root[i].find("file").text.strip()
        except AttributeError:
          common.bsay("?","XML formatting error in %s! Probably an empty relat tag." % fileid)
        node = common.validateFileid(node)
        drel[node] = {}
        for j in root[i]:
          if j.tag == "events":
            if not drel[node].get('events'): drel[node]['events'] = {}
            for k in j:
              stone = str(len(drel[node]['events']))
              drel[node]['events'][stone] = {}
              for m in k:
                if m.tag and m.text:
                  drel[node]['events'][stone][m.tag] = [m.text.strip(),False]
          else: # elif j.tag != "file":
            if j.tag and j.text:
              drel[node][j.tag] = [j.text.strip(),False]
        if config['debug'] > 3: print drel[node]
      elif root[i].tag == "note":
#        print ",",
        if not dinf.get("notes"):
          dinf['notes'] = {}
        x = str(len(dinf['notes']))
        dinf['notes'][x] = {}
        try:
          dinf['notes'][x]['content'] = [root[i].find("content").text.strip(),False]
        except AttributeError:
          del dinf['notes'][x]
        if dinf['notes'].get(x):
          dinf['notes'][x]['date'] = [root[i].find("date").text.strip(),False]
#      elif root[i].tag == "formocc":
#        print ",",
      elif root[i].tag == "aspects":
        if len(root[i]) > 0:
          nodes = root[i]
          for node in nodes:
            k = str(len(dinf['aspects']))
            dinf['aspects'][k] = {}
            if node.tag and node.text:
              dinf['aspects'][k] = [node.text.strip(),False]
            else:
              if config['debug'] > 0:
                print "Invalid aspects tag:"
                print node.tag + ': ' + node.text,
        else: # no aspects length
          if config['debug'] > 0: print "Empty aspects tag."
      elif root[i].text is not None:
        if root[i].tag == "statefile":
          statef = root[i].text.strip()
          statef = common.validateFileid(statef)
          if statef is None: statef = ""
        elif root[i].tag == "state":
          state = root[i].text.strip()
        elif root[i].tag == "locfile":
          cityf = root[i].text.strip()
          cityf = common.validateFileid(cityf)
          if cityf is None: cityf = ""
        elif root[i].tag == "loc":
          city = root[i].text.strip()
        elif root[i].tag == "name":
          placename = root[i].text.strip()
        dinf[root[i].tag] = [root[i].text.strip(), False]
        if config['debug'] > 2: print str(i) + " ",
  if len(statef) > 0 and len(cityf) > 0: pushLoc(statef,state,cityf,city,fileid,placename)
  return (dinf,drel)
Ejemplo n.º 6
0
def loadPerson(fileid):
  """Given an id (filename) matching an XML file in the appropriate
  directory, loads the tree from the file and pushes its data into
  two dictionaries, which it returns as a tuple.
  """
  dinf = {}
  drel = {}
  root = etree.Element("person")
  text = None
  # TODO: put this in a global variable, and make a function to populate it from the DTD.
  tags = ["commonname", "ctitle", "gname", "mname", "fname", "nname", "nameorder", "gender", "bday", "dday", "stories", "mention", "appear1ch", "appear1wr", "conflict", "leadrel", "bodytyp", "age", "skin", "eyes", "hair", "dmarks", "dress", "attposs", "asmell", "personality", "speech", "formocc", "currocc", "strength", "weak", "mole", "hobby", "misc", "ethnic", "origin", "backstory", "residence", "minchar", "talent", "abil", "sgoal", "other", "relat", "aspects", "update"]
  tags.remove("currocc")
  tags.remove("formocc")
  tags.remove("relat")
  tags.append("file")
  for tag in tags:
    dinf[tag] = ["",False]
  dinf['currocc'] = {}
  dinf['currocc']['pos'] = ["",False]
  dinf['formocc'] = {}
  dinf['formocc']['pos'] = ["",False]
  dinf['aspects'] = {}
  events = {}
  events['0'] = {}
  events['0']['date'] = ["",False]
  events['0']['event'] = ["",False]
  dinf['currocc']['events'] = events
  dinf['formocc']['events'] = events
  if not idExists(fileid):
    status.push(0,"new person created... '%s'" % fileid)
    return (dinf,drel)
  fn = os.path.join(config['realmdir'],fileid + ".xml")
  status.push(0,"loading person from XML... '%s'" % fn)
  try:
    with codecs.open(fn,'rU','utf-8') as f:
      tree = etree.parse(f)
      f.close()
      root = tree.getroot()
  except IOError as e:
    print " Could not open configuration file: %s" % e

  ir = 0
  for i in range(len(root)):
    if root[i].tag is not None:
      if root[i].tag == "relat":
        if len(root[i]) > 0:
          node = ""
          node = root[i].find("file")
          if node is not None and node.text:
            node = node.text.strip()
            node = common.validateFileid(node)
            drel[node] = {}
            for j in root[i]:
              if j.tag == "events":
                if not drel[node].get('events'): drel[node]['events'] = {}
                for k in j:
                  stone = str(len(drel[node]['events']))
                  drel[node]['events'][stone] = {}
                  for m in k:
                    if m.tag and m.text:
                      drel[node]['events'][stone][m.tag] = [m.text.strip(),False]
              else: # elif j.tag != "file":
                if j.tag and j.text:
                  drel[node][j.tag] = [j.text.strip(),False]
            if config['debug'] > 3: print drel[node]
          else:
            if config['debug'] > 0:
              print "Invalid relat tag:"
              for c in root[i]:
                print c.tag
        else: # no relat length
          if config['debug'] > 0: print "Empty relat tag."
      elif root[i].tag == "currocc":
#        print ",",
        dinf['currocc'] = {}
        try:
          dinf['currocc']['pos'] = [root[i].find("pos").text.strip(),False]
        except AttributeError:
          del dinf['currocc']
        if dinf.get('currocc'):
          events = {}
          if len(root[i]) > 1:
            for j in root[i]:
              if j.tag is not None:
                if j.tag == "events":
                  for k in j:
                    if k.tag == "mstone":
                      le = str(len(events))
                      events[le] = {}
                      events[le]['date'] = ["",False]
                      events[le]['event'] = ["",False]
                      for m in k:
                        if m.tag and m.text:
                          events[le][m.tag] = [m.text.strip(),False]
          else:
            events['0'] = {}
            events['0']['date'] = ["",False]
            events['0']['event'] = ["",False]
          dinf['currocc']['events'] = events
        else:
          dinf['currocc'] = {}
          dinf['currocc']['pos'] = ["",False]
          events = {}
          events['0'] = {}
          events['0']['date'] = ["",False]
          events['0']['event'] = ["",False]
          dinf['currocc']['events'] = events
      elif root[i].tag == "formocc":
#        print ",",
        dinf['formocc'] = {}
        try:
          dinf['formocc']['pos'] = [root[i].find("pos").text.strip(),False]
        except AttributeError:
          del dinf['formocc']
        if dinf.get('formocc'):
          events = {}
          if len(root[i]) > 1:
            for j in root[i]:
              if j.tag is not None:
                if j.tag == "events":
                  for k in j:
                    if k.tag == "mstone":
                      le = str(len(events))
                      events[le] = {}
                      events[le]['date'] = ["",False]
                      events[le]['event'] = ["",False]
                      for m in k:
                        if m.tag and m.text:
                          events[le][m.tag] = [m.text.strip(),False]
          else:
            events['0'] = {}
            events['0']['date'] = ["",False]
            events['0']['event'] = ["",False]
          dinf['formocc']['events'] = events
        else:
          dinf['formocc'] = {}
          dinf['formocc']['pos'] = ["",False]
          events = {}
          events['0'] = {}
          events['0']['date'] = ["",False]
          events['0']['event'] = ["",False]
          dinf['formocc']['events'] = events
      elif root[i].tag == "aspects":
        if len(root[i]) > 0:
          nodes = root[i]
          for node in nodes:
            k = str(len(dinf['aspects']))
            dinf['aspects'][k] = {}
            if node.tag and node.text:
              dinf['aspects'][k] = [node.text.strip(),False]
            else:
              if config['debug'] > 0:
                print "Invalid aspects tag:"
                print node.tag + ': ' + node.text,
        else: # no aspects length
          if config['debug'] > 0: print "Empty aspects tag."
      elif root[i].text is not None:
#        print ".",
        dinf[root[i].tag] = [root[i].text.strip(), False]
        if config['debug'] > 2: print str(i) + " ",
#  print str(dinf)
  return (dinf,drel)
Ejemplo n.º 7
0
def initCinfo(self, fileid, tabs, ar, ctalts):
    data = {}
    scroll = self.get_parent()
    try:
        data = cities.get(fileid)
    except KeyError as e:
        print "initCinfo: An error occurred accessing %s: %s" % (fileid, e)
        return
    scroll = self.get_parent()
    label = gtk.Label("City:")
    label.set_alignment(0, 0)
    label.show()
    self.pack_start(label, 0, 0, 1)
    self.s1 = gtk.HSeparator()
    self.pack_start(self.s1, False, False, 2)
    self.s1.show()
    name = buildarow(scroll, "Name:", data, fileid, "name", ar, ctalts)
    self.pack_start(name, 0, 0, 2)
    state = buildStateRow(scroll, data, fileid)
    self.pack_start(state, 0, 0, 2)
    row = gtk.HBox()
    row.show()
    path = ["info", "start"]
    label = gtk.Label("Start Date:")
    label.show()
    row.pack_start(label, False, False, 2)
    start = gtk.Entry(25)
    start.show()
    start.set_text(getInf(data, path))
    activateInfoEntry(start, ar, ctalts, scroll, data, fileid, "start")
    row.pack_start(start, True, True, 2)
    path2 = [fileid, "info"]
    path2.append(path[-1])
    placeCalendarButton(data, row, start, path2, ctalts, counter=ar)
    label = gtk.Label("Cue:")
    label.show()
    row.pack_start(label, False, False, 2)
    scue = gtk.Entry(25)
    scue.show()
    path[1] = "scue"
    scue.set_text(getInf(data, path))
    activateInfoEntry(scue, ar, ctalts, scroll, data, fileid, "scue")
    row.pack_start(scue, True, True, 2)
    self.pack_start(row, False, False, 2)
    row = gtk.HBox()
    row.show()
    label = gtk.Label("End Date:")
    label.show()
    row.pack_start(label, False, False, 2)
    end = gtk.Entry(25)
    end.show()
    path[1] = "end"
    end.set_text(getInf(data, path))
    activateInfoEntry(end, ar, ctalts, scroll, data, fileid, "end")
    row.pack_start(end, True, True, 2)
    path2 = [fileid, "info"]
    path2.append(path[-1])
    placeCalendarButton(data, row, end, path2, ctalts, counter=ar)
    label = gtk.Label("Cue:")
    label.show()
    row.pack_start(label, False, False, 2)
    ecue = gtk.Entry(25)
    ecue.show()
    path[1] = "ecue"
    ecue.set_text(getInf(data, path))
    activateInfoEntry(ecue, ar, ctalts, scroll, data, fileid, "ecue")
    row.pack_start(ecue, True, True, 2)
    self.pack_start(row, False, False, 2)
    self.aspects = buildaspectrow(scroll, cities.get(fileid), fileid, ar, ctalts)  # ,display = 0)
    self.add(self.aspects)
    """
	Population
	Major products/industries
	Major landmarks (list?)
	Primary power
	Secondary powers
	Demographics/Main race
	Districts (notebox)
	History?
"""
    self.notebox = gtk.VBox()
    self.notebox.show()
    self.pack_start(self.notebox, True, False, 2)
    label = gtk.Label("Places")
    label.set_alignment(0, 0)
    label.show()
    self.notebox.pack_start(label, 0, 0, 1)
    s1 = gtk.HSeparator()
    self.notebox.pack_start(s1, False, False, 2)
    s1.show()
    box = gtk.HBox()
    box.show()
    addbut = gtk.Button("Register Place")
    image = gtk.Image()
    image.set_from_file("img/add.png")
    image.show()
    addbut.set_image(image)
    addbut.show()
    path = ["info", "places"]
    state = validateFileid(getInf(data, ["info", "statefile"], ""))
    cityname = getInf(data, ["info", "name"], "")
    cityplaces = getInf(data, path, {})
    for l in cityplaces.keys():
        fi = l
        name = getInf(cityplaces, [l, "name"], "")
        pushLoc(state, "", fileid, cityname, fi, name)
    lbook = getPlacesIn(fileid)
    addbut.connect(
        "clicked", choosePlace, self.notebox, tabs, scroll, data, fileid, ar, ctalts, "Register in %s..." % cityname
    )
    box.pack_end(addbut, False, False, 1)
    self.notebox.pack_start(box, False, False, 1)
    for l in sorted(lbook.keys()):
        if l != "_name":
            newplace = False
            if l not in cityplaces.keys():
                newplace = True
                pushPlace(fileid, l, lbook[l])
            packPlace(self.notebox, scroll, data, fileid, l, lbook[l], tabs, newplace)
    el = gtk.Label("End of record")
    el.show()
    el.set_alignment(1, 1)
    self.pack_start(el, 0, 0, 3)