mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-15 02:54:09 -04:00
Extract an edit-text-dialog base class.
This commit is contained in:
parent
d97b20b17b
commit
e525a823fa
4 changed files with 58 additions and 106 deletions
|
@ -27,18 +27,15 @@ __all__ = ['EditTextDialog']
|
||||||
import Tkinter
|
import Tkinter
|
||||||
import ttk
|
import ttk
|
||||||
|
|
||||||
# PySol imports
|
|
||||||
from pysollib.mygettext import _, n_
|
|
||||||
from pysollib.mfxutil import KwStruct
|
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from tkwidget import MfxDialog
|
from tkwidget import MfxDialog
|
||||||
|
from pysollib.ui.tktile.edittextdialog import BaseEditTextDialog
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# *
|
# *
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
class EditTextDialog(MfxDialog):
|
class EditTextDialog(BaseEditTextDialog, MfxDialog):
|
||||||
|
|
||||||
def _calcToolkit(self):
|
def _calcToolkit(self):
|
||||||
return ttk
|
return ttk
|
||||||
|
@ -48,51 +45,3 @@ class EditTextDialog(MfxDialog):
|
||||||
|
|
||||||
def _calc_Resizable(self):
|
def _calc_Resizable(self):
|
||||||
return False
|
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,18 +26,15 @@ __all__ = ['EditTextDialog']
|
||||||
# imports
|
# imports
|
||||||
import Tkinter
|
import Tkinter
|
||||||
|
|
||||||
# PySol imports
|
|
||||||
from pysollib.mygettext import _, n_
|
|
||||||
from pysollib.mfxutil import KwStruct
|
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from tkwidget import MfxDialog
|
from tkwidget import MfxDialog
|
||||||
|
from pysollib.ui.tktile.edittextdialog import BaseEditTextDialog
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# *
|
# *
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
class EditTextDialog(MfxDialog):
|
class EditTextDialog(BaseEditTextDialog, MfxDialog):
|
||||||
|
|
||||||
def _calcToolkit(self):
|
def _calcToolkit(self):
|
||||||
return Tkinter
|
return Tkinter
|
||||||
|
@ -47,51 +44,3 @@ class EditTextDialog(MfxDialog):
|
||||||
|
|
||||||
def _calc_Resizable(self):
|
def _calc_Resizable(self):
|
||||||
return True
|
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
53
pysollib/ui/tktile/edittextdialog.py
Normal file
53
pysollib/ui/tktile/edittextdialog.py
Normal 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
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,7 @@ for module_name in [
|
||||||
'pysollib.tk.wizarddialog',
|
'pysollib.tk.wizarddialog',
|
||||||
'pysollib.ui.tktile.card',
|
'pysollib.ui.tktile.card',
|
||||||
'pysollib.ui.tktile.colorsdialog',
|
'pysollib.ui.tktile.colorsdialog',
|
||||||
|
'pysollib.ui.tktile.edittextdialog',
|
||||||
'pysollib.ui.tktile.menubar',
|
'pysollib.ui.tktile.menubar',
|
||||||
'pysollib.ui.tktile.solverdialog',
|
'pysollib.ui.tktile.solverdialog',
|
||||||
'pysollib.ui.tktile.tkcanvas',
|
'pysollib.ui.tktile.tkcanvas',
|
||||||
|
|
Loading…
Add table
Reference in a new issue