Page 1 of 1

NVL Autoscrolling Code

Posted: Mon Apr 02, 2012 5:48 pm
by Shadowren
I found these instances of autoscrolling code, I was wondering how easily they could be implemented for games that did not wish to employ pagination:

Code: Select all

def append_txt(self, message_str):      
       curr_time = datetime.now()      

      msg_txt = str(curr_time.strftime("%H:%M:%S - ")) + message_str
      piter = msg_area.append([msg_txt])
      x =  msg_scrolled_window.get_vscrollbar().get_value()
      v_adj = msg_scrolled_window.get_vadjustment()
      v_adj.set_value(x + 50)
      msg_scrolled_window.set_vadjustment(v_adj)

Code: Select all

        def update_log(self, data):# message, style = 'normal'):
            message, style = data
            sob, eob = self.textbuffer.get_bounds()
            present_time = '  [%02d:%02d:%02d]  ' % (time.localtime()[3], time.localtime()[4], time.localtime()[5])
            self.textview.scroll_mark_onscreen(self.textbuffer.get_insert())
            self.textbuffer.insert_with_tags_by_name(eob, ''.join([present_time, message, '\n']), style)

Code: Select all

    #!/usr/bin/env python

    # base.py

    import pygtk
    pygtk.require('2.0')
    import gtk
    from datetime import datetime

    msg_area = gtk.ListStore(str)
    msg_scrolled_window = gtk.ScrolledWindow()

    class message_area:

       #*******************************************************************************************************************
       ## Create message area as a list store inside a scrolled window.
       #  @param self The object pointer
       #  @return path_scrolled_window Scrolled window containing liststore

       #*******************************************************************************************************************
       def create_msg_widget(self):
          msg_tree = gtk.TreeView(msg_area)
          msg_tree.set_headers_visible(False)
          tvcolumn = gtk.TreeViewColumn()
          msg_tree.append_column(tvcolumn)
          cell = gtk.CellRendererText()
          tvcolumn.pack_start(cell, True)   
          tvcolumn.add_attribute(cell, 'text', 0)
          msg_tree.set_search_column(0)
          msg_tree.set_reorderable(True)
          msg_tree.set_cursor(0)
          msg_scrolled_window.set_border_width(5)
          msg_scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
          msg_scrolled_window.show()
          msg_scrolled_window.add_with_viewport(msg_tree)
          return (msg_scrolled_window)

       #*******************************************************************************************************************
       ## Insert string in message area (list store).
       #  @param self The object pointer
       #  @param message_str Message string

       #*******************************************************************************************************************
       def append_txt(self, message_str):      
           curr_time = datetime.now()      

          msg_txt = str(curr_time.strftime("%H:%M:%S - ")) + message_str
          piter = msg_area.append([msg_txt])
          x =  msg_scrolled_window.get_vscrollbar().get_value()
          v_adj = msg_scrolled_window.get_vadjustment()
          v_adj.set_value(x + 50)
          msg_scrolled_window.set_vadjustment(v_adj)

    class base:

       def chg_adj(self, widget):
          print "\nin chg_adj" + str(widget.get_value())      

       def add_text_cb(self,  widget):
          y = message_area()
          y.append_txt("text")

       # close the window and quit
       def delete_event(self, widget, event, data=None):
          gtk.main_quit()
          return False

       def __init__(self):

          # Create a new window
          self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

          self.window.set_title("Base")
          self.window.set_size_request(200, 200)
          self.window.connect("delete_event", self.delete_event)

          # Create frame for message area
          msg_frame = gtk.VBox(True)

          button = gtk.Button("Add")
          button.connect("clicked", self.add_text_cb)

          x = message_area()
          msg_area = x.create_msg_widget()

          msg_frame.add(msg_area)
          msg_frame.add(button)
          self.window.add(msg_frame)
          self.window.show_all()


    def main():
        gtk.main()

    if __name__ == "__main__":
        base()
        main() 
Source: http://www.python-forum.org/pythonforum ... =4&t=14734

Perhaps of use as well:

Code: Select all

text.see(END)
http://www.python-forum.org/pythonforum ... =4&t=13254

Edit: Or perhaps, now that I consider it: Is it possible to simply order nvl_erase to take effect on the top line whenever a turn-page indicator would be shown?

Re: NVL Autoscrolling Code

Posted: Mon Apr 02, 2012 7:52 pm
by Shadowren
Update:

Adding

Code: Select all

    def nvl_scroll():
        if nvl_list:
            nvl_list.pop(0)
to 00nvl_mode.rpy enables simple manual scrolling through

Code: Select all

$ nvl_scroll()
There's probably an easy way to automate it off a page-end indicator, will likely look into it later.

Edit: May be a way to set a "scrolling mode", declare a number of lines to maintain on screen, then count the lines present.
If the number of lines present in the list is equal to or greater than the declared number, it applies "nvl_scroll()" to each "say".

Re: NVL Autoscrolling Code

Posted: Tue Apr 03, 2012 6:47 pm
by Shadowren
After delving the secrets of Python and pouring over the Ren'Py documentation I've come up with a way to define a character that scrolls nvl text whenever it speaks:

To 00nvl_mode.rpy add this code below the nvl_erase() definition:

Code: Select all

    def nvl_scroll():
        if nvl_list and len(nvl_list) > 1:
            nvl_list.pop(0)
            return True
        else:
            return True
Then, the scrolling character should be defined with the line:

Code: Select all

condition = "nvl_scroll()"
This is a pretty sloppy way of doing it I believe, but functional. I'm not sure if there's a way to simply call a custom function when a character speaks. (I looked at the character page "callback" segment, but it wasn't really clear where the function would go, and there were no code examples on using it.)

As a note, I added the "and len(nvl_list) > 1" after experiencing some weirdness without it. (Clearing more than one line at a time, I believe.)