Esempio n. 1
0
    def __init__(self, jokebook, last_joke=0):  # last_joke is for 'back' button
        Page.__init__(self, spacing=10)

        # create a new joke
        joke = Joke()
        joke.id = jokebook.next_joke_id
        logging.info("Created new joke with id: %d" % joke.id)
        joke.joker = Globals.nickname

        # info
        self.append(self.make_field(_("Submission For:"), 250, jokebook, "title", 300, False))
        self.append(self.make_field(_("Your Name:"), 250, joke, "joker", 300, True))

        self.append(hippo.CanvasBox(box_height=theme.SPACER_VERTICAL))  # spacer

        # joke editor
        jokebox = JokeEditor(joke)
        nav = hippo.CanvasBox(padding_right=8, padding_top=8, spacing=18, orientation=hippo.ORIENTATION_HORIZONTAL)
        button = gtk.Button(_("Submit"))
        button.connect("clicked", self.__do_clicked_submit, jokebook, joke)
        nav.append(hippo.CanvasWidget(widget=theme.theme_widget(button), padding_right=10, padding_top=20))
        button = gtk.Button(_("Back"))
        button.connect("clicked", self.__do_clicked_back, jokebook, last_joke)
        nav.append(hippo.CanvasWidget(widget=theme.theme_widget(button), padding_top=20))
        jokebox.right.append(nav)
        self.append(jokebox)
Esempio n. 2
0
  def broadcast_joke_cb(self, jokebook_id, joke_pickle, sender_nick, sender):
    '''handle a BroadCast Joke by creating a new joke in the local store'''
    if sender == self.my_bus_name:
      # Ignore my own signal
      return

    logging.debug('In broadcast_joke_cb. sender: %r' % sender)
    
    # 1. unpickle joke
    joke_pickle = str(joke_pickle)
    if len(joke_pickle) == 0:
      logging.debug('JokeMachineSession.broadcast_joke_cb() -> empty joke_pickle - doing nothing')
      return
    joke = Joke.loads(joke_pickle)
    if joke is None:
      logging.error('JokeMachineSession.broadcast_joke_cb -> could not unpickle joke')
      return
    
    # 2. get the jokebook it belongs to
    jokebook = Globals.JokeMachineState.jokebook(jokebook_id)
    if jokebook is None:
      logging.error('Joke was broadcast to non-existent jokebook id %d', jokebook_id)
      return
    
    # 3. add it to jokes in the appropriate jokebook
    logging.debug('%s broadcast a joke to my jokebook# %d with text: %s and answer %s', joke.joker, jokebook_id, joke.text, joke.answer)    
    jokebook.jokes.append(joke)

    
    # 4. TODO - show some kind of alert - ask on #sugar
    message = str(sender_nick) + _(' accepted a joke submitted to ') + \
              str(jokebook.title) + _(' by ') + str(joke.joker)
    Globals.JokeMachineActivity.alert(_('Joke Machine'), message)
Esempio n. 3
0
 def submit_cb(self, jokebook_id, joke_pickle, sender=None):
   '''Receive someones submission
   jokebook_id -- the jokebook to submit joke to
   joke_pickle -- a pickled joke'''
   if sender == self.my_bus_name: # don't respond to own submit signal
     return
   logging.debug('In submit_cv. sender: %r' % sender)
   
   # 1. unpickle joke
   joke_pickle = str(joke_pickle)
   if len(joke_pickle) == 0:
     logging.debug('JokeMachineSession.submit_cb() -> empty joke_pickle - doing nothing')
     return
   joke = Joke.loads(joke_pickle)
   if joke is None:
     logging.error('JokeMachineSession.submit_cb -> could not unpickle joke')
     return
   
   # 2. get the jokebook it belongs to
   jokebook = Globals.JokeMachineState.jokebook(jokebook_id)
   if jokebook is None:
     logging.error('Joke was submitted to non-existent jokebook id %d', jokebook_id)
     return
   
   # 3. add it to submissions in the appropriate jokebook
   logging.debug('%s submitted a joke to my jokebook# %d with text: %s and answer %s', joke.joker, jokebook_id, joke.text, joke.answer)
   jokebook.submissions.append(joke)
 
   # 4. alert the owner 
   message = str(joke.joker) + _(' submitted a joke to ') + str(jokebook.title)
   Globals.JokeMachineActivity.alert(_('Joke Machine'), message)
Esempio n. 4
0
    def __init__(self,
                 jokebook,
                 last_joke=0):  # last_joke is for 'back' button
        Page.__init__(self, spacing=10)

        # create a new joke
        joke = Joke()
        joke.id = jokebook.next_joke_id
        logging.info('Created new joke with id: %d' % joke.id)
        joke.joker = Globals.nickname

        # info
        self.append(
            self.make_field(_('Submission For:'), 250, jokebook, 'title', 300,
                            False))
        self.append(
            self.make_field(_('Your Name:'), 250, joke, 'joker', 300, True))

        self.append(
            hippo.CanvasBox(box_height=theme.SPACER_VERTICAL))  # spacer

        # joke editor
        jokebox = JokeEditor(joke)
        nav = hippo.CanvasBox(padding_right=8,
                              padding_top=8,
                              spacing=18,
                              orientation=hippo.ORIENTATION_HORIZONTAL)
        button = gtk.Button(_('Submit'))
        button.connect('clicked', self.__do_clicked_submit, jokebook, joke)
        nav.append(
            hippo.CanvasWidget(widget=theme.theme_widget(button),
                               padding_right=10,
                               padding_top=20))
        button = gtk.Button(_('Back'))
        button.connect('clicked', self.__do_clicked_back, jokebook, last_joke)
        nav.append(
            hippo.CanvasWidget(widget=theme.theme_widget(button),
                               padding_top=20))
        jokebox.right.append(nav)
        self.append(jokebox)
Esempio n. 5
0
 def test_data(self):
   self.id = 1
   # add some jokebooks with jokes
   num_jokebooks = 0
   num_jokes = 2
   num_submissions = 2
   for jokebook_id in range(1, num_jokebooks + 1):
     jokebook = Jokebook()
     jokebook.id = jokebook_id
     jokebook.owner = 'hummingbird'
     jokebook.title = 'Jokebook ' + str(jokebook.id)
     #jokebook.image = 'images/smile-big.png'
     for joke_id in range(1, num_jokes + 1):
       joke = Joke().test_data()
       joke.id = joke_id
       jokebook.jokes.append(joke)
     for joke_id in range(1, num_submissions + 1):
       joke = Joke().test_data()
       joke.id = joke_id
       jokebook.submissions.append(joke)
     self.jokebooks.append(jokebook)
   return self
Esempio n. 6
0
    def broadcast_joke_cb(self, jokebook_id, joke_pickle, sender_nick, sender):
        '''handle a BroadCast Joke by creating a new joke in the local store'''
        if sender == self.my_bus_name:
            # Ignore my own signal
            return

        logging.debug('In broadcast_joke_cb. sender: %r' % sender)

        # 1. unpickle joke
        joke_pickle = str(joke_pickle)
        if len(joke_pickle) == 0:
            logging.debug(
                'JokeMachineSession.broadcast_joke_cb() -> empty joke_pickle - doing nothing'
            )
            return
        joke = Joke.loads(joke_pickle)
        if joke is None:
            logging.error(
                'JokeMachineSession.broadcast_joke_cb -> could not unpickle joke'
            )
            return

        # 2. get the jokebook it belongs to
        jokebook = Globals.JokeMachineState.jokebook(jokebook_id)
        if jokebook is None:
            logging.error('Joke was broadcast to non-existent jokebook id %d',
                          jokebook_id)
            return

        # 3. add it to jokes in the appropriate jokebook
        logging.debug(
            '%s broadcast a joke to my jokebook# %d with text: %s and answer %s',
            joke.joker, jokebook_id, joke.text, joke.answer)
        jokebook.jokes.append(joke)

        # 4. TODO - show some kind of alert - ask on #sugar
        message = str(sender_nick) + _(' accepted a joke submitted to ') + \
                  str(jokebook.title) + _(' by ') + str(joke.joker)
        Globals.JokeMachineActivity.alert(_('Joke Machine'), message)
Esempio n. 7
0
    def submit_cb(self, jokebook_id, joke_pickle, sender=None):
        '''Receive someones submission
    jokebook_id -- the jokebook to submit joke to
    joke_pickle -- a pickled joke'''
        if sender == self.my_bus_name:  # don't respond to own submit signal
            return
        logging.debug('In submit_cv. sender: %r' % sender)

        # 1. unpickle joke
        joke_pickle = str(joke_pickle)
        if len(joke_pickle) == 0:
            logging.debug(
                'JokeMachineSession.submit_cb() -> empty joke_pickle - doing nothing'
            )
            return
        joke = Joke.loads(joke_pickle)
        if joke is None:
            logging.error(
                'JokeMachineSession.submit_cb -> could not unpickle joke')
            return

        # 2. get the jokebook it belongs to
        jokebook = Globals.JokeMachineState.jokebook(jokebook_id)
        if jokebook is None:
            logging.error('Joke was submitted to non-existent jokebook id %d',
                          jokebook_id)
            return

        # 3. add it to submissions in the appropriate jokebook
        logging.debug(
            '%s submitted a joke to my jokebook# %d with text: %s and answer %s',
            joke.joker, jokebook_id, joke.text, joke.answer)
        jokebook.submissions.append(joke)

        # 4. alert the owner
        message = str(joke.joker) + _(' submitted a joke to ') + str(
            jokebook.title)
        Globals.JokeMachineActivity.alert(_('Joke Machine'), message)
 def test_data(self):
     self.id = 1
     # add some jokebooks with jokes
     num_jokebooks = 0
     num_jokes = 2
     num_submissions = 2
     for jokebook_id in range(1, num_jokebooks + 1):
         jokebook = Jokebook()
         jokebook.id = jokebook_id
         jokebook.owner = 'hummingbird'
         jokebook.title = 'Jokebook ' + str(jokebook.id)
         #jokebook.image = 'images/smile-big.png'
         for joke_id in range(1, num_jokes + 1):
             joke = Joke().test_data()
             joke.id = joke_id
             jokebook.jokes.append(joke)
         for joke_id in range(1, num_submissions + 1):
             joke = Joke().test_data()
             joke.id = joke_id
             jokebook.submissions.append(joke)
         self.jokebooks.append(jokebook)
     return self
Esempio n. 9
0
state = JokeMachineState()
state = state.test_data()
dump(state)
print "\n========================================================================\n"
pickle = state.dumps()
j = JokeMachineState.loads(pickle)
jokebook = j.jokebooks[0]
jokebook.owner = "new owner"
dump(j)


sys.exit()


joke = Joke()

print "Joke.id.doc: ", Joke.id.__doc__
print "Joke.joke_text.doc: ", Joke.text.__doc__
print

print "joke.id default should be 0 = ", joke.id
print "joke is dirty = ", joke.__dirty__
print

joke.id = 66
print "joke.id set to 66 = ", joke.id
print "joke is dirty = ", joke.__dirty__
print

print "joke.joke_text has no default:", joke.text
Esempio n. 10
0
    print indent + 'is_dirty =', obj.__dirty__


state = JokeMachineState()
state = state.test_data()
dump(state)
print "\n========================================================================\n"
pickle = state.dumps()
j = JokeMachineState.loads(pickle)
jokebook = j.jokebooks[0]
jokebook.owner = 'new owner'
dump(j)

sys.exit()

joke = Joke()

print 'Joke.id.doc: ', Joke.id.__doc__
print 'Joke.joke_text.doc: ', Joke.text.__doc__
print

print 'joke.id default should be 0 = ', joke.id
print 'joke is dirty = ', joke.__dirty__
print

joke.id = 66
print 'joke.id set to 66 = ', joke.id
print 'joke is dirty = ', joke.__dirty__
print

print 'joke.joke_text has no default:', joke.text