Again I have problems with my classes :s
I want to test if there is still text in the text_ctrl, if so it should give a warning in which you can chose to cancel, save or continue;

but somehow the deditor.st = "continue" is not passed :s

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Sun Nov 29 18:42:47 2009

import wx, os, datetime, stat
from ftplib import FTP

# begin wxGlade: extracode
# end wxGlade

class StillText(wx.Dialog):
    def __init__(self, *args, **kwds):
        # begin wxGlade: StillText.__init__
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)
        self.label_1 = wx.StaticText(self, -1, "ATTENTION: THERE IS STILL A FILE OPENED!", style=wx.ALIGN_CENTRE)
        self.button_1 = wx.Button(self, -1, "Save")
        self.button_2 = wx.Button(self, -1, "Continue")
        self.button_3 = wx.Button(self, -1, "Cancel")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.save_file, self.button_1)
        self.Bind(wx.EVT_BUTTON, self.continu, self.button_2)
        self.Bind(wx.EVT_BUTTON, self.cancel, self.button_3)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: StillText.__set_properties
        self.SetTitle("ATTENTION!")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: StillText.__do_layout
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
        sizer_2_copy = wx.BoxSizer(wx.HORIZONTAL)
        sizer_2.Add(self.label_1, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        sizer_2_copy.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        sizer_2_copy.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        sizer_2_copy.Add(self.button_3, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        sizer_2.Add(sizer_2_copy, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
        self.SetSizer(sizer_2)
        sizer_2.Fit(self)
        self.Layout()
        # end wxGlade

    def save_file(self, event): # wxGlade: StillText.<event_handler>
        deditor.save_file("")
        deditor.st = "save"
        self.Close()

    def continu(self, event): # wxGlade: StillText.<event_handler>
        deditor.st = "continue"
        self.Close()

    def cancel(self, event): # wxGlade: StillText.<event_handler>
        deditor.st = "cancel"
        self.Close()

# end of class StillText


class DEDITOR(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: DEDITOR.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        
        # Menu Bar
        self.deditor_menubar = wx.MenuBar()
        wxglade_tmp_menu = wx.Menu()
        wxglade_tmp_menu.Append(1, "&New", "", wx.ITEM_NORMAL)
        wxglade_tmp_menu.Append(2, "&Open", "", wx.ITEM_NORMAL)
        wxglade_tmp_menu.Append(3, "&Save", "", wx.ITEM_NORMAL)
        wxglade_tmp_menu.Append(4, "Save &As", "", wx.ITEM_NORMAL)
        wxglade_tmp_menu.AppendSeparator()
        wxglade_tmp_menu.Append(5, "&Quit", "", wx.ITEM_NORMAL)
        self.deditor_menubar.Append(wxglade_tmp_menu, "File")
        wxglade_tmp_menu = wx.Menu()
        wxglade_tmp_menu.Append(6, "Current &File", "", wx.ITEM_NORMAL)
        wxglade_tmp_menu.Append(7, "&FTP", "", wx.ITEM_NORMAL)
        wxglade_tmp_menu.Append(8, "Configuration", "", wx.ITEM_NORMAL)
        self.deditor_menubar.Append(wxglade_tmp_menu, "Options")
        self.SetMenuBar(self.deditor_menubar)
        # Menu Bar end
        self.deditor_statusbar = self.CreateStatusBar(1, 0)
        self.text_ctrl_1 = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.HSCROLL)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_MENU, self.new_file, id=1)
        self.Bind(wx.EVT_MENU, self.open_file, id=2)
        self.Bind(wx.EVT_MENU, self.save_file, id=3)
        # end wxGlade
        
        self.initialize()

    def __set_properties(self):
        # begin wxGlade: DEDITOR.__set_properties
        self.SetTitle("Deditor")
        self.SetSize((500, 600))
        self.deditor_statusbar.SetStatusWidths([-1])
        # statusbar fields
        deditor_statusbar_fields = ["deditor_statusbar"]
        for i in range(len(deditor_statusbar_fields)):
            self.deditor_statusbar.SetStatusText(deditor_statusbar_fields[i], i)
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: DEDITOR.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.text_ctrl_1, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        self.SetSizer(sizer_1)
        self.Layout()
        self.SetSize((500, 600))
        # end wxGlade
        
    def initialize(self):
        self.deddir = os.path.dirname(__file__) + "/"
        self.filedir = self.deddir
        self.st = "cancel"

    def still_text(self):
        if(self.text_ctrl_1.GetValue() != ""):
            self.stilltext = StillText(DEDITOR(self), -1, "")
            self.stilltext.Show()
            print self.st
        else:
            self.st = "continue"

    def new_file(self, event): # wxGlade: DEDITOR.<event_handler>
        self.still_text()
        if(self.st != "cancel"):
            self.text_ctrl_1.SetValue("")

    def open_file(self, event): # wxGlade: DEDITOR.<event_handler>
        self.still_text()
        if(self.st=="cancel"):
            pass
        else:
            dlg = wx.FileDialog(self, message="Open File", defaultDir=self.filedir, defaultFile="", style=wx.OPEN)
            if dlg.ShowModal() == wx.ID_OK:   
                self.opnfl = dlg.GetPath()
                self.editfl(self.opnfl)
            dlg.Destroy()

    def editfl(self, fl):
        f = open(fl, 'r')
        txt = ""
        for line in f.readlines():
            txt = txt + line
        f.close()
        self.text_ctrl_1.SetValue(txt)

    def save_file(self, event): # wxGlade: DEDITOR.<event_handler>
        print "Event handler `save_file' not implemented!"

# end of class DEDITOR


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    deditor = DEDITOR(None, -1, "")
    app.SetTopWindow(deditor)
    deditor.Show()
    app.MainLoop()

In line 127
self.stilltext = StillText(DEDITOR(self), -1, "")
creates a new instance of class DEDITOR, you want to use the instance created in __main__

In line 127
self.stilltext = StillText(DEDITOR(self), -1, "")
creates a new instance of class DEDITOR, you want to use the instance created in __main__

I would think that I should use deditor (in lowercase) then, but that throws an error: DEDITOR object is not callable

if I try StillText(None, -1, "") instead it just won't work either =s

Edited 6 Years Ago by Kruptein: n/a

Okay never-mind I found the problem, it had to be: self.stilltext.ShowModal()

This question has already been answered. Start a new discussion instead.