How to handle Shape when creating a theme for Material Design 3 for compose - material-design

I currently have an app written in jetpack compose which uses Material-Theming-Support from androidx.compose.material:material.
from / import androidx.compose.material.MaterialTheme
#Composable
fun MaterialTheme(
colors: Colors = MaterialTheme.colors,
typography: Typography = MaterialTheme.typography,
shapes: Shapes = MaterialTheme.shapes,
content: #Composable () -> Unit
)
I now plan to migrate to Material3: androidx.compose.material3:material3 (still in alpha, i know).
However, the theme-composable now doesn't allow any shapes anymore
from / import androidx.compose.material3.MaterialTheme
#Composable
fun MaterialTheme(
colorScheme: ColorScheme = MaterialTheme.colorScheme,
typography: Typography = MaterialTheme.typography,
content: #Composable () -> Unit
)
What should i do now with my old shape definitions?
The material-website only talks how to do that in xml & the old view-system.

Material Design 3 / Material You still don't have shapes.
So to use shapes create composition local,
In directory ui/theme create Shape.kt Kotlin file in that file paste following code
Shape.kt
data class Shape(
val default: RoundedCornerShape = RoundedCornerShape(0.dp),
val small: RoundedCornerShape = RoundedCornerShape(4.dp),
val medium: RoundedCornerShape = RoundedCornerShape(8.dp),
val large: RoundedCornerShape = RoundedCornerShape(16.dp)
)
val LocalShape = compositionLocalOf { Shape() }
val MaterialTheme.shapeScheme: Shape
#Composable
#ReadOnlyComposable
get() = LocalShape.current
Now, to use shape in compose
shape = MaterialTheme.shapeScheme.large
eg. In card compose
Card(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(all = 16.dp),
shape = MaterialTheme.shapeScheme.large,
backgroundColor = MaterialTheme.colorScheme.surface,
border = BorderStroke(width = 1.dp, color = MaterialTheme.colorScheme.inverseOnSurface),
elevation = 1.dp
) {
...
}
Edit :
Check this

Related

R Shiny Dashboard Header dropdown buttons lead to scrolling

The buttons in the header of my shiny dashboard should be easy to see and press. However, at the moment the dropdownbuttons pop up within the header and people have to scroll in order to see the buttons.
Below you will find a reproducible code sample.
Here is some further information on my session:
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
shinythemes_1.1.2
shinyWidgets_0.5.3
shinyBS_0.61
if (interactive()) {
library(shiny)
require(dplyr)
require(shinydashboard)
require(shinyWidgets)
library(shinythemes)
# A dashboard header with 3 dropdown menus
header <- dashboardHeader(
title = "Dashboard Demo",
tags$li(class = "dropdown",tags$br(),
dropdownButton(inputId = "mydropdown",label = "",# style="minimal",
# label="Language",
circle = FALSE,
icon = icon("globe"),#,status = "primary",
badgeStatus = "success",
prettyRadioButtons(inputId = "selected_language", label="",
choiceNames = list(
HTML("<font color='black'>Deutsch</font>"),
tags$span(style = "color:black", "English")
),
choiceValues = c( "de", "en"),
# inline=TRUE,
selected = "en"
)
)# useShinyalert(), # Set up shinyalert #
,
block = TRUE) ,
tags$li(class = "dropdown",introjsUI(), tags$br(),actionBttn(inputId = "Help",
# color = "primary",
style =
"minimal",
icon = icon("question", lib="font-awesome"),label ="Help", size="sm"),
block = TRUE),tags$li( class = "dropdown",tags$br(),
introBox(dropdownMenu(
type = "notifications",
icon = icon("envelope", lib = "glyphicon"),
badgeStatus = NULL,
headerText = "App maintainer contact:",
notificationItem("TestMailAdress", icon("envelope", lib = "glyphicon"))
), data.step=5, data.intro = "Any further questions? Contact us!")
))
shinyApp(
ui = dashboardPage(
header,
dashboardSidebar(),
dashboardBody()
),
server = function(input, output) { }
)
}
# }
thanks a lot for your answers. I figured it out myself. The introBox referring to the header button messed things up. So without the helping window it works... still would be nice to have the introBox working, but I guess it is just not supported yet...
if (interactive()) {
library(shiny)
require(dplyr)
require(shinydashboard)
require(shinyWidgets)
library(shinythemes)
# A dashboard header with 3 dropdown menus
header <- dashboardHeader(
title = "Dashboard Demo",
tags$li(class = "dropdown",tags$br(),
dropdownButton(inputId = "mydropdown",label = "",# style="minimal",
# label="Language",
circle = FALSE,
icon = icon("globe"),#,status = "primary",
badgeStatus = "success",
prettyRadioButtons(inputId = "selected_language", label="",
choiceNames = list(
HTML("<font color='black'>Deutsch</font>"),
tags$span(style = "color:black", "English")
),
choiceValues = c( "de", "en"),
# inline=TRUE,
selected = "en"
)
)# useShinyalert(), # Set up shinyalert #
,
block = TRUE) ,
tags$li(class = "dropdown",introjsUI(), tags$br(),actionBttn(inputId = "Help",
# color = "primary",
style =
"minimal",
icon = icon("question", lib="font-awesome"),label ="Help", size="sm"),
block = TRUE),tags$li( class = "dropdown",tags$br(),
dropdownMenu(
type = "notifications",
icon = icon("envelope", lib = "glyphicon"),
badgeStatus = NULL,
headerText = "App maintainer contact:",
notificationItem("TestMailAdress", icon("envelope", lib = "glyphicon"))
)
))
shinyApp(
ui = dashboardPage(
header,
dashboardSidebar(),
dashboardBody()
),
server = function(input, output) { }
)
}
# }

Why doesn't my font.name property affect the fonts on ppt made using Python-pptx? I always get arial font

So I'm trying to write some program to convert html to pptx using Python.
I'm using some code to parse through the file and then format text at run level.
I am using 2 textframes on a blank slide to work, the first textframe is used for title and 2nd one is used for rendering the body of html.
But no matter what I do (Paragraph.font.name or run.font.name), I am always getting Arial font in my 2nd textframe.
I've tried to update the fontnames by looping over tf.paragraphs and also by looping over all runs (paragraph.runs) nothing seems to work.
Here is my function which I use for setting the font
def setFont(font,tags,fontStyle,size):
font.language_id = MSO_LANGUAGE_ID.HEBREW
font.size = Pt(size)
font.name = fontStyle
for tag in tags:
if tag == 'b':
font.bold = True
elif tag == 'i':
font.italic = True
elif tag == 'u':
font.underline = True
return font
and here is my main calling function (I've removed some other calls which are not directly related to python-pptx)
def makeSlide(prs,title,body,fontStyle,titleSize,bodySize):
#Add title Slide
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)
width = height = Inches(8)
txBox = slide.shapes.add_textbox(Inches(1), Inches(0.5), Inches(8), Inches(1))
tf = txBox.text_frame
tf.text = title
tf.paragraphs[0].font.size=Pt(titleSize)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = RGBColor(255,0,0)
tf.paragraphs[0].font.name = fontStyle
tf.paragraphs[0].alignment = PP_ALIGN.CENTER
styles = MY_CUSTOM_HTML_BODY_PARSER() #Removed this part from here, its just a parser which gives output in a desired format
#Start 2nd textbox for body
txBox2 = slide.shapes.add_textbox(Inches(0.5), Inches(1.7), Inches(9), Inches(5.5))
tf = txBox2.text_frame
tf.clear()
tf.word_wrap = True
tf.paragraphs[0].text = ''
tf.paragraphs[0].font.name = fontStyle
paragraph = tf.add_paragraph()
paragraph.alignment = alignment
#Loop over styles (Tag info and render pptx accordingly)
new_line = True
level = 0
number = 0
for _ in styles:
#Can ignore this part, I'm just checking to see if I have to go on a new line or not
if _ == '\n':
paragraph = tf.add_paragraph()
paragraph.alignment = alignment
new_line = True
else:
tags = _[1]
#Can also ignore this, I'm checking to see if I have to be on next level in lists or not
#(I use custom bullet function, since python-pptx doesn't have a function for numbered bullets.
if _[1].count('ul') > 1 or _[1].count('ol') > 1 or _[1].count('ul') + _[1].count('ol') > 1:
level = 1
if new_line:
paragraph.level = level
level = 0
else:
paragraph = tf.add_paragraph()
paragraph.alignment = alignment
paragraph.level = level
level = 0
new_line = True
if new_line:
run = paragraph.add_run()
#Custom bullet function as u can see I send in fontStyle here and apply style inside function
run,number = addBullets(run,tags,bodySize-3,number,fontStyle)
new_line = False
run = paragraph.add_run()
run.text = parser.words_styles[_[0]][0]
font = run.font
#SetFont function Defined above
font = setFont(font,tags,fontStyle,bodySize)
new_line = False
for paragraph in tf.paragraphs:
paragraph.font.name = fontStyle
for run in paragraph.runs:
if run.font.name != fontStyle:
print(run.text)
#return slide
return slide
I'm not quite sure where I am doing wrong, would appreciate any help, I can clean up code more if that's needed.

How to disable anti-aliasing in QGIS export (pyqgis)

I'm trying to save a print layout as BMP in QGIS through python code, but want to turn of antialiasing and can't seem to figure out how to do it
def saveImage(self, layout, filename="defaultexport", extension=".bmp"):
"""Saves given layout as an image"""
filefolder = get_save_location()
filepath = os.path.join(filefolder, filename + extension)
if not os.path.isdir(filefolder):
os.makedirs(filefolder)
exporter = QgsLayoutExporter(layout)
context = QgsLayoutRenderContext(layout)
context.setFlag(context.FlagAntialiasing, False)
export_settings = exporter.ImageExportSettings()
export_settings.generateWorldFile = False
export_settings.dpi = 25
export_settings.flags = context.FlagAntialiasing
result = exporter.exportToImage(filepath, export_settings)
Is what I have. I have no idea what I'm doing with the QgsLayoutRenderContext, but it's about the only thing that seemed like it might do it. Saving manually and turning of the AA setting in save dialog works fine, but I need to do it through pyqgis
Revisting this project knowing some more Python and PyQt5 stuff this was an easy one
exporter = QgsLayoutExporter(layout)
context = QgsLayoutRenderContext(layout)
context.setFlag(context.FlagAntialiasing, False)
export_settings = exporter.ImageExportSettings()
export_settings.generateWorldFile = False
export_settings.dpi = 25
export_settings.flags = context.flags()
result = exporter.exportToImage(self.filepath, export_settings)
Needed to use context.flags()

How to dynamically add/remove widgets from Gtk 3 Window

I am using python3 with Gtk3 and i need to basically remove some widgets from my Gtk.Window and replace them with other widgets when a Gtk.Button is clicked.I have tried using Gtk.ListBoxes with Gtk.ListBoxRows and so far i can remove all the Rows from the ListBox but when i try to add them back,essentially nothing happens.This is part of my code:
def left_view(self, box):
listbox = box
row0 = Gtk.ListBoxRow()
row0.set_halign(Gtk.Align.START)
listbox.add(row0)
#Adding HorizontalBox to place widgets
hbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL)
row0.add(hbox)
prod_name = Gtk.Label()
stock_count = Gtk.Label()
prod_name.set_text('Product Name')
stock_count.set_text('Stock ')
self.prod_name_input = Gtk.Entry()
self.stock_count_input = Gtk.Entry()
#Packaging 101
hbox.pack_start(prod_name, True, True, 0)
hbox.pack_start(self.prod_name_input, True, True, 0)
hbox.pack_start(stock_count, True, True, 0)
hbox.pack_start(self.stock_count_input, True, True, 0)
the function will be given a Gtk.ListBox as the argument.And what i have so far when trying to remove() and add() things to the listbox is:
def remover(self,widget):
vbox = widget.get_parent()
base = vbox.get_parent()
children = base.get_children()
listbox = children[1]
for row in listbox.get_children():
listbox.remove(row)
with open('product_info.json', 'r') as d:
data = d.read()
j = json.loads(data)
d.close()
self.keys = list(j.keys())
row0 = Gtk.ListBoxRow()
listbox.add_child(row0)
scrollwindow = Gtk.ScrolledWindow()
scrollwindow.set_hexpand(True)
scrollwindow.set_vexpand(True)
row0.add_child(scrollwindow)
tview = Gtk.TextView()
scrollwindow.add(tview)
textbuffer = tview.get_buffer()
for item in range(0, len(self.keys)):
textbuffer.insert_at_cursor(' %s\t\t %s \n' %(item, self.keys[item]))
By the way,If there is a simpler way of just replacing widgets on the go in PyGObject,please do let me know coz most of the answers that i saw on the related questions where totally useless
I was baffled by this, too. It turned out the created widgets must be explicitly shown with show() or show_all(). In your case:
row0.show_all()
as the last statement.

Excel writer Module for Play Framework v2.x

How it would be possible to generate Excell reports from Play Framework v2.x(Scala). I found there's a Play-Excel module but it supports PlayFramework v1.0. Is there anything suitable for v2.x?
In the end I choose to use Spoiwo. Scala Wrapper for Apache POI. It has a neat starting guide. However, doesn't have an example with PlayFramework.
Here's my quick and dirty hack to generate simple report from case class.
def generateReportXLSX(waybillId: Long) = Action{ implicit request =>
val headerStyle =
CellStyle(fillPattern = CellFill.Solid, fillForegroundColor = Color.DarkGrey, fillBackgroundColor = Color.AquaMarine, font = Font(bold = true))
val listItems: List[Item] = Items.findByWaybillId(waybillId)
val listRows = listItems.map{ item =>
Row().withCellValues(item.id.getOrElse(1), item.itemCode, item.senderName.getOrElse(""))
}
val gettingStartedSheet = Sheet(name = "Накладная ")
.withRows(listRows)
.withColumns(
Column(index = 0, style = CellStyle(font = Font(bold = true)), autoSized = true)
)
gettingStartedSheet.saveAsXlsx("/home/user/dumps/"+waybillId+".xlsx")
Ok.sendFile(new File(("/home/user/dumps/"+waybillId+".xlsx")))
}

Resources