python 2.7 - wxPython: GridBagSizer - Growable List Object -


im using gridbagsizer ui layout. im facing following problem.

the grid im using has 4 rows , 12 columns. on second row (row 1) ad ultimatelistctrl , want to grow if window resized vertically or horizontally.

ulc_style = ulc.ulc_report | wx.lc_vrules | wx.lc_hrules | wx.lc_single_sel | ulc.ulc_has_variable_row_height self.list = ulc = ulc.ultimatelistctrl(self.panel, agwstyle=ulc_style)      self.sizer_grid = grid = wx.gridbagsizer(5,5)     grid.add(self.list, (1,0), (1,12), flag=wx.expand) 

i use following function make columns growable , set row 1 growable.

for in range(13):     grid.addgrowablecol(i) grid.addgrowablerow(1) 

i can resize window horzizontally fine , alle elements resize vertically list stays is.

if add size parameters listctrl row expand size entered, , expand further horizontally vertically still fixed size , wont adjust window size.

grid.addgrowablerow(1) 

doesnt seem anything, when remove it, ui still looks same. im new python , wxpython maybe im doing wrong.

everything sits in panel sits in frame, @ end call:

self.panel.setsizerandfit(self.sizer_grid) 

ok, here how got work wanted.

full code window:

class listview(wx.frame): def __init__( self, parent, id) :     wx.frame.__init__(self, wx.getapp().topwindow, title='studenten liste', size=(890, 740))      self.panel = wx.panel(self)      # font mods     font_underline = wx.font(9, wx.fontfamily_default, wx.fontstyle_normal, wx.fontweight_bold, true)      # grid sizer     self.sizer_grid = grid = wx.gridbagsizer(5,5)      # row 0, col 0+1     self.label_auswahl = wx.statictext(self.panel, label="auswahl:")     self.label_auswahl.setfont(font_underline)     grid.add(self.label_auswahl, (0,0), flag=wx.align_center_vertical | wx.align_center_horizontal)     init_choice = ['temp1','temp2','temp3','temp4']     self.input_auswahl = textctrlautocomplete(self.panel, size=(280,24), choices=init_choice, showhead=false)     grid.add(self.input_auswahl, (0,1), (1,4), flag=wx.align_left | wx.align_center_vertical)      # row 0, col 9,10,11     self.label_kat = wx.statictext(self.panel, label="kategorie:")     self.label_kat.setfont(font_underline)     grid.add(self.label_kat, (0,9), flag=wx.align_right | wx.align_center_vertical)     kategorie_ch = ['demo1', 'demo2', 'demo3']     self.ch_kategorie = wx.choice(self.panel, choices=kategorie_ch)     self.ch_kategorie.db_name = 'kategorie'     self.ch_kategorie.bind(wx.evt_choice, self.onkatchoice)     grid.add(self.ch_kategorie, (0,10), (1,2), flag=wx.align_right | wx.align_center_vertical | wx.expand)      #row 1, col 0-12 - ultimate list ctrl     self.list = ulc = ultimatelc(self.panel, 12)     # give columns.     # id col we'll customize bit:     ulc.insertcolumn(0, 'name:', width=120)     ulc.insertcolumn(1, 'vorname:', width=120)     ulc.insertcolumn(2, 'anschrift:', width=160)     ulc.insertcolumn(3, 'telefon:', width=100)     ulc.insertcolumn(4, 'email:', width=200)     ulc.insertcolumn(5, 'studium:', format=ulc.ulc_format_center, width=60)     ulc.insertcolumn(6, 'matr. nr.:', format=ulc.ulc_format_center, width=70)     ulc.insertcolumn(7, 'hauptfach:', width=100)     ulc.insertcolumn(8, 'nebenfach:', width=100)     ulc.insertcolumn(9, 'start sem.:', width=70)     ulc.insertcolumn(10, 'letzte akt.:', width=70)     ulc.insertcolumn(11, 'kategorie:', width=70)      grid.add(self.list, (1,0), (1,12), flag=wx.expand)       # row 2+3     self.label_sel = wx.statictext(self.panel, label='daten drucken:')     grid.add(self.label_sel, (2,0), flag=wx.align_left | wx.align_center_vertical)      # dict print selection     self.selectdefs = selectdefs = {         # id: ( label, header name, db name, column width         101 : ('name', 'name:', 'name', 0.9 ),         102 : ('vorame', 'vorname:', 'vorname', 0.85 ),         103 : ('anschrift', 'anschrift:', 'anschrift', 1.4 ),         104 : ('telefon', 'telefon:', 'tele', 0.9 ),         105 : ('email', 'email:', 'email', 1.65 ),         106 : ('studium', '', 'studium', 0.31 ),         107 : ('matrikel', 'matrikel:', 'matrikel', 0.6 ),         108 : ('hauptfach', 'haupftach:', 'hauptf', 0.9 ),         109 : ('nebenfach', 'nebenfach:', 'nebenf', 0.9 ),         110 : ('start sem.', 'start:', 'startsem', 0.6 ),         111 : ('letzte akt.', 'last:', 'lastakt', 0.6 ),         112 : ('kategorie', '', 'kategorie', 0.5 ),         }     # max width portrait or landscape printout     self.max_portrait = 7.8     self.max_landscape = 10.11      keys = selectdefs.keys()     i,k in enumerate(keys):         col = + 1         row = 2         if > 5:             col = - 5             row = 3         label = selectdefs[k][0]         chk = wx.checkbox(self.panel, k, label)         grid.add(chk, (row,col), flag=wx.align_left | wx.align_center_vertical)         self.bind(wx.evt_checkbox, self.oncheckbox, chk)      self.button_print_sel = wx.button(self.panel, 201, label="auswahl drucken")     self.button_print_sel.bind(wx.evt_button, self.onprint)     self.button_print_all = wx.button(self.panel, 202, label="liste drucken")     self.button_print_all.bind(wx.evt_button, self.onprint)     grid.add(self.button_print_sel, (2,10), (2,1), flag=wx.expand | wx.align_center_vertical)     grid.add(self.button_print_all, (2,11), (2,1), flag=wx.expand | wx.align_center_vertical)      # column 8 expand, column 8 holds listctrl     grid.addgrowablecol(8)     # row 1 expand, row 1 holds listctrl     grid.addgrowablerow(1)      # list binds     self.list.bind(ulc.evt_list_item_checked, self.oncheck)     self.list.bind(ulc.evt_list_item_activated, self.onactivated)      # lists checked items     self.checked_ids = []     self.checked_sel = []      # set defaults     self.setdefaults()      # set min windows size     self.setminsize((890, 540))      # main sizer     self.sizer_v = wx.boxsizer(wx.vertical)     self.sizer_v.add(grid, 1, wx.all | wx.expand, 5)     self.panel.setsizerandfit(self.sizer_v) 

the important parts are:

  1. when adding list set flag: wx.expand

  2. set columns , rows want stretch setgrowable. in example want list resize vertically , horizontally set row , column growable ones holding list. other elements stay in position, on left or right.

  3. finally adding vertical boxsizer proportion=1 , style wx.expand. proportion 1 allows vertical stretch , wx.expand horizontal. same horizontal boxsizer guess. wx.all , ',5' @ end sets margin arround gridbagsizer looks nicer imo.

ps: code above needs functions , custom widgets not included.

ultimalistctrl (with sorter mixin):

self.list = ulc = ultimatelc(self.panel, 12) 

can replaced with:

self.list = list = wx.listctrl(self.panel, ...) 

textctrlautocomplete:

init_choice = ['temp1','temp2','temp3','temp4'] self.input_auswahl = textctrlautocomplete(self.panel, size=(280,24), choices=init_choice, showhead=false) 

which can removed or replaced.

and function adds data , preselect checkboxes:

self.setdefaults() 

this 1 can removed well.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -