How to modify current ScreenManager to another - python-3.x

Good afternoon.
I have a code structure with two ScreenManager:
id: sm ==> besides being my root it has only two screens
LoginScreen:
name: 'screen_login'
MainScreen:
name: 'main'
When the login is performed it directs me to the main screen:
On the screen named 'main' it has:
1 - MDToolbar
1 - MDNavigationLayout and it has a ScreenManager of
id: screen_manager with the following screens:
ScreenRecycleView
LoginScreen
ScreenSingUp
ScreenItem
1 - MDNavigationDrawer and it has a ContentNavigationDrawer with a creen_manager variable that inherits from the one described above.
There it is working beautifully!
I call any of the screens above and everything runs.
The problem is that I have a screen called
<ScreenRecycleView>:
name: 'recycle_view'
and this one has a MyImageCard class that has a button:
MDFlatButton:
text: "New Screen Here"
increment_width: "164dp"
On it I click and I can't call the screen that I pointed out in the example.
on_release:
app.root.screen_manager.current = 'screen_item'
I've tried everything I know, I'm for your help.
Below is my code reduced to the max to help them help me:
My code here.
I know my problem is screen manager but I can't solve it!

With your help I was able to discover:
app.root.get_screen('main').ids.screen_manager.current = 'screen_item'

Related

Connecting Rasa to a database to store responses

I'm trying to connect my rasa open source chatbot to a local database and store response from the user. But I couldn't succeed in the process of integrating database to my chatbot. I tried using google but nothing seems to be working. I hope I'll get a solution from community members. Attaching the data for your reference.
nlu.yml
nlu:
- intent: painting_request
examples: |
- im interested in buying a painting
- i'm interested in buying a painting
- I'm interested in buying a painting
- interested in buying canvas
- id like to request a painting
- id like to buy a painting
- im looking for a painting that have a beautuful background
- i would like to get a sketch of my photograph
- i would like to get a sketch of my photo
- intent: art_type_entry
examples: |
- im looking for a [graphite](art_type) painting
- i'm looking for a [graphite](art_type) sketch
- i want to buy a [graphite](art_type) painting
- i want to buy a [graphite](art_type) sketch
- can i able to get a [graphite](art_type) art
- i want my picture to be drawn in [graphite](art_type)
- im looking for a [charcoal](art_type) painting
- i'm looking for a [charcoal](art_type) sketch
- i want to buy a [charcoal](art_type) painting
- i want to buy a [charcoal](art_type) sketch
- can i able to get a [charcoal](art_type) art
- i want my picture to be drawn in [charcoal](art_type)
- im looking for a [coloured pencil art](art_type) painting
- i'm looking for a [coloured pencil art](art_type) sketch
- i want to buy a [coloured pencil art](art_type) painting
- i want to buy a [coloured pencil art](art_type) sketch
- can i able to get a [coloured pencil art](art_type) art
- i want my picture to be drawn in [coloured pencil art](art_type)
- i want my picture to be drawn in [oil painting](art_type)
- im looking for a [oil painting](art_type) painting
- i'm looking for a [oil painting](art_type) sketch
- i want to buy a [oil painting](art_type) painting
- i want to buy a [oil painting](art_type) sketch
- can i able to get a [oil painting](art_type) art
- i want my picture to be drawn in [oil painting](art_type)
- intent: size_entry
examples: |
- size should be of [a4](size)
- size should be of [a3](size)
- size should be of [a2](size)
- size should be of [a1](size)
- painting should be of [a4](size)
- painting should be of [a3](size)
- painting should be of [a2](size)
- painting should be of [a1](size)
- intent: frame_entry
examples: |
- my frame should be of [standard](frame)
- my frame should be of [wooden](frame)
- my frame should be of [designer](frame)
- my canvas should be fitted with a [standard](frame)
- my canvas should be fitted with a [wooden](frame)
- my canvas should be fitted with a [designer](frame)
- frame should be of [standard](frame)
- frame should be of [Wooden](frame)
- frame should be of [designer](frame)
- intent: finishing_entry
examples: |
- the outer finishing should be done with [maple](finishing)
- the outer finishing should be done with [walnut](finishing)
- the outer finishing should be done with [black](finishing)
- the outer finishing should be done with [white](finishing)
- the outer finishing should be done with [glass](finishing)
- outer finishing should be done with [brass](finishing)
- outer finishing should be done with [maple](finishing)
- outer finishing should be done with [walnut](finishing)
- outer finishing should be done with [black](finishing)
- outer finishing should be done with [white](finishing)
- outer finishing should be done with [glass](finishing)
- outer finishing should be done with [brass](finishing)
- intent: orientation_entry
examples: |
- orientation of canvas should be in [landscape](orientation)
- orientation of canvas should be in [potrait](orientation)
- orientation of canvas should be in [designer choice](orientation)
rules.yml
rules:
- rule: activate painting form
steps:
- intent: painting_request
- action: painting_form
- active_loop: painting_form
- rule: submit form
condition:
- active_loop: painting_form
steps:
- action: painting_form
- active_loop: null
- action: utter_submit
- action: utter_slots_values
stories.yml
stories:
- story: confirmation
steps:
- intent: affirm
- action: utter_affirm
- story: stop form + continue
steps:
- intent: painting_request
- action: painting_form
- active_loop: painting_form
- intent: out_of_scope
- action: utter_ask_continue
- intent: affirm
- action: painting_form
- active_loop: null
- action: utter_submit
- action: utter_slots_values
- story: stop form + stop
steps:
- intent: painting_request
- action: painting_form
- active_loop: painting_form
- intent: out_of_scope
- action: utter_ask_continue
- intent: deny
- action: action_deactivate_loop
- active_loop: null
domain.yml
intents:
- greet
- goodbye
- affirm
- reject
- mood_great
- mood_unhappy
- bot_challenge
- askname
- help
- out_of_scope
- art_type_entry
- size_entry
- frame_entry
- finishing_entry
- orientation_entry
- painting_request:
use_entities: []
entities:
- art_type
- size
- frame
- finishing
- orientation
actions:
- validate_painting_form # From actions.py page
slots:
model:
type: text
influence_conversation: false
auto_fill: false
frame_size:
type: text
influence_conversation: false
auto_fill: false
frame_type:
type: text
influence_conversation: false
auto_fill: false
frame_orientation:
type: text
influence_conversation: false
auto_fill: false
frame_finishing:
type: text
influence_conversation: false
auto_fill: false
requested_slot:
type: text
influence_conversation: false
forms:
painting_form:
required_slots:
model:
- type: from_entity
entity: art_type
frame_size:
- type: from_entity
entity: size
frame_type:
- type: from_entity
entity: frame
frame_orientation:
- type: from_entity
entity: orientation
frame_finishing:
- type: from_entity
entity: finishing
responses:
utter_greet:
- text: "Hey! Welcome to My Website, how can I help you? "
- text: "Hi Welcome to My Website, how can I help you?"
utter_reject:
- text: "Sorry to hear it,How can I help you?"
- text: "Did that help you?"
utter_default:
- text: "I am not sure what you're aiming for."
- text: "I am sorry but I am not able to get you."
- text: "My appologies but I am not able to get you."
utter_happy:
- text: "Great, carry on!"
utter_cheer_up:
- text: "Sorry to hear that."
utter_affirm:
- text: "Nice to hear it"
utter_goodbye:
- text: "Bye"
utter_name:
- text: "I am a bot, powered by Rasa."
utter_bot_help:
- text: "I'm here to help you in customising your painting."
- text: "I'm powered by A.I here to helps you in guide to buy a beautiful painting with your desired customisation."
- text: "I'm here to gather information of how you want your painting to be."
utter_ask_continue:
- text: "Do you want to continue?"
utter_wrong_art_type:
- text: "Sorry we are unable to proceed with your art type, please try again"
utter_wrong_size_type:
- text: "Sorry we are unable to proceed with your size type, please try again"
utter_wrong_frame_type:
- text: "Sorry we are unable to proceed with your frame type, please try again"
utter_wrong_finishing_type:
- text: "Sorry we are unable to proceed with your finishing type, please try again"
utter_wrong_orientation_type:
- text: "Sorry we are unable to proceed with your orientation type, please try again"
utter_ask_model:
- text: "What is your desired art model"
utter_ask_frame_size:
- text: "Please enter your required size"
utter_ask_frame_type:
- text: "Please enter your desired frame type"
utter_ask_frame_finishing:
- text: "Please enter your deisired finishing"
utter_ask_frame_orientation:
- text: "Please enter orientation"
utter_submit:
- text: "Thanks for the information provided."
utter_slots_values:
- text: "I am going to run a search using the following parameters:\n
- art_type: {model}\n
- size: {frame_size}\n
- frame: {frame_type}\n
- finishing: {frame_finishing}\n
- orientation: {frame_orientation}"
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
actions.py
from database_connector import DataUpdate
from typing import Any, Text, Dict, List, Union
from rasa_sdk import Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormValidationAction
class PaintingFormValidation(FormValidationAction):
"""Example of a form validation action."""
def name(self) -> Text:
return "validate_painting_form"
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
return{
"model": [self.from_entity(entity='art_type', intent='art_type_entry')],
"frame_size": [self.from_entity(entity='size', intent='size_entry')],
"frame_type": [self.from_entity(entity='frame', intent='frame_entry')],
"frame_finishing": [self.from_entity(entity='finishing', intent='finishing_entry')],
"frame_orientation": [self.from_entity(entity='orientation', intent='orientation_entry')]
}
#staticmethod
def art_type_db() -> List[Text]:
"""Database of supported cuisines."""
return [
"graphite",
"charcoal",
"sketching",
"oilPainting",
"colored pencil"
]
#staticmethod
def size_db() -> List[Text]:
"""Database of supported sizes"""
return [
"a1",
"a2",
"a3",
"a4"
]
#staticmethod
def frame_db() -> List[Text]:
"""Database of supported frame types"""
return [
"no frame",
"standard",
"designer"
]
#staticmethod
def finishing_db() -> List[Text]:
"""Database of supported finishing"""
return [
"maple",
"wood",
"metal",
"glass",
"walnut"
]
#staticmethod
def orientation_db() -> List[Text]:
"""Database of supported orientations."""
return [
"landscape",
"potrait",
"designer choice"
]
#staticmethod
def is_int(string: Text) -> bool:
"""Check if a string is an integer."""
try:
int(string)
return True
except ValueError:
return False
def validate_model(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate art type value."""
if value.lower() in self.art_type_db():
# validation succeeded, set the value of the "art_type" slot to value
return {"model": value}
else:
dispatcher.utter_message(response="utter_wrong_art_type")
# validation failed, set this slot to None, meaning the
# user will be asked for the slot again
return {"model": None}
def validate_frame_size(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate size value."""
if value.lower() in self.size_db():
# validation succeeded, set the value of the "size" slot to value
return {"frame_size": value}
else:
dispatcher.utter_message(response="utter_wrong_size_type")
# validation failed, set this slot to None, meaning the
# user will be asked for the slot again
return {"frame_size": None}
def validate_frame_type(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate frame type value."""
if value.lower() in self.frame_db():
# validation succeeded, set the value of the "frame" slot to value
return {"frame_type": value}
else:
dispatcher.utter_message(response="utter_wrong_frame_type")
# validation failed, set this slot to None, meaning the
# user will be asked for the slot again
return {"frame_type": None}
def validate_frame_finishing(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate finishing value."""
if value.lower() in self.finishing_db():
# validation succeeded, set the value of the "finishing" slot to value
return {"frame_finishing": value}
else:
dispatcher.utter_message(response="utter_wrong_finishing_type")
# validation failed, set this slot to None, meaning the
# user will be asked for the slot again
return {"frame_finishing": None}
def validate_frame_orientation(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
"""Validate orientation value."""
if value.lower() in self.orientation_db():
# validation succeeded, set the value of the "orientation" slot to value
return {"frame_orientation": value}
else:
dispatcher.utter_message(response="utter_wrong_orientation_type")
# validation failed, set this slot to None, meaning the
# user will be asked for the slot again
return {"frame_orientation": None}
def submit(
self,
dispatcher:CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]
) -> List[Dict]:
dispatcher.utter_message(template="utter_submit")
DataUpdate(tracker.get_slot("model"), tracker.get_slot("frame_size"), tracker.get_slot("frame_type"), tracker.get_slot("frame_finishing"), tracker.get_slot("frame_orientation"))
dispatcher.utter_message("Your response has been loaded.")
return []
database_connector.py
import psycopg2
def DataUpdate(art_type_entry, size_entry, frame_entry, finishing_entry, orientation_entry):
'''
Pushes Descriptive Analytics Data to the Database
'''
db = psycopg2.connect(
host="localhost",
database="Rasa_Chatbot",
user="postgres",
password="postgres"
)
mycursor = db.connect()
postgres_insert_query = """INSERT INTO rasainfo(model,size,type,orientation,finishing) VALUES (%s,%s,%s,%s,%s);""".format(art_type_entry,size_entry, frame_entry, finishing_entry, orientation_entry)
mycursor.execute(postgres_insert_query)
db.commit()
print("Record inserted successfully into table")
You need to define this in your endpoints.yml
tracker_store:
type: SQL
dialect: "postgresql" # the dialect used to interact with the db
url: "postgres"
db: "rasa" # path to your db
username: # username used for authentication
password: # password used for authentication
query: # optional dictionary to be added as a query string to the connection URL
driver: my-driver

cannot set position of wx.frame on openbox

i am playing with wxPython and try to set position of frame:
import wx
app = wx.App()
p = wx.Point(200, 200)
frame = wx.Frame(None, title = 'test position', pos = p)
frame.Show(True)
print('frame position: ', frame.GetPosition())
app.MainLoop()
even though print('frame position: ', frame.GetPosition()) shows the correct postion, the frame is shown in top left corner of screen.
Alternatively i tried
frame.SetPosition(p)
frame.Move(p)
without success.
my environment: ArchLinux 5.3.13, python 3.8.0, wxpython 4.0.7, openbox 3.6.1
On cinnamom the code works as expected. How to solve this on openbox?
edit 07,12,2019:
i could set postion of a dialog in openbox config ~/.config/openbox/rc.xml:
<application name="fahrplan.py"
class="Fahrplan.py"
groupname="fahrplan.py"
groupclass="Fahrplan.py"
title="Fahrplan *"
type="dialog">
<position force="no">
<x>760</x>
<y>415</y>
</position>
</application>
i got name, class etc. from obxprop. x and y are calculated to center a dialog of 400 x 250 px on screen of 1920 x 1080 px.
This static solution is not suitable for me. I want to place dynamically generated popups.
I had the same problem under Windows and played around with the style flags. With wxICONIZE sytle set active the window finally used the positioning information
The position is provided to the window manager as a "hint". It is totally up to the window manager whether it will actually honor the hint or not. Check the openbox settings or preferences and see if there is anything relevant that can be changed.

How can I draw a tree with TikZ using PyLatex?

I have a homework assignment where I need to generate a PDF file containing a tree image using Python 3 and LaTeX's tikz package. It'd be really helpful if someone has a simple sample code.
I need to know how to create a child node.
from pylatex import (Document, TikZ, TikZNode, TikZDraw,TikZCoordinate,TikZUserPath, TikZOptions)
doc = Document()
# add our sample drawings
with doc.create(TikZ()) as pic:
node_kwargs = {'align': 'center', 'shape' : 'circle','minimum size': '50pt', 'fill': 'black!20'}
# create our test node
box = TikZNode(text='My block',
handle='box',
options=TikZOptions('draw',
'rounded corners',
**node_kwargs))
n_kw = {'shape' : 'circle',
'minimum size': '50pt',
'fill': 'black!20'}
#I DONT KNOW HOW TO PUT A CHILD NODE !!
box.child = TikZNode(text='My block 2',
handle='box2',
options=TikZOptions('draw',
'rounded corners',
**node_kwargs))
pic.append(box)
pic.append(box.child)
doc.generate_pdf('tikzdraw', clean_tex=False)

Kivy FileChooserListView - Modifying the display of the file list?

I was wondering if anyone knew how to add numbers (purely for reference) to Kivy's FileChooserListView such that the file list is displayed like:
# Name Size
1. File 1 2k
2. File 2 2k
3. File 3 2k
...
OK, it's not a perfect answer but here's what I tried to do:
First thing was to edit kivy's default filechooser.py file. Find this section:
ctx = {'name': basename(fn),
'get_nice_size': get_nice_size,
'path': fn,
'controller': wself,
'isdir': self.file_system.is_dir(fn),
'parent': parent,
'sep': sep}
and change it to:
ctx = {'name': basename(fn),
'get_nice_size': get_nice_size,
'path': fn,
'controller': wself,
'isdir': self.file_system.is_dir(fn),
'parent': parent,
'sep': sep,
'index': index}
Next up, find kivy's style.kv file (you could probably create a custom class to do this but I was being lazy!). Look for this section [FileListEntry#FloatLayout+TreeViewNode]:
I then took this part:
Label:
id: filename
text_size: self.width, None
halign: 'left'
shorten: True
text: ctx.name
and changed it to:
Label:
id: filename
text_size: self.width, None
halign: 'left'
shorten: True
text: "{}. {}".format(ctx.index, ctx.name)
As per my comment above, it seems to throw an error if you try to navigate folders.
It may be the case that one of the kivy experts knows a better way of doing this.
I know this is quite late but to complete the answer of elParaguayo, you also have to replace the lines
pardir = self._create_entry_widget(dict(
name=back, size='', path=new_path, controller=ref(self),
isdir=True, parent=None, sep=sep,
get_nice_size=lambda: ''))
with
pardir = self._create_entry_widget(dict(
name=back, size='', path=new_path, controller=ref(self),
isdir=True, parent=None, sep=sep,
get_nice_size=lambda: '', index= 0))
(be careful there are 2 occurences of these lines). This is what throws the exception when you navigate: the parent directory ../ is not created with the same lines as the other files.
Also, I would advise to create a local copy of filechooser.py and style.kv and load them into your app instead of modifying the source code of the kivy modules.

How to get All thread ids and names of a process

I wrote a program using c# that list all running process in window, i want to list all running process in window, and in each process, i want to list all running thread (both name and id). i can't find any function on Window Api to list thread name, how can i do it ?
Example: plz look at this picture:
lh4.googleusercontent.com/HwP6dpts5uRPJIElH7DgUd3x95aQKO36tynkfsaDMBbM=w607-h553-no
in the image, i want to list
FireFox ID: 123
Google Chorme ID 456
...
Explorer ID 789
Documents ID 654
Temp ID 231
...
Thankyou !
You can use the Systems.Diagnostic namespace and then use:
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
Source
More info

Resources