I'm sure this is something super simple, but I'm trying to create a dashboard in python's dash. I have no prior experience in dash or html. I've managed to create div boxes in the layout I want, but when I add in a header to one of the div's, it completely destroys my layout (See attached screenshots). Can someone please help me understand where I've gone wrong?
Dashboard before div
import dash
from dash import dcc
from dash import html
import pandas as pd
from dash.dependencies import Input, Output, State
app = dash.Dash()
app.layout = html.Div(
[
html.H1(
children="ML Dashboard",
className="main_title",
style={
"color": "black",
"text-align": "center"
},
),
html.Div(
[
html.Div(
[
],
style={
"background-color": "#096484",
"height": "5vh",
"width": "20vw",
"margin-left": "9vw",
}
),
],
style={
"background-color": "#74B6CE",
"height": "88vh",
"width": "39vw",
"margin-left": "1vw",
"display": "inline-block"
}
),
html.Div(
[
],
style={
"background-color": "#74B6CE",
"height": "88vh",
"width": "26vw",
"margin-left": "1vw",
"display": "inline-block"
}
),
html.Div(
[
html.Div(
[
],
style={
"background-color": "#4796B3",
"height": "40vh",
"width": "24vw",
"margin-left": "1vw",
"margin-top": "3vh"
}
),
html.Div(
[
],
style={
"background-color": "#4796B3",
"height": "40vh",
"width": "24vw",
"margin-left": "1vw",
"margin-top": "1.5vh"
}
),
],
style={
"background-color": "#74B6CE",
"height": "88vh",
"width": "26vw",
"margin-left": "1vw",
"display": "inline-block"
}
),
],
style={
"background-color": "#52ACCC",
"height": "95vh",
"width": "95vw",
"margin-left": "2vw"
}
)
if __name__ == '__main__':
app.run_server(host='0.0.0.0', port=8080, debug=True)
Dashboard after div
import dash
from dash import dcc
from dash import html
import pandas as pd
from dash.dependencies import Input, Output, State
app = dash.Dash()
app.layout = html.Div(
[
html.H1(
children="ML Dashboard",
className="main_title",
style={
"color": "black",
"text-align": "center"
},
),
html.Div(
[
html.Div(
[
html.H1(
children="PIPELINE",
className="title_1",
style={
"color": "white",
"text-align": "center"
},
),
],
style={
"background-color": "#096484",
"height": "5vh",
"width": "20vw",
"margin-left": "9vw",
}
),
],
style={
"background-color": "#74B6CE",
"height": "88vh",
"width": "39vw",
"margin-left": "1vw",
"display": "inline-block"
}
),
html.Div(
[
],
style={
"background-color": "#74B6CE",
"height": "88vh",
"width": "26vw",
"margin-left": "1vw",
"display": "inline-block"
}
),
html.Div(
[
html.Div(
[
],
style={
"background-color": "#4796B3",
"height": "40vh",
"width": "24vw",
"margin-left": "1vw",
"margin-top": "3vh"
}
),
html.Div(
[
],
style={
"background-color": "#4796B3",
"height": "40vh",
"width": "24vw",
"margin-left": "1vw",
"margin-top": "1.5vh"
}
),
],
style={
"background-color": "#74B6CE",
"height": "88vh",
"width": "26vw",
"margin-left": "1vw",
"display": "inline-block"
}
),
],
style={
"background-color": "#52ACCC",
"height": "95vh",
"width": "95vw",
"margin-left": "2vw"
}
)
if __name__ == '__main__':
app.run_server(host='0.0.0.0', port=8080, debug=True)
Exciting that you're getting started with Dash — it's an awesome web framework and the fact that it's all Python is a win-win; great way to get started.
Couple things though I'd point out:
I think you're going a little overboard with the nested div's, unless you're absolutely attached to the exact style you have shared in your example, I'd recommend just using one main Div for the most part
It's a particular Dash-specific quirk that all CSS style keywords must be written in "camel case" (e.g. camelCase); so, actually none of your margin or any other style settings containing hyphens were actually being implemented/rendered
I've provided an example template you're free to use, which I've basically copy pasted and simplified down rather hastily from a work in progress open source github repo I'm working on called "dash-webapp-template"!
It looks like this, maybe this makes sense to you and you could use it as a jumping off point?
#import url('https://fonts.googleapis.com/css?family=Cinzel:300,400,500,600,700|Muli:200,300,400,500,600|Open+Sans:200,300,400,500,600|Oswald:200,300,400,500,600&subset=latin-ext');
#import url('https://fonts.googleapis.com/css?family=Montserrat:200,200i,300,300i,400,400i,500,500i');
#import url('https://fonts.googleapis.com/css?family=Raleway:300,400,500,600,800&subset=latin-ext');
#import url('https://fonts.googleapis.com/css?family=Roboto+Mono:200,300,400,500');
a { color: rgb(146, 146, 146); cursor: pointer; text-decoration: none; -o-transition: color 2.0s ease-out, background .1s ease-in; -ms-transition: color 2.0s ease-out, background .1s ease-in; -moz-transition: color 2.0s ease-out, background .1s ease-in; -webkit-transition: color 2.0s ease-out, background .1s ease-in; transition: all 1.67s ease-out; padding: 10px 10px 10px 10px }
a.fails { color: rgb(146, 146, 146); }
a.success { box-shadow: inset 0px 0px 20px 2px #96ffa2ab, 0px 0px 0px 4px rgb(165, 255, 200); border-radius: 18px; padding: 4px 50px 4px 10px; color: #147b01 !important; }
a.tool-ref { background: #dcdcdc4f; padding: 1px 3px 2px 3px; font-weight: 600; vertical-align: bottom; border-radius: 5px; color: rgb(35, 84, 148); border: 1px inset transparent }
a.tool-ref:hover { background: #fff; border: 1px outset #00ffc8; color: #3df5b4; text-decoration: underline }
a:hover, a:focus { color: #00efb8 !important; transition-duration: 2.75 s !important; transition-property: transform !important }
a:hover:before, a:focus:before, span:hover:before { pointer-events: none; position: absolute; z-index: -1; content: ''; opacity: .75; color: radial-gradient(ellipse at center, rgba(0, 0, 0, .11) 50 %, rgba(0, 0, 0, 0.30) 90 %) !important; transition-duration: 1.5 s; transition-property: transform opacity 0.95 }
blockquote { border-left: 4px lightgrey solid; padding-left: 1rem; margin-top: 2rem; margin-bottom: 2rem; margin-left: 0rem }
body { font-size: 1.15rem; line-height: 1.1; font-weight: 400; font-family: "Oswald", "Muli", "Open Sans", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif; color: rgb(50, 50, 50) }
body { margin: 0; overflow-x: hidden; text-align: center }
button#clear-pipeline { background-color: #cccccc24 !important; color: #000000bd !important; border: 2px outset; border-color: #d4d4d4a3; }
button#initiate-pipeline { font-size: 90%; padding: .67% 6% .67% 6%; border-width: 1px; margin: 2%; mix-blend-mode: color; letter-spacing: 8px; text-transform: uppercase; border-radius: 200px }
button#initiate-pipeline:hover { border-color: #00ffb54a; border-width: 0.5px; box-shadow: inset 0px -30px 0px -5px #efefef4a; background-blend-mode: exclusion; background: #ffffff5e; animation: pact-gradient-text-flow 5s infinite linear; }
button#refresh-downloads-links:hover { border: 2px inset #d9d9d921 }
button#sign-on-submit, button#log-out-submit, button#refresh-downloads-links, button.submit-buttons { background: rgb(65, 0, 255); mix-blend-mode: luminosity; margin-top: 1px; border: 2px outset #aaa; font-size: 60%; border-radius: 100px; letter-spacing: .5rem; display: inline-flex; }
button#sign-on-submit:hover, button#log-out-submit:hover, button.submit-buttons:hover { background-color: rgba(117, 117, 117, 0.5) !important; filter: invert(1) brightness(0.75) contrast(1.5) saturate(2) }
button, .button { margin-bottom: 0rem }
button, .button, button:focus { outline: none !important }
code { font-family: 'Roboto Mono', monospace; font-size: 0.85rem !important }
div.dash-spreadsheet, .dash-freeze-left, .dash-spreadsheet, .dash-spreadsheet-container, .dash-freeze-left, .dash-grow { max-width: 100% !important }
h1 { font-size: 3.5rem; font-family: 'Montserrat'; text-rendering: optimizeLegibility; color: #0d04a5; font-weight: 500; text-decoration: none; border-bottom: 0.0px solid gray; line-height: 4rem; text-decoration: underline }
h2 { font-family: 'Oswald', serif; color: var(--pph-color-8); cursor: default; font-weight: 300; font-size: 2rem; }
h3 { font-size: 2.0rem; font-family: 'Montserrat', sans-serif; font-weight: 300; color: rgb(32, 92, 188); cursor: default }
h4 { font-size: 1.5rem; font-family: 'Oswald', sans-serif; color: var(--pph-color-57); font-weight: 400; cursor: default }
h5 { font-size: 1.2rem; font-family: 'Muli', sans-serif; cursor: default }
h6 { font-size: 1.1rem; color: #333; font-weight: 400 }
header.a:link { color: rgb(18, 116, 165) }
hr { margin-top: 2%; justify-content: center; margin-bottom: 3% }
hr { margin-top: 3rem; margin-bottom: 3.5rem; border-width: 0; border-top: 1px solid #E1E1E1 }
input, textarea, select, fieldset { margin-bottom: 0rem }
input:-internal-autofill-previewed, input:-internal-autofill-selected, textarea:-internal-autofill-previewed, textarea:-internal-autofill-selected, select:-internal-autofill-previewed, select:-internal-autofill-selected { background-color: #ffffff00 !important }
label, legend { display: block; margin-bottom: 0px }
label>.label-body { display: inline-block }
p { margin-top: 0 }
p, h2, h4, h5, h6 { margin-top: .5%; margin-bottom: 1% }
p, ul, ol { margin-bottom: 0.75rem }
pre, dl, figure, table, form { margin-bottom: 0rem }
section.wrapper { padding: 10px 0 }
span.menubar-title:hover { color: rgb(13, 4, 145) !important }
.button, button, input[type="submit"], input[type="reset"], input[type="button"] { display: inline-block; padding: 0 25px; color: #000000; text-align: center; font-size: 14px; font-weight: 500; font-family: "Cinzel", serif !important; line-height: 32px; text-decoration: none; white-space: nowrap; background-color: #ffffffcc !important; border-radius: 30px; border: 1px ridge #00000050; cursor: pointer; box-sizing: border-box }
.button.button-primary, button.button-primary, input[type="submit"].button-primary, input[type="reset"].button-primary, input[type="button"].button-primary { color: #00000075 !important; background-color: #33C3F050; border-color: #33C3F0 }
.button.button-primary:hover, button.button-primary:hover, input[type="submit"].button-primary:hover, input[type="reset"].button-primary:hover, input[type="button"].button-primary:hover, .button.button-primary:focus, button.button-primary:focus, input[type="submit"].button-primary:focus, input[type="reset"].button-primary:focus, input[type="button"].button-primary:focus { color: #00000075 !important; background-color: transparent; border-color: #1EAEDB }
.button:focus, button:focus, input[type="submit"]:focus, input[type="reset"]:focus, input[type="button"]:focus { color: #5C5D86; border-color: #00000075 !important }
.button:hover, button:hover, input[type="submit"]:hover, input[type="reset"]:hover, input[type="button"]:hover { border-color: #00FFC050; background: #00000075 }
.fader-line-long { display: flex; border: none; color: #fff0; height: 1px; background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 650, from(rgba(200, 210, 220, 0.5)), to(#fff0)); }
.fader-line-short { display: flex; border: none; color: #fff0; height: 1px; background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 350, from(rgba(120, 120, 150, 0.5)), to(#fff0)) }
.hr-style-2 { border-top: 3px double #8c8b8b; margin: 10px 10px 10px 10px; width: 67% }
.hvr-float-shadow, .workflow-css label { display: inline-block; vertical-align: middle; position: relative; -webkit-transition-duration: 1.0s; transition-duration: 1.0s; -webkit-transition-property: transform; transition-property: transform; text-rendering: optimizeLegibility }
.hvr-float-shadow:before, .workflow-css label:before { pointer-events: none; position: absolute; z-index: 99; content: ''; top: 180%; left: -10%; height: 6px; width: 120%; opacity: 0.05; background: -webkit-radial-gradient(center, ellipse, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0) 80%); background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0) 80%); -webkit-transition-duration: 0.15s; transition-duration: 0.15s; -webkit-transition-property: transform, opacity; transition-property: transform, opacity }
.hvr-float-shadow:hover, .hvr-float-shadow:focus, .hvr-float-shadow:active, .workflow-css label:hover, .workflow-css label:focus, .workflow-css label:active { -webkit-transform: translateY(-1px)translateY(-1px); color: rgba(0, 215, 198, 1.0); opacity: 0.99; animation-name: anim-rainbow-flow-keys; animation-duration: 1s; animation-iteration-count: infinite; mix-blend-mode: hard-light }
.hvr-float-shadow:hover:before, .hvr-float-shadow:focus:before, .hvr-float-shadow:active:before, .workflow-css label:hover:before, .workflow-css label:focus:before, .workflow-css label:active:before { opacity: 0.9; -webkit-transform: translateY(-1px); transform: translateY(1px) }
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<h1>ML Dashboard</h1>
<h2>PIPELINE</h2>
<hr style="margin-left: 25%; width: 50%;">
<h3 style="margin-top: -10px; text-align: center;">Step One: Upload [e.g., insert expected data input files].</h3>
<h2 style="margin-top: -0.75%;">Then, click “Launch Pipeline” to launch analysis.</h2>
<hr style="margin-left: 25%; width: 50%;">
<div id="upload-data">
<div class="" aria-disabled="false" style="position: relative;">
<div style="background-color: rgba(255, 255, 255, 0.5); border-color: transparent; border-radius: 100px; border-style: solid; border-width: 1px; box-shadow: rgba(0, 0, 50, 0.16) 0px 1px 5px 2px; margin: 2% 15%; padding: 0.5%; text-align: center;">Drag/Drop ⤓ file(s) here —or—<a class="hvr-float-shadow" style="font-weight: 400; margin-bottom: 5px;">📂 Select from your computer</a>
<h6 style="font-family: Cinzel, serif; font-size: 70%; letter-spacing: 1px; text-align: center;">(Other Info/Note)</h6>
<h6 style="font-family: Cinzel, serif; letter-spacing: 4px; margin-top: -8px; text-align: center;">(...Note details / description...)</h6><span><h5 style="font-size: 80%; margin-left: 27.5%; width: 45%;">(Optional supplementary message...)</h5></span></div><input type="file" multiple="" autocomplete="off" style="position: absolute; inset: 0px; opacity: 1e-05; pointer-events: none;"></div>
</div><br><br>
<div style="position: relative; text-align: center;"><button class="hvr-float-shadow" id="initiate-pipeline">—Launch Pipeline—</button><br></div>
<h5 id="pipeline-progress-disclaimer" style="color: rgba(0, 0, 0, 0.5); font-size: 0.85rem; margin-left: 22.5%; text-align: justify; width: 55%;">
<div>
<blockquote> ⚠ Cautionary notes / hints / advice / warnings - #1</blockquote>
</div>
</h5><br><button id="clear-pipeline">—Clear Current QC Results Output—</button><br></div>
</body>
</html>
import dash
import pandas as pd
from dash import dcc
from dash import html
from dash.dependencies import Input
from dash.dependencies import Output
from dash.dependencies import State
app = dash.Dash()
app.layout = html.Div(
[
html.H1("ML Dashboard"),
html.H2("PIPELINE"),
html.Hr(style={"width": "50%", "marginLeft": "25%"}),
html.H3(
"Step One: Upload [e.g., insert expected data input files].",
style={"textAlign": "center", "marginTop": "-10px"},
),
html.H2(
"Then, click “Launch Pipeline” to launch analysis.",
style={"marginTop": "-0.75%"},
),
html.Hr(style={"width": "50%", "marginLeft": "25%"}),
dcc.Upload(
id="upload-data",
children=html.Div(
[
"Drag/Drop ⤓ file(s) here —or—",
html.A(
"📂 Select from your computer",
className="hvr-float-shadow",
style={"fontWeight": "400", "marginBottom": "5px"},
),
html.H6(
"(Other Info/Note)",
style={
"textAlign": "center",
"letterSpacing": "1px",
"fontFamily": "'Cinzel', serif",
"fontSize": "70%",
},
),
html.H6(
"(...Note details / description...)",
style={
"textAlign": "center",
"letterSpacing": "4px",
"fontFamily": "'Cinzel', serif",
"marginTop": "-8px",
},
),
html.Span(
html.H5(
"(Optional supplementary message...)",
style={
"width": "45%",
"marginLeft": "27.5%",
"fontSize": "80%",
},
)
),
],
style={
"borderWidth": "1px",
"borderStyle": "solid",
"borderRadius": "100px",
"textAlign": "center",
"margin": "2% 15%",
"boxShadow": "0px 1px 5px 2px rgba(0, 0, 50, 0.16)",
"borderColor": "transparent",
"padding": "0.5%",
"backgroundColor": "rgba(255,255,255,0.5)",
},
),
multiple=True, # (Allow multiple files to be uploaded)
),
html.Br(),
html.Br(),
html.Div(
[
html.Button(
"—Launch Pipeline—",
id="initiate-pipeline",
n_clicks=0,
className="hvr-float-shadow",
),
html.Br(),
],
style={"textAlign": "center", "position": "relative"},
),
html.H5(
html.Div(
[
html.Blockquote(
" ⚠ Cautionary notes / hints / advice / warnings - #1"
),
]
),
style={
"fontSize": "0.85rem",
"color": "#00000080",
"width": "55%",
"marginLeft": "22.5%",
"textAlign": "justify",
},
id="pipeline-progress-disclaimer",
),
html.Br(),
html.Button(
"—Clear Current QC Results Output—",
id="clear-pipeline",
n_clicks=0,
),
html.Br(),
]
)
if __name__ == "__main__":
app.run_server(
host="0.0.0.0", port=8080, debug=True, dev_tools_hot_reload=True
)
Here's the file structure following Dash docs recommended convention, and which I used here:
.
|-- [1.9K Nov 19 10:42] app.py
`-- [ 96 Nov 19 10:48] assets
`-- [ 24K Nov 19 11:02] custom.css
1 directory, 3 files
where all the CSS in the SO in-answer HTML/CSS snippet CSS simply goes cutcopy into the custom.css file, specifically under a subdir called "assets" (which Dash is programmed to lookout for).
I have a PyQt stylesheet given as a str type where I insert it into app.setStyleSheet() to change CSS properties. I want to remove a specific section of code within this string, specifically this section:
QSlider::groove:horizontal {
background: #32414B;
border: 1px solid #32414B;
height: 4px;
margin: 0px;
border-radius: 4px;
}
This is the entire stylesheet string
stylesheet = '''
/* QWidget ---------------------------------------------------------------- */
QWidget {
background-color: #19232D;
border: 0px solid #32414B;
padding: 0px;
color: #F0F0F0;
selection-background-color: #1464A0;
selection-color: #F0F0F0;
}
QWidget:disabled {
background-color: #19232D;
color: #787878;
selection-background-color: #14506E;
selection-color: #787878;
}
QWidget:item:selected {
background-color: #1464A0;
}
QWidget:item:hover {
background-color: #148CD2;
color: #32414B;
}
/* QMainWindow ------------------------------------------------------------ */
/* This adjusts the splitter in the dock widget, not qsplitter */
QMainWindow::separator {
background-color: #32414B;
border: 0 solid #19232D;
spacing: 0;
padding: 2px;
}
QMainWindow::separator:hover {
background-color: #505F69;
border: 0px solid #148CD2;
}
QMainWindow::separator:horizontal {
width: 5px;
margin-top: 2px;
margin-bottom: 2px;
image: url(:/qss_icons/rc/Vsepartoolbar.png);
}
QMainWindow::separator:vertical {
height: 5px;
margin-left: 2px;
margin-right: 2px;
image: url(:/qss_icons/rc/Hsepartoolbar.png);
}
/* QToolTip --------------------------------------------------------------- */
QToolTip {
background-color: #148CD2;
border: 1px solid #19232D;
color: #19232D;
padding: 0; /*remove padding, for fix combo box tooltip*/
opacity: 230; /*reducing transparency to read better*/
}
/* QStatusBar ------------------------------------------------------------- */
QStatusBar {
border: 1px solid #32414B;
background: #32414B; /*fixes spyder #9120,#9121*/
}
QStatusBar QToolTip {
background-color: #148CD2;
border: 1px solid #19232D;
color: #19232D;
padding: 0; /*remove padding, for fix combo box tooltip*/
opacity: 230; /*reducing transparency to read better*/
}
QStatusBar QLabel {
background-color: transparent; /*fixes spyder #9120,#9121*/
}
/* QCheckBox -------------------------------------------------------------- */
QCheckBox {
background-color: #19232D;
color: #F0F0F0;
spacing: 4px;
outline: none;
padding-top: 4px;
padding-bottom: 4px;
}
QCheckBox:focus {
border: none;
}
QCheckBox QWidget:disabled {
background-color: #19232D;
color: #787878;
}
QCheckBox::indicator {
margin-left: 4px;
width: 16px;
height: 16px;
}
QCheckBox::indicator:unchecked {
image: url(:/qss_icons/rc/checkbox_unchecked.png);
}
QCheckBox::indicator:unchecked:hover,
QCheckBox::indicator:unchecked:focus,
QCheckBox::indicator:unchecked:pressed {
border: none;
image: url(:/qss_icons/rc/checkbox_unchecked_focus.png);
}
QCheckBox::indicator:unchecked:disabled {
image: url(:/qss_icons/rc/checkbox_unchecked_disabled.png);
}
QCheckBox::indicator:checked {
image: url(:/qss_icons/rc/checkbox_checked.png);
}
QCheckBox::indicator:checked:hover,
QCheckBox::indicator:checked:focus,
QCheckBox::indicator:checked:pressed {
border: none;
image: url(:/qss_icons/rc/checkbox_checked_focus.png);
}
QCheckBox::indicator:checked:disabled{
image: url(:/qss_icons/rc/checkbox_checked_disabled.png);
}
QCheckBox::indicator:indeterminate {
image: url(:/qss_icons/rc/checkbox_indeterminate.png);
}
QCheckBox::indicator:indeterminate:disabled {
image: url(:/qss_icons/rc/checkbox_indeterminate_disabled.png);
}
QCheckBox::indicator:indeterminate:focus,
QCheckBox::indicator:indeterminate:hover,
QCheckBox::indicator:indeterminate:pressed {
image: url(:/qss_icons/rc/checkbox_indeterminate_focus.png);
}
/* QGroupBox -------------------------------------------------------------- */
QGroupBox {
font-weight: bold;
border: 1px solid #32414B;
border-radius: 4px;
padding: 4px;
margin-top: 16px;
}
QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top left;
left: 3px;
padding-left: 3px;
padding-right: 5px;
padding-top: 8px;
padding-bottom: 16px;
}
QGroupBox::indicator {
margin-left: 4px;
width: 16px;
height: 16px;
}
QGroupBox::indicator {
margin-left: 2px;
}
QGroupBox::indicator:unchecked:hover,
QGroupBox::indicator:unchecked:focus,
QGroupBox::indicator:unchecked:pressed {
border: none;
image: url(:/qss_icons/rc/checkbox_unchecked_focus.png);
}
QGroupBox::indicator:checked:hover,
QGroupBox::indicator:checked:focus,
QGroupBox::indicator:checked:pressed {
border: none;
image: url(:/qss_icons/rc/checkbox_checked_focus.png);
}
QGroupBox::indicator:checked:disabled {
image: url(:/qss_icons/rc/checkbox_checked_disabled.png);
}
QGroupBox::indicator:unchecked:disabled {
image: url(:/qss_icons/rc/checkbox_unchecked_disabled.png);
}
/* QRadioButton ----------------------------------------------------------- */
QRadioButton {
background-color: #19232D;
color: #F0F0F0;
spacing: 0;
padding: 0;
border: none;
outline: none;
}
QRadioButton:focus {
border: none;
}
QRadioButton:disabled {
background-color: #19232D;
color: #787878;
border: none;
outline: none;
}
QRadioButton QWidget {
background-color: #19232D;
color: #F0F0F0;
spacing: 0px;
padding: 0px;
outline: none;
border: none;
}
QRadioButton::indicator {
border: none;
outline: none;
margin-bottom: 2px;
width: 25px;
height: 25px;
}
QRadioButton::indicator:unchecked {
image: url(:/qss_icons/rc/radio_unchecked.png);
}
QRadioButton::indicator:unchecked:hover,
QRadioButton::indicator:unchecked:focus,
QRadioButton::indicator:unchecked:pressed {
border: none;
outline: none;
image: url(:/qss_icons/rc/radio_unchecked_focus.png);
}
QRadioButton::indicator:checked {
border: none;
outline: none;
image: url(:/qss_icons/rc/radio_checked.png);
}
QRadioButton::indicator:checked:hover,
QRadioButton::indicator:checked:focus,
QRadioButton::indicator:checked:pressed {
border: none;
outline: none;
image: url(:/qss_icons/rc/radio_checked_focus.png);
}
QRadioButton::indicator:checked:disabled {
outline: none;
image: url(:/qss_icons/rc/radio_checked_disabled.png);
}
QRadioButton::indicator:unchecked:disabled {
image: url(:/qss_icons/rc/radio_unchecked_disabled.png);
}
/* QMenuBar --------------------------------------------------------------- */
QMenuBar {
background-color: #32414B;
padding: 2px;
border: 1px solid #19232D;
color: #F0F0F0;
}
QMenuBar:focus {
border: 1px solid #148CD2;
}
QMenuBar::item {
background: transparent;
padding: 4px;
}
QMenuBar::item:selected {
padding: 4px;
background: transparent;
border: 0px solid #32414B;
}
QMenuBar::item:pressed {
padding: 4px;
border: 0px solid #32414B;
background-color: #148CD2;
color: #F0F0F0;
margin-bottom: 0px;
padding-bottom: 0px;
}
/* QMenu ------------------------------------------------------------------ */
QMenu {
border: 0px solid #32414B;
color: #F0F0F0;
margin: 0px;
}
QMenu::separator {
height: 2px;
background-color: #505F69;
color: #F0F0F0;
padding-left: 4px;
margin-left: 2px;
margin-right: 2px;
}
QMenu::icon {
margin: 0px;
padding-left:4px;
}
QMenu::item {
padding: 4px 24px 4px 24px;
border: 1px transparent #32414B; /* reserve space for selection border */
}
QMenu::item:selected {
color: #F0F0F0;
}
QMenu::indicator {
width: 12px;
height: 12px;
padding-left:6px;
}
/* non-exclusive indicator = check box style indicator (see QActionGroup::setExclusive) */
QMenu::indicator:non-exclusive:unchecked {
image: url(:/qss_icons/rc/checkbox_unchecked.png);
}
QMenu::indicator:non-exclusive:unchecked:selected {
image: url(:/qss_icons/rc/checkbox_unchecked_disabled.png);
}
QMenu::indicator:non-exclusive:checked {
image: url(:/qss_icons/rc/checkbox_checked.png);
}
QMenu::indicator:non-exclusive:checked:selected {
image: url(:/qss_icons/rc/checkbox_checked_disabled.png);
}
/* exclusive indicator = radio button style indicator (see QActionGroup::setExclusive) */
QMenu::indicator:exclusive:unchecked {
image: url(:/qss_icons/rc/radio_unchecked.png);
}
QMenu::indicator:exclusive:unchecked:selected {
image: url(:/qss_icons/rc/radio_unchecked_disabled.png);
}
QMenu::indicator:exclusive:checked {
image: url(:/qss_icons/rc/radio_checked.png);
}
QMenu::indicator:exclusive:checked:selected {
image: url(:/qss_icons/rc/radio_checked_disabled.png);
}
QMenu::right-arrow {
margin: 5px;
image: url(:/qss_icons/rc/right_arrow.png)
}
/* QAbstractItemView ------------------------------------------------------ */
QAbstractItemView {
alternate-background-color: #19232D;
color: #F0F0F0;
border: 1px solid #32414B;
border-radius: 4px;
}
QAbstractItemView QLineEdit {
padding: 2px;
}
/* QAbstractScrollArea ---------------------------------------------------- */
QAbstractScrollArea {
background-color: #19232D;
border: 1px solid #32414B;
border-radius: 4px;
padding: 4px;
color: #F0F0F0;
}
QAbstractScrollArea:disabled {
color: #787878;
}
/* QScrollArea ------------------------------------------------------------ */
QScrollArea QWidget QWidget:disabled {
background-color: #19232D;
}
/* QScrollBar ------------------------------------------------------------- */
QScrollBar:horizontal {
height: 16px;
margin: 2px 16px 2px 16px;
border: 1px solid #32414B;
border-radius: 4px;
background-color: #19232D;
}
QScrollBar::handle:horizontal {
background-color: #787878;
border: 1px solid #32414B;
border-radius: 4px;
min-width: 8px;
}
QScrollBar::handle:horizontal:hover {
background-color: #148CD2;
border: 1px solid #148CD2;
border-radius: 4px;
min-width: 8px;
}
QScrollBar::add-line:horizontal {
margin: 0px 0px 0px 0px;
border-image: url(:/qss_icons/rc/right_arrow_disabled.png);
width: 10px;
height: 10px;
subcontrol-position: right;
subcontrol-origin: margin;
}
QScrollBar::sub-line:horizontal {
margin: 0px 3px 0px 3px;
border-image: url(:/qss_icons/rc/left_arrow_disabled.png);
height: 10px;
width: 10px;
subcontrol-position: left;
subcontrol-origin: margin;
}
QScrollBar::add-line:horizontal:hover,
QScrollBar::add-line:horizontal:on {
border-image: url(:/qss_icons/rc/right_arrow.png);
height: 10px;
width: 10px;
subcontrol-position: right;
subcontrol-origin: margin;
}
QScrollBar::sub-line:horizontal:hover,
QScrollBar::sub-line:horizontal:on {
border-image: url(:/qss_icons/rc/left_arrow.png);
height: 10px;
width: 10px;
subcontrol-position: left;
subcontrol-origin: margin;
}
QScrollBar::up-arrow:horizontal,
QScrollBar::down-arrow:horizontal {
background: none;
}
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
QScrollBar:vertical {
background-color: #19232D;
width: 16px;
margin: 16px 2px 16px 2px;
border: 1px solid #32414B;
border-radius: 4px;
}
QScrollBar::handle:vertical {
background-color: #787878;
border: 1px solid #32414B;
min-height: 8px;
border-radius: 4px;
}
QScrollBar::handle:vertical:hover {
background-color: #148CD2;
border: 1px solid #148CD2;
border-radius: 4px;
min-height: 8px;
}
QScrollBar::sub-line:vertical {
margin: 3px 0px 3px 0px;
border-image: url(:/qss_icons/rc/up_arrow_disabled.png);
height: 10px;
width: 10px;
subcontrol-position: top;
subcontrol-origin: margin;
}
QScrollBar::add-line:vertical {
margin: 3px 0px 3px 0px;
border-image: url(:/qss_icons/rc/down_arrow_disabled.png);
height: 10px;
width: 10px;
subcontrol-position: bottom;
subcontrol-origin: margin;
}
QScrollBar::sub-line:vertical:hover,
QScrollBar::sub-line:vertical:on {
border-image: url(:/qss_icons/rc/up_arrow.png);
height: 10px;
width: 10px;
subcontrol-position: top;
subcontrol-origin: margin;
}
QScrollBar::add-line:vertical:hover,
QScrollBar::add-line:vertical:on {
border-image: url(:/qss_icons/rc/down_arrow.png);
height: 10px;
width: 10px;
subcontrol-position: bottom;
subcontrol-origin: margin;
}
QScrollBar::up-arrow:vertical,
QScrollBar::down-arrow:vertical {
background: none;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
/* QTextEdit--------------------------------------------------------------- */
QTextEdit {
background-color: #19232D;
color: #F0F0F0;
border: 1px solid #32414B;
}
QTextEdit:hover {
border: 1px solid #148CD2;
color: #F0F0F0;
}
QTextEdit:selected {
background: #1464A0;
color: #32414B;
}
/* QPlainTextEdit --------------------------------------------------------- */
QPlainTextEdit {
background-color: #19232D;
color: #F0F0F0;
border-radius: 4px;
border: 1px solid #32414B;
}
QPlainTextEdit:hover {
border: 1px solid #148CD2;
color: #F0F0F0;
}
QPlainTextEdit:selected {
background: #1464A0;
color: #32414B;
}
/* QSizeGrip --------------------------------------------------------------- */
QSizeGrip {
image: url(:/qss_icons/rc/sizegrip.png);
width: 12px;
height: 12px;
}
/* QStackedWidget --------------------------------------------------------- */
QStackedWidget {
padding: 4px;
border: 1px solid #32414B;
border: 1px solid #19232D;
}
/* QToolBar --------------------------------------------------------------- */
QToolBar {
background-color: #32414B;
border-bottom: 1px solid #19232D;
padding: 2px;
font-weight: bold;
}
QToolBar QToolButton{
background-color: #32414B;
}
QToolBar::handle:horizontal {
width: 6px;
image: url(:/qss_icons/rc/Hmovetoolbar.png);
}
QToolBar::handle:vertical {
height: 6px;
image: url(:/qss_icons/rc/Vmovetoolbar.png);
}
QToolBar::separator:horizontal {
width: 3px;
image: url(:/qss_icons/rc/Hsepartoolbar.png);
}
QToolBar::separator:vertical {
height: 3px;
image: url(:/qss_icons/rc/Vsepartoolbar.png);
}
QToolButton#qt_toolbar_ext_button {
background: #32414B;
border: 0px;
color: #F0F0F0;
image: url(:/qss_icons/rc/right_arrow.png);
}
/* QAbstractSpinBox ------------------------------------------------------- */
QAbstractSpinBox {
background-color: #19232D;
border: 1px solid #32414B;
color: #F0F0F0;
padding-top: 2px; /* This fix 103, 111*/
padding-bottom: 2px; /* This fix 103, 111*/
padding-left: 4px;
padding-right: 4px;
border-radius: 4px;
/* min-width: 5px; removed to fix 109 */
}
QAbstractSpinBox:up-button {
background-color: transparent #19232D;
subcontrol-origin: border;
subcontrol-position: top right;
border-left: 1px solid #32414B;
margin: 1px;
}
QAbstractSpinBox::up-arrow,
QAbstractSpinBox::up-arrow:disabled,
QAbstractSpinBox::up-arrow:off {
image: url(:/qss_icons/rc/up_arrow_disabled.png);
width: 9px;
height: 9px;
}
QAbstractSpinBox::up-arrow:hover {
image: url(:/qss_icons/rc/up_arrow.png);
}
QAbstractSpinBox:down-button {
background-color: transparent #19232D;
subcontrol-origin: border;
subcontrol-position: bottom right;
border-left: 1px solid #32414B;
margin: 1px;
}
QAbstractSpinBox::down-arrow,
QAbstractSpinBox::down-arrow:disabled,
QAbstractSpinBox::down-arrow:off {
image: url(:/qss_icons/rc/down_arrow_disabled.png);
width: 9px;
height: 9px;
}
QAbstractSpinBox::down-arrow:hover {
image: url(:/qss_icons/rc/down_arrow.png);
}
QAbstractSpinBox:hover{
border: 1px solid #148CD2;
color: #F0F0F0;
}
QAbstractSpinBox:selected {
background: #1464A0;
color: #32414B;
}
/* ------------------------------------------------------------------------ */
/* DISPLAYS --------------------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/* QLabel ----------------------------------------------------------------- */
QLabel {
background-color: #19232D;
border: 0px solid #32414B;
padding: 2px;
margin: 0px;
color: #F0F0F0
}
QLabel::disabled {
background-color: #19232D;
border: 0px solid #32414B;
color: #787878;
}
/* QTextBrowser ----------------------------------------------------------- */
QTextBrowser {
background-color: #19232D;
border: 1px solid #32414B;
color: #F0F0F0;
border-radius: 4px;
}
QTextBrowser:disabled {
background-color: #19232D;
border: 1px solid #32414B;
color: #787878;
border-radius: 4px;
}
QTextBrowser:hover,
QTextBrowser:!hover,
QTextBrowser::selected,
QTextBrowser::pressed {
border: 1px solid #32414B;
}
/* QGraphicsView --------------------------------------------------------- */
QGraphicsView {
background-color: #19232D;
border: 1px solid #32414B;
color: #F0F0F0;
border-radius: 4px;
}
QGraphicsView:disabled {
background-color: #19232D;
border: 1px solid #32414B;
color: #787878;
border-radius: 4px;
}
QGraphicsView:hover,
QGraphicsView:!hover,
QGraphicsView::selected,
QGraphicsView::pressed {
border: 1px solid #32414B;
}
/* QCalendarWidget -------------------------------------------------------- */
QCalendarWidget {
border: 1px solid #32414B;
border-radius: 4px;
}
QCalendarWidget:disabled {
background-color: #19232D;
color: #787878;
}
/* QLCDNumber ------------------------------------------------------------- */
QLCDNumber {
background-color: #19232D;
color: #F0F0F0;
}
QLCDNumber:disabled {
background-color: #19232D;
color: #787878;
}
/* QProgressBar ----------------------------------------------------------- */
QProgressBar {
background-color: #19232D;
border: 1px solid #32414B;
color: #F0F0F0;
border-radius: 4px;
text-align: center;
}
QProgressBar:disabled {
background-color: #19232D;
border: 1px solid #32414B;
color: #787878;
border-radius: 4px;
text-align: center;
}
QProgressBar::chunk {
background-color: #1464A0;
color: #19232D;
border-radius: 4px;
}
QProgressBar::chunk:disabled {
background-color: #14506E;
color: #787878;
border-radius: 4px;
}
/* ------------------------------------------------------------------------ */
/* BUTTONS ---------------------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/* QPushButton ------------------------------------------------------------ */
QPushButton {
background-color: #505F69 ;
border: 1px solid #32414B;
color: #F0F0F0;
border-radius: 4px;
padding: 3px;
outline: none;
}
QPushButton:disabled {
background-color: #32414B;
border: 1px solid #32414B;
color: #787878;
border-radius: 4px;
padding: 3px;
}
QPushButton:checked {
background-color: #32414B;
border: 1px solid #32414B;
border-radius: 4px;
padding: 3px;
outline: none;
}
QPushButton:checked:disabled {
background-color: #19232D;
border: 1px solid #32414B;
color: #787878;
border-radius: 4px;
padding: 3px;
outline: none;
}
QPushButton::menu-indicator {
subcontrol-origin: padding;
subcontrol-position: bottom right;
bottom: 4px;
}
QPushButton:pressed {
background-color: #19232D;
border: 1px solid #19232D;
}
QPushButton:hover,
QPushButton:checked:hover{
border: 1px solid #148CD2;
color: #F0F0F0;
}
QPushButton:pressed:hover{
border: 1px solid #1464A0;
}
QPushButton:selected,
QPushButton:checked:selected{
background: #1464A0;
color: #32414B;
}
/* QToolButton ------------------------------------------------------------ */
QToolButton {
background-color: transparent;
border: 1px solid #32414B;
border-radius: 4px;
margin: 0px;
padding: 2px;
}
QToolButton:checked {
background-color: #19232D;
border: 1px solid #19232D;
}
QToolButton:pressed {
background-color: #19232D;
border: 1px solid #19232D;
}
QToolButton:disabled {
border: 1px solid #32414B;
}
QToolButton:hover,
QToolButton:checked:hover{
border: 1px solid #148CD2;
}
QToolButton:pressed:hover{
border: 1px solid #1464A0;
}
/* the subcontrols below are used only in the MenuButtonPopup mode */
QToolButton[popupMode="1"] {
padding: 2px;
padding-right: 12px; /* only for MenuButtonPopup */
border: 1px solid #32414B; /* make way for the popup button */
border-radius: 4px;
}
/* The subcontrol below is used only in the InstantPopup or DelayedPopup mode */
QToolButton[popupMode="2"] {
padding: 2px;
padding-right: 12px; /* only for InstantPopup */
border: 1px solid #32414B; /* make way for the popup button */
}
QToolButton::menu-button {
padding: 2px;
border-radius: 4px;
border: 1px solid #32414B;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
/* 16px width + 4px for border = 20px allocated above */
width: 16px;
outline: none;
}
QToolButton::menu-button:hover,
QToolButton::menu-button:checked:hover {
border: 1px solid #148CD2;
}
QToolButton::menu-indicator {
image: url(:/qss_icons/rc/down_arrow.png);
top: -8px; /* shift it a bit */
left: -4px; /* shift it a bit */
}
QToolButton::menu-arrow {
image: url(:/qss_icons/rc/down_arrow.png);
}
QToolButton::menu-arrow:open {
border: 1px solid #32414B;
}
/* QCommandLinkButton ----------------------------------------------------- */
QCommandLinkButton {
background-color: transparent;
border: 1px solid #32414B;
color: #F0F0F0;
border-radius: 4px;
padding: 0px;
margin: 0px;
}
QCommandLinkButton:disabled {
background-color: transparent;
color: #787878;
}
/* ------------------------------------------------------------------------ */
/* INPUTS - NO FIELDS ----------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/* QCombobox -------------------------------------------------------------- */
QComboBox {
border: 1px solid #32414B;
border-radius: 4px;
selection-background-color: #1464A0;
padding-top: 2px; /* This fix #103, #111*/
padding-bottom: 2px; /* This fix #103, #111*/
padding-left: 4px;
padding-right: 4px;
/* min-width: 75px; removed to fix 109 */
}
QComboBox:disabled {
background-color: #19232D;
color: #787878;
}
QComboBox:hover{
border: 1px solid #148CD2;
}
QComboBox:on {
selection-background-color: #19232D;
}
QComboBox QAbstractItemView {
background-color: #19232D;
border-radius: 4px;
border: 1px solid #32414B;
selection-color: #148CD2;
selection-background-color: #32414B;
}
QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
width: 20px;
border-left-width: 0px;
border-left-color: #32414B;
border-left-style: solid;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
QComboBox::down-arrow {
image: url(:/qss_icons/rc/down_arrow_disabled.png);
}
QComboBox::down-arrow:on,
QComboBox::down-arrow:hover,
QComboBox::down-arrow:focus {
image: url(:/qss_icons/rc/down_arrow.png);
}
/* QSlider ---------------------------------------------------------------- */
QSlider:disabled {
background: #19232D;
}
QSlider:focus {
border: none;
}
QSlider::groove:horizontal {
background: #32414B;
border: 1px solid #32414B;
height: 4px;
margin: 0px;
border-radius: 4px;
}
QSlider::sub-page:horizontal {
background: #1464A0;
border: 1px solid #32414B;
height: 4px;
margin: 0px;
border-radius: 4px;
}
QSlider::sub-page:horizontal:disabled {
background: #14506E;
}
QSlider::handle:horizontal {
background: #787878;
border: 1px solid #32414B;
width: 8px;
height: 8px;
margin: -8px 0;
border-radius: 4px;
}
QSlider::handle:horizontal:hover {
background: #148CD2;
border: 1px solid #148CD2;
}
QSlider::groove:vertical {
background: #32414B;
border: 1px solid #32414B;
width: 4px;
margin: 0px;
border-radius: 4px;
}
QSlider::sub-page:vertical {
background: #1464A0;
border: 1px solid #32414B;
width: 4px;
margin: 0px;
border-radius: 4px;
}
QSlider::sub-page:vertical:disabled {
background: #14506E;
}
QSlider::handle:vertical {
background: #787878;
border: 1px solid #32414B;
width: 8px;
height: 8px;
margin: 0 -8px;
border-radius: 4px;
}
QSlider::handle:vertical:hover {
background: #148CD2;
border: 1px solid #148CD2;
}
/* QLine ------------------------------------------------------------------ */
QLineEdit {
background-color: #19232D;
padding-top: 2px; /* This QLineEdit fix 103, 111 */
padding-bottom: 2px; /* This QLineEdit fix 103, 111 */
padding-left: 4px;
padding-right: 4px;
border-style: solid;
border: 1px solid #32414B;
border-radius: 4px;
color: #F0F0F0;
}
QLineEdit:disabled {
background-color: #19232D;
color: #787878;
}
QLineEdit:hover{
border: 1px solid #148CD2;
color: #F0F0F0;
}
QLineEdit:selected{
background: #1464A0;
color: #32414B;
}
/* QTabWiget -------------------------------------------------------------- */
QTabWidget {
padding: 2px;
selection-background-color: #32414B;
}
QTabWidget QFrame{
border: 1px solid #32414B;
}
QTabWidget::pane {
border: 1px solid #32414B;
border-radius: 4px;
padding: 2px;
margin: 0px;
}
QTabWidget::pane:selected {
background-color: #32414B;
border: 1px solid #1464A0;
}
/* QTabBar ---------------------------------------------------------------- */
QTabBar {
qproperty-drawBase: 0;
border-radius: 4px;
margin: 0px;
padding: 2px;
border: 0;
/* left: 5px; move to the right by 5px - removed for fix */
}
QTabBar::close-button {
border: 0;
margin: 2px;
padding: 0;
image: url(:/qss_icons/rc/close.png);
}
QTabBar::close-button:hover {
image: url(:/qss_icons/rc/close-hover.png);
}
QTabBar::close-button:pressed {
image: url(:/qss_icons/rc/close-pressed.png);
}
/* QTabBar::tab - selected ----------------------------------------------- */
QTabBar::tab:top:selected:disabled {
border-bottom: 3px solid #14506E;
color: #787878;
background-color: #32414B;
}
QTabBar::tab:bottom:selected:disabled {
border-top: 3px solid #14506E;
color: #787878;
background-color: #32414B;
}
QTabBar::tab:left:selected:disabled {
border-left: 3px solid #14506E;
color: #787878;
background-color: #32414B;
}
QTabBar::tab:right:selected:disabled {
border-right: 3px solid #14506E;
color: #787878;
background-color: #32414B;
}
/* QTabBar::tab - !selected and disabled ---------------------------------- */
QTabBar::tab:top:!selected:disabled {
border-bottom: 3px solid #19232D;
color: #787878;
background-color: #19232D;
}
QTabBar::tab:bottom:!selected:disabled {
border-top: 3px solid #19232D;
color: #787878;
background-color: #19232D;
}
QTabBar::tab:left:!selected:disabled {
border-right: 3px solid #19232D;
color: #787878;
background-color: #19232D;
}
QTabBar::tab:right:!selected:disabled {
border-left: 3px solid #19232D;
color: #787878;
background-color: #19232D;
}
'''
Since I'm not reading from a file, I can't use readline(). I already tried to use a for loop to iterate through and check if QSlider::groove:horizontal is inside but I can't figure out how to remove the remaining lines. How can I remove this snippet of CSS and return the other untouched CSS as a str?
stylesheet = 'the really big CSS stylesheet string'
def remove_qslider_tick_bug():
# Remove snippet
return filtered_stylesheet
You can use .find to get the location of your substring, then Python allow string slicing the same as slicing lists. So if you want to do this all yourself you could do something like:
def snip_outside_str(text,start_text,end_text):
start = text.find(start_text)
end = text[start:].find(end_text) #fails if start_text=end_text
end = end + start + len(end_text)
return text[:start]+ text[end:]
stylesheet = 'the really big /*CSS*/ stylesheet string'
def remove_qslider_tick_bug(my_str, start_str='/*', end_str='*/'):
while my_str.find(start_str) != -1:
my_str = snip_outside_str(my_str, start_str, end_str)
return my_str
WARNING: This code is just an example of how to tackle the problem, it's going to produce some weird results when start_str=end_str or when end_str doesn't exist. So if you want to work with CSS there are libraries that can do that for you. For example: https://tinycss.readthedocs.io/en/latest/
(Disclaimer, I'm not a web guy and I've never used tinycss in anger)
i have a problem with my html parser. I convert emails filled with html code into nice clean text, except for the "< style > content < /style >" part, which it completely ignores and i have no clue as to what i did wrong:
# Remove any HTML code from our raw content
htmlparse = re.sub(r'<.*?>', '', clean) \
.replace(" ", '') \
.replace("é", 'é') \
.replace("è", 'è') \
clean_email = htmlparse
what it actually should delete is:
<style> .MailHeader { font: normal 10pt Tahoma, Verdana, Sans-Serif; vertical-align: top; padding-bottom: 0px; padding-top: 0px; spacing: 0px 0px 0px 0px; } .DataHeader { font-family: Tahoma; font-size: 8pt; color: #666666; text-decoration: none; padding-left: 15px; padding-right: 15px; border: solid 1px #E0E0E0; vertical-align: text-top; } .Data { font: normal 8pt Tahoma,Verdana; padding-left: 3px; padding-right: 15px; border: solid 1px #E0E0E0; background: #F9F9F9; font-size: 8pt; color: #666666; height: 20px !important; } .GridHeader { font: normal 8pt Tahoma,Verdana; padding-left: 6px; background: #DAEBFF; height: 20px; } .DataRow { padding-left: 3px; padding-right: 15px; border: solid 1px #E0E0E0; font-size: 8pt; color: #003399; } .GridRow { font: normal 8pt Tahoma, Verdana, Sans-serif; padding-left: 6px; background: transparent; height: 20px !important; min-height: 1%; } .GridAltRow { font: normal 8pt Tahoma, Verdana, Sans-serif; padding-left: 6px; background: #F9F9F9; height: 20px !important; min-height: 1%; } .li { font: normal 10pt Tahoma, Verdana, Sans-Serif; vertical-align: top; padding-left: 5px; } .TableHeader { font-family: Tahoma,calibri,verdana; font-size: 8pt; font-weight: bold; height: 22px; color: #003399; border: solid 1px #E0E0E0; border-collapse: collapse; padding-left: 5px; padding-right: 5px; background-color: #BBD8FF; } .TableSubHeader { font: normal 8pt Tahoma, Verdana, Sans-Serif; vertical-align: middle; padding-left: 3px; font-weight: bold; color: #666666; } .Separator { background-repeat: repeat-x; background-position: center; background: #666666; } .tableDetail { padding: 0 0 0 0; spacing: 0 0 0 0; border-collapse: collapse; width: 750px; margin-left: 5px; border: solid 1px #E0E0E0; } .style1 { font: normal 10pt Tahoma, Verdana, Sans-Serif; vertical-align: top; padding-bottom: 0px; padding-top: 0px; spacing: 0px 0px 0px 0px; height: 18px; } </style>
What it actually does is delete style and /style but leaves the whole garbage of the stylesheet in the parsed file...
.MailHeader { font: normal 10pt Tahoma, Verdana, Sans-Serif; vertical-align: top; padding-bottom: 0px; padding-top: 0px; spacing: 0px 0px 0px 0px; } .DataHeader { font-family: Tahoma; font-size: 8pt; color: #666666; text-decoration: none; padding-left: 15px; padding-right: 15px; border: solid 1px #E0E0E0; vertical-align: text-top; } .Data { font: normal 8pt Tahoma,Verdana; padding-left: 3px; padding-right: 15px; border: solid 1px #E0E0E0; background: #F9F9F9; font-size: 8pt; color: #666666; height: 20px !important; } .GridHeader { font: normal 8pt Tahoma,Verdana; padding-left: 6px; background: #DAEBFF; height: 20px; } .DataRow { padding-left: 3px; padding-right: 15px; border: solid 1px #E0E0E0; font-size: 8pt; color: #003399; } .GridRow { font: normal 8pt Tahoma, Verdana, Sans-serif; padding-left: 6px; background: transparent; height: 20px !important; min-height: 1%; } .GridAltRow { font: normal 8pt Tahoma, Verdana, Sans-serif; padding-left: 6px; background: #F9F9F9; height: 20px !important; min-height: 1%; } .li { font: normal 10pt Tahoma, Verdana, Sans-Serif; vertical-align: top; padding-left: 5px; } .TableHeader { font-family: Tahoma,calibri,verdana; font-size: 8pt; font-weight: bold; height: 22px; color: #003399; border: solid 1px #E0E0E0; border-collapse: collapse; padding-left: 5px; padding-right: 5px; background-color: #BBD8FF; } .TableSubHeader { font: normal 8pt Tahoma, Verdana, Sans-Serif; vertical-align: middle; padding-left: 3px; font-weight: bold; color: #666666; } .Separator { background-repeat: repeat-x; background-position: center; background: #666666; } .tableDetail { padding: 0 0 0 0; spacing: 0 0 0 0; border-collapse: collapse; width: 750px; margin-left: 5px; border: solid 1px #E0E0E0; } .style1 { font: normal 10pt Tahoma, Verdana, Sans-Serif; vertical-align: top; padding-bottom: 0px; padding-top: 0px; spacing: 0px 0px 0px 0px; height: 18px; } Hello, this is a test mail.
Can anyone help me?
thank you guys in advance,
regards
First remove the style itself, and then in second pass, do what you want to do.
import re
some = """
<style>.MailHeader { font: normal 10pt Tahoma, Verdana, Sans-Serif;
vertical-align: top; padding-bottom: 0px; padding-top: 0px; spacing: 0px 0px 0px 0px; }
.DataHeader { font-family: Tahoma; font-size: 8pt; color: #666666; text-decoration: none;
padding-left: 15px; padding-right: 15px; border: solid 1px #E0E0E0; vertical-align: text-top; }
.Data { font: normal 8pt Tahoma,Verdana; padding-left: 3px; padding-right: 15px; border: solid 1px #E0E0E0;
\ background: #F9F9F9; font-size: 8pt; color: #666666; height: 20px !important; }
.GridHeader { font: normal 8pt Tahoma,Verdana; padding-left: 6px; background: #DAEBFF; height: 20px; }
.DataRow { padding-left: 3px; padding-right: 15px; border: solid 1px #E0E0E0; font-size: 8pt; color: #003399; }
.GridRow { font: normal 8pt Tahoma, Verdana, Sans-serif; padding-left: 6px; background: transparent;
height: 20px !important; min-height: 1%; } .GridAltRow { font: normal 8pt Tahoma, Verdana, Sans-serif;
padding-left: 6px; background: #F9F9F9; height: 20px !important; min-height: 1%; }
.li { font: normal 10pt Tahoma, Verdana, Sans-Serif; vertical-align: top; padding-left: 5px; }
.TableHeader { font-family: Tahoma,calibri,verdana; font-size: 8pt; font-weight: bold; height: 22px;
color: #003399; border: solid 1px #E0E0E0; border-collapse: collapse; padding-left: 5px;
padding-right: 5px; background-color: #BBD8FF; }
.TableSubHeader { font: normal 8pt Tahoma, Verdana, Sans-Serif;
vertical-align: middle; padding-left: 3px; font-weight: bold; color: #666666; }
.Separator { background-repeat: repeat-x; background-position: center; background: #666666; }
.tableDetail { padding: 0 0 0 0;
spacing: 0 0 0 0; border-collapse: collapse; width: 750px; margin-left: 5px; border: solid 1px #E0E0E0; }
.style1 { font: normal 10pt Tahoma, Verdana, Sans-Serif; vertical-align: top; padding-bottom:
0px; padding-top: 0px; spacing: 0px 0px 0px 0px; height: 18px; }
</style>
<h1>Hello, this is a test mail.</h1>
"""
some1 = re.sub(r'<style>.*</style>', '', some, flags=re.DOTALL)
print some1
Result :
I have no name!#sla-334:~/stack_o$ python stack_o_html.py
<h1>Hello, this is a test mail.</h1>
Now, do what you want to do with this html.
I kinda fixed it myself by reparsing trough the parsed text and using this as parameters
cleaner = re.sub(r'{.*}', '', clean_email)\
.replace(".MailHeader", '') \
Ill try out your solutions