Loading previous image and sound file?

Presumably you have generator for the images and a next method doing
something like initialising it to the list and returning the current
image+1 - I would consider implementing a double iterable something
like:
class DIter:
“”" Iterable with next and previous “”"
def init(self, ItemList):
“”" Creator “”"
self.ItemList = ItemList
self.Index = -1
self.ListEnd = len(ItemList)
def next(self):
“”" Return the next item “”"
self.Index += 1
self.Index %= self.ListEnd # or to avoid wrapping self.Index =
min([self.Index, self.ListEnd-1])
return self.ItemList[self.Index]
def prev(self):
“”" Return the previous item “”"
self.Index -= 1
if self.Index < 0:
self.Index = self.ListEnd-1 # or to avoid wrapping
self.Index = 0
return self.ItemList[self.Index]

···

On 19/02/13 19:13, Sion Jones wrote:

Hello!

    Bit of a back story. For my 3rd year project I am creating a

Drum Rhythm Trainer. I am creating the software through Python
and using Wxpython to create the UI.

    So my main function is to load a drum notation image along

with a associated sound file that matches the notation and plays
the drum beat shown.

    Now the users will scroll through the notations by using a

“Next” and “Back” buttons. So far I have the “Next” function
working. It loads the image and the associated .wav file (Both
the image and sound file are named the same i.e “notation1.png”
“notation1.wav” and so forth). Here’s the code that loads the
image and sound file using the next button-

def loadImage(self, event):

 self.image_file = next(self.images)
 print(self.image_file)
             image_file = os.path.join(IMAGE_DIR,

self.image_file)

             img = wx.Image(image_file,

wx.BITMAP_TYPE_ANY)

 img = img.Scale(680,143)

self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))

      So you can guess what I'm going to ask next?

Getting the “Back” function working -

             def previousPicture(self,

event):

               self.image_file

= next(self.images)

print(self.image_file)

               self.image_file

= os.path.join(IMAGE_DIR, self.image_file)

               img =

wx.Image(self.image_file, wx.BITMAP_TYPE_ANY)

               img =

img.Scale(680,143)

 self.image_file 
               self.image_file

= 0

               self.image_file

+= -1

self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))

          This is what it looks like

so far. I know what the problem is. Its the
“self.image_file =next(self.images)” line, since this just
loads the “Next” image.

          I just don't understand

why it can’t have a “previous” or “back” event. I’ve been
trying to get my head around it. But as a newbie it’s
quite difficult.

          If needed I'll post my

whole code.

          Anyway, any help will be

greatly appreciated!

Thanks

Sion Jones

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to .
For more options, visit .


Steve Gadget Barnes

wxpython-users+unsubscribe@googlegroups.com
https://groups.google.com/groups/opt_out

So would I bind the next and prev with the buttons that I use?

I’ll attack the code so you can have a better view of the code.

Rhythm.py (17.4 KB)

···

On Tuesday, February 19, 2013 8:56:05 PM UTC, Gadget Steve wrote:

On 19/02/13 19:13, Sion Jones wrote:

Hello!

    Bit of a back story. For my 3rd year project I am creating a

Drum Rhythm Trainer. I am creating the software through Python
and using Wxpython to create the UI.

    So my main function is to load a drum notation image along

with a associated sound file that matches the notation and plays
the drum beat shown.

    Now the users will scroll through the notations by using a

“Next” and “Back” buttons. So far I have the “Next” function
working. It loads the image and the associated .wav file (Both
the image and sound file are named the same i.e “notation1.png”
“notation1.wav” and so forth). Here’s the code that loads the
image and sound file using the next button-

def loadImage(self, event):

 self.image_file = next(self.images)
 print(self.image_file)
             image_file = os.path.join(IMAGE_DIR,

self.image_file)

             img = wx.Image(image_file,

wx.BITMAP_TYPE_ANY)

 img = img.Scale(680,143)

self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))

      So you can guess what I'm going to ask next?

Getting the “Back” function working -

             def previousPicture(self,

event):

               self.image_file

= next(self.images)

print(self.image_file)

               self.image_file

= os.path.join(IMAGE_DIR, self.image_file)

               img =

wx.Image(self.image_file, wx.BITMAP_TYPE_ANY)

               img =

img.Scale(680,143)

 self.image_file 
               self.image_file

= 0

               self.image_file

+= -1

self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))

          This is what it looks like

so far. I know what the problem is. Its the
“self.image_file =next(self.images)” line, since this just
loads the “Next” image.

          I just don't understand

why it can’t have a “previous” or “back” event. I’ve been
trying to get my head around it. But as a newbie it’s
quite difficult.

          If needed I'll post my

whole code.

          Anyway, any help will be

greatly appreciated!

Thanks

Sion Jones

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-user...@googlegroups.com.

  For more options, visit [https://groups.google.com/groups/opt_out](https://groups.google.com/groups/opt_out).
Presumably you have generator for the images and a next method doing

something like initialising it to the list and returning the current
image+1 - I would consider implementing a double iterable something
like:

class DIter:

    """ Iterable with next and previous """

   def __init__(self, ItemList):

       """ Creator """

       self.ItemList = ItemList

       self.Index = -1

       self.ListEnd = len(ItemList)



   def next(self):

      """ Return the next item """

      self.Index += 1

      self.Index %= self.ListEnd # or to avoid wrapping self.Index =

min([self.Index, self.ListEnd-1])

      return self.ItemList[self.Index]



   def prev(self):

      """ Return the previous item """

      self.Index -= 1

      if self.Index < 0:

         self.Index = self.ListEnd-1 # or to avoid wrapping

self.Index = 0

      return self.ItemList[self.Index]


Steve Gadget Barnes

*Attach

···

On Tuesday, February 19, 2013 9:21:00 PM UTC, Sion Jones wrote:

So would I bind the next and prev with the buttons that I use?
I’ll attack the code so you can have a better view of the code.

On Tuesday, February 19, 2013 8:56:05 PM UTC, Gadget Steve wrote:

On 19/02/13 19:13, Sion Jones wrote:

Hello!

    Bit of a back story. For my 3rd year project I am creating a

Drum Rhythm Trainer. I am creating the software through Python
and using Wxpython to create the UI.

    So my main function is to load a drum notation image along

with a associated sound file that matches the notation and plays
the drum beat shown.

    Now the users will scroll through the notations by using a

“Next” and “Back” buttons. So far I have the “Next” function
working. It loads the image and the associated .wav file (Both
the image and sound file are named the same i.e “notation1.png”
“notation1.wav” and so forth). Here’s the code that loads the
image and sound file using the next button-

def loadImage(self, event):

 self.image_file = next(self.images)
 print(self.image_file)
             image_file = os.path.join(IMAGE_DIR,

self.image_file)

             img = wx.Image(image_file,

wx.BITMAP_TYPE_ANY)

 img = img.Scale(680,143)

self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))

      So you can guess what I'm going to ask next?

Getting the “Back” function working -

             def previousPicture(self,

event):

               self.image_file

= next(self.images)

print(self.image_file)

               self.image_file

= os.path.join(IMAGE_DIR, self.image_file)

               img =

wx.Image(self.image_file, wx.BITMAP_TYPE_ANY)

               img =

img.Scale(680,143)

 self.image_file 
               self.image_file

= 0

               self.image_file

+= -1

self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))

          This is what it looks like

so far. I know what the problem is. Its the
“self.image_file =next(self.images)” line, since this just
loads the “Next” image.

          I just don't understand

why it can’t have a “previous” or “back” event. I’ve been
trying to get my head around it. But as a newbie it’s
quite difficult.

          If needed I'll post my

whole code.

          Anyway, any help will be

greatly appreciated!

Thanks

Sion Jones

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-user...@googlegroups.com.

  For more options, visit [https://groups.google.com/groups/opt_out](https://groups.google.com/groups/opt_out).
Presumably you have generator for the images and a next method doing

something like initialising it to the list and returning the current
image+1 - I would consider implementing a double iterable something
like:

class DIter:

    """ Iterable with next and previous """

   def __init__(self, ItemList):

       """ Creator """

       self.ItemList = ItemList

       self.Index = -1

       self.ListEnd = len(ItemList)



   def next(self):

      """ Return the next item """

      self.Index += 1

      self.Index %= self.ListEnd # or to avoid wrapping self.Index =

min([self.Index, self.ListEnd-1])

      return self.ItemList[self.Index]



   def prev(self):

      """ Return the previous item """

      self.Index -= 1

      if self.Index < 0:

         self.Index = self.ListEnd-1 # or to avoid wrapping

self.Index = 0

      return self.ItemList[self.Index]


Steve Gadget Barnes

I have it working thanks to your post Gadget Steve and help by Nemo7 on wxPython IRC Chat.

I am truly greatful for the help. I’ve been stuck on this for a while, and now it works perfectly!

Thank you!

···

On Tuesday, February 19, 2013 9:21:56 PM UTC, Sion Jones wrote:

*Attach

On Tuesday, February 19, 2013 9:21:00 PM UTC, Sion Jones wrote:

So would I bind the next and prev with the buttons that I use?
I’ll attack the code so you can have a better view of the code.

On Tuesday, February 19, 2013 8:56:05 PM UTC, Gadget Steve wrote:

On 19/02/13 19:13, Sion Jones wrote:

Hello!

    Bit of a back story. For my 3rd year project I am creating a

Drum Rhythm Trainer. I am creating the software through Python
and using Wxpython to create the UI.

    So my main function is to load a drum notation image along

with a associated sound file that matches the notation and plays
the drum beat shown.

    Now the users will scroll through the notations by using a

“Next” and “Back” buttons. So far I have the “Next” function
working. It loads the image and the associated .wav file (Both
the image and sound file are named the same i.e “notation1.png”
“notation1.wav” and so forth). Here’s the code that loads the
image and sound file using the next button-

def loadImage(self, event):

 self.image_file = next(self.images)
 print(self.image_file)
             image_file = os.path.join(IMAGE_DIR,

self.image_file)

             img = wx.Image(image_file,

wx.BITMAP_TYPE_ANY)

 img = img.Scale(680,143)

self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))

      So you can guess what I'm going to ask next?

Getting the “Back” function working -

             def previousPicture(self,

event):

               self.image_file

= next(self.images)

print(self.image_file)

               self.image_file

= os.path.join(IMAGE_DIR, self.image_file)

               img =

wx.Image(self.image_file, wx.BITMAP_TYPE_ANY)

               img =

img.Scale(680,143)

 self.image_file 
               self.image_file

= 0

               self.image_file

+= -1

self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))

          This is what it looks like

so far. I know what the problem is. Its the
“self.image_file =next(self.images)” line, since this just
loads the “Next” image.

          I just don't understand

why it can’t have a “previous” or “back” event. I’ve been
trying to get my head around it. But as a newbie it’s
quite difficult.

          If needed I'll post my

whole code.

          Anyway, any help will be

greatly appreciated!

Thanks

Sion Jones

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-user...@googlegroups.com.

  For more options, visit [https://groups.google.com/groups/opt_out](https://groups.google.com/groups/opt_out).
Presumably you have generator for the images and a next method doing

something like initialising it to the list and returning the current
image+1 - I would consider implementing a double iterable something
like:

class DIter:

    """ Iterable with next and previous """

   def __init__(self, ItemList):

       """ Creator """

       self.ItemList = ItemList

       self.Index = -1

       self.ListEnd = len(ItemList)



   def next(self):

      """ Return the next item """

      self.Index += 1

      self.Index %= self.ListEnd # or to avoid wrapping self.Index =

min([self.Index, self.ListEnd-1])

      return self.ItemList[self.Index]



   def prev(self):

      """ Return the previous item """

      self.Index -= 1

      if self.Index < 0:

         self.Index = self.ListEnd-1 # or to avoid wrapping

self.Index = 0

      return self.ItemList[self.Index]


Steve Gadget Barnes

Nice to know & glad to have been able to help :slight_smile:

···

On 20/02/13 02:47, Sion Jones wrote:

  I have it working thanks to your post Gadget Steve and

help by Nemo7 on wxPython IRC Chat.

    I am truly greatful for the help. I've been stuck on this for

a while, and now it works perfectly!

Thank you!


Steve Gadget Barnes