So, I am trying to make this program for a project I was assigned. The code is still a draft and I really didn't know anything about wxPython when I was assigned this project.
Anyway. What this program does, is create an application that manages photo albums. I got it to create/remove folders and be able to change its root directory and move the program files elsewhere. I also got it to generate bitmap buttons for each 'album' and place them in a FlexGridSizer.
My problem is that these Bitmap Buttons are unclickable.
class RightPanel(wx.Panel):
global path
def __init__(self, parent):
a = wx.GetDisplaySize()
width = 3 * a[0] / 4
height = 3 * a[1] / 4
wx.Panel.__init__(self, parent=parent,
size=(3*width/4, height),
style=wx.EXPAND)
self.SetBackgroundColour('dark grey')
self.widgetSizer = wx.BoxSizer(wx.VERTICAL)
class MasterPanel(wx.Panel):
global delete, CurrentDirg, locale
delete = False
a = wx.GetDisplaySize()
width = 3 * a[0] / 4
height = 3 * a[1] / 4
id = {}
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.MasterPanel = wx.Panel(self,
wx.ID_ANY,
size=(self.width, self.height),
)
self.SetBackgroundColour('light grey')
self.sizer = wx.BoxSizer(wx.VERTICAL)
splitter1 = wx.SplitterWindow(self)
splitter2 = wx.SplitterWindow(splitter1)
left_pt = LeftPanelTop(splitter2)
left_pb = LeftPanelBottom(splitter2)
self.rightP = RightPanel(splitter1)
self.boxsizer2 = wx.BoxSizer(wx.VERTICAL)
splitter2.SetSashGravity(0.5)
splitter2.SplitHorizontally(left_pt, left_pb)
splitter1.SplitVertically(splitter2, self.rightP)
splitter1.SetSashGravity(0.5)
self.gSizer = wx.FlexGridSizer(0, 5, 10, 10)
self.dir_search()
self.boxsizer2.Add(self.gSizer, 1, wx.EXPAND|wx.ALL)
self.rightP.SetSizer(self.boxsizer2)
self.boxsizer2.Layout()
self.sizer.Add(splitter1, 1, wx.EXPAND)
self.SetSizer(self.sizer)
def dir_search(self):
global path, delete
try:
if self.id != {} or delete == True:
sizer = self.gSizer
for i in sizer.GetChildren():
sizer.Hide(0)
sizer.Remove(0)
self.boxsizer2.Layout()
self.gSizer.Layout()
self.id = {}
with open('albums.dir', mode='r', buffering=1) as alb:
names = alb.readlines()
for i in range(len(names)):
names[i] = names[i].rstrip('\n')
paths = [path + '\\' + i for i in names]
counter = 0
for i in paths:
self.dirimcreate(i, counter)
counter += 1
print(self.id)
except Exception as E:
print(E)
sizer = self.gSizer
while sizer.GetChildren():
sizer.Hide(0)
sizer.Remove(0)
self.boxsizer2.Layout()
def dirimcreate(self, path, counter):
pic = wx.Image('input.ico', wx.BITMAP_TYPE_ANY)
pic = pic.Scale(self.width / 10, self.width / 10, wx.IMAGE_QUALITY_HIGH)
pic = pic.ConvertToBitmap()
self.saasda = wx.BitmapButton(self.rightP,
wx.ID_ANY,
pic,
size=(self.width / 10, self.width / 10),
style=wx.NO_BORDER
)
self.saasda.Bind(wx.EVT_BUTTON, self.chdir)
self.saasda.SetDefault()
self.saasda.myname = self.saasda.GetId()
self.id[self.saasda.GetId()] = path
self.gSizer.Add(self.saasda, 0, wx.ALL, 5)
self.boxsizer2.Layout()
def chdir(self, event):
self.Info(message='You clicked a button')
This is what the result looks like.
Thank you in advance.
I found the solution!
It seems that the code for the MasterPanel class included a size parameter in the init, which created an invisible panel that covered everything else, rendering it unclickable.