a subject is foundation of programming

1 answer below »
Answered 4 days AfterFeb 04, 2021

Answer To: a subject is foundation of programming

Swapnil answered on Feb 09 2021
156 Votes
75369/Code/android.py
import collections
import json
import os
import socket
import sys
PORT = os.environ.get('AP_PORT')
HOST = os.environ.get('AP_HOST')
HANDSHAKE = os.environ.get('AP_HANDSHAKE')
Result = collections.namedtuple('Result', 'id,result,error')
class Android(object):
    def __init__(self, addr=None):
    if addr is None:
        addr = HOST, PORT
        self.conn = socket.create_connection(addr)
        self.client = self.conn.makefile()
        self.id = 0
        self._authenticate(HANDSHAKE)
    def _rpc(self, method, *args):
        data = {'id': self.id,
        'method': method,
        'params': args}
        request = json.dumps(data)
        self.client.write(request+'\n')
        self.client.flush()
        response = self.client.readline()
        self.id += 1
        result = json.loads(response)
        if result['error'] is not None:
            print result['error']
            r
eturn Result(id=result['id'], result=result['result'],
            error=result['error'], )
    def __getattr__(self, name):
    def rpc_call(*args):
        return self._rpc(name, *args)
        return rpc_call
75369/Code/data_report.py
import android
import pdb
class DataReport:

def __init__(self,droid):
self.droid=droid
def get_data_report(self,cursor):
query="select item.item_name,dat.entered_date,sum(item.amount) from date_table as dat,items as item where item.entered_date=dat.id group by item.item_name"
cursor.execute(query)
data_info_tuple=cursor.fetchall()
return list(data_info_tuple)

def start_gui(self,cursor):
xml=open("layout/data_report.xml","r").read()
data_info_tuple_list=self.get_data_report(cursor)
print data_info_tuple_list
self.droid.fullShow(xml)
data_list=[]
coloumn_list=["Item_Name","Date","Amount"]
data_list.append(" ".join(coloumn_list))

for data in data_info_tuple_list:
temp_data=list(data)
temp_data[-1]=str(temp_data[-1])
data_str=" ".join(temp_data)
data_list.append(data_str)
print data_list

self.droid.fullSetList("mylist",data_list)
while True:
result=self.droid.eventWait().result
if result["name"]=="key":
id=result["data"]["key"]
if id == "4":
self.droid.fullDismiss()
return

def start_data_report(cursor):

data=DataReport()
data.start_gui(cursor)
return
75369/Code/Gui.py
class Gui:

def __init__(self):

'''
'''
self.basic_ui_layout="""
android:id="@+id/background"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#ff000000">

android:layout_height="wrap_content" android:id="@+id/linearLayout1">

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Item:" />

android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:prompt="Select Item from List"
/>

android:layout_height="wrap_content" android:id="@+id/linearLayout2">

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Amount" />

android:layout_height="wrap_content" android:id="@+id/Amount"
android:tag="Tag Me" android:inputType="textCapWords|textPhonetic|number">





android:layout_height="wrap_content" android:id="@+id/linearLayout3">





"""
75369/Code/Money_Planner.py
import android
import sqlite3
import urlparse
import json
import datetime,time
import sys
from Gui import Gui
from data_report import DataReport
import pdb
class Event:

def __init__(self):
pass
class DB_Connection:

def __init__(self):
self.connection=None
self.cursor=None
def set_db_connection(self):
self.connection=sqlite3.connect("Testing.db")
cursor=self.connection.cursor()
return cursor
class Items:

def __init__(self):
pass
def add_description(self,description):
self.description=description

def add_item_info(self,cursor,itemname,amount):
query="insert into items(item_name,amount) values(?,?)"
query_args=(itemname,int(amount))
cursor.execute(query,query_args)

def get_default_items_list(self,cursor):
query="select itemname from default_items"
cursor.execute(query)
result=cursor.fetchall()
return [item[0] for item in result]

def remove_item_info(self):
pass
class Money_Planner:

def __init__(self,droid):
self.droid=droid
self.gui=Gui()
self.items=Items()

def add_options(self):
self.droid.addOptionsMenuItem("Off","off",None,"ic_menu_revert")
self.droid.addOptionsMenuItem("Main Menu",None,"star_on")

def on_save_click(self,default_item_list,cursor):
Amount=self.droid.fullQueryDetail("Amount").result["text"]
item_index=self.droid.fullQueryDetail("spinner").result["selectedItemPosition"]
item_name=default_item_list[int(item_index)]
self.items.add_item_info(cursor,item_name,Amount)
self.droid.makeToast("Record Inserted")

def on_display_click(self):
data_obj=DataReport()
data_report_tuple_list=data_obj.get_data_report(self.connection_obj,"2012-06-30")
print data_report_tuple_list

def start_gui(self,cursor):
self.add_options()
self.droid.fullShow(self.gui.basic_ui_layout)
default_item_list=self.items.get_default_items_list(cursor)
self.droid.fullSetList("spinner",default_item_list)

while True:
result=self.droid.eventWait().result
print result
print "----> event_name is %s"%(result['name'])

if result['name'] == "click":
id=result["data"]["id"]

if id == "Save":
self.on_save_click(default_item_list,cursor)
elif id == "Cancel":
self.droid.makeToast("No Record Inserted")
self.droid.fullDismiss()
return
elif id == "Display":
self.on_display_click()

elif result["name"]=="off":
self.droid.fullDismiss()
return

elif result["name"]=="key":
id=result["data"]["key"]

if id == "4":
self.droid.fullDismiss()
return

def start(cursor):
planner=Money_Planner()
planner.start(cursor)
if __name__ == "__main__":
start()
75369/Code/money_planner_db.sql
drop table if exists default_items;
create table default_items (id integer primary key,itemname text);
insert into default_items (itemname)
select "Petrol"
union
select "Internet"
union
select "Dish Recharge"
union
select "Mobile"
union
select "Shopping";
drop table if exists date_table;
create table date_table(
id integer primary key,
entered_date date unique on conflict ignore
);
drop table if exists...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here