How to create program like wizard with Glade3

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to create program like wizard with Glade3

Petr Hracek
Hi folks,


I have just one question regarding pygtk, Glade3 and my program which should looks like wizard.
I have one GLADE3 file which contains 5 GtkWindows.

Main program is called mainWindow.py which loads GLADE3 file.

I would like to create python program which will be separate into several *.py modules which will corresponds with
names of dialogs.

mainWindow.py ->
after pressing on Next
-> secondWindow.py (from GLADE3 will be loaded secondWindow (type GtkWindow)) with relevant handlers
 ...

 -> finalWindow.py (from GLADE3 will be loaded finalWindow (type GtkWindow)) with relevant handlers

Current situation is only mainWindow.py file with a lot of handlers.
But when I did it always I am receiving error messages like some handler is not defined in mainWindow.py class

My current mainWindow.py looks like:

from gi.repository import Gtk


logger = logging.getLogger()


console_handler = logging.StreamHandler(stream=sys.stdout)

console_formatter = logging.Formatter('%(levelname)s - %(message)s')

console_handler.setFormatter(console_formatter)


logger.addHandler(console_handler)

logger.setLevel(logging.INFO)


gladefile = "./devel-assistant.glade"



class mainWindow(Gtk.Window):


def __init__(self):

builder = Gtk.Builder()

builder.add_from_file(gladefile)

self.mainWin = builder.get_object("mainWindow")

self.pathWin = builder.get_object("pathWindow")

self.finalWin = builder.get_object("finalWindow")

self.winNumber = 0

handlers = {

"on_nextMainBtn_clicked": self.nextWindow,

"on_nextPathBtn_clicked": self.nextWindow,

"on_runFinalBtn_clicked": self.runWizard,

"on_prevPathBtn_clicked": self.prevWindow,

"on_prevFinalBtn_clicked": self.prevWindow,

"on_cancelMainBtn_clicked": Gtk.main_quit,

"on_cancelPathBtn_clicked": Gtk.main_quit,

"on_cancelFinalBtn_clicked": Gtk.main_quit,

"on_mainWindow_delete_event": Gtk.main_quit,

"on_pathWindow_delete_event": Gtk.main_quit,

"on_pathWindow_delete_event": Gtk.main_quit,

"on_storeView_row_activated": self.storeRowActivated,

"on_browsePathBtn_clicked": self.browsePath,

}

builder.connect_signals(handlers)

self.listView = builder.get_object("storeView")

self.labelMainWindow = builder.get_object("sublabel")

self.sublistView = builder.get_object("subStoreView")

self.substoreList = builder.get_object("substoreList")

self.labelProjectName = builder.get_object("labelProjectName")

self.main, self.subas = DevelAssistants().get_subassistant_chain()

self.store = Gtk.ListStore(str)

self.substore = Gtk.ListStore(str)

k = 0

for ass in self.subas:

self.store.append([ass[0].fullname])

if k == 0:

if not ass[1]:

self.labelMainWindow.hide()

self.sublistView.hide()

else:

for sub in ass[1]:

logger.info("subas:%s and %s" % (sub[0].name, sub[0].fullname))

self.substore.append([sub[0].fullname])

self.labelMainWindow.show()

self.sublistView.show()

k += 1


self.listView.set_model(self.store)

self.sublistView.set_model(self.substore)


renderer = Gtk.CellRendererText()

column = Gtk.TreeViewColumn("List of languages", renderer, text=0)

self.listView.append_column(column)

subrenderer = Gtk.CellRendererText()

subcolumn = Gtk.TreeViewColumn("List of languages", subrenderer, text=0)

self.sublistView.append_column(subcolumn)

self.pathWin.hide()

self.mainWin.show_all()

Gtk.main()


def windowQuit(self, widget):

Gtk.main_quit


def nextWindow(self, widget):

logger.info("Next window")

self.winNumber += 1

self.showWindow()


def showWindow(self):

if self.winNumber == 1:

self.mainWin.hide()

self.pathWin.show_all()

elif self.winNumber == 2:

self.pathWin.hide()

self.finalWin.show_all()


def prevWindow(self, widget):

logger.info("Prev window")

self.mainWin.hide()

self.pathWin.show_all()


def cancelWindow(self, widget):

logger.info("Cancel window")


def storeRowActivated(self, widget, row, col):

logger.info("handler for switch betwenn tools")

model = widget.get_model()

self.substore.clear()

tool = model[row][0]

logger.info("tools is: {0}".format(tool))

if tool in map(lambda x: x[0].fullname, self.subas):

for ass in self.subas:

logger.info(ass[0].fullname)

if tool == ass[0].fullname:

for sub in ass[1]:

self.labelMainWindow.show_all()

self.sublistView.show_all()

self.substore.append([sub[0].fullname])

else:

self.labelMainWindow.hide()

self.substore.hide()


def browsePath(self, window):

logger.info("Browse path")

dialog = Gtk.FileChooserDialog(

"Please choose directory", self,

Gtk.FileChooserAction.SELECT_FOLDER,

(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,

Gtk.STOCK_OPEN, Gtk.ResponseType.OK)

)

response = dialog.run()

if response == Gtk.ResponseType.OK:

self.labelProjectName.set_text(dialog.get_filename())

dialog.destroy()


def runWizard(self, window):

logger.info("Run wizard")

name = self.labelProjectName.get_text()

logger.info("Project name is: %s" % name)



Thank you for any help:)


-- 
S pozdravem / Best regards

Petr Hracek

_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/