Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """
- integrator.py (the app)
- """
- import wx
- from pubsub import pub
- from flask import Flask
- from flask_graphql import GraphQLView
- from models import db_session
- from schema import schema
- from models import engine, db_session, Base, Idiom
- flaskapp = Flask(__name__)
- flaskapp.debug = True
- flaskapp.add_url_rule(
- '/graphql',
- view_func=GraphQLView.as_view(
- 'graphql',
- schema=schema,
- graphiql=True
- )
- )
- flaskapp.run(threaded=True,use_reloader=False)
- @flaskapp.teardown_appcontext
- def shutdown_session(exception=None):
- db_session.remove()
- class IntegratorTarget(wx.TextDropTarget):
- def __init__(self, object):
- wx.DropTarget.__init__(self)
- self.object = object
- def OnDropText(self, x, y, data):
- print(f"<publish>{data}</publish>")
- pub.sendMessage('default', arg1=data)
- return True
- class IntegratorFrame(wx.Frame):
- def __init__(self, parent, title):
- super(IntegratorFrame, self).__init__(parent, title = title,size = wx.DisplaySize())
- self.panel = wx.Panel(self)
- box = wx.BoxSizer(wx.HORIZONTAL)
- dropTarget = IntegratorTarget(self.panel)
- self.panel.SetDropTarget(dropTarget)
- pub.subscribe(self.catcher, 'default')
- self.panel.SetSizer(box)
- self.panel.Fit()
- self.Centre()
- self.Show(True)
- def catcher(self,arg1):
- data = arg1
- print(f"<subscribed>{data}</subscribed>\n\n")
- return
- ex = wx.App()
- Base.metadata.create_all(bind=engine)
- IntegratorFrame(None,'Praxis:Integrator')
- ex.MainLoop()
- -- eof --
- """ models.py """
- from sqlalchemy import *
- from sqlalchemy.orm import (scoped_session, sessionmaker, relationship, backref)
- from sqlalchemy.ext.declarative import declarative_base
- engine = create_engine('sqlite:///.praxis/lexicon/unbound.db3', convert_unicode=True)
- db_session = scoped_session(sessionmaker(autocommit=False,
- autoflush=False,
- bind=engine))
- Base = declarative_base()
- # We will need this for querying
- Base.query = db_session.query_property()
- class Idiom(Base):
- __tablename__ = "idiomae"
- id = Column(Integer, primary_key=True)
- src = Column(String) # the text of the drag/paste operation
- taxonomy = Column(String) # the type of resource referenced in the drag/paste operation
- localblob = Column(String) # local path to media referenced in 'src'
- timestamp = Column(DateTime) # date and time of capture
- -- eof --
- """ schema.py """
- import graphene
- from graphene import relay
- from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
- from models import db_session, Idiom as IdiomaticModel
- class Idiom(SQLAlchemyObjectType):
- class Meta:
- model = IdiomaticModel
- interfaces = (relay.Node, )
- class Query(graphene.ObjectType):
- node = relay.Node.Field()
- # Allows sorting over multiple columns, by default over the primary key
- all_idioms = SQLAlchemyConnectionField(Idiom.connection)
- # Disable sorting over this field
- # all_departments = SQLAlchemyConnectionField(Department.connection, sort=None)
- schema = graphene.Schema(query=Query)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement