⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 post_panel.py

📁 pyLJclient是一个跨平台的livejournal客户端
💻 PY
字号:
# pyLJclient - a python based live journal client with a wxPython gui
# Copyright (C) 2002 Sameer Chowdhury
# refer to "about this software.txt" for info on licensing

from wxPython.wx import *
from lj import lj_journal, identity, offline_journal, lj_event
from lj.error_windows import fatal_error, nonfatal_error
from lj.lj_exceptions import *
import sys

# post panel options

ID_SUBJECT = 60
ID_SECURITY = 61 
ID_ENTRY_BOX = 62 
ID_POST = 63
ID_JOURNAL = 64
ID_MOODS = 65
ID_CUSTOM_MOOD = 66
ID_MUSIC = 67
ID_MOOD_PICS = 68

SEP = '------'
DEFAULT_SECURITY = 'public'

# post panel is used to post journal entries
class PostPanel(wxPanel):
    def __init__(self, parent, id, journal=None, journal_access_list=[], moods_list=[], pic_url_association={}):
        #wxPanel.__init__(self, parent, -1, size=wxSize(600,400))
        wxPanel.__init__(self, parent, -1)
        self.journal = journal
	self.moods_list = moods_list.getMoods()
	self.moods_list.sort(lambda x,y: cmp(x.name, y.name))
	mood_names = []
	print "--------in post panel---------------"
	#print pic_url_association
	for i in self.moods_list:
	    mood_names.append(i.name)
	mood_names.insert(0,SEP)
	sizer = wxBoxSizer(wxVERTICAL)
	security_and_journal_sizer = wxBoxSizer(wxHORIZONTAL)
	security_sizer = wxBoxSizer(wxVERTICAL)
	journal_sizer = wxBoxSizer(wxVERTICAL)
	sizer.Add(wxStaticText(self, -1, "Subject"), 0, wxALIGN_LEFT|wxTOP, 10)
	self.subject_box = wxTextCtrl(self, ID_SUBJECT, "", size=(400,-1))
	sizer.Add(self.subject_box, 0, wxALL|wxALIGN_LEFT|wxEXPAND, 3)
	security_sizer.Add(wxStaticText(self, -1, "Security"), 0, wxALIGN_LEFT|wxEXPAND,0)
	security_options = self.journal.get_friend_groups().get_group_names()
        self.security =  wxChoice(self, ID_SECURITY, choices = security_options)
	self.journal_access_list = wxChoice(self, ID_JOURNAL, choices=journal_access_list)
	security_sizer.Add(self.security, 0, wxALIGN_LEFT|wxEXPAND, 0)
        self.security.SetStringSelection(DEFAULT_SECURITY)
	journal_sizer.Add(wxStaticText(self, -1, "Active Journal"), 0, wxALIGN_LEFT|wxTOP,0)
	journal_sizer.Add(self.journal_access_list, 0, wxALIGN_LEFT|wxTOP, 0)

	security_and_journal_sizer.Add(security_sizer, 0, wxALIGN_LEFT|wxRIGHT, 15)
	security_and_journal_sizer.Add(journal_sizer, 0, wxALIGN_LEFT|wxRIGHT, 15)
	
	sizer.Add(security_and_journal_sizer, 0, wxALIGN_LEFT|wxEXPAND, 0)
        self.journal_access_list.SetSelection(0)
        sizer.Add(wxStaticText(self, -1, "Journal Entry Here"), 0, wxALIGN_LEFT|wxTOP, 10)
        self.text_box = wxTextCtrl(self, ID_ENTRY_BOX, "", size=wxSize(300,200), style=wxTE_MULTILINE|wxTE_RICH)
        self.text_box.SetInsertionPoint(0)
	sizer.Add(self.text_box, 1, wxALIGN_LEFT|wxEXPAND, 5)
	
	mood_music_post_sizer = wxBoxSizer(wxHORIZONTAL)
	# add mood info
	mood_sizer = wxBoxSizer(wxVERTICAL)
	mood_sizer.Add(wxStaticText(self, -1, "Current Mood"), 0, wxALIGN_RIGHT|wxTOP|wxEXPAND,0)
        self.moods =  wxChoice(self, ID_MOODS, choices = mood_names)
	self.moods.SetSelection(0)
	self.custom_mood = wxTextCtrl(self, ID_CUSTOM_MOOD, "", size=(95,-1))
	mood_sizer.Add(self.moods, 0, wxALIGN_LEFT|wxTOP, 0)
	mood_sizer.Add(wxStaticText(self, -1, "OR Make your own"), 0, wxALIGN_RIGHT|wxTOP|wxEXPAND,0)
	mood_sizer.Add(self.custom_mood, 0, wxALL|wxALIGN_LEFT, 0) 
	mood_music_post_sizer.Add(mood_sizer, 0, wxALIGN_RIGHT|wxRIGHT, 30)
	# add music info
	music_sizer = wxBoxSizer(wxVERTICAL)
	music_sizer.Add(wxStaticText(self, -1, "Current Music"), 0, wxALIGN_RIGHT|wxTOP|wxEXPAND,0)
	self.music = wxTextCtrl(self, ID_MUSIC, "", size=(200,-1))	
	music_sizer.Add(self.music, 0, wxALL|wxALIGN_LEFT, 0)
	# mood pic
	music_sizer.Add(wxStaticText(self, -1, "Mood Picture"), 0, wxALIGN_RIGHT|wxTOP|wxEXPAND,0)
	pic_keywords = pic_url_association.keys()
	pic_keywords.insert(0, 'Default')
	self.mood_pic_keywords = wxChoice(self, ID_MOOD_PICS, choices = pic_keywords)
	self.mood_pic_keywords.SetSelection(0)
	music_sizer.Add(self.mood_pic_keywords, 0, wxALIGN_LEFT|wxTOP, 0)
	mood_music_post_sizer.Add(music_sizer, 1, wxALIGN_LEFT|wxLEFT, 0)
	# add post button 
	mood_music_post_sizer.Add(wxButton(self, ID_POST, "POST"), 0, wxALIGN_RIGHT|wxALL|wxBOTTOM, 10)
	# add mood, music, and post button to main sizer
	sizer.Add(mood_music_post_sizer, 0, wxALIGN_RIGHT|wxEXPAND, 0)

        EVT_BUTTON(self, ID_POST, self.onClick)
	# main_sizer.Add(sizer, 1, wxEXPAND|wxALL, 0)
	self.SetAutoLayout(1)
	self.SetSizer(sizer)
	sizer.Fit(self)
	sizer.SetSizeHints(self)
	#self.name = 'Post'
	#EVT_SIZE(self, self.Resize)

    def Resize(self, event):
	self.SetAutoLayout(TRUE)

    def onClick(self, event):
        #if not isinstance(self.journal, lj_journal.LJ_Journal):
        #    raise "Offline Journal temproraily unavailable"
	entry = self.text_box.GetValue()
	if not entry:
	    nonfatal_error(self,"Cannot leave the entry blank")
	    return 0
	security_level = self.security.GetString(self.security.GetSelection())
	if security_level != SEP:
	    security_group = self.journal.get_friend_groups().get_group_by_name(security_level)
	else:
	    raise "Non valid security level provided"
	if self.moods.GetSelection() != 0:
	    mood = self.moods.GetString(self.moods.GetSelection())
	    for i in self.moods_list:
		if i.name == mood:
		    mood_id = i.id
		    break
	elif self.custom_mood.GetValue():
	    mood = self.custom_mood.GetValue()
	    mood_id=''
	else:
	    mood = ''
	    mood_id = ''
	use_journal = self.journal_access_list.GetString(self.journal_access_list.GetSelection())
	if self.mood_pic_keywords.GetSelection() != 0:
	    pic_keyword = self.mood_pic_keywords.GetString(self.mood_pic_keywords.GetSelection())
	    #print "non default pic found ---> ", pic_keyword
	else:
	    pic_keyword = ''
	    
	# print "use journal = %s"%str(use_journal)
	if use_journal != 'Default':
	    # print "Journals found to post to"
	    if use_journal == self.journal.username:
		use_journal =''
	else:
	    # print "Use Journal field is empty"
	    use_journal = ''
	print "value of security group before being put into new_event: %s"%security_group
	new_event = lj_event.Event(self.text_box.GetValue(), subject = self.subject_box.GetValue(),
		security_group = security_group, journal = use_journal, mood = mood, mood_id = mood_id,
		mood_pic = pic_keyword, current_music = self.music.GetValue()) 
        self.journal.post_event(new_event)
        # make this into a function call later - reduce coupling
        try:
            if new_event:
		# reset to page defaults
                self.text_box.Clear()
                self.subject_box.Clear()
		self.moods.SetSelection(0)
		self.security.SetStringSelection(DEFAULT_SECURITY)
		self.custom_mood.Clear()
		self.journal_access_list.SetSelection(0)
		self.mood_pic_keywords.SetSelection(0)
		self.music.Clear()
		print "Event posted"
        except:
            pass

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -