I'm trying to implement a desktop application. However, I'm encountering some issues.
When I try to insert my data using the DataTable implementation, the layout of my data table may not appear at the top or the layout and length of the data table may affect the layout of other components after inserting the data.
If you know how to solve this problem, I would appreciate your advice or provide me with reference documentation. Thank you very much.
Here's the example code I wrote
import flet as ft
class MainWindow(UserControl):
def build(self):
self.Entry_URL = TextField(label = 'input keyword', width = 300)
searchLine = Row(spacing = 70, controls = [
ElevatedButton(text = 'btn1', on_click = self.startSpider),
ElevatedButton(text = 'btn2', disabled = True)])
ControlLine = Row(spacing = 70, controls = [
ElevatedButton(text = 'btn3'),
ElevatedButton(text = 'btn4', disabled = True)])
self.Table = DataTable(
columns = [DataColumn(Checkbox(label = 'Info')),
DataColumn(Text('col1')),
DataColumn(Text('col2')),
DataColumn(Text('col3')),
],
)
return Column(controls = [Row(controls = [self.Entry_URL, self.Table]), searchLine, ControlLine,
ElevatedButton(text = 'quit', width = 300), ], scroll = ft.ScrollMode.AUTO)
def startSpider(self, event):
# if (not self.Entry_URL.value):
# return
self.Table.rows.append(ft.DataRow(
cells = [
ft.DataCell(ft.Text("John", text_align = ft.TextAlign.CENTER)),
ft.DataCell(ft.Text("Smith", text_align = ft.TextAlign.CENTER)),
ft.DataCell(ft.Text("43", text_align = ft.TextAlign.CENTER)),
ft.DataCell(ft.Text("43", text_align = ft.TextAlign.CENTER), ),
],
),)
self.update()
def main(page:Page):
page.title = 'Test'
page.padding = 20
page.add(MainWindows())
ft.app(target = main)
Related
I'm working on a npyscreen interface and want a popup with a folderselection, but I don't know how to do it. I have a working basic Interface and within menu are 2 Options ("C1" and "C2"). For example: Select C1 -> hit enter -> Popup appears and let me pick a folder. At the second step, the selection should be displayed at the status box:
"C1: [selected_folder]"
This is the code for the Interface:
class qmkdevice(npyscreen.NPSApp):
def main(self):
F = npyscreen.Form(name = "DEVICE", lines=20, columns=53)
column_height = terminal_dimensions()[0] -9
widget_top = F.add(
Column,
name = "MENU",
relx = 2,
rely = 7,
max_width = 48,
max_height = 11,
)
widget_bottom = F.add(
Column,
name = "STATUS",
relx = 2,
rely = 2,
max_width = 48,
max_height = 5,
)
widget_top.values = ["C1", "C2"]
widget_bottom.values = ["C1: [ ]", "C2: [ ]"]
F.edit()
print(ms.get_selected_objects())
class Column(npyscreen.BoxTitle):
def resize(self):
self.max_height = int(0.73 * terminal_dimensions()[0])
def terminal_dimensions():
return curses.initscr().getmaxyx()
Thanks for your help.
I have created an "input form" with several ipywidget boxes. I want to be able to reference all the values to create a new dataframe.
I'm currently doing this in a horrible way.
portfolio_df = pd.DataFrame([[VBox1.children[0].value, VBox2.children[0].value, VBox3.children[0].value, VBox4.children[0].value]],
columns=['Product Name','Units','Price', 'Invested Amount'])
row_2 = [VBox1.children[1].value, VBox2.children[1].value, VBox3.children[1].value, VBox4.children[21].value]
portfolio_df.loc[len(portfolio_df)] = row_2
row_3 = [VBox1.children[2].value, VBox2.children[2].value, VBox3.children[2].value, VBox4.children[2].value]
portfolio_df.loc[len(portfolio_df)] = row_3
row_4 = [VBox1.children[3].value, VBox2.children[3].value, VBox3.children[3].value, VBox4.children[3].value]
portfolio_df.loc[len(portfolio_df)] = row_4
and so on up till row 23 in this instance !! (but the length will vary up to the number of children within a VBox)
I suspect I can do this more pythonically using a for loop but cant figure it out.
Full code as per requests (I've edited columns so my live data is different but this is exact replica of the set up)
import pandas as pd
import numpy as np
import datetime as dt
import ipywidgets as ipw
from ipywidgets import *
barrier_list = pd.DataFrame(np.random.randn(24, 4), columns=('Product
Name','ISIN','A','B'))
barrier_list= barrier_list.astype(str)
dd_list = []
for i in range(len(barrier_list['Product Name'])):
dropdown = ipw.FloatText(description=barrier_list['ISIN'][i],
value=barrier_list['Product Name'][i],
disabled=False,
layout = {'width':'350px'})
dropdown.style.description_width = 'initial'
dd_list.append(dropdown)
dd_list1 = []
for i in range(len(barrier_list['Product Name'])):
dropdown1 = ipw.FloatText(description='Units',
value=0,
layout = {'width':'200px'})
dd_list1.append(dropdown1)
dd_list2 = []
for i in range(len(barrier_list['Product Name'])):
dropdown2 = ipw.FloatText(description='Price',
value=0,
layout = {'width':'200px'})
dd_list2.append(dropdown2)
dd_list3 = []
for i in range(len(barrier_list['Product Name'])):
dropdown3 = ipw.FloatText(description='Value',
value=0,
layout = {'width':'200px'})
dd_list3.append(dropdown3)
VBox1 = ipw.VBox(dd_list)
VBox2 = ipw.VBox(dd_list1)
VBox3 = ipw.VBox(dd_list2)
VBox4 = ipw.VBox(dd_list3)
HBox = widgets.HBox([VBox1, VBox2, VBox3, VBox4])
solved this one by looping through the VBoxes one by one and then concatenating the dataframes into one main one.
product_df = pd.DataFrame()
for i in range(len(dd_list)):
product_name_df = pd.DataFrame([[VBox1.children[i].value]],columns=
['Product Name'])
product_df = product_df.append(product_name_df)
unit_df = pd.DataFrame()
for i in range(len(dd_list)):
unit_amount_df = pd.DataFrame([[VBox2.children[i].value]],columns=
['Units'])
unit_df = unit_df.append(unit_amount_df)
price_df = pd.DataFrame()
for i in range(len(dd_list)):
price_amount_df = pd.DataFrame([[VBox3.children[i].value]],columns=
['Price'])
price_df = price_df.append(price_amount_df)
value_df = pd.DataFrame()
for i in range(len(dd_list)):
value_amount_df = pd.DataFrame([[VBox4.children[i].value]],columns=
['Value'])
value_df = value_df.append(value_amount_df)
df_list = [product_df.reset_index(drop=True),unit_df.reset_index(drop=True),
price_df.reset_ind ex(drop=True),value_df.reset_index(drop=True)]
portfolio_df = pd.concat((df_list), axis=1)
portfolio_df
I copied some HTML from Quasar for a page layout with a drawer and can not figure out how to toggle the drawer (sidebar). The button works to hide the drawer, but can not get it visible again. Or if you have an example or can point me in direction of a non-Quasar sidebar that works in a similar manner, that would be helpful.
def show_drawer(self,msg):
self.wbDrawer.show = True
def toggle_show_drawer(self, msg):
self.wbDrawer.show = not self.wbDrawer.show
def toggle_visible_drawer(self, msg):
if self.wbDrawerDiv.visibility_state == 'visible':
self.wbDrawerDiv.set_class('invisible')
self.wbDrawerDiv.visibility_state = 'invisible'
else:
self.wbDrawerDiv.set_class('visible')
self.wbDrawerDiv.visibility_state = 'visible'
self.btn1.visibility_state = 'visible'
def quasar_print():
wp = jp.QuasarPage()
c = jp.parse_html(html_string, a=wp)
for i in c.commands:
print(i)
return wp
def quasar_page():
wp = jp.QuasarPage()
wp.data["drawer"] = "open"
root = jp.Div(a=wp)
c1 = jp.Div(classes='q-pa-md', a=root)
wbLayout = jp.QLayout(view='hHh Lpr lff', container=True, style='height: 300px', classes='shadow-2 rounded-borders', a=c1)
wbHeader = jp.QHeader(elevated=True, classes='bg-black', a=wbLayout)
wbToolbar = jp.QToolbar(a=wbHeader)
wbToolbarBtn = jp.QBtn(flat=True, round=True, dense=True, icon='menu', a=wbToolbar,click=toggle_visible_drawer)
wbToolbarTitle = jp.QToolbarTitle(a=wbToolbar, text='Header')
wbDrawerDiv = jp.Div(a=wbLayout)
wbDrawer = jp.QDrawer( width=200, breakpoint=500, bordered=True, classes='bg-grey-3', a=wbDrawerDiv, model=[wp, 'drawer'])
wbScrollArea = jp.QScrollArea(classes='fit', a=wbDrawer)
c9 = jp.QList(a=wbScrollArea)
c10 = jp.Div(a=c9, text='scroll area')
btn1 = jp.Button(text='Hide me', a=wbScrollArea)
wbPageContainer = jp.QPageContainer(a=wbLayout)
wbPage = jp.QPage(padding=True, a=wbPageContainer)
pageText = jp.Div(a=wbPage, text='page container')
btnSideBar = jp.Button(text="button on SideBar", a=wbScrollArea)
# try both visible and show
btnVisible = jp.QBtn(text="toggle_visible_drawer", a=wbPage,click=toggle_visible_drawer)
btnShow = jp.QBtn(text="toggle_visible_drawer", a=wbPage,click=toggle_show_drawer)
return wp
jp.justpy(quasar_page)
import justpy as jp
def toggle_visible_drawer(self, msg):
self.drawer.value = not self.drawer.value
def quasar_page():
wp = jp.QuasarPage()
btn_drawer = jp.QBtn(
flat=True,
round=True,
dense=True,
icon="menu",
a=wp,
click=toggle_visible_drawer,
)
wp_layout = jp.QLayout(a=wp)
PageContainer = jp.QPageContainer(a=wp_layout)
pageText = jp.Div(a=PageContainer, text="page container")
drawer = jp.QDrawer(
width=200,
breakpoint=500,
bordered=True,
a=wp_layout,
)
btn_drawer.drawer = drawer
ScrollArea = jp.QScrollArea(classes="fit", a=drawer)
c2 = jp.Div(a=ScrollArea, text="scroll area left")
return wp
jp.justpy(quasar_page)
https://github.com/justpy-org/justpy/blob/9aa6a8264da7317f25ed3a01266d7d5dca99e0d9/justpy/quasarcomponents.py#L2651
I would like to know how to query a selection entered into a text field group, so I can do something with it. I have created a window to just translate an object that I loaded in the text field. The error is that cont is not defined.
import maya.cmds as cmds
import maya.mel as ml
def set_selected_name (text_field):
cont = cmds.ls (selection = True)
text_field = cmds.textFieldButtonGrp (text_field, edit = True,
text = ''.join (cont),
buttonLabel = '<<<<',
backgroundColor = [0.5098039215686274,
0.5098039215686274,
0.5098039215686274])
return text_field
def translate_x(cont):
cmds.setAttr( cont[0] + '.translateX', 10)
def translate_y():
cmds.setAttr( cont[0] + '.translateY', 10)
def translate_z(*Args):
cmds.setAttr( cont[0] + '.translateZ', 10)
if cmds.window ('window1', q = 1, ex = 1):
cmds.deleteUI ('window1')
cmds.window ('window1',
title = 'Translate Attr',
sizeable = 0,
resizeToFitChildren = True,
menuBar = 1)
cmds.rowLayout (numberOfColumns = 3)
cmds.separator (style = 'double',
height = 6)
cmds.rowLayout (parent = 'window1',
numberOfColumns = 4)
ddd = cmds.textFieldButtonGrp (editable = False,
text = 'Obj',
backgroundColor = [0.029495689326314183,
0.5488975356679637,
0.5488975356679637],
buttonLabel = '<<<<')
cmds.textFieldButtonGrp (ddd, edit = True,
buttonCommand = 'set_selected_name (ddd)')
cmds.separator (style = 'double',
height = 6)
cmds.rowLayout (parent = 'window1',
numberOfColumns = 6)
cmds.separator (style = 'double',
height = 6)
cmds.button (command = 'translate_y()',
backgroundColor = [1.0,
0.7300068665598535,
0.7300068665598535],
label = 'Translate Y')
cmds.separator (style = 'double',
height = 6)
cmds.button (command = 'translate_x(cont)',
backgroundColor = [1.0,
0.9733272297245746,
0.7333333333333333],
label = 'Translate X')
cmds.separator (style = 'double',
height = 6)
cmds.button (command = 'translate_z()',
backgroundColor = [0.7333333333333333,
1.0,
0.7600061036087586],
label = 'Translate Z')
cmds.columnLayout (parent = 'window1')
cmds.separator (style = 'double',
height = 3)
cmds.showWindow ('window1')
# ~ BABLAAM ~
Create any object you like, loaded into the text field and then try to translate with buttons.
You have several problems in your code.
In the translate commands you always use cont[0]. cont is only used in the function set_selected_name() and is a local variable what means it is deleted as soon as the function is completed.
You can use a string as command in the button command, but this only works with static values. You should use lambdas to use functions with arguments.
The cont Problem can be solved by using a global variable, but it shouldn't since global variables are the source of all evil. A much more elegant way would be to enclose you UI in one python class and use instance variables to get the selection.
I have adjusted the code to add the class as you recommended but still having the same issue. By not using the quotes in the button command I get this error when I try to run the script, instead of getting it when I press the button.
Error: NameError: file line 28: name 'translate_x' is not defined
Can you please write a workable version, or place a link from the internet that shows a method using the class and calling methods using buttons? Nothing I have found from my internet search has anything like this and I'm just guessing where thigs should go.
import maya.cmds as cmds
import maya.mel as ml
class move_obj(object):
def __int__(self, *args):
self.cont = cont
self.trans = trans
def set_selected_name(self, *args):
cont = cmds.ls (selection = True)
return cont
def translate_x(self, *args):
trans = cmds.setAttr( cont[0] + '.translateX', 10)
print trans
if cmds.window ('window1', q = 1, ex = 1):
cmds.deleteUI ('window1')
cmds.window ('window1',
title = 'Translate Attr',
sizeable = 0,
resizeToFitChildren = True,
menuBar = 1)
cmds.rowLayout (numberOfColumns = 3)
cmds.button (command = translate_x,
backgroundColor = [1.0,
0.7300068665598535,
0.7300068665598535],
label = 'Translate X')
cmds.showWindow ('window1')
So guys here's my problem I would like to fill my table cells with different colors from the default ones... I've checked the docs and made multiple searches on google but couldn´t find something helpful.
Here's my code:
def create_default_slide(user, ppt, shapes, experience_text, skills):
max_height = Inches(ppt.slide_height.inches - kBASE_BOTTOM_INCHES)
height = Inches(kBASE_TOP_INCHES)
left = Inches(0)
top = Inches(.1)
shapes.add_picture(kASSETS_DIRECTORY + "ppt_softinsa_header.png",
left, top,
height=height,
width=ppt.slide_width)
# shapes.title.text = "curriculum vitae – Resource {}".format(1)
title_box = shapes.add_textbox(left=Inches(0.5),
top=Inches(kBASE_TOP_INCHES * 1.5),
width=ppt.slide_width, height=Pt(px_to_pt(50)))
title_box.text = u'Curriculum Vitae – {}'.format(user.name)
info_table = shapes.add_table(rows=3, cols=2,
left=Inches(.2), top=Inches(kBASE_TOP_INCHES * 3),
width=200, height=200).table
# set table properties
info_table.first_row = False
info_table.horz_banding = False
info_table.vert_banding = True
# set column widths
info_table.columns[0].width = Inches(1.4)
info_table.columns[1].width = Inches(3)
rows_number = len(info_table.rows)
user_info = user.basic_info()
for i in range(rows_number):
info_table.cell(i, 0).text = kINTRODUCTION_COLUMN[i]
info_table.cell(i, 1).text = user_info[i]
# sets the font size for the content info of the table
info_cell = info_table.rows[i].cells[1]
info_cell.text_frame.paragraphs[0].font.size = Pt(kCELL_INFO_FONT_SIZE)
experiences_table = shapes.add_table(rows=2, cols=1,
left=Inches(5), top=Inches(kBASE_TOP_INCHES * 3),
width=200, height=Inches(9.9).).table
# set table dimensions
experiences_table.columns[0].width = Inches(4.7)
experiences_table.rows[0].height = Inches(kTABLE_HEADER_INCHES)
# set cell font size
experience_title_cell = experiences_table.rows[0].cells[0]
experience_cell = experiences_table.rows[1].cells[0]
experience_cell.text_frame.paragraphs[0].font.size = Pt(kCELL_INFO_FONT_SIZE)
# set header
# "Professional Experience"
experiences_table.cell(0, 0).text = u"Experiência Profissional"
import re
expr = re.compile(ur'- .+ até [^\n]+\n')
for experience_item in experience_text:
if expr.search(experience_item):
lines = experience_item.split('\n')
paragraph = experiences_table.cell(1, 0).text_frame.paragraphs[0]
bold_run = paragraph.add_run()
bold_run.font.bold = True
bold_run.text = lines[0] + '\n'
rest_run = paragraph.add_run()
rest_run.font.bold = False
rest_run.text = '\n'.join(lines[1:]) + '\n'
else:
experiences_table.cell(1, 0).text = '\n'.join(experience_text)
education_table = shapes.add_table(rows=2, cols=1,
left=Inches(.2), top=Inches(kBASE_TOP_INCHES * 5.5),
width=200, height=Inches(3.2)).table
# set column widths
education_table.columns[0].width = Inches(4.4)
education_table.rows[0].height = Inches(kTABLE_HEADER_INCHES)
# set header title
education_table.cell(0, 0).text = "Formação"
# set font size for table info
education_cell = education_table.rows[1].cells[0]
education_cell.text_frame.paragraphs[0].font.size = Pt(kCELL_INFO_FONT_SIZE)
user_education = user.education_info()
education_info = []
skills_table = shapes.add_table(rows=2, cols=1,
left=Inches(.2), top=Inches(kBASE_TOP_INCHES * 9.5),
width=200, height=Inches(3.3)).table
# set column widths
skills_table.columns[0].width = Inches(4.4)
skills_table.rows[0].height = Inches(kTABLE_HEADER_INCHES)
# set header title
skills_table.cell(0, 0).text = "Competências"
# set font size for table info
skills_cell = skills_table.rows[1].cells[0]
skills_cell.text_frame.paragraphs[0].font.size = Pt(kCELL_INFO_FONT_SIZE)
skills_table.cell(1, 0).text = "".join(skills)
# TODO: check if it always on object or if it can be a list
for course in user_education['courses']:
education_info.append(
u'{} de {}'.format(
DEGREE_LEVELS[course['degree']] if course['degree'] else course['degree'],
course['name']
)
)
user_certifications = user_education['certifications']
if len(user_certifications) is not 0:
education_info.append(
u'Certificações: {}'.format(u', '.join(user_certifications))
)
bullets = ""
for i in range(len(education_info)):
bullets += u'- {}\n'.format(education_info[i])
education_table.cell(1, 0).text = bullets
text_box = shapes.add_textbox(left=Inches(0),
top=Inches(ppt.slide_height.inches - kBASE_BOTTOM_INCHES),
width=ppt.slide_width, height=Pt(px_to_pt(50)))
# text_box.text = "Proposta Nº{} - Confidencial".format("P63838/1")
p = text_box.text_frame.add_paragraph()
p.text = u'Confidencial' # "Proposta Nº{} - Confidencial".format("P63838/1")
p.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
p.font.size = Pt(8)
shapes.add_picture(kASSETS_DIRECTORY + "ppt_footer.png",
left=Inches(ppt.slide_width.inches - 2.5),
top=Inches(ppt.slide_height.inches - (kBASE_BOTTOM_INCHES / 2)),
height=Pt(px_to_pt(10)),
width=Pt(px_to_pt(185)))
return shapes
This piece of code sets the color of a single cell in a table:
from pptx.dml.color import RGBColor
# cell is a table cell
# set fill type to solid color first
cell.fill.solid()
# set foreground (fill) color to a specific RGB color
cell.fill.fore_color.rgb = RGBColor(0xFB, 0x8F, 0x00)
I got this piece of code from an issue on the github page of the project. Sadly I don't know how to change the border color and width using this library.