.AddPage to eg.ConfigDialog wx.Notebook

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
dequi
Experienced User
Posts: 79
Joined: Wed Jul 20, 2016 12:31 pm
Location: Belgium

.AddPage to eg.ConfigDialog wx.Notebook

Post by dequi » Wed Apr 12, 2017 8:31 pm

Hi yall,

Busy trying to learn some basic Python at this point, got myself a little learning project defined: a PluginManager plugin, kinda in the way notepad++ handles it's plugins.
Starting with some plugin GUI stuff (you got to start somewhere). Everywhere I can see all plugins put GUI items in the eg.ConfigPanel class

Code: Select all

panel = eg.ConfigPanel(self, resizable=True)
That I have working fine but I'm wondering how I can add a page (well three to be exact) to the parent so I don't have a double "settings" page
Any way this can be done?
Attachments
ConfigDialog-notebook-AddPage.png
/dequi

User avatar
kgschlosser
Site Admin
Posts: 3021
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: .AddPage to eg.ConfigDialog wx.Notebook

Post by kgschlosser » Wed Apr 12, 2017 11:47 pm

This is untested code. but it should give you the general idea. and when you initialize eg.ConfigPanel you do not need to pass it any arguments. it is defaulted to resizable. but also the only thing you are going to use eg.ConfigPanel for is to grab the notebook from the dialog.. unless you need to add things to the Settings (page 0) page.

You are able to also change the label for a specific notebook page as well. if you do not require a page with the label "Settings". I have added an example of that below as well.

you can also use notebook.RemovePage(0) if you wanted to remove the Settings page all together. You can do many things like setting icons to the tabs if you wish.

the code below can be condensed a lot but for making it easier to understand it's done the long way

Code: Select all

panel = eg.ConfigPanel()
notebook = panel.dialog.notebook

notebook.SetPageText(0, "PAGE 0")

page1 = wx.Panel(notebook)
sizer_page1 = wx.BoxSizer(wx.HORIZONTAL)
page1.SetSizer(sizer_page1)
notebook.AddPage(page1, 'PAGE 1')

st_page1= panel.StaticText("widget:")
ctrl_page1 =  panel.TextCtrl("enter something here")

sizer_page1.Add(st_page1, 0, wx.EXPAND | wx.ALL, 5)
sizer_page1.Add(ctrl_page1, 1, wx.EXPAND | wx.ALL, 5)

page2= wx.Panel(notebook)
sizer_page2 = wx.BoxSizer(wx.HORIZONTAL)
page2.SetSizer(sizer_page2)
notebook.AddPage(page2, 'PAGE 2')

st_page2= panel.StaticText("widget:")
ctrl_page2 =  panel.TextCtrl("enter something here")

sizer_page2.Add(st_page2, 0, wx.EXPAND | wx.ALL, 5)
sizer_page2.Add(ctrl_page2, 1, wx.EXPAND | wx.ALL, 5)

If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3021
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: .AddPage to eg.ConfigDialog wx.Notebook

Post by kgschlosser » Wed Apr 12, 2017 11:53 pm

if you want to have the tabs you add before the Settings tab. then you will have to use notebook.InsertPage and not notebook.AddPage
If you like the work I have been doing then feel free to Image

dequi
Experienced User
Posts: 79
Joined: Wed Jul 20, 2016 12:31 pm
Location: Belgium

Re: .AddPage to eg.ConfigDialog wx.Notebook

Post by dequi » Thu Apr 13, 2017 8:08 pm

Thanks kgschlosser, that worked (for the most part)

The only thing I can't get to work is InsertPage to insert a page before index 0, if I use -1 I get an error, if I use 0 I get a weird little black rectangle left upper corner of the notebook.
Managed to get the look I was after by using first RemovePage(0) and then just AddPage

Any good getting started Python / wxWidgets tutorials you can recommend? Do you use a IDE? wxFormBuilder? have you used gitKraken or another git GUI?
They are predicting cold weather this long easter-weekend, and it looks I'll have some spare time on my hands to do some studying :D
Attachments
ConfigDialog-notebook-AddPage-2.png
/dequi

User avatar
kgschlosser
Site Admin
Posts: 3021
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: .AddPage to eg.ConfigDialog wx.Notebook

Post by kgschlosser » Thu Apr 13, 2017 8:21 pm

use 0... insert is the index number you want it to be.. then it will move the current page that is at 0 to 1. that is how it should work.

i would have to play with it to see why it's not working
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3021
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: .AddPage to eg.ConfigDialog wx.Notebook

Post by kgschlosser » Thu Apr 13, 2017 8:53 pm

dequi wrote:Any good getting started Python / wxWidgets tutorials you can recommend?

if you have python 2.7 installed download wx from here
http://downloads.sourceforge.net/wxpyth ... 0-py27.exe

then download the python demo from here
http://downloads.sourceforge.net/wxpyth ... .0.2.0.exe

if it doesn't work in the demo it is not going to work in EG

but the demo will show just about every bit of wx. and it also shows the code used to create that bit. it does not show every single thing that bit can do... that is going to require yout to Google it.
learn the google syntax and boolean it will help greatly filter things. what i normally do for a search would be as follows
python wx notebook phoenix

change out notebook to any control you want to know about

NOTE... wx phoenix is not in EG but it has a much better webpage layout. just keep in mind that most of the functions and methods are the same but there are things that can sometimes be different and will require you to remove the phoenix from the search. but when using the old style web

the biggest trick is that you have to look at the inheritance diagrams for each thing you look up. so something like the wx.Notebook will be a subclass of wx.Window. so wx.Notebook will have all of it's own methods and attributes. but also has all of the methods and attributes from wx.Window. it works like this all the way down the diagram. so the top level item has it's own abilities plus all of the abilities of each level beneath it

dequi wrote:wxFormBuilder?
I do not use any wx layout programs as i find that none of them actually work properly. or they cost money that I am not willing to spend. the easiest is to grab a pencil and some graph paper. and draw out the dialog you want. because you have to remember that everything GUI based is drawn in pixels and pixels are squares. and so is graph paper. so it makes it pretty easy for understanding things like borders on different elements because upi have to remember that borders are compounded so if you add a border of 10 to the widget when you add it to the sizer. and then you add that sizer to another sizer with a border of 10 that widget now has a border of 20 so learn the sizer flags.


Add(widget, proportion, flags, border size)

allows widget to expand
wx.EXPAND

applies to borders
wx.ALL
wx.LEFT
wx.RIGHT
wx.TOP
wx.BOTTOM

applies to alignment of the widget
wx.ALIGN_BOTTOM
wx.ALIGN_CENTER
wx.ALIGN_CENTER_HORIZONTAL
wx.ALIGN_CENTER_VERTICAL
wx.ALIGN_LEFT
wx.ALIGN_RIGHT
wx.ALIGN_TOP

and can be combined
wx.ALIGN_BOTTOM | wx.ALIGN_CENTER aligns the widget center of the cell at the bottom of the cell

so typically you would see
sizer.Add(widget, 0, wx.EXPAND | wx.ALL, 10)

but you can do

sizer.Add(widget, 0, wx.EXPAND | wx.ALIGN_BOTTOM | wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)

which would expand it align bottom center and place a border of 10 pixels at the top and bottom


this is how i believe this functions.. i never really read up on it too much
the second parameter when adding to a sizer is the proportion.. so a 0 will expand only in the opposite direction the sizer is made for.. so if the sizer is made for horizontal then the widget will only grow vertically
a 1 means that it will grow in both directions. this also controls what % of the grown space is gotten by what widget. so if you have a 0 and another widget has a 1 then the one with the 1 gets more space then the widget with a 0

dequi wrote:Do you use a IDE?
I use PyCharm with a couple of plugins for things like xml and markdown I do not use the version control built into pycharm.
dequi wrote:have you used gitKraken or another git GUI?
I use GitKraken tho i have been thinking about changing because they still have not fixed this crappy memory leak in it. and it's a HUGE one.. after a few days it's up to 4-5 gigs of ram used. I have told them several times about it. with screen shots of my task manager and I have never gotten a response back and with each new version they have not fixed it.
dequi wrote:They are predicting cold weather this long easter-weekend, and it looks I'll have some spare time on my hands to do some studying :D
I am going to send you a PM with a way to contact me that will typically get an instant reply. I know how frustrating it can be when you are having an issue and you know that a simple reply from someone can greatly spped up the process. or at the very least give you a better understanding.

I wish i had someone i could do this with. to many months spent doing the trial and error thing to gain an understanding of how things work. because you can't always draw a clear picture from what you find on the internet or in a book
I know this is going to sound pretty corny.. but even tho you have the basics down. if you have an android device download an app called "Learn Python" and do the lessons and tests. even tho i have been doing this for a little bit that app taught me quite a few things
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3021
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: .AddPage to eg.ConfigDialog wx.Notebook

Post by kgschlosser » Thu Apr 13, 2017 9:18 pm

and remember sub classing is your friend. so if you have a control that you need to perform specific things to and this control is used more then one time. then subclass the control and add methods/binders or any other repeat code to it.

Code: Select all

class NoteBookPanel(wx.Panel):

    def __init__(self, parent, some_value):
        wx.Panel.__init__(self, parent)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.ctrl = wx.TextCtrl(self, -1, some_value)
        self.sizer.Add(self.ctrl, 1, wx.EXPAND | wx.ALL, 10)
        self.SetSizer(self.sizer)

        self.ctrl.Bind(wx.EVT_CHAR_HOOK, self.OnText)

    def OnText(self, evt):
        print self.ctrl.GetValue()
        evt.Skip()

    def Add(self, *args):
        self.sizer.Add(*args)

    def SetValue(self, value):
        self.ctrl.SetValue(value)

    def GetValue(self):
        return self.ctrl.GetValue()

doing something like this for each page in a notebook if they have similar controls can really cut down on code. if you notice i added the method add. which will allow me to add controls to the sizer for that page. so if there is something specific to that page it can be added. but this also allows me to get the values form widgets created inside of the class
If you like the work I have been doing then feel free to Image

Post Reply