วันอังคารที่ 15 พฤศจิกายน พ.ศ. 2559

Memo : เพิ่มปุ่ม Setting

เพิ่มใน memo.kv
+    ToolButton:
+        text: 'Setting'
+        background_color: .2,1,1,1
+        on_release: root.show_setting(*args)

เพิ่มใน memo.py
+    def show_setting(self,instance):
+        print("Setting PAGE")

Memo : แก้ไข favourite ให้ทำงานถูกต้อง

แก้ไขตอน save favourite
เป็น
fav_txt.write(path_leaf(self.all_file.files[self.index])+",")
จากเดิม
fav_txt.write(","+path_leaf(self.all_file.files[self.index]))

วันอาทิตย์ที่ 13 พฤศจิกายน พ.ศ. 2559

Memo : ใช้งาน favourite ได้แล้ว

เพิ่มฟังก์ชั่น save_favourite เรียกใช้ตอนกดปุ่ม Add to favourite (ในหน้า View)

โดยจะเซฟลงไฟล์ favourite หากไม่ซ้ำกับชื่อไฟล์ใน favourite (มีอยู่ก่อนแล้ว)

Memo : เพิ่มฟังก์ชั่น favourtie


เรียกใช้ฟังก์ชั่น favourite เมื่อกดปุ่ม Favourite ( ดู )

Memo : เพิ่มปุ่ม favourtie

    ToolButton:
        text: 'Favourite'
        background_color: 1,1,.5,1
        on_release: root.favourite()

เพิ่มปุ่มใน memo.kv
-------------------------------------------------------

btn_add_fav = Button(text="Add to favourite", size_hint=(1,.1), background_color=(1,1,.5,1))

เพิ่มปุ่มใน memo.py

วันอังคารที่ 1 พฤศจิกายน พ.ศ. 2559

Memo : Edit







สร้างไฟล์ Edtior.kv โดยใช้เป็น AnchorLayout



method สร้าง popup โดย ปุ่ม save จะ bind กับ method self.save ( เมื่อกดปุ่ม save จะเรียกใช้ method self.save)

method เมื่อกดปุ่ม edit ใน Editor.py (เช็คว่ามีการเลือกไหม)

ถูกเรียกจาก method show_edit (รูปบน) ใน Editor.py




 เมื่อเลือกไฟล์แล้วกด Edit
จะขึ้น Popup โดยใน popup มี textbox ที่มีเนื้อหาในไฟล์ที่เลือกอยู่แล้ว พอแก้ไขเสร็จให้กด Save จะเรียกใช้ method self.save



method self.save จะ save ไฟล์ที่ทำการแก้ไข จากนั้น update ไฟล์ใน FileChooser (หน้าต่างเลือกไฟล์) แล้วทำการปิด popup แล้วสร้าง popup ใหม่ที่บอกว่า Save ไฟล์นี้แล้วนะ
จากนั้น เรียกใช้ method self.refresh เพื่อ unselect ไฟล์ที่ถูกเลือกอยู่





reference
การทำ path ให้เหลือชื่อไฟล์อย่างเดียว

วันศุกร์ที่ 21 ตุลาคม พ.ศ. 2559

OX : Save and Load

Option อยู่ใน GameOX
Option ในไฟล์ kivy

class ButtonOX
แยกคำสั่งพวกตั้งรูปภาพไปอยู่ใน method set_picture





แยกปุ่ม Restart ไปอยู่ในคลาสใหม่ที่ชื่อ Option
และเพิ่มปุ่ม Save , Load
class Option
method restart แยกจาก StatusBar มาอยู่ใน Option
เพิ่ม method save_game , load_save


update 22/10/16
ในmethod save ให้ save ผู้เล่น ด้วย

method load ให้นำเข้าผู้เล่นด้วย

การโหลดไฟล์
http://stackoverflow.com/questions/25924720/filenotfounderror-errno-2

วันพฤหัสบดีที่ 20 ตุลาคม พ.ศ. 2559

OX : Show Winner และ ปุ่ม playagain ตอนจบเกม

class EndGame ในไฟล์ .py

เจอผู้ชนะ ! ไปเรียก show_winner ใน EndGame เพื่ออัพเดทว่าใครชนะ

มี Winner เพื่อแสดงผู้ชนะ
ในหน้า end game จะมี PlayAgain เพื่อถามว่าต้องการเล่นใหม่ไหม ?

class Winner ใน kivy
class PlayAgain ใน kivy

วันพฤหัสบดีที่ 13 ตุลาคม พ.ศ. 2559

Quiz2 description

Quiz2

ข้อที่ 1 change on_children to on_30september

drawingspace.py
ไปเปลี่ยนชื่อ method ใน drawingspace.py จาก on_children เป็น on_30september

เพิ่มให้เรียกใช้ on_30september เพื่อนับจำนวน children ใน toolbox.py หลัง add_widget
toolbox.py
toolbox.py
เพิ่มให้เรียกใช้ on_30september ใน method clear และ remove ใน generaloption.py
generaloption.py












ข้อที่ 2 เมื่อ group แล้ว พอกด remove ให้ remove ที่เลือกทั้งหมด

generaloption.py
ไปแก้ไขในไฟล์ generaloption.py โดยการเพิ่มเงื่อนไข 
if self.group_mode == True ให้ remove แบบ group นอกนั้นให้ remove แบบเดิม

โดยการ remove จะเช็คว่าโดนเลือกอยู่หรือไม่
ถ้าใช่ก็จะ remove 



ที่วนเป็นแบบ reversed เพราะว่าหากวนแบบไปข้างหน้าเมื่อทำการ remove ไป 1 ตัว 
[1,2,3,4]  //remove
  | < ตัวชี้
[2,3,4, ] // ตัวชี้จะชี้เลข 3 ซึ่งข้ามเลข 2 ไป เพราะว่า ตัวที่ 2,3,4 จะเลื่อนมาตำแหน่งตัว 1 ที่ถูก remove 
     |
หากเป็นแบบ reversed จะไม่ข้าม

ข้อที่ 3 นับ Stickman และไปแสดงใน statusbar

เมื่อใช้คำสั่งprint(str(type(child))) ดู พบว่า 
ลอง print(str(type(child))) 
จึงนำมาใช้เช็คเงื่อนไขเพื่อนับ stickman ได้
drawingspace.py
 เพิ่ม label ใน statusbar.kv
statusbar.kv
 เพิ่มตัวแปร stick เป็นแบบ NumericProperty เพื่อให้อัพเดทค่าใน label เอง เมื่อมีการเปลี่ยนแปลงค่า
statusbar.py

Quiz2 description

Quiz2

ข้อที่ 1 change on_children to on_30september

drawingspace.py
ไปเปลี่ยนชื่อ method ใน drawingspace.py จาก on_children เป็น on_30september

เพิ่มให้เรียกใช้ on_30september เพื่อนับจำนวน children ใน toolbox.py หลัง add_widget
toolbox.py
toolbox.py
เพิ่มให้เรียกใช้ on_30september ใน method clear และ remove ใน generaloption.py
generaloption.py












ข้อที่ 2 เมื่อ group แล้ว พอกด remove ให้ remove ที่เลือกทั้งหมด

generaloption.py
ไปแก้ไขในไฟล์ generaloption.py โดยการเพิ่มเงื่อนไข 
if self.group_mode == True ให้ remove แบบ group นอกนั้นให้ remove แบบเดิม

โดยการ remove จะเช็คว่าโดนเลือกอยู่หรือไม่
ถ้าใช่ก็จะ remove 



ที่วนเป็นแบบ reversed เพราะว่าหากวนแบบไปข้างหน้าเมื่อทำการ remove ไป 1 ตัว 
[1,2,3,4]  //remove
  | < ตัวชี้
[2,3,4, ] // ตัวชี้จะชี้เลข 3 ซึ่งข้ามเลข 2 ไป เพราะว่า ตัวที่ 2,3,4 จะเลื่อนมาตำแหน่งตัว 1 ที่ถูก remove 
     |
หากเป็นแบบ reversed จะไม่ข้าม

ข้อที่ 3 นับ Stickman และไปแสดงใน statusbar

เมื่อใช้คำสั่งprint(str(type(child))) ดู พบว่า 
ลอง print(str(type(child))) 
จึงนำมาใช้เช็คเงื่อนไขเพื่อนับ stickman ได้
drawingspace.py
 เพิ่มตัวแปร stick เป็นแบบ NumericProperty เพื่อให้อัพเดทค่าใน label เอง เมื่อมีการเปลี่ยนแปลงค่า
statusbar.py
 เพิ่ม label ใน statusbar.kv
statusbar.kv

วันศุกร์ที่ 30 กันยายน พ.ศ. 2559

Progress


วิธีการ push
  • พิมพ์คำสั่ง hg push https://bitbucket.org/nuttaphon_rodphakdeekul/quiz2/
  • ใส่ username และ password 
วิธีการตั้ง default path เพื่อให้พิมพ์คำสั่ง hg push อย่างเดียวไม่ต้องมี url ... [link]
  • เข้าโฟลเดอร์ .hg และสร้างไฟล์ hgrc
  • เข้าไป edit ไฟล์ hgrc แล้วแก้ไขดังนี้
[paths]
default = https://bitbucket.org/nuttaphon_rodphakdeekul/quiz2/
วิธีการ pull

  • พิมพ์คำสั่ง hg pull -u




วันพฤหัสบดีที่ 18 สิงหาคม พ.ศ. 2559

argument

รับค่าจาก command line

factorial


import sys
def setup():
    number = int(sys.argv[1])
    print factorial(number)

def factorial(a):
    if a == 1:
        return 1
    else:
        return a * factorial(a-1)
    

setup()

วันอังคารที่ 16 สิงหาคม พ.ศ. 2559

Python

Odd Or Even
Ask the user for a number. Depending on whether the number is even or odd, print out an appropriate message to the user. Hint: how does an even / odd number react differently when divided by 2?
code:
def setup():
    num = int(input("Please enter num:"))
    if num%2==0:
        print(num,"is even")
    else:
        print(num,"is odd")
setup()

Guessing Game One
Generate a random number between 1 and 9 (including 1 and 9). Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right.

code:
import random
def setup():
    count=0
    number = random.randint(1,9)
    while True:
        num = int(input("Please guess num between 1-9:"))
        if num==number:
            print(num," is correct")
            print("your guess count is ",count)
            break
        else:
            count+=1
            if num>number:
                print("it's too high")
            else:
                print("it's too low")
setup()



วันจันทร์ที่ 15 สิงหาคม พ.ศ. 2559

Basic Python

ทบทวน Python

def setup():
    a = [-1,-2,3,5,8,4,10]
    print(calc_postive_sum(a))


def calc_postive_sum(a):
    sum = 0
    for i in a:
        if(i > 0):
            sum+=i
     
    return sum

setup()


การใช้ Class

class Person:
    def __init__(self,name,age):
        self.name=name
        self.age=age
    def display(self):
        print("Name:",self.name)
        print("Age:",self.age)

def setup():
    person1 = Person("John",20)
    person2 = Person("Jan",19)
    people = [person1,person2]
    for i in people:
        i.display()
setup()
     


built-in data structure
List


Sets
def setup():
   a = [5,2,3,5,5,6,8,6,5,2]
   a = remove_duplicate(a)
   print(a)
   
def remove_duplicate(a):
   return list(set(a))
setup()


วันพฤหัสบดีที่ 11 สิงหาคม พ.ศ. 2559

http://www.practicepython.org/exercise/2014/01/29/01-character-input.html
http://www.practicepython.org/
http://www.ostechnix.com/upgrade-ubuntu-16-04-lts-ubuntu-15-10-2/

Install Ubuntu


File Commands

ls -al แสดงข้อมูลของไฟล์/โฟลเดอร์
cd เปลี่ยน directory
mkdir directory-name สร้างโฟลเดอร์
rm file-name ลบไฟล์
rm -r directory-name ลบโฟลเดอร์
cp file1 file2 คัดลอกfile1 ไป file2
cp -r dir1 dir2 copy โฟลเดอร์[dir1] ไปยัง โฟลเดอร์[dir2] (ถ้าไม่มี dir2 จะสร้างขึ้นเอง)

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...