1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Extract an edit-text-dialog base class.

This commit is contained in:
Shlomi Fish 2016-11-13 13:29:46 +02:00
parent d97b20b17b
commit e525a823fa
4 changed files with 58 additions and 106 deletions

View file

@ -27,18 +27,15 @@ __all__ = ['EditTextDialog']
import Tkinter
import ttk
# PySol imports
from pysollib.mygettext import _, n_
from pysollib.mfxutil import KwStruct
# Toolkit imports
from tkwidget import MfxDialog
from pysollib.ui.tktile.edittextdialog import BaseEditTextDialog
# ************************************************************************
# *
# ************************************************************************
class EditTextDialog(MfxDialog):
class EditTextDialog(BaseEditTextDialog, MfxDialog):
def _calcToolkit(self):
return ttk
@ -48,51 +45,3 @@ class EditTextDialog(MfxDialog):
def _calc_Resizable(self):
return False
def __init__(self, parent, title, text, **kw):
kw = self.initKw(kw)
self._calc_MfxDialog().__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
#
self.text_w = Tkinter.Text(top_frame, bd=1, relief="sunken",
wrap="word", width=64, height=16)
self.text_w.pack(side='left', fill="both", expand=True)
###self.text_w.pack(side='top', padx=kw.padx, pady=kw.pady)
vbar = self._calcToolkit().Scrollbar(top_frame)
vbar.pack(side='right', fill='y')
self.text_w["yscrollcommand"] = vbar.set
vbar["command"] = self.text_w.yview
#
self.text = ""
if text:
self.text = text
old_state = self.text_w["state"]
self.text_w.config(state="normal")
self.text_w.insert("insert", self.text)
self.text_w.config(state=old_state)
#
focus = self.createButtons(bottom_frame, kw)
focus = self.text_w
self.mainloop(focus, kw.timeout)
def initKw(self, kw):
kw = KwStruct(kw,
strings=(_("&OK"), _("&Cancel")),
default=-1,
resizable=self._calc_Resizable(),
separator=False,
)
return self._calc_MfxDialog().initKw(self, kw)
def destroy(self):
self.text = self.text_w.get("1.0", "end")
self._calc_MfxDialog().destroy(self)
def wmDeleteWindow(self, *event): # ignore
pass
def mCancel(self, *event): # ignore <Escape>
pass

View file

@ -26,18 +26,15 @@ __all__ = ['EditTextDialog']
# imports
import Tkinter
# PySol imports
from pysollib.mygettext import _, n_
from pysollib.mfxutil import KwStruct
# Toolkit imports
from tkwidget import MfxDialog
from pysollib.ui.tktile.edittextdialog import BaseEditTextDialog
# ************************************************************************
# *
# ************************************************************************
class EditTextDialog(MfxDialog):
class EditTextDialog(BaseEditTextDialog, MfxDialog):
def _calcToolkit(self):
return Tkinter
@ -47,51 +44,3 @@ class EditTextDialog(MfxDialog):
def _calc_Resizable(self):
return True
def __init__(self, parent, title, text, **kw):
kw = self.initKw(kw)
self._calc_MfxDialog().__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
#
self.text_w = Tkinter.Text(top_frame, bd=1, relief="sunken",
wrap="word", width=64, height=16)
self.text_w.pack(side='left', fill="both", expand=True)
###self.text_w.pack(side='top', padx=kw.padx, pady=kw.pady)
vbar = self._calcToolkit().Scrollbar(top_frame)
vbar.pack(side='right', fill='y')
self.text_w["yscrollcommand"] = vbar.set
vbar["command"] = self.text_w.yview
#
self.text = ""
if text:
self.text = text
old_state = self.text_w["state"]
self.text_w.config(state="normal")
self.text_w.insert("insert", self.text)
self.text_w.config(state=old_state)
#
focus = self.createButtons(bottom_frame, kw)
focus = self.text_w
self.mainloop(focus, kw.timeout)
def initKw(self, kw):
kw = KwStruct(kw,
strings=(_("&OK"), _("&Cancel")),
default=-1,
resizable=self._calc_Resizable(),
separator=False,
)
return self._calc_MfxDialog().initKw(self, kw)
def destroy(self):
self.text = self.text_w.get("1.0", "end")
self._calc_MfxDialog().destroy(self)
def wmDeleteWindow(self, *event): # ignore
pass
def mCancel(self, *event): # ignore <Escape>
pass

View file

@ -0,0 +1,53 @@
import Tkinter
from pysollib.mygettext import _, n_
from pysollib.mfxutil import KwStruct
class BaseEditTextDialog:
def __init__(self, parent, title, text, **kw):
kw = self.initKw(kw)
self._calc_MfxDialog().__init__(self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
#
self.text_w = Tkinter.Text(top_frame, bd=1, relief="sunken",
wrap="word", width=64, height=16)
self.text_w.pack(side='left', fill="both", expand=True)
###self.text_w.pack(side='top', padx=kw.padx, pady=kw.pady)
vbar = self._calcToolkit().Scrollbar(top_frame)
vbar.pack(side='right', fill='y')
self.text_w["yscrollcommand"] = vbar.set
vbar["command"] = self.text_w.yview
#
self.text = ""
if text:
self.text = text
old_state = self.text_w["state"]
self.text_w.config(state="normal")
self.text_w.insert("insert", self.text)
self.text_w.config(state=old_state)
#
focus = self.createButtons(bottom_frame, kw)
focus = self.text_w
self.mainloop(focus, kw.timeout)
def initKw(self, kw):
kw = KwStruct(kw,
strings=(_("&OK"), _("&Cancel")),
default=-1,
resizable=self._calc_Resizable(),
separator=False,
)
return self._calc_MfxDialog().initKw(self, kw)
def destroy(self):
self.text = self.text_w.get("1.0", "end")
self._calc_MfxDialog().destroy(self)
def wmDeleteWindow(self, *event): # ignore
pass
def mCancel(self, *event): # ignore <Escape>
pass

View file

@ -181,6 +181,7 @@ for module_name in [
'pysollib.tk.wizarddialog',
'pysollib.ui.tktile.card',
'pysollib.ui.tktile.colorsdialog',
'pysollib.ui.tktile.edittextdialog',
'pysollib.ui.tktile.menubar',
'pysollib.ui.tktile.solverdialog',
'pysollib.ui.tktile.tkcanvas',