#!/usr/bin/env python
# -*- mode: python; coding: koi8-r; -*-
# (c) anonymous
# Требования:
#     - python
#     - Tkinter
# Использование:
#     - запускаем программу
#     - копируем в форуме ссылку "[Ответить на это сообщение]"
#     - жмем кнопку "Convert" (или Ctrl-C)
#     - вставляем новую ссылку средней клавишей мыши
import re
from Tkinter import *
import tkMessageBox
patterns = (
    re.compile(r'topic=(\d+).*replyto=(\d+)'),
    re.compile(r'topic=(\d+).*msgid=(\d+)'),
    re.compile(r'nocache=(\d+#\d+)'),
    re.compile(r'msgid=(\d+#\d+)'),
    re.compile(r'msgid=(\d+)'),
    )
def insert_url(url):
    entry.delete(0, END)
    entry.insert(0, url)
    entry.select_from(0)
    entry.select_to(END)
def convert_url():
    try:
        url = root.selection_get().strip()
    except TclError, err:
        tkMessageBox.Message(root,
                             type=tkMessageBox.OK,
                             icon=tkMessageBox.ERROR,
                             message='Can\'t convert url: ' + str(err)
                             ).show()
        return
    for pat in patterns:
        mo = pat.search(url)
        if mo:
            if len(mo.groups()) == 1:
                insert_url('http://www.linux.org.ru/jump-message.jsp?msgid=%s'
                           % mo.group(1))
            else:
                insert_url('http://www.linux.org.ru/jump-message.jsp?msgid=%s#%s'
                           % (mo.group(1), mo.group(2)))
            return
    tkMessageBox.Message(root,
                         type=tkMessageBox.OK,
                         icon=tkMessageBox.ERROR,
                         message='Can\'t convert url: invalid url:' + url
                         ).show()
root = Tk()
root.title('LOR url converter')
Wm.minsize(root, width=400, height=0)
# конфигуряние виджетов
root.config(borderwidth=2, background='green4')
root.option_add('*Font', 'Helvetica 22 bold')
root.option_add('*Entry.Font', 'Courier 22 bold')
root.option_add('*BorderWidth', 1)
root.option_add('*HighlightThickness', 4)
root.option_add('*Background', 'green4')
root.option_add('*HighlightBackground', 'red')
root.option_add('*HighlightForeground', 'blue')
root.option_add('*HighlightColor', 'orange')
root.option_add('*ActiveBackground', 'blue')
root.option_add('*ActiveForeground', 'aquamarine')
root.option_add('*Frame.HighlightBackground', 'green')
root.option_add('*Button.Background', 'yellow3')
root.option_add('*Button.Foreground', 'blue')
root.option_add('*Button.Cursor', 'hand2')
root.option_add('*Button.HighlightBackground', 'CadetBlue3')
root.option_add('*Entry.Background', 'wheat')
root.option_add('*Entry.Foreground', 'black')
root.option_add('*selectBackground', 'purple')
root.option_add('*selectForeground', 'green')
root.option_add('*Entry.HighlightColor', 'PaleVioletRed3')
# горячие клавиши
root.bind('<Control-c>', lambda x: convert_url())
root.bind('<Control-q>', lambda x: root.destroy())
frame = Frame(root)
frame.pack(expand=YES, fill=BOTH)
entry = Entry(frame)
entry.pack(expand=YES, fill=X)
button = Button(frame, text='Convert', underline=0, command=convert_url)
button.pack(side=LEFT, expand=YES)
entry.focus()
root.mainloop()
    
        Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.
      
Похожие темы
- Форум Текстовое поле Tkinter (2013)
 - Форум matplotlib, мракобесие какое-то (2009)
 - Форум Tkinter+xterm. Почему терминал xterm не выводит результат работы программы? (2023)
 - Форум python tkinter вопрос по canvas (2009)
 - Форум LOR Dark blue (2024)
 
- Форум Сжатие окна в Tkinter (2013)
 - Форум Теряется ввод терминала, как можно исправить? (2023)
 - Форум Как закрыть тред при выходе из Tkinter-приложения? (2023)
 - Форум Версия для слабовидящих на JavaScript + CSS (2018)
 - Форум [python] Помогите оптимизировать маленькую прогу, пж. (2009)