By lew Founder on Tag:

เรื่องทั้งหมดมันสืบเนื่องมาจากความขี้เกียจเวลาจะรีวิวลง Blognone สักที ทั้งหมดที่ผมอยากได้คือโปรแกรมที่ดักรอ Clipboard แล้วส่งเข้า Picasa แล้วเอาโค้ดมา embed ได้ทันที

ปัญหามีอย่างเดียว...

ผมไม่เคยเขียน GUI!!! ตอนป. ตรีทำงานกลุ่มก็โยนให้เพื่อนออกแบบหน้าจอ ผมเขียนไส้ในอย่างเดียว

เลยมาลองคลำๆ ดูอยู่สองวันก็ได้เจ้านี่ออกมา

(ภูมิใจมาก เพราะภาพนี้อัพโหลดขึ้น Picasa ด้วยตัวมันเอง)

ขั้นตอนการใช้งานก็มี

  1. ใส่ Username / Password กด Login
  2. เลือก Album หลังจาก Login แล้ว
  3. โปรแกรมจะดักรอ clipboard เราไปเรื่อยๆ ทุก 5 วินาที
  4. กดที่ภาพเมื่อได้ภาพที่ต้องการจะอัพโหลด
  5. กดที่ Text box ด้านบนเพื่อคัดลอกข้อความเข้า Clipboard โดยไม่ได้กด CTRL+C
  6. เอาไปวางตามใจชอบ


# Copyright (c) 2009 by Wason Liwlompaisan
#
# GNU General Public Licence (GPL)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#

from PythonCard import model,clipboard,timer
import wx
import tempfile as tf
import Image
import threading
import gdata.photos.service
import gdata.media
import time
import sys

class MyBackground(model.Background):

def on_initialize(self, event):
    # if you have any initialization
    # including sizer setup, do it here
    self.tmp_dir = tf.mkdtemp()
    self.gclient = None
    self.full_name = self.tmp_dir+"/curfile.jpg"
    self.thumb_name = self.tmp_dir+"/icon.jpg"
    self.clipboardTimer = timer.Timer(self.components.ImagePlace,-1)
    self.clipboardTimer.Start(5000)
    
def on_ImagePlace_timer(self,event):
    size = 300,200
    print "Fired"
    try:
        print "process"
        img = clipboard.getClipboard()
        img.SaveFile(self.full_name,wx.BITMAP_TYPE_JPEG)
        im = Image.open(self.full_name)
        im.thumbnail(size)
        im.save(self.thumb_name,"JPEG")
        self.components.ImagePlace.file = self.thumb_name
    except:
        print "Error" , sys.exc_info()[0]
        pass

def on_TextMe_gainFocus(self,event):
    clipboard.setClipboard(self.components.TextMe.text)
    print "yeshoo"
    self.components.TextMe.SetFocus()
    self.components.TextMe.SetSelection(-1,-1)
    
def on_TextMe_mouseDown(self,event):
    self.components.TextMe.SetFocus()
    self.components.TextMe.SetSelection(-1,-1)

    
def on_ImagePlace_mouseClick(self, event):
    if self.gclient == None:
        self.components.TextMe.text = "Please Login."
        return
    photo = self.gclient.InsertPhotoSimple("/data/feed/api/user/default/albumid/"+self.albums[self.components.AlbumName.stringSelection],"Simple Photo","Upload via API",self.full_name,content_type='image/jpeg')
    link_text = '<a href="%s"><img src="%s" /></a>' % (photo.GetHtmlLink().href, photo.GetMediaURL())
    self.components.TextMe.text = link_text

def on_Login_mouseClick(self,event):
    if self.gclient == None:
        self.gclient = gdata.photos.service.PhotosService()
        self.gclient.email = self.components.Username.text
        self.gclient.password = self.components.Password.text
        self.gclient.source = "PicasaNow! 0.1"
        try:
            self.components.TextMe.text = "Login success. Now ,select you album to upload to."
            self.gclient.ProgrammaticLogin()
        except:
            self.gclient = None
            self.components.TextMe.text = "Login error"
            return
    albums = self.gclient.GetUserFeed(user=str(self.components.Username.text))
    self.albums={}
    for album in albums.entry:
        self.components.AlbumName.append(album.title.text)
        self.albums[album.title.text]=album.gphoto_id.text
        
def on_AlbumName_select(self,event):
    print self.components.AlbumName.stringSelection

if name == 'main':
app = model.Application(MyBackground)
app.MainLoop()

ตัวโปรแกรมสร้างจาก Pythoncard ต้องใช้ resource file อีกอัน

{'application':{'type':'Application',
'name':'Template',
'backgrounds': [
{'type':'Background',
'name':'bgTemplate',
'title':u'PicasaNow!',
'size':(319, 385),

     'components': [

{'type':'Button',
'name':'Login',
'position':(220, 275),
'size':(80, 30),
'label':'Login',
},

{'type':'Choice',
'name':'AlbumName',
'position':(10, 275),
'size':(200, 30),
'items':[],
},

{'type':'TextField',
'name':'Username',
'position':(10, 245),
'size':(140, 25),
'text':'Picasa',
},

{'type':'PasswordField',
'name':'Password',
'position':(155, 245),
'size':(150, 25),
'text':'memenono',
},

{'type':'ImageButton',
'name':'ImagePlace',
'position':(10, 40),
'size':(300, 200),
'border':'none',
'file':'03-10CBFOB_lg.jpg',
},

{'type':'TextField',
'name':'TextMe',
'position':(10, 10),
'size':(300, 25),
'text':'foo bar',
},

] # end components
} # end background
] # end backgrounds
} }

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand