Hello,
So here is the basics of my question http://stackoverflow.com/questions/15394229/wxpython-loading-text/15395331?noredirect=1#comment21800452_15395331
Now Mike Driscoll has given a solution, however I was wondering if anyone had a solution for this to be loaded in the same way as the Image and sound file is being loaded.
For example this is how the Image and sound file are loaded together -
self.images = DIter([filename for filename in os.listdir(IMAGE_DIR) if any(filename.lower().endswith(ext) for ext in (’.png’))])
self.img = wx.Image(‘Background.png’)
self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(self.img), size=(680,143), pos=(0, 0))
def loadImage(self, event):
self.image_file = self.images.next()
print(self.image_file)
image_file = os.path.join(IMAGE_DIR, self.image_file)
img = wx.Image(image_file, wx.BITMAP_TYPE_ANY)
width = img.GetWidth()
height = img.GetHeight()
self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
def previousPicture(self, event):
self.image_file = self.images.prev()
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))
def onPlaySound (self, event):
sound_file, ext = os.path.splitext(self.image_file)
sound_file = os.path.join(SOUND_DIR, sound_file + '.wav')
print(sound_file)
sound = wx.Sound(sound_file)
sound.Play(wx.SOUND_ASYNC)
I use an additional class to create a list and the “Next” and “Previous” functions -
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.Index = 0 #self.ListEnd-1 # or to avoid wrapping
return self.ItemList[self.Index]
Now I would of thought I could of created the text to be loaded in the same manner using something like this -
self.text = DIter([filename for filename in os.listdir(TEXT_DIR) if any(filename.lower().endswith(ext) for ext in (’.txt’))])
self.txt = wx.TextCtrl(self, style=wx.TE_MULTILINE, pos=(150,300), size=(680,200))
def loadImage(self, event):
self.text_file = self.text.next()
print(self.image_text)
text_file = os.path.join(TEXT_DIR, self.tex_file)
self.TextCtrl
Though I’m not sure where to go from there so that the text is loaded onto a field on the form.
I do appreciate Mike’s solution, I just thought there would of been a similar way to the other Load function.
Thanks
Sion Jones
(Sorry to post here regularly)