mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2025-05-21 10:45:30 -04:00
Fixed message Gui alignment
This commit is contained in:
parent
59fe27744e
commit
abd093d949
2 changed files with 39 additions and 28 deletions
|
@ -84,7 +84,7 @@ class KmsGui(tk.Tk):
|
||||||
self.btnwinfont = tkFont.Font(family = 'Times', size = 12, weight = 'bold')
|
self.btnwinfont = tkFont.Font(family = 'Times', size = 12, weight = 'bold')
|
||||||
self.othfont = tkFont.Font(family = 'Times', size = 9, weight = 'bold')
|
self.othfont = tkFont.Font(family = 'Times', size = 9, weight = 'bold')
|
||||||
self.optfont = tkFont.Font(family = 'Helvetica', size = 11, weight = 'bold')
|
self.optfont = tkFont.Font(family = 'Helvetica', size = 11, weight = 'bold')
|
||||||
self.msgfont = tkFont.Font(family = 'Helvetica', size = 7)
|
self.msgfont = tkFont.Font(family = 'Monospace', size = 6) # need a monospaced type (like courier, etc..).
|
||||||
|
|
||||||
self.customcolors = { 'black' : '#000000',
|
self.customcolors = { 'black' : '#000000',
|
||||||
'white' : '#FFFFFF',
|
'white' : '#FFFFFF',
|
||||||
|
@ -241,7 +241,7 @@ class KmsGui(tk.Tk):
|
||||||
chksql.grid(row = 12, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
chksql.grid(row = 12, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
|
|
||||||
## Create widgets and layout (msgsrvwin) -----------------------------------------------------------------------------------------------
|
## Create widgets and layout (msgsrvwin) -----------------------------------------------------------------------------------------------
|
||||||
self.textboxsrv = TextDoubleScroll(self.msgsrvwin, background = self.customcolors['black'], wrap = 'word', state = 'disabled',
|
self.textboxsrv = TextDoubleScroll(self.msgsrvwin, background = self.customcolors['black'], wrap = 'none', state = 'disabled',
|
||||||
relief = 'ridge', font = self.msgfont)
|
relief = 'ridge', font = self.msgfont)
|
||||||
self.textboxsrv.put()
|
self.textboxsrv.put()
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ class KmsGui(tk.Tk):
|
||||||
self.cltlevel.grid(row = 7, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
self.cltlevel.grid(row = 7, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
|
|
||||||
# Create widgets and layout (msgcltwin) ----------------------------------------------------------------------------------------------------------
|
# Create widgets and layout (msgcltwin) ----------------------------------------------------------------------------------------------------------
|
||||||
self.textboxclt = TextDoubleScroll(self.msgcltwin, background = self.customcolors['black'], wrap = 'word', state = 'disabled',
|
self.textboxclt = TextDoubleScroll(self.msgcltwin, background = self.customcolors['black'], wrap = 'none', state = 'disabled',
|
||||||
relief = 'ridge', font = self.msgfont)
|
relief = 'ridge', font = self.msgfont)
|
||||||
self.textboxclt.put()
|
self.textboxclt.put()
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,8 @@ class TextRedirect(object):
|
||||||
lenarrow = len(arrows[0])
|
lenarrow = len(arrows[0])
|
||||||
srv_msg_nonewline = [ item[0] for item in unformat_message([MsgMap[2], MsgMap[5], MsgMap[13], MsgMap[18]]) ]
|
srv_msg_nonewline = [ item[0] for item in unformat_message([MsgMap[2], MsgMap[5], MsgMap[13], MsgMap[18]]) ]
|
||||||
terminator = unformat_message([MsgMap[21]])[0][0]
|
terminator = unformat_message([MsgMap[21]])[0][0]
|
||||||
|
msg_align = [ msg[0].replace('\t', '').replace('\n', '') for msg in unformat_message([MsgMap[-2], MsgMap[-4]])]
|
||||||
|
newlinecut = [-1, -2, -4, -5]
|
||||||
|
|
||||||
def __init__(self, srv_text_space, clt_text_space, customcolors, runclt, str_to_print, where):
|
def __init__(self, srv_text_space, clt_text_space, customcolors, runclt, str_to_print, where):
|
||||||
self.srv_text_space = srv_text_space
|
self.srv_text_space = srv_text_space
|
||||||
|
@ -148,11 +150,13 @@ class TextRedirect(object):
|
||||||
def textbox_finish(self, message):
|
def textbox_finish(self, message):
|
||||||
if message == self.terminator:
|
if message == self.terminator:
|
||||||
TextRedirect.StdoutRedirect.tag_num = 0
|
TextRedirect.StdoutRedirect.tag_num = 0
|
||||||
|
TextRedirect.StdoutRedirect.newlinecut = [-1, -2, -4, -5]
|
||||||
self.runclt.configure(state = 'normal')
|
self.runclt.configure(state = 'normal')
|
||||||
|
|
||||||
def textbox_write(self, tag, message, color, extras):
|
def textbox_write(self, tag, message, color, extras):
|
||||||
widget = self.textbox_choose(message)
|
widget = self.textbox_choose(message)
|
||||||
self.maxchar = widget['width']
|
self.w_maxpix, self.h_maxpix = widget.winfo_width(), widget.winfo_height()
|
||||||
|
self.xfont = tkFont.Font(font = widget['font'])
|
||||||
widget.configure(state = 'normal')
|
widget.configure(state = 'normal')
|
||||||
widget.insert('end', self.textbox_format(message), tag)
|
widget.insert('end', self.textbox_format(message), tag)
|
||||||
self.textbox_color(tag, widget, color, self.customcolors['black'], extras)
|
self.textbox_color(tag, widget, color, self.customcolors['black'], extras)
|
||||||
|
@ -169,40 +173,47 @@ class TextRedirect(object):
|
||||||
return self.clt_text_space
|
return self.clt_text_space
|
||||||
|
|
||||||
def textbox_color(self, tag, widget, forecolor = 'white', backcolor = 'black', extras = []):
|
def textbox_color(self, tag, widget, forecolor = 'white', backcolor = 'black', extras = []):
|
||||||
xfont = tkFont.Font(font = widget['font'])
|
|
||||||
|
|
||||||
for extra in extras:
|
for extra in extras:
|
||||||
if extra == 'bold':
|
if extra == 'bold':
|
||||||
xfont.configure(weight = "bold")
|
self.xfont.configure(weight = "bold")
|
||||||
elif extra == 'italic':
|
elif extra == 'italic':
|
||||||
xfont.configure(slant = "italic")
|
self.xfont.configure(slant = "italic")
|
||||||
elif extra == 'underlined':
|
elif extra == 'underlined':
|
||||||
xfont.text_font.configure(underline = True)
|
self.xfont.text_font.configure(underline = True)
|
||||||
elif extra == 'strike':
|
elif extra == 'strike':
|
||||||
xfont.configure(overstrike = True)
|
self.xfont.configure(overstrike = True)
|
||||||
|
elif extra == 'reverse':
|
||||||
|
forecolor, backcolor = backcolor, forecolor
|
||||||
|
|
||||||
widget.tag_configure(tag, foreground = forecolor, background = backcolor, font = xfont)
|
widget.tag_configure(tag, foreground = forecolor, background = backcolor, font = self.xfont)
|
||||||
widget.tag_add(tag, "insert linestart", "insert lineend")
|
widget.tag_add(tag, "insert linestart", "insert lineend")
|
||||||
|
|
||||||
|
def textbox_newline(self, message):
|
||||||
|
if not message.endswith('\n'):
|
||||||
|
return message + '\n'
|
||||||
|
else:
|
||||||
|
return message
|
||||||
|
|
||||||
def textbox_format(self, message):
|
def textbox_format(self, message):
|
||||||
lenfixed = self.maxchar - len(message.replace('\t', ''))
|
# vertical align.
|
||||||
|
self.w_maxpix = self.w_maxpix - 5 # pixel reduction for distance from border.
|
||||||
if self.where == "srv":
|
w_fontpix, h_fontpix = (self.xfont.measure('0'), self.xfont.metrics('linespace'))
|
||||||
if message in self.srv_msg_nonewline:
|
msg_unformat = message.replace('\t', '').replace('\n', '')
|
||||||
lung = lenfixed - self.lenarrow + 4
|
lenfixed_chars = int((self.w_maxpix / w_fontpix) - len(msg_unformat))
|
||||||
else:
|
|
||||||
lung = lenfixed + self.lenarrow + 10
|
if message in self.srv_msg_nonewline + self.clt_msg_nonewline:
|
||||||
if not message.endswith('\n'):
|
lung = lenfixed_chars - self.lenarrow
|
||||||
message += '\n'
|
|
||||||
elif self.where == "clt":
|
|
||||||
if message in self.clt_msg_nonewline:
|
if message in self.clt_msg_nonewline:
|
||||||
lung = lenfixed - self.lenarrow
|
message = self.textbox_newline(message)
|
||||||
if not message.endswith('\n'):
|
else:
|
||||||
message += '\n'
|
lung = lenfixed_chars
|
||||||
else:
|
if (self.where == "srv") or (self.where == "clt" and message not in self.arrows):
|
||||||
lung = lenfixed + 10
|
message = self.textbox_newline(message)
|
||||||
if not message.endswith('\n') and message not in self.arrows:
|
# horizontal align.
|
||||||
message += '\n'
|
if msg_unformat in self.msg_align:
|
||||||
|
msg_strip = message.lstrip('\n')
|
||||||
|
message = '\n' * (len(message) - len(msg_strip) + TextRedirect.StdoutRedirect.newlinecut[0]) + msg_strip
|
||||||
|
TextRedirect.StdoutRedirect.newlinecut.pop(0)
|
||||||
|
|
||||||
count = Counter(message)
|
count = Counter(message)
|
||||||
countab = (count['\t'] if count['\t'] != 0 else 1)
|
countab = (count['\t'] if count['\t'] != 0 else 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue