Exemplo n.º 1
0
 def Do(self):
     # get a random obj matching given adjectives
             
     # get a list of all objects matching adjectives
     cmd = List(self.abby, self.adjectives)
     layout = cmd.Do()
     oball = layout.ob
     if oball:
         ## print 'possibilities:',oball
         ob = Objects.Objs() # start with empty list
         for i in range(self.n):
             # now choose one of them at random
             #. we'll want to weight this according to 'popularity'
             # which will take various things into account, including
             # last accessed time, number of times accessed, duration of access,
             # number of times right (er, tied in through other db?),
             # uh...
             obj = random.choice(oball)
             ob.append(obj) # add to our list of objects
             
         self.abby.it = ob
         
         if self.n==1:
             layout = Layouts.Properties(self.abby, ob)
         else:
             layout = Layouts.Table(self.abby, ob)
             
     return layout
Exemplo n.º 2
0
    def initialize_layout(self):
        self.settings_layout = Layouts.SettingsLayout()
        self.game_board_layout = Layouts.GameBoardLayout(grid_size)
        self.main_layout = Layouts.ScreenLayout(self.settings_layout,
                                                self.game_board_layout)

        self.add_widget(self.main_layout)
Exemplo n.º 3
0
    def Do(self):
        
        # Build the export file and wrap it in a stream object
        # bug: forgot self in filename in similar case - wound up overwriting stuff.abby file by passing None!!!!!
        # bug: must write in binary mode or screws up endline!!
        stream = Streams.Factory(self.filename, 'wb', self.streamtype)
        
        # Build a list command to get the objects to export
        # export all properties!
        cmd = List(self.abby, self.adjectives, showprops='all') #, groupby, sortby)
        layout = cmd.Do() # don't tie into history
        
        # Pass the layout object to the stream object, which will pull 
        # the information from the layout and write it to the file in the
        # proper format.
        stream.WriteFromLayout(layout)

        #, i think the list command will set this via abby.get!
#        self.abby.it = layout.ob #, set current object(s)

        # wrap the status string in a simple String layout object
        nobjects = len(layout.ob)
        s = "%d objects exported to file '%s'." % (nobjects, self.filename)
#        self.abby.status = s #, standardize this
        return Layouts.String(s)
Exemplo n.º 4
0
    def Do(self):
#        filename = '__tempedit.txt'
        newname = self.name[:20].replace(' ','_')
        newname = newname.replace('/','_')
        filename = '__' + newname + '_description.txt'
        # get description
        s = self.obj.GetValue('description') 
        # save it to a temp file
        open(filename,'w').write(s)
        # edit file in notepad
        command = "notepad.exe %s" % filename
        pipe = os.popen(command)
        nada = pipe.read() # pipe will return '' when notepad closes
        # load file
        snew = open(filename,'r').read()
        # if description changed, save to the object
        ischanged = s != snew
        if ischanged:
            self.obj.SetValue('description', snew) # save new description
            status = "Object '%s' edited." % self.name
        else:
            status = "No changes made to object '%s'." % self.name
        # make sure to delete the temporary file also
        os.remove(filename)
        # set current object
        self.abby.it = self.obj 
        # return status message
        layout = Layouts.String(status)
        return layout
Exemplo n.º 5
0
    def Do(self):
        
        # this can throw an exception - let caller handle it.
        obj = self.abby.Add(self.type,self.name,self.description) #,self.altname)

        # set any adjectives
        # bug: had a loop here using obj as loop variable also, clobbering the original obj!!
        obj.PutIn(self.adjectives)

        # set any other property values defined in the assignments object
#        self.assignments.ApplyToObj(obj)

        # save state for undo
        self.id = obj.id

        # set abby.it
        self.abby.it = obj

        #, resolve this (string vs view of object...)
        if len(obj.name) > 30:
            name = obj.name[:30]+'...'
        else:
            name = obj.name
        s = "Added %s '%s'." % (obj.type, name)
        return Layouts.String(s)
Exemplo n.º 6
0
	def __init__(self, dataSet):
		self.dataSet = dataSet
		
		self.cardType = CardType.createType(self.generateList('type'), self.model)
		self.cardTypes = CardTypes.createTypes(self.generateList('types'), self.model)
		self.cmc = Cmc.createCmc(self.generateList('cmc'), self.model)
		self.colorIdentity = ColorIdentity.createColorIdentity(self.generateList('colorIdentity'), self.model)
		self.colors = Colors.createColors(self.generateList('colors'), self.model)
		self.hand = Hand.createHand(self.generateList('hand'), self.model)
		self.imageName = ImageName.createImageName(self.generateList('imageName'), self.model)
		self.layouts = Layouts.createLayouts(self.generateList('layout'), self.model)
		self.legalities = Legalities.createLegalities(self.generateList('legalities'), self.model)
		self.life = Life.createLife(self.generateList('life'), self.model)
		self.loyalty = Loyalty.createLoyalty(self.generateList('loyalty'), self.model)
		self.manaCost = ManaCost.createManaCost(self.generateList('manaCost'), self.model)
		self.name = Name.createName(self.generateList('name'), self.model)
		self.names = Names.createNames(self.generateList('names'), self.model)
		self.power = Power.createPower(self.generateList('power'), self.model)
		self.printings = Printings.createPrintings(self.generateList('printings'), self.model)
		self.rulings = Rulings.createRulings(self.generateList('rulings'), self.model)
		self.source = Source.createSource(self.generateList('source'), self.model)
		self.starter = Starter.createStarter(self.generateList('starter'), self.model)
		self.cardSubTypes = CardSubTypes.createSubTypes(self.generateList('subtypes'), self.model)
		self.cardSuperTypes = CardSuperTypes.createSuperTypes(self.generateList('supertypes'), self.model)
		self.text = Text.createText(self.generateList('text'), self.model)
		self.toughness = Toughness.createToughness(self.generateList('toughness'), self.model)
Exemplo n.º 7
0
 def Do(self):
     rs = self.abby.Get(afilter = self.filter)
     log.debug('cmd list.do -> ob=%s' % `rs`)
     #, let the layout sort the list (since user might change this interactively)?
     # set abby.it
     self.abby.it = rs
     # let ui handle printing the objects...
     layout = Layouts.Table(self.abby, rs, self.groupby, self.sortby, self.showprops)
     return layout
Exemplo n.º 8
0
 def Do(self):
     # put the objects in the given adjectives
     # eg 'put alarmclock in kalispell' is equivalent to 'alarmclock.company = kalispell'
     for obj in self.ob:
         obj.PutIn(self.adjectives)
     
     # set abby.it
     self.abby.it = self.ob
     s = 'Put %s in %s' % (self.ob, self.adjectives)
     layout = Layouts.String(s)
     return layout        
Exemplo n.º 9
0
 def loadSinks(self):
     self.sink_list.add(Info.init())
     self.sink_list.add(Buttons.init())
     self.sink_list.add(Menus.init())
     self.sink_list.add(Images.init())
     self.sink_list.add(Layouts.init())
     self.sink_list.add(Lists.init())
     self.sink_list.add(Popups.init())
     self.sink_list.add(Tables.init())
     self.sink_list.add(Text.init())
     self.sink_list.add(Trees.init())
     self.sink_list.add(Frames.init())
     self.sink_list.add(Tabs.init())
Exemplo n.º 10
0
 def loadSinks(self):
     self.sink_list.addSink(Info.init())
     self.sink_list.addSink(Buttons.init())
     self.sink_list.addSink(Menus.init())
     self.sink_list.addSink(Images.init())
     self.sink_list.addSink(Layouts.init())
     self.sink_list.addSink(Lists.init())
     self.sink_list.addSink(Popups.init())
     self.sink_list.addSink(Tables.init())
     self.sink_list.addSink(Text.init())
     self.sink_list.addSink(Trees.init())
     self.sink_list.addSink(Frames.init())
     self.sink_list.addSink(Tabs.init())
Exemplo n.º 11
0
def Options_Menu(saveIndex=-1):
    options = [
        "Multiple Choice", "Fill in The Blanks", "Ordering", "True and False",
        "Standard", "Connecting"
    ]
    option_buttons = []
    option_buttons.append(Button((0, HEIGHT - 50, 175, 50), text="Back"))
    for b in range(len(options)):
        option_buttons.append(
            Button([WIDTH / 2 - 175 / 2, b * (50 + 25) + 100, 175, 50],
                   text=options[b],
                   fontSize=18))
    options = Screen((WIDTH, HEIGHT), "Options", 25, option_buttons, BGCOLOR)
    mp = 0, 0
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return "EXIT"
            if event.type == pygame.MOUSEMOTION:
                mp = pygame.mouse.get_pos()
                for button in options.buttons:
                    button.isOver(mp)
            if event.type == pygame.MOUSEBUTTONDOWN:
                for button in options.buttons:
                    if button.isOver(mp):
                        response = button.text
                        if response == "Multiple Choice":
                            qstn = QuestionTypes.MC("", ["", ""])
                            layout = Layouts.MultipleChoiceLayout(
                                qstn, defaultRect.copy())
                        elif response == "Fill in The Blanks":
                            qstn = QuestionTypes.FITB("")
                            layout = Layouts.FITBQuestionLayout(
                                qstn, defaultRect.copy())
                        elif response == "Ordering":
                            qstn = QuestionTypes.Ordering("", ["", ""])
                            layout = Layouts.OrderingLayout(
                                qstn, defaultRect.copy())
                        elif response == "True and False":
                            qstn = QuestionTypes.True_False("")
                            layout = Layouts.TrueFalseLayout(
                                qstn, defaultRect.copy())
                        elif response == "Standard":
                            qstn = QuestionTypes.Normal("")
                            layout = Layouts.NormalQuestionLayout(
                                qstn, defaultRect.copy())
                        elif response == "Connecting":
                            qstn = QuestionTypes.Connecting(
                                "", ["", ""], ["", ""])
                            layout = Layouts.ConnectingQuestionLayout(
                                qstn, defaultRect.copy())
                        elif response == "Back":
                            return "Menu"
                        response = Question_Editor(layout, saveIndex)
                        return response

        options.draw(screen)
        pygame.display.flip()
Exemplo n.º 12
0
    def Do(self):

        # build command to start browser...
        #. use popen to hide cmd console
        url = "http://www.google.com/search?q=dictionary+etymology+" + self.name
        browser = r'C:\Program Files\Mozilla Firefox\firefox.exe'
        cmd = ''' "%s" %s '''  % (firefox, url)
        log.debug(cmd)
        os.system(cmd)

        # return status message
        status = "Looked up '%s' in Google" % self.name
        layout = Layouts.String(status)
        return layout
Exemplo n.º 13
0
    def Do(self):
        #. pick 4 rnd objects
        # display def of 0, let user pick object,
        # or display name, let user pick def
        n = 4
        cmd = Random(self.abby, self.adjectives, n)
        layout = cmd.Do()
        
#        obj = layout.ob[0]
#        return layout

        # want to define a new layout to present data in quiz format...
        ob = layout.ob
        newlayout = Layouts.Quiz(self.abby, ob, self.properties)
        
        return newlayout
Exemplo n.º 14
0
    def Do(self):

        #, modify the objects in the list
#        self.ob.SetValue(self.propname, self.propvalue)

        # for now assert just one object
        assert(len(self.ob)==1)
        obj = self.ob[0]
#        obj.SetValue(self.propname, self.propvalue)
        obj.SetData(self.prop, self.data)
        
        s = "Set %s.%s to %s" % (obj, self.prop, self.data)
        self.abby.status = s #, update abby status
        self.abby.it = obj
        log.debug('set abby.it to %s' % obj)
        return Layouts.String(s)
Exemplo n.º 15
0
 def loadSinks(self):
     #self.sink_list.addSink(DataTree.init())
     #self.sink_list.addSink(RecipeSystemIFACE.init())
     self.sink_list.addSink(ADViewerIFACE.init())
     self.sink_list.addSink(RecipeViewer.init())
     self.sink_list.addSink(FITSStoreFACE.init())
     self.sink_list.addSink(DisplayIFACE.init())
     self.sink_list.addSink(Info.init())
     if False:
         self.sink_list.addSink(Buttons.init())
         self.sink_list.addSink(Menus.init())
         self.sink_list.addSink(Images.init())
         self.sink_list.addSink(Layouts.init())
         self.sink_list.addSink(Lists.init())
         self.sink_list.addSink(Popups.init())
         self.sink_list.addSink(Tables.init())
         self.sink_list.addSink(Text.init())
     if False: #preserving originaly order
         self.sink_list.addSink(Frames.init())
         self.sink_list.addSink(Tabs.init())
Exemplo n.º 16
0
    def Do(self):

        import Abby  # for exception

        # Build the import file and wrap it in a stream object
        ## print 'streamtype:',self.streamtype
        # may throw exception if file not found
        stream = Streams.Factory(self.filename, 'r', self.streamtype) 
        layout = Layouts.Factory(self.abby, stream.layouttype)
        
        ## print 'stream:',stream
        ## print 'layout:',layout
        
        #stream.ReadToLayout()
        
        # the stream will return tokens one by one from the file, 
        # and layout will parse the tokens into commands.
        
        # get a composite command object
        ## cmd = layout.ParseFrom(stream)
        ## layoutresult = cmd.Do()
        
        # more efficient to do this way, so don't get a huge honkin composite cmd!
        ob = Objects.Objs()
        errors = []
        try:
            for cmd in layout.Parse(stream):
                try:
                    # cmd will usually be an Add command
                    layout = cmd.Do()
                    #, build up a list of all the objects added so can report to user
                    ob.append(layout.ob)
                except Abby.AbbyError, e:
                    #. add error to a file also?
                    errors.append(str(e))
        except Exception, e: #, Parser.ParserError, e:
            #errors.append(e)
            #errors.append(str(e))
            raise # pass it on
Exemplo n.º 17
0
def Test():

    import Abby
    import Commands
    import Streams
    import Layouts

    #.. ditch abby from the tests!!!

    filename = 'test.abby'
    abby = Abby.Abby()
    abby.Open(filename, False)

    print 'Get equations...'
    rs = abby.Get(type='equation')
    print rs
    print Layouts.Table(abby, rs)
    print

    print 'get desc'
    rs = abby.Get(id=1012)
    obj = rs[0]
    desc = obj.GetValue('description')
    print desc
    assert (desc == 'iawjiejlijij')
    print

    s = 'creation_date'
    print s
    s = GetExternalName(s)
    print s
    s = GetInternalName(s)
    print s
    print

    print 'test desc'
    obj = Obj('Project', 'abby')
    print 'obj:', obj
    obj.SetValue('desc', 'laiwjelai jwlei ajlwij e')
    s = obj.GetValue('desc')
    print s
    print

    obj = Obj('Project', 'neomem')
    print 'obj:', obj
    propId = Obj('property', 'id')
    data = obj.GetData(propId)
    print 'obj.id:', data
    #    print type(data) #, why gives 'instance' instead of actual classname??
    print 'data.__class__:', data.__class__
    propName = Obj('property', 'name')
    data = obj.GetData(propName)
    print 'obj name:', data
    print

    print 'Test extend...'
    rs = abby.Get(id=1001)
    rs2 = abby.Get(id=1002)
    rs.extend(rs2)
    print rs
    print

    abby.Close(False)  # lose all changes
Exemplo n.º 18
0
 def GetLayout(self, abby, showprops='all'):  # ie show all properties
     if len(self) == 1:
         layout = self[0].GetLayout(abby, showprops)
     else:
         layout = Layouts.Table(abby, self, showprops)
     return layout
Exemplo n.º 19
0
 def Do(self):
     # open a pipe to the shell command
     # the pipe is like a file object, which you read
     pipe = os.popen(self.s)
     s = pipe.read()
     return Layouts.String(s)
Exemplo n.º 20
0
 def GetLayout(self, abby, showprops):
     data = self.obj.GetData(self.prop)
     log.debug('getlayout: data=%s' % data)
     s = data.GetString()
     return Layouts.String(s)
Exemplo n.º 21
0
 def Do(self):
     # should always return a layout object
     return Layouts.String('(did nothing)')
Exemplo n.º 22
0
 def Do(self):
     s = self.abby.Verify()
     return Layouts.String(s)
Exemplo n.º 23
0
 def Do(self):
     self.abby.SetDebug(self.debug)
     ## self.abby.debug = not self.abby.debug
     s = "Debug set to %s" % self.debug
     return Layouts.String(s)
Exemplo n.º 24
0
 def Do(self):
     self.abby.Save()
     s = "%d objects saved to file '%s'." % (len(self.abby), self.abby.filename)
     return Layouts.String(s)
Exemplo n.º 25
0
 def Do(self):
     self.abby.Delete(self.ob)
     s = "Deleted '%s'." % self.name
     return Layouts.String(s)
Exemplo n.º 26
0
class Import(Command):
    
    name = "Import"
    type = "Command"
    description = "Import objects from a file into the main namespace."
    example = "import words from 'test.txt'"
    grammar = "IMPORT [adjectives] [FROM] filename"
    code = "cmd = Commands.Import(adjectives, filename)"
    
    def __init__(self, abby, filename, streamtype=None):
        self.abby = abby
        self.filename = filename
        self.streamtype = streamtype

    def Do(self):

        import Abby  # for exception

        # Build the import file and wrap it in a stream object
        ## print 'streamtype:',self.streamtype
        # may throw exception if file not found
        stream = Streams.Factory(self.filename, 'r', self.streamtype) 
        layout = Layouts.Factory(self.abby, stream.layouttype)
        
        ## print 'stream:',stream
        ## print 'layout:',layout
        
        #stream.ReadToLayout()
        
        # the stream will return tokens one by one from the file, 
        # and layout will parse the tokens into commands.
        
        # get a composite command object
        ## cmd = layout.ParseFrom(stream)
        ## layoutresult = cmd.Do()
        
        # more efficient to do this way, so don't get a huge honkin composite cmd!
        ob = Objects.Objs()
        errors = []
        try:
            for cmd in layout.Parse(stream):
                try:
                    # cmd will usually be an Add command
                    layout = cmd.Do()
                    #, build up a list of all the objects added so can report to user
                    ob.append(layout.ob)
                except Abby.AbbyError, e:
                    #. add error to a file also?
                    errors.append(str(e))
        except Exception, e: #, Parser.ParserError, e:
            #errors.append(e)
            #errors.append(str(e))
            raise # pass it on
            
        nobjs = len(ob)
        nerrors = len(errors)
        self.abby.it = ob #, set current object(s)
        s = "%d objects imported from file '%s' [%d errors]." % (nobjs, self.filename, nerrors)
        if errors:
            s = s + '\nErrors:\n\t' + '\n\t'.join(errors)
        return Layouts.String(s)
Exemplo n.º 27
0
 def GetLayout(self, abby, showprops='all'):  # ie show all properties
     layout = Layouts.Properties(abby, self, showprops)
     return layout